$text = $params['text'];
$title = $params['title'];
$page = $params['page'];
+ $pageid = $params['pageid'];
$oldid = $params['oldid'];
if ( !is_null( $page ) && ( !is_null( $text ) || $title != 'API' ) ) {
$this->dieUsage( 'The page parameter cannot be used together with the text and title parameters', 'params' );
// The parser needs $wgTitle to be set, apparently the
// $title parameter in Parser::parse isn't enough *sigh*
global $wgParser, $wgUser, $wgTitle, $wgEnableParserCache, $wgLang;
-
- // Current unncessary, code to act as a safeguard against any change in current behaviour of uselang breaks
+
+ // Currently unncessary, code to act as a safeguard against any change in current behaviour of uselang breaks
$oldLang = null;
if ( isset( $params['uselang'] ) && $params['uselang'] != $wgLang->getCode() ) {
$oldLang = $wgLang; // Backup wgLang
$wgLang = Language::factory( $params['uselang'] );
}
-
+
$popts = new ParserOptions();
$popts->setTidy( true );
$popts->enableLimitReport();
$redirValues = null;
- if ( !is_null( $oldid ) || !is_null( $page ) ) {
+ if ( !is_null( $oldid ) || !is_null( $pageid ) || !is_null( $page ) ) {
if ( !is_null( $oldid ) ) {
// Don't use the parser cache
$rev = Revision::newFromID( $oldid );
$wgTitle = $titleObj;
$p_result = $wgParser->parse( $text, $titleObj, $popts );
} else {
- if ( $params['redirects'] ) {
- $req = new FauxRequest( array(
- 'action' => 'query',
- 'redirects' => '',
- 'titles' => $page
- ) );
- $main = new ApiMain( $req );
- $main->execute();
- $data = $main->getResultData();
- $redirValues = @$data['query']['redirects'];
- $to = $page;
- foreach ( (array)$redirValues as $r ) {
- $to = $r['to'];
+ if ( !is_null ( $pageid ) ) {
+ $titleObj = Title::newFromID( $pageid );
+
+ if ( !$titleObj ) {
+ $this->dieUsageMsg( array( 'nosuchpageid', $pageid ) );
}
} else {
- $to = $page;
- }
- $titleObj = Title::newFromText( $to );
- if ( !$titleObj ) {
- $this->dieUsage( "The page you specified doesn't exist", 'missingtitle' );
+ if ( $params['redirects'] ) {
+ $req = new FauxRequest( array(
+ 'action' => 'query',
+ 'redirects' => '',
+ 'titles' => $page
+ ) );
+ $main = new ApiMain( $req );
+ $main->execute();
+ $data = $main->getResultData();
+ $redirValues = @$data['query']['redirects'];
+ $to = $page;
+ foreach ( (array)$redirValues as $r ) {
+ $to = $r['to'];
+ }
+ } else {
+ $to = $page;
+ }
+ $titleObj = Title::newFromText( $to );
+ if ( !$titleObj ) {
+ $this->dieUsage( "The page you specified doesn't exist", 'missingtitle' );
+ }
}
+ $wgTitle = $titleObj;
$articleObj = new Article( $titleObj );
if ( isset( $prop['revid'] ) ) {
);
$this->setIndexedTagNames( $result_array, $result_mapping );
$result->addValue( null, $this->getModuleName(), $result_array );
-
+
if ( !is_null( $oldLang ) ) {
$wgLang = $oldLang; // Reset $wgLang to $oldLang
}
'text' => null,
'summary' => null,
'page' => null,
+ 'pageid' => null,
'redirects' => false,
'oldid' => null,
'prop' => array(
'redirects' => 'If the page parameter is set to a redirect, resolve it.',
'title' => 'Title of page the text belongs to.',
'page' => 'Parse the content of this page. Cannot be used together with text and title.',
- 'oldid' => 'Parse the content of this revision. Overrides page.',
+ 'pageid' => 'Parse the content of this page. Overrides page.',
+ 'oldid' => 'Parse the content of this revision. Overrides page and pageid.',
'prop' => array( 'Which pieces of information to get.',
'NOTE: Section tree is only generated if there are more than 4 sections, or if the __TOC__ keyword is present.'
),
'pst' => array( 'Do a pre-save transform on the input before parsing it.',
- 'Ignored if page or oldid is used.'
+ 'Ignored if page, pageid or oldid is used.'
),
'onlypst' => array( 'Do a pre-save transform (PST) on the input, but don\'t parse it.',
- 'Returns the same wikitext, after a PST has been applied. Ignored if page or oldid is used.'
+ 'Returns the same wikitext, after a PST has been applied. Ignored if page, pageid or oldid is used.'
),
'uselang' => 'Which language to parse the request in.'
);
array( 'code' => 'missingrev', 'info' => 'There is no revision ID oldid' ),
array( 'code' => 'permissiondenied', 'info' => 'You don\'t have permission to view deleted revisions' ),
array( 'code' => 'missingtitle', 'info' => 'The page you specified doesn\'t exist' ),
+ array( 'nosuchpageid' ),
) );
}