X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fapi%2FApiExpandTemplates.php;h=fe49b259373e12b7f63518469a94b81a1678213e;hp=e15d7da1e588d6d8bb5feaf563c7ec6e9b1f6863;hb=7babd362babcbf7f20adb8e12edb4f4bc1d4249f;hpb=237d3271fd313ebe09858a5c442a91216a7b61cf diff --git a/includes/api/ApiExpandTemplates.php b/includes/api/ApiExpandTemplates.php index e15d7da1e5..fe49b25937 100644 --- a/includes/api/ApiExpandTemplates.php +++ b/includes/api/ApiExpandTemplates.php @@ -1,9 +1,5 @@ @gmail.com" * * This program is free software; you can redistribute it and/or modify @@ -41,6 +37,15 @@ class ApiExpandTemplates extends ApiBase { $params = $this->extractRequestParams(); $this->requireMaxOneParameter( $params, 'prop', 'generatexml' ); + $title = $params['title']; + if ( $title === null ) { + $titleProvided = false; + // A title is needed for parsing, so arbitrarily choose one + $title = 'API'; + } else { + $titleProvided = true; + } + if ( $params['prop'] === null ) { $this->addDeprecation( 'apiwarn-deprecation-expandtemplates-prop', 'action=expandtemplates&!prop' @@ -50,6 +55,11 @@ class ApiExpandTemplates extends ApiBase { $prop = array_flip( $params['prop'] ); } + $titleObj = Title::newFromText( $title ); + if ( !$titleObj || $titleObj->isExternal() ) { + $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['title'] ) ] ); + } + // Get title and revision ID for parser $revid = $params['revid']; if ( $revid !== null ) { @@ -57,11 +67,17 @@ class ApiExpandTemplates extends ApiBase { if ( !$rev ) { $this->dieWithError( [ 'apierror-nosuchrevid', $revid ] ); } - $title_obj = $rev->getTitle(); - } else { - $title_obj = Title::newFromText( $params['title'] ); - if ( !$title_obj || $title_obj->isExternal() ) { - $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['title'] ) ] ); + $pTitleObj = $titleObj; + $titleObj = $rev->getTitle(); + if ( $titleProvided ) { + if ( !$titleObj->equals( $pTitleObj ) ) { + $this->addWarning( [ 'apierror-revwrongpage', $rev->getId(), + wfEscapeWikiText( $pTitleObj->getPrefixedText() ) ] ); + } + } else { + // Consider the title derived from the revid as having + // been provided. + $titleProvided = true; } } @@ -78,12 +94,12 @@ class ApiExpandTemplates extends ApiBase { $reset = null; $suppressCache = false; Hooks::run( 'ApiMakeParserOptions', - [ $options, $title_obj, $params, $this, &$reset, &$suppressCache ] ); + [ $options, $titleObj, $params, $this, &$reset, &$suppressCache ] ); $retval = []; if ( isset( $prop['parsetree'] ) || $params['generatexml'] ) { - $wgParser->startExternalParse( $title_obj, $options, Parser::OT_PREPROCESS ); + $wgParser->startExternalParse( $titleObj, $options, Parser::OT_PREPROCESS ); $dom = $wgParser->preprocessToDom( $params['text'] ); if ( is_callable( [ $dom, 'saveXML' ] ) ) { $xml = $dom->saveXML(); @@ -103,9 +119,9 @@ 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( $title_obj, $options, Parser::OT_PREPROCESS ); + $wgParser->startExternalParse( $titleObj, $options, Parser::OT_PREPROCESS ); $frame = $wgParser->getPreprocessor()->newFrame(); - $wikitext = $wgParser->preprocess( $params['text'], $title_obj, $options, $revid, $frame ); + $wikitext = $wgParser->preprocess( $params['text'], $titleObj, $options, $revid, $frame ); if ( $params['prop'] === null ) { // the old way ApiResult::setContentValue( $retval, 'wikitext', $wikitext ); @@ -169,9 +185,7 @@ class ApiExpandTemplates extends ApiBase { public function getAllowedParams() { return [ - 'title' => [ - ApiBase::PARAM_DFLT => 'API', - ], + 'title' => null, 'text' => [ ApiBase::PARAM_TYPE => 'text', ApiBase::PARAM_REQUIRED => true,