$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();
$this->logFeatureUsage( 'action=expandtemplates&generatexml' );
}
- $wgParser->startExternalParse( $title_obj, $options, OT_PREPROCESS );
+ $wgParser->startExternalParse( $title_obj, $options, Parser::OT_PREPROCESS );
$dom = $wgParser->preprocessToDom( $params['text'] );
if ( is_callable( array( $dom, 'saveXML' ) ) ) {
$xml = $dom->saveXML();
// 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, OT_PREPROCESS );
+ $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 );
} else {
if ( isset( $prop['categories'] ) ) {
$categories = $wgParser->getOutput()->getCategories();
- if ( !empty( $categories ) ) {
+ if ( $categories ) {
$categories_result = array();
foreach ( $categories as $category => $sortkey ) {
$entry = array();
$retval['categories'] = $categories_result;
}
}
+ if ( isset( $prop['properties'] ) ) {
+ $properties = $wgParser->getOutput()->getProperties();
+ if ( $properties ) {
+ $properties_result = array();
+ foreach ( $properties as $name => $value ) {
+ $entry = array();
+ $entry['name'] = $name;
+ ApiResult::setContent( $entry, $value );
+ $properties_result[] = $entry;
+ }
+ $result->setIndexedTagName( $properties_result, 'property' );
+ $retval['properties'] = $properties_result;
+ }
+ }
if ( isset( $prop['volatile'] ) && $frame->isVolatile() ) {
$retval['volatile'] = '';
}
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true,
),
+ 'revid' => array(
+ ApiBase::PARAM_TYPE => 'integer',
+ ),
'prop' => array(
ApiBase::PARAM_TYPE => array(
'wikitext',
'categories',
+ 'properties',
'volatile',
'ttl',
'parsetree',
);
}
- public function getParamDescription() {
- return array(
- 'text' => 'Wikitext to convert',
- 'title' => 'Title of page',
- 'prop' => array(
- 'Which pieces of information to get',
- ' wikitext - The expanded wikitext',
- ' categories - Any categories present in the input that are not represented in ' .
- 'the wikitext output',
- ' volatile - Whether the output is volatile and should not be reused ' .
- 'elsewhere within the page',
- ' ttl - The maximum time after which caches of the result should be ' .
- 'invalidated',
- ' parsetree - The XML parse tree of the input',
- 'Note that if no values are selected, the result will contain the wikitext,',
- 'but the output will be in a deprecated format.',
- ),
- 'includecomments' => 'Whether to include HTML comments in the output',
- 'generatexml' => 'Generate XML parse tree (replaced by prop=parsetree)',
- );
- }
-
- public function getDescription() {
- return 'Expands all templates in wikitext.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=expandtemplates&text={{Project:Sandbox}}'
+ 'action=expandtemplates&text={{Project:Sandbox}}'
+ => 'apihelp-expandtemplates-example-simple',
);
}