Made getUndoText() not use unreliable getContent() function (weird wgRequest dependency)
[lhc/web/wiklou.git] / includes / Article.php
index dc9d5d5..0999bdb 100644 (file)
@@ -321,9 +321,13 @@ class Article {
         * @return mixed string on success, false on failure
         */
        public function getUndoText( Revision $undo, Revision $undoafter = null ) {
+               $currentRev = Revision::newFromTitle( $this->mTitle );
+               if ( !$currentRev ) {
+                       return false; // no page
+               }
                $undo_text = $undo->getText();
                $undoafter_text = $undoafter->getText();
-               $cur_text = $this->getContent();
+               $cur_text = $currentRev->getText();
 
                if ( $cur_text == $undo_text ) {
                        # No use doing a merge if it's just a straight revert.
@@ -997,13 +1001,10 @@ class Article {
 
                                        $this->checkTouched();
                                        $key = $parserCache->getKey( $this, $parserOptions );
-                                       $poolCounter = PoolCounter::factory( 'Article::view', $key );
-                                       $dirtyCallback = $useParserCache ? array( $this, 'tryDirtyCache' ) : false;
-                                       $status = $poolCounter->executeProtected( array( $this, 'doViewParse' ), $dirtyCallback );
-
-                                       if ( !$status->isOK() ) {
+                                       $poolArticleView = new PoolWorkArticleView( $this, $key, $useParserCache, $parserOptions );
+                                       
+                                       if ( !$poolArticleView->execute() ) {
                                                # Connection or timeout error
-                                               $this->showPoolError( $status );
                                                wfProfileOut( __METHOD__ );
                                                return;
                                        } else {
@@ -1482,6 +1483,8 @@ class Article {
                
                $useParserCache = $this->useParserCache( $oldid );
                $this->outputWikiText( $this->getContent(), $useParserCache, $parserOptions );
+               
+               return true;
        }
 
        /**
@@ -1521,23 +1524,6 @@ class Article {
                }
        }
 
-       /**
-        * Show an error page for an error from the pool counter.
-        * @param $status Status
-        */
-       public function showPoolError( $status ) {
-               global $wgOut;
-
-               $wgOut->clearHTML(); // for release() errors
-               $wgOut->enableClientCache( false );
-               $wgOut->setRobotPolicy( 'noindex,nofollow' );
-               $wgOut->addWikiText(
-                       '<div class="errorbox">' .
-                       $status->getWikiText( false, 'view-pool-error' ) .
-                       '</div>'
-               );
-       }
-
        /**
         * View redirect
         *
@@ -4632,3 +4618,56 @@ class Article {
        }
 
 }
+
+class PoolWorkArticleView extends PoolCounterWork {
+       private $mArticle;
+       
+       function __construct( $article, $key, $useParserCache, $parserOptions ) {
+               parent::__construct( __CLASS__, $key );
+               $this->mArticle = $article;
+               $this->cacheable = $useParserCache;
+               $this->parserOptions = $parserOptions;
+       }
+       
+       function doWork() {
+               return $this->mArticle->doViewParse();
+       }
+       
+       function getCachedWork() {
+               global $wgOut;
+               
+               $parserCache = ParserCache::singleton();
+               $this->mArticle->mParserOutput = $parserCache->get( $this->mArticle, $this->parserOptions );
+
+               if ( $this->mArticle->mParserOutput !== false ) {
+                       wfDebug( __METHOD__ . ": showing contents parsed by someone else\n" );
+                       $wgOut->addParserOutput( $this->mArticle->mParserOutput );
+                       # Ensure that UI elements requiring revision ID have
+                       # the correct version information.
+                       $wgOut->setRevisionId( $this->mArticle->getLatest() );
+                       return true;
+               }
+               return false;
+       }
+       
+       function fallback() {
+               return $this->mArticle->tryDirtyCache();
+       }
+       
+       function error( $status ) {
+               global $wgOut;
+
+               $wgOut->clearHTML(); // for release() errors
+               $wgOut->enableClientCache( false );
+               $wgOut->setRobotPolicy( 'noindex,nofollow' );
+               
+               if ( $status instanceof Status ) {
+                       $errortext = $status->getWikiText( false, 'view-pool-error' );
+               } else {
+                       $errortext = wfMsgNoTrans( 'view-pool-error', '' );
+               }
+               $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
+               
+               return false;
+       }
+}