$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();
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 );
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true,
),
+ 'revid' => array(
+ ApiBase::PARAM_TYPE => 'integer',
+ ),
'prop' => array(
ApiBase::PARAM_TYPE => array(
'wikitext',
"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).",
"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}}",