merged master
[lhc/web/wiklou.git] / includes / api / ApiParse.php
index ca5fe7e..7c61291 100644 (file)
@@ -79,10 +79,6 @@ class ApiParse extends ApiBase {
                        $this->getContext()->setLanguage( Language::factory( $params['uselang'] ) );
                }
 
-               $popts = ParserOptions::newFromContext( $this->getContext() );
-               $popts->setTidy( true );
-               $popts->enableLimitReport( !$params['disablepp'] );
-
                $redirValues = null;
 
                // Return result
@@ -100,14 +96,17 @@ class ApiParse extends ApiBase {
                                }
 
                                $titleObj = $rev->getTitle();
-
                                $wgTitle = $titleObj;
+                               $pageObj = WikiPage::factory( $titleObj );
+                               $popts = $pageObj->makeParserOptions( $this->getContext() );
+                               $popts->enableLimitReport( !$params['disablepp'] );
 
                                // If for some reason the "oldid" is actually the current revision, it may be cached
-                               if ( $titleObj->getLatestRevID() === intval( $oldid ) )  {
+                               if ( $rev->isCurrent() )  {
                                        // May get from/save to parser cache
                                        $pageObj = WikiPage::factory( $titleObj );
-                                       $p_result = $this->getParsedContent( $pageObj, $popts, $pageid, isset( $prop['wikitext'] ) ) ;
+                                       $p_result = $this->getParsedContent( $pageObj, $popts, $pageid, 
+                                               isset( $prop['wikitext'] ) ) ;
                                } else { // This is an old revision, so get the text differently
                                        $this->content = $rev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
 
@@ -140,34 +139,28 @@ class ApiParse extends ApiBase {
                                        foreach ( (array)$redirValues as $r ) {
                                                $to = $r['to'];
                                        }
-                                       $titleObj = Title::newFromText( $to );
-                               } else {
-                                       if ( !is_null ( $pageid ) ) {
-                                               $reqParams['pageids'] = $pageid;
-                                               $titleObj = Title::newFromID( $pageid );
-                                       } else { // $page
-                                               $to = $page;
-                                               $titleObj = Title::newFromText( $to );
-                                       }
-                               }
-                               if ( !is_null ( $pageid ) ) {
-                                       if ( !$titleObj ) {
-                                               // Still throw nosuchpageid error if pageid was provided
-                                               $this->dieUsageMsg( array( 'nosuchpageid', $pageid ) );
-                                       }
-                               } elseif ( !$titleObj || !$titleObj->exists() ) {
-                                       $this->dieUsage( "The page you specified doesn't exist", 'missingtitle' );
+                                       $pageParams = array( 'title' => $to );
+                               } elseif ( !is_null( $pageid ) ) {
+                                       $pageParams = array( 'pageid' => $pageid );
+                               } else { // $page
+                                       $pageParams = array( 'title' => $page );
                                }
+
+                               $pageObj = $this->getTitleOrPageId( $pageParams, 'fromdb' );
+                               $titleObj = $pageObj->getTitle();
                                $wgTitle = $titleObj;
 
                                if ( isset( $prop['revid'] ) ) {
-                                       $oldid = $titleObj->getLatestRevID();
+                                       $oldid = $pageObj->getLatest();
                                }
 
-                               $pageObj = WikiPage::factory( $titleObj );
+
+                               $popts = $pageObj->makeParserOptions( $this->getContext() );
+                               $popts->enableLimitReport( !$params['disablepp'] );
 
                                // Potentially cached
-                               $p_result = $this->getParsedContent( $pageObj, $popts, $pageid, isset( $prop['wikitext'] ) ) ;
+                               $p_result = $this->getParsedContent( $pageObj, $popts, $pageid, 
+                                       isset( $prop['wikitext'] ) ) ;
                        }
                } else { // Not $oldid, $pageid, $page. Hence based on $text
                        $titleObj = Title::newFromText( $title );
@@ -175,6 +168,10 @@ class ApiParse extends ApiBase {
                                $this->dieUsageMsg( array( 'invalidtitle', $title ) );
                        }
                        $wgTitle = $titleObj;
+                       $pageObj = WikiPage::factory( $titleObj );
+
+                       $popts = $pageObj->makeParserOptions( $this->getContext() );
+                       $popts->enableLimitReport( !$params['disablepp'] );
 
                        if ( is_null( $text ) ) {
                                $this->dieUsage( 'The text parameter should be passed with the title parameter. Should you be using the "page" parameter instead?', 'params' );