Populate revision data when expanding templates
authorArlo Breault <abreault@wikimedia.org>
Thu, 27 Nov 2014 22:43:12 +0000 (14:43 -0800)
committerArlo Breault <abreault@wikimedia.org>
Mon, 1 Dec 2014 20:32:33 +0000 (12:32 -0800)
 * 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
includes/api/i18n/en.json
includes/api/i18n/qqq.json

index eea10e9..751be75 100644 (file)
@@ -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',
index e941f1a..a15b9cf 100644 (file)
        "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 <nowiki>{{REVISIONID}}</nowiki> 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).",
index 8382edc..31d8871 100644 (file)
        "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}}",