Merge "Fix use of GenderCache in ApiPageSet::processTitlesArray"
[lhc/web/wiklou.git] / includes / api / ApiExpandTemplates.php
index 22f5235..4b74a3d 100644 (file)
@@ -76,17 +76,12 @@ class ApiExpandTemplates extends ApiBase {
                                        $this->addWarning( [ 'apierror-revwrongpage', $rev->getId(),
                                                wfEscapeWikiText( $pTitleObj->getPrefixedText() ) ] );
                                }
-                       } else {
-                               // Consider the title derived from the revid as having
-                               // been provided.
-                               $titleProvided = true;
                        }
                }
 
                $result = $this->getResult();
 
                // Parse text
-               global $wgParser;
                $options = ParserOptions::newFromContext( $this->getContext() );
 
                if ( $params['includecomments'] ) {
@@ -100,12 +95,16 @@ class ApiExpandTemplates extends ApiBase {
 
                $retval = [];
 
+               $parser = MediaWikiServices::getInstance()->getParser();
                if ( isset( $prop['parsetree'] ) || $params['generatexml'] ) {
-                       $wgParser->startExternalParse( $titleObj, $options, Parser::OT_PREPROCESS );
-                       $dom = $wgParser->preprocessToDom( $params['text'] );
+                       $parser->startExternalParse( $titleObj, $options, Parser::OT_PREPROCESS );
+                       $dom = $parser->preprocessToDom( $params['text'] );
+                       // @phan-suppress-next-line PhanUndeclaredMethodInCallable
                        if ( is_callable( [ $dom, 'saveXML' ] ) ) {
+                               // @phan-suppress-next-line PhanUndeclaredMethod
                                $xml = $dom->saveXML();
                        } else {
+                               // @phan-suppress-next-line PhanUndeclaredMethod
                                $xml = $dom->__toString();
                        }
                        if ( isset( $prop['parsetree'] ) ) {
@@ -121,14 +120,14 @@ class ApiExpandTemplates extends ApiBase {
                // if they didn't want any output except (probably) the parse tree,
                // then don't bother actually fully expanding it
                if ( $prop || $params['prop'] === null ) {
-                       $wgParser->startExternalParse( $titleObj, $options, Parser::OT_PREPROCESS );
-                       $frame = $wgParser->getPreprocessor()->newFrame();
-                       $wikitext = $wgParser->preprocess( $params['text'], $titleObj, $options, $revid, $frame );
+                       $parser->startExternalParse( $titleObj, $options, Parser::OT_PREPROCESS );
+                       $frame = $parser->getPreprocessor()->newFrame();
+                       $wikitext = $parser->preprocess( $params['text'], $titleObj, $options, $revid, $frame );
                        if ( $params['prop'] === null ) {
                                // the old way
                                ApiResult::setContentValue( $retval, 'wikitext', $wikitext );
                        } else {
-                               $p_output = $wgParser->getOutput();
+                               $p_output = $parser->getOutput();
                                if ( isset( $prop['categories'] ) ) {
                                        $categories = $p_output->getCategories();
                                        if ( $categories ) {