Krinkle has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/350115 )

Change subject: [WIP] ApiParse#useOutputPage
......................................................................

[WIP] ApiParse#useOutputPage

Sketch related to Idc41934eb89.

Change-Id: Iaa85ac49f6e0cbdf7f1bb0f50a8f7730d119f0a2
---
M includes/OutputPage.php
M includes/api/ApiParse.php
2 files changed, 25 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/15/350115/1

diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index 52e4e24..6b43521 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -1858,6 +1858,7 @@
                // TODO: Once OutputPage::setTOCEnabled() is removed, move this 
up.
                $parserOutput->setTOCEnabled( $this->mEnableTOC );
                if ( $parserOutput->getTOCEnabled() && 
$parserOutput->getTOCHTML() ) {
+                       $parserOutput->addModules( 'mediawiki.toc' ); // Compat 
with ApiParse
                        $this->addModules( 'mediawiki.toc' );
                }
        }
diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php
index d648968..59d17b3 100644
--- a/includes/api/ApiParse.php
+++ b/includes/api/ApiParse.php
@@ -278,6 +278,28 @@
                $result_array['title'] = $titleObj->getPrefixedText();
                $result_array['pageid'] = $pageid ?: $pageObj->getId();
 
+               // This ensures these get run:
+               // - ParserOutputHooks
+               // - Hook: LanguageLinks
+               // - Hook: OutputPageParserOutput
+               $useOutputPage = isset( $prop['headhtml'] ) ||
+                       isset( $prop['modules'] ) ||
+                       isset( $prop['jsconfigvars'] ) ||
+                       isset( $prop['encodedjsconfigvars'] ) ||
+                       ( isset( $prop['langlinks'] ) &&  
$params['effectivelanglinks'] );
+
+               if ( $useOutputPage ) {
+                       $context = new DerivativeContext( $this->getContext() );
+                       $context->setTitle( $titleObj );
+                       $context->setWikiPage( $pageObj );
+
+                       // We need an OutputPage tied to $context, not to the
+                       // RequestContext at the root of the stack.
+                       $outputPage = new OutputPage( $context );
+                       $outputPage->addParserOutputMetadata( $p_result );
+                       $outputSkin = $context->getSkin();
+               }
+
                if ( !is_null( $oldid ) ) {
                        $result_array['revid'] = intval( $oldid );
                }
@@ -303,20 +325,7 @@
                }
 
                if ( isset( $prop['langlinks'] ) ) {
-                       $langlinks = $p_result->getLanguageLinks();
-
-                       if ( $params['effectivelanglinks'] ) {
-                               // Link flags are ignored for now, but may in 
the future be
-                               // included in the result.
-                               $linkFlags = [];
-                               Hooks::run( 'LanguageLinks', [ $titleObj, 
&$langlinks, &$linkFlags ] );
-                       }
-               } else {
-                       $langlinks = false;
-               }
-
-               if ( isset( $prop['langlinks'] ) ) {
-                       $result_array['langlinks'] = $this->formatLangLinks( 
$langlinks );
+                       $result_array['langlinks'] = $this->formatLangLinks( 
$p_result->getLanguageLinks() );
                }
                if ( isset( $prop['categories'] ) ) {
                        $result_array['categories'] = 
$this->formatCategoryLinks( $p_result->getCategories() );
@@ -355,16 +364,7 @@
                }
 
                if ( isset( $prop['headhtml'] ) ) {
-                       $context = new DerivativeContext( $this->getContext() );
-                       $context->setTitle( $titleObj );
-                       $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 );
-
-                       $result_array['headhtml'] = $output->headElement( 
$context->getSkin() );
+                       $result_array['headhtml'] = $outputPage->headElement( 
$outputSkin );
                        $result_array[ApiResult::META_BC_SUBELEMENTS][] = 
'headhtml';
                }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/350115
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaa85ac49f6e0cbdf7f1bb0f50a8f7730d119f0a2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to