Merge "(Bug 41352) Provide tests for edit conflicts."
[lhc/web/wiklou.git] / includes / api / ApiParse.php
index 312e439..12c20fb 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'] ) {
@@ -147,18 +147,20 @@ class ApiParse extends ApiBase {
 
                                $pageObj = $this->getTitleOrPageId( $pageParams, 'fromdb' );
                                $titleObj = $pageObj->getTitle();
+                               if ( !$titleObj || !$titleObj->exists() ) {
+                                       $this->dieUsage( "The page you specified doesn't exist", 'missingtitle' );
+                               }
                                $wgTitle = $titleObj;
 
                                if ( isset( $prop['revid'] ) ) {
                                        $oldid = $pageObj->getLatest();
                                }
 
-
                                $popts = $pageObj->makeParserOptions( $this->getContext() );
                                $popts->enableLimitReport( !$params['disablepp'] );
 
                                // Potentially cached
-                               $p_result = $this->getParsedContent( $pageObj, $popts, $pageid, 
+                               $p_result = $this->getParsedContent( $pageObj, $popts, $pageid,
                                        isset( $prop['wikitext'] ) ) ;
                        }
                } else { // Not $oldid, $pageid, $page. Hence based on $text
@@ -166,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 );
 
@@ -204,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 );
                        }
                }
 
@@ -354,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
@@ -628,7 +633,7 @@ class ApiParse extends ApiBase {
                        'uselang' => 'Which language to parse the request in',
                        'section' => 'Only retrieve the content of this section number',
                        'disablepp' => 'Disable the PP Report from the parser output',
-                       'generatexml' => 'Generate XML parse tree',
+                       'generatexml' => 'Generate XML parse tree (requires prop=wikitext)',
                        'contentformat' => 'Content serialization format used for the input text',
                        'contentmodel' => 'Content model of the new content',
                );
@@ -653,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" ),
                ) );
        }