From f168638da2b3eae04255ae10c88902ffb3268de9 Mon Sep 17 00:00:00 2001 From: Arlo Breault Date: Thu, 27 Nov 2014 14:43:12 -0800 Subject: [PATCH] Populate revision data when expanding templates * Add a $revid parameter to the expandtemplates api action so that, when passed, the correct revision information is set for {{REVISIONID}} and similar variables. Bug: T73306 Change-Id: I93ef39fdabbaa5f394efce9b5c5e080666ff6119 --- includes/api/ApiExpandTemplates.php | 22 +++++++++++++++++----- includes/api/i18n/en.json | 1 + includes/api/i18n/qqq.json | 1 + 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/includes/api/ApiExpandTemplates.php b/includes/api/ApiExpandTemplates.php index eea10e9b83..751be75fbb 100644 --- a/includes/api/ApiExpandTemplates.php +++ b/includes/api/ApiExpandTemplates.php @@ -52,10 +52,19 @@ class ApiExpandTemplates extends ApiBase { $prop = array_flip( $params['prop'] ); } - // Create title for parser - $title_obj = Title::newFromText( $params['title'] ); - if ( !$title_obj || $title_obj->isExternal() ) { - $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); + // Get title and revision ID for parser + $revid = $params['revid']; + if ( $revid !== null ) { + $rev = Revision::newFromId( $revid ); + if ( !$rev ) { + $this->dieUsage( "There is no revision ID $revid", 'missingrev' ); + } + $title_obj = $rev->getTitle(); + } else { + $title_obj = Title::newFromText( $params['title'] ); + if ( !$title_obj || $title_obj->isExternal() ) { + $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); + } } $result = $this->getResult(); @@ -98,7 +107,7 @@ class ApiExpandTemplates extends ApiBase { if ( $prop || $params['prop'] === null ) { $wgParser->startExternalParse( $title_obj, $options, Parser::OT_PREPROCESS ); $frame = $wgParser->getPreprocessor()->newFrame(); - $wikitext = $wgParser->preprocess( $params['text'], $title_obj, $options, null, $frame ); + $wikitext = $wgParser->preprocess( $params['text'], $title_obj, $options, $revid, $frame ); if ( $params['prop'] === null ) { // the old way ApiResult::setContent( $retval, $wikitext ); @@ -141,6 +150,9 @@ class ApiExpandTemplates extends ApiBase { ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => true, ), + 'revid' => array( + ApiBase::PARAM_TYPE => 'integer', + ), 'prop' => array( ApiBase::PARAM_TYPE => array( 'wikitext', diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index e941f1a433..a15b9cf1f6 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -112,6 +112,7 @@ "apihelp-expandtemplates-description": "Expands all templates in wikitext.", "apihelp-expandtemplates-param-title": "Title of page.", "apihelp-expandtemplates-param-text": "Wikitext to convert.", + "apihelp-expandtemplates-param-revid": "Revision ID, for {{REVISIONID}} and similar variables.", "apihelp-expandtemplates-param-prop": "Which pieces of information to get:\n;wikitext:The expanded wikitext.\n;categories:Any categories present in the input that are not represented in the wikitext output.\n;volatile:Whether the output is volatile and should not be reused elsewhere within the page.\n;ttl:The maximum time after which caches of the result should be invalidated.\n;parsetree:The XML parse tree of the input.\nNote that if no values are selected, the result will contain the wikitext, but the output will be in a deprecated format.", "apihelp-expandtemplates-param-includecomments": "Whether to include HTML comments in the output.", "apihelp-expandtemplates-param-generatexml": "Generate XML parse tree (replaced by $1prop=parsetree).", diff --git a/includes/api/i18n/qqq.json b/includes/api/i18n/qqq.json index 8382edce2b..31d88711fa 100644 --- a/includes/api/i18n/qqq.json +++ b/includes/api/i18n/qqq.json @@ -104,6 +104,7 @@ "apihelp-expandtemplates-description": "{{doc-apihelp-description|expandtemplates}}", "apihelp-expandtemplates-param-title": "{{doc-apihelp-param|expandtemplates|title}}", "apihelp-expandtemplates-param-text": "{{doc-apihelp-param|expandtemplates|text}}", + "apihelp-expandtemplates-param-revid": "{{doc-apihelp-param|expandtemplates|revid}}", "apihelp-expandtemplates-param-prop": "{{doc-apihelp-param|expandtemplates|prop}}", "apihelp-expandtemplates-param-includecomments": "{{doc-apihelp-param|expandtemplates|includecomments}}", "apihelp-expandtemplates-param-generatexml": "{{doc-apihelp-param|expandtemplates|generatexml}}", -- 2.20.1