X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2Fapi%2FApiExpandTemplates.php;h=4b74a3d4d9106734e2c083f8c51622fa48948ed1;hb=e27d974043e8c03c49148db0456c4933f720d7ba;hp=22f52356f205503e23c00febac0a792289318adb;hpb=ae58991566bd7f666982cdfcac9c84a79173d6ab;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiExpandTemplates.php b/includes/api/ApiExpandTemplates.php index 22f52356f2..4b74a3d4d9 100644 --- a/includes/api/ApiExpandTemplates.php +++ b/includes/api/ApiExpandTemplates.php @@ -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 ) {