Add option to allow SpecialPageExecutor return the full HTML content
The property OutputPage::mBodytext does not always hold the full HTML to be output only the body text which will be greatly altered when Skin::outputPage is called. I noticed this when a test that tries to check existence of a 'blocklink' in Special:Contributions subtitle consistently fails. This happens because the links are only added when Skin::outputPage is called but by calling OutputPage::getHTML() here and collecting the buffer contents, the link is nowhere to be found since the skin method will never be called if we didn't call OutputPage::output() (which - will call the skin method) Also OutputPage::output() already can return the fully generated html via its optional parameter which we can just use here. This patch adds optional parameter to specify that the caller wants the entirety of the generated HTML. The default remains false, which is to return OutputPage::getHTML(). Bug: T268322 Change-Id: I9b580e4ed93d989028d394803dba1ea7a9117592
This commit is contained in:
parent
f59afd50a9
commit
da8ace4020
2 changed files with 19 additions and 5 deletions
|
|
@ -14,6 +14,10 @@ class SpecialPageExecutor {
|
|||
* @param Language|string|null $language The language which should be used in the context;
|
||||
* if not specified, the pseudo-code 'qqx' is used
|
||||
* @param User|null $user The user which should be used in the context of this special page
|
||||
* @param bool $fullHtml if true, the entirety of the generated HTML will be returned, this
|
||||
* includes the opening <!DOCTYPE> declaration and closing </html> tag. If false, only value
|
||||
* of OutputPage::getHTML() will be returned except if the page is redirect or where OutputPage
|
||||
* is completely disabled.
|
||||
*
|
||||
* @throws Exception
|
||||
* @return array [ string, WebResponse ] A two-elements array containing the HTML output
|
||||
|
|
@ -24,7 +28,8 @@ class SpecialPageExecutor {
|
|||
$subPage = '',
|
||||
WebRequest $request = null,
|
||||
$language = null,
|
||||
User $user = null
|
||||
User $user = null,
|
||||
$fullHtml = false
|
||||
) {
|
||||
$context = $this->newContext( $request, $language, $user );
|
||||
|
||||
|
|
@ -34,7 +39,7 @@ class SpecialPageExecutor {
|
|||
$page->setContext( $context );
|
||||
$output->setTitle( $page->getPageTitle() );
|
||||
|
||||
$html = $this->getHTMLFromSpecialPage( $page, $subPage );
|
||||
$html = $this->getHTMLFromSpecialPage( $page, $subPage, $fullHtml );
|
||||
$response = $context->getRequest()->response();
|
||||
|
||||
if ( $response instanceof FauxResponse ) {
|
||||
|
|
@ -96,11 +101,12 @@ class SpecialPageExecutor {
|
|||
/**
|
||||
* @param SpecialPage $page
|
||||
* @param string $subPage
|
||||
* @param bool $fullHtml
|
||||
*
|
||||
* @throws Exception
|
||||
* @return string HTML
|
||||
*/
|
||||
private function getHTMLFromSpecialPage( SpecialPage $page, $subPage ) {
|
||||
private function getHTMLFromSpecialPage( SpecialPage $page, $subPage, $fullHtml ) {
|
||||
ob_start();
|
||||
|
||||
try {
|
||||
|
|
@ -113,6 +119,8 @@ class SpecialPageExecutor {
|
|||
$html = ob_get_contents();
|
||||
} elseif ( $output->isDisabled() ) {
|
||||
$html = ob_get_contents();
|
||||
} elseif ( $fullHtml ) {
|
||||
$html = $output->output( true );
|
||||
} else {
|
||||
$html = $output->getHTML();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,10 @@ abstract class SpecialPageTestBase extends MediaWikiIntegrationTestCase {
|
|||
* @param WebRequest|null $request Web request that may contain URL parameters, etc
|
||||
* @param Language|string|null $language The language which should be used in the context
|
||||
* @param User|null $user The user which should be used in the context of this special page
|
||||
* @param bool $fullHtml if true, the entirety of the generated HTML will be returned, this
|
||||
* includes the opening <!DOCTYPE> declaration and closing </html> tag. If false, only value
|
||||
* of OutputPage::getHTML() will be returned except if the page is redirect or where OutputPage
|
||||
* is completely disabled.
|
||||
*
|
||||
* @throws Exception
|
||||
* @return array [ string, WebResponse ] A two-elements array containing the HTML output
|
||||
|
|
@ -60,14 +64,16 @@ abstract class SpecialPageTestBase extends MediaWikiIntegrationTestCase {
|
|||
$subPage = '',
|
||||
WebRequest $request = null,
|
||||
$language = null,
|
||||
User $user = null
|
||||
User $user = null,
|
||||
$fullHtml = false
|
||||
) {
|
||||
return ( new SpecialPageExecutor() )->executeSpecialPage(
|
||||
$this->newSpecialPage(),
|
||||
$subPage,
|
||||
$request,
|
||||
$language,
|
||||
$user
|
||||
$user,
|
||||
$fullHtml
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue