From: Brad Jorsch Date: Thu, 7 Jul 2016 13:40:57 +0000 (-0400) Subject: API: Generate head items in the context of the given title X-Git-Tag: 1.31.0-rc.0~6427^2 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=2ecba36c4f46c248cfdcd0acb3b6b17efdb53db2;p=lhc%2Fweb%2Fwiklou.git API: Generate head items in the context of the given title $context->getOutput() returns an OutputPage tied to the main RequestContext at the root of the chain, not to the modified context we're actually using. Bug: T139565 Change-Id: Ie086d7f2ad3f7b5f50e3a2f83b1680e760b85e5e --- diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index f96acf3121..3e66cadbee 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -346,22 +346,27 @@ class ApiParse extends ApiBase { } if ( isset( $prop['headitems'] ) || isset( $prop['headhtml'] ) ) { - $context = $this->getContext(); + $context = new DerivativeContext( $this->getContext() ); $context->setTitle( $titleObj ); - $context->getOutput()->addParserOutputMetadata( $p_result ); + $context->setWikiPage( $pageObj ); + + // We need an OutputPage tied to $context, not to the + // RequestContext at the root of the stack. + $output = new OutputPage( $context ); + $output->addParserOutputMetadata( $p_result ); if ( isset( $prop['headitems'] ) ) { $headItems = $this->formatHeadItems( $p_result->getHeadItems() ); - $css = $this->formatCss( $context->getOutput()->buildCssLinksArray() ); + $css = $this->formatCss( $output->buildCssLinksArray() ); - $scripts = [ $context->getOutput()->getHeadScripts() ]; + $scripts = [ $output->getHeadScripts() ]; $result_array['headitems'] = array_merge( $headItems, $css, $scripts ); } if ( isset( $prop['headhtml'] ) ) { - $result_array['headhtml'] = $context->getOutput()->headElement( $context->getSkin() ); + $result_array['headhtml'] = $output->headElement( $context->getSkin() ); $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'headhtml'; } }