* (bug 23458) Add support for pageid parameter to action=parse requests
authorSam Reed <reedy@users.mediawiki.org>
Mon, 10 May 2010 14:17:21 +0000 (14:17 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Mon, 10 May 2010 14:17:21 +0000 (14:17 +0000)
Nest code in else for oldid. Add in missing assignment to $wgTitle in that code path

Remove some whitespace. Fix minor typo/wrong word

RELEASE-NOTES
includes/api/ApiParse.php

index 84e9618..03b9392 100644 (file)
@@ -169,6 +169,7 @@ in a negative namespace (which is invalid).
 * (bug 22290) prop=revisions now outputs "comment" field even when comment
   is empty, for consistency with list=recentchanges
 * (bug 19721) API action=help should have a way to just list for a specific module
+* (bug 23458) Add support for pageid parameter to action=parse requests
 
 === Languages updated in 1.17 ===
 
index 8658713..92b1512 100644 (file)
@@ -43,6 +43,7 @@ class ApiParse extends ApiBase {
                $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' );
@@ -53,19 +54,19 @@ class ApiParse extends ApiBase {
                // 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 );
@@ -81,27 +82,36 @@ class ApiParse extends ApiBase {
                                $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'] ) ) {
@@ -212,7 +222,7 @@ class ApiParse extends ApiBase {
                );
                $this->setIndexedTagNames( $result_array, $result_mapping );
                $result->addValue( null, $this->getModuleName(), $result_array );
-               
+
                if ( !is_null( $oldLang ) ) {
                        $wgLang = $oldLang; // Reset $wgLang to $oldLang
                }
@@ -284,6 +294,7 @@ class ApiParse extends ApiBase {
                        'text' => null,
                        'summary' => null,
                        'page' => null,
+                       'pageid' => null,
                        'redirects' => false,
                        'oldid' => null,
                        'prop' => array(
@@ -316,15 +327,16 @@ class ApiParse extends ApiBase {
                        '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.'
                );
@@ -340,6 +352,7 @@ class ApiParse extends ApiBase {
                        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' ),
                ) );
        }