Merge "(bug 41042) Regression: API action=parse with nonexistent page"
[lhc/web/wiklou.git] / includes / api / ApiParse.php
index 9d95648..2c8349f 100644 (file)
@@ -114,7 +114,7 @@ class ApiParse extends ApiBase {
                                        }
 
                                        // Should we save old revision parses to the parser cache?
-                                       $p_result = $this->content->getParserOutput( $titleObj, $popts );
+                                       $p_result = $this->content->getParserOutput( $titleObj, $rev->getId(), $popts );
                                }
                        } else { // Not $oldid, but $pageid or $page
                                if ( $params['redirects'] ) {
@@ -156,7 +156,6 @@ class ApiParse extends ApiBase {
                                        $oldid = $pageObj->getLatest();
                                }
 
-
                                $popts = $pageObj->makeParserOptions( $this->getContext() );
                                $popts->enableLimitReport( !$params['disablepp'] );
 
@@ -169,6 +168,9 @@ class ApiParse extends ApiBase {
                        if ( !$titleObj ) {
                                $this->dieUsageMsg( array( 'invalidtitle', $title ) );
                        }
+                       if ( !$titleObj->canExist() ) {
+                               $this->dieUsage( "Namespace doesn't allow actual pages", 'pagecannotexist' );
+                       }
                        $wgTitle = $titleObj;
                        $pageObj = WikiPage::factory( $titleObj );
 
@@ -207,9 +209,9 @@ class ApiParse extends ApiBase {
 
                        // Not cached (save or load)
                        if ( $params['pst'] ) {
-                               $p_result = $this->pstContent->getParserOutput( $titleObj, $popts );
+                               $p_result = $this->pstContent->getParserOutput( $titleObj, null, $popts );
                        } else {
-                               $p_result = $this->content->getParserOutput( $titleObj, $popts );
+                               $p_result = $this->content->getParserOutput( $titleObj, null, $popts );
                        }
                }
 
@@ -357,13 +359,13 @@ class ApiParse extends ApiBase {
        private function getParsedContent( WikiPage $page, $popts, $pageId = null, $getWikitext = false ) {
                $this->content = $page->getContent( Revision::RAW ); //XXX: really raw?
 
-               if ( $this->section !== false ) {
+               if ( $this->section !== false && $this->content !== null ) {
                        $this->content = $this->getSectionContent(
                                $this->content,
                                !is_null( $pageId ) ? 'page id ' . $pageId : $page->getTitle()->getText() );
 
                        // Not cached (save or load)
-                       return $this->content->getParserOutput( $page->getTitle(), $popts );
+                       return $this->content->getParserOutput( $page->getTitle(), null, $popts );
                } else {
                        // Try the parser cache first
                        // getParserOutput will save to Parser cache if able
@@ -656,6 +658,7 @@ class ApiParse extends ApiBase {
                        array( 'invalidtitle', 'title' ),
                        array( 'code' => 'parseerror', 'info' => 'Failed to parse the given text.' ),
                        array( 'code' => 'notwikitext', 'info' => 'The requested operation is only supported on wikitext content.' ),
+                       array( 'code' => 'pagecannotexist', 'info' => "Namespace doesn't allow actual pages" ),
                ) );
        }