Made getUndoText() not use unreliable getContent() function (weird wgRequest dependency)
[lhc/web/wiklou.git] / includes / Article.php
index 3e6b019..0999bdb 100644 (file)
@@ -95,13 +95,16 @@ class Article {
                # Query the redirect table
                $dbr = wfGetDB( DB_SLAVE );
                $row = $dbr->selectRow( 'redirect',
-                       array( 'rd_namespace', 'rd_title' ),
+                       array( 'rd_namespace', 'rd_title', 'rd_fragment', 'rd_interwiki' ),
                        array( 'rd_from' => $this->getID() ),
                        __METHOD__
                );
 
-               if ( $row ) {
-                       return $this->mRedirectTarget = Title::makeTitle( $row->rd_namespace, $row->rd_title );
+               // rd_fragment and rd_interwiki were added later, populate them if empty
+               if ( $row && !is_null( $row->rd_fragment ) && !is_null( $row->rd_interwiki ) ) {
+                       return $this->mRedirectTarget = Title::makeTitle(
+                               $row->rd_namespace, $row->rd_title,
+                               $row->rd_fragment, $row->rd_interwiki );
                }
 
                # This page doesn't have an entry in the redirect table
@@ -112,36 +115,44 @@ class Article {
         * Insert an entry for this page into the redirect table.
         *
         * Don't call this function directly unless you know what you're doing.
-        * @return Title object
+        * @return Title object or null if not a redirect
         */
        public function insertRedirect() {
-               $retval = Title::newFromRedirect( $this->getContent() );
-
+               // recurse through to only get the final target
+               $retval = Title::newFromRedirectRecurse( $this->getContent() );
                if ( !$retval ) {
                        return null;
                }
-
+               $this->insertRedirectEntry( $retval );
+               return $retval;
+       }
+       
+       /**
+        * Insert or update the redirect table entry for this page to indicate
+        * it redirects to $rt .
+        * @param $rt Title redirect target
+        */
+       public function insertRedirectEntry( $rt ) {
                $dbw = wfGetDB( DB_MASTER );
                $dbw->replace( 'redirect', array( 'rd_from' ),
                        array(
                                'rd_from' => $this->getID(),
-                               'rd_namespace' => $retval->getNamespace(),
-                               'rd_title' => $retval->getDBkey()
+                               'rd_namespace' => $rt->getNamespace(),
+                               'rd_title' => $rt->getDBkey(),
+                               'rd_fragment' => $rt->getFragment(),
+                               'rd_interwiki' => $rt->getInterwiki(),
                        ),
                        __METHOD__
                );
-
-               return $retval;
        }
 
        /**
-        * Get the Title object this page redirects to
+        * Get the Title object or URL this page redirects to
         *
         * @return mixed false, Title of in-wiki target, or string with URL
         */
        public function followRedirect() {
-               $text = $this->getContent();
-               return $this->followRedirectText( $text );
+               return $this->getRedirectURL( $this->getRedirectTarget() );
        }
 
        /**
@@ -149,11 +160,21 @@ class Article {
         *
         * @param $text string article content containing redirect info
         * @return mixed false, Title of in-wiki target, or string with URL
+        * @deprecated
         */
        public function followRedirectText( $text ) {
                // recurse through to only get the final target
-               $rt = Title::newFromRedirectRecurse( $text );
-
+               return $this->getRedirectURL( Title::newFromRedirectRecurse( $text ) );
+       }
+       
+       /**
+        * Get the Title object or URL to use for a redirect. We use Title
+        * objects for same-wiki, non-special redirects and URLs for everything
+        * else.
+        * @param $rt Title Redirect target
+        * @return mixed false, Title object of local target, or string with URL
+        */
+       public function getRedirectURL( $rt ) {
                if ( $rt ) {
                        if ( $rt->getInterwiki() != '' ) {
                                if ( $rt->isLocal() ) {
@@ -229,7 +250,7 @@ class Article {
         * @return Return the text of this revision
         */
        public function getContent() {
-               global $wgUser, $wgContLang, $wgOut, $wgMessageCache;
+               global $wgUser, $wgContLang, $wgMessageCache;
 
                wfProfileIn( __METHOD__ );
 
@@ -239,7 +260,6 @@ class Article {
                        if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
                                # If this is a system message, get the default text.
                                list( $message, $lang ) = $wgMessageCache->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) );
-                               $wgMessageCache->loadAllMessages( $lang );
                                $text = wfMsgGetKey( $message, false, $lang, false );
 
                                if ( wfEmptyMsg( $message, $text ) )
@@ -301,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.
@@ -805,9 +829,8 @@ class Article {
         * page of the given title.
         */
        public function view() {
-               global $wgUser, $wgOut, $wgRequest, $wgContLang;
-               global $wgEnableParserCache, $wgStylePath, $wgParser;
-               global $wgUseTrackbacks, $wgUseFileCache;
+               global $wgUser, $wgOut, $wgRequest, $wgParser;
+               global $wgUseFileCache, $wgUseETag;
 
                wfProfileIn( __METHOD__ );
 
@@ -815,16 +838,17 @@ class Article {
                $oldid = $this->getOldID();
                $parserCache = ParserCache::singleton();
 
-               $parserOptions = clone $this->getParserOptions();
+               $parserOptions = $this->getParserOptions();
                # Render printable version, use printable version cache
                if ( $wgOut->isPrintable() ) {
                        $parserOptions->setIsPrintable( true );
+                       $parserOptions->setEditSection( false );
+               } else if ( $wgUseETag && !$this->mTitle->quickUserCan( 'edit' ) ) {
+                       $parserOptions->setEditSection( false );
                }
 
                # Try client and file cache
                if ( $oldid === 0 && $this->checkTouched() ) {
-                       global $wgUseETag;
-
                        if ( $wgUseETag ) {
                                $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
                        }
@@ -869,10 +893,14 @@ class Article {
                        return;
                }
 
+               if ( !$wgUseETag && !$this->mTitle->quickUserCan( 'edit' ) ) {
+                       $parserOptions->setEditSection( false );
+               }
+
                # Should the parser cache be used?
                $useParserCache = $this->useParserCache( $oldid );
                wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
-               if ( $wgUser->getOption( 'stubthreshold' ) ) {
+               if ( $wgUser->getStubThreshold() ) {
                        wfIncrStats( 'pcache_miss_stub' );
                }
 
@@ -938,13 +966,11 @@ class Article {
                                                if ( $oldid === $this->getLatest() && $this->useParserCache( false ) ) {
                                                        $this->mParserOutput = $parserCache->get( $this, $parserOptions );
                                                        if ( $this->mParserOutput ) {
-                                                               wfDebug( __METHOD__ . ": showing parser cache for current rev permalink\n" );
+                                                               wfDebug( __METHOD__ . ": showing parser cache for current rev permalink\n" );                                                           
                                                                $wgOut->addParserOutput( $this->mParserOutput );
                                                                $wgOut->setRevisionId( $this->mLatest );
-                                                               $this->showViewFooter();
-                                                               $this->viewUpdates();
-                                                               wfProfileOut( __METHOD__ );
-                                                               return;
+                                                               $outputDone = true;
+                                                               break;                                                          
                                                        }
                                                }
                                        }
@@ -972,14 +998,13 @@ class Article {
                                case 4:
                                        # Run the parse, protected by a pool counter
                                        wfDebug( __METHOD__ . ": doing uncached parse\n" );
-                                       $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() ) {
+                                       $this->checkTouched();
+                                       $key = $parserCache->getKey( $this, $parserOptions );
+                                       $poolArticleView = new PoolWorkArticleView( $this, $key, $useParserCache, $parserOptions );
+                                       
+                                       if ( !$poolArticleView->execute() ) {
                                                # Connection or timeout error
-                                               $this->showPoolError( $status );
                                                wfProfileOut( __METHOD__ );
                                                return;
                                        } else {
@@ -1027,7 +1052,7 @@ class Article {
         * Article::view() only, other callers should use the DifferenceEngine class.
         */
        public function showDiffPage() {
-               global $wgOut, $wgRequest, $wgUser;
+               global $wgRequest, $wgUser;
 
                $diff = $wgRequest->getVal( 'diff' );
                $rcid = $wgRequest->getVal( 'rcid' );
@@ -1056,7 +1081,7 @@ class Article {
         * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
         * page views.
         */
-       public function showCssOrJsPage() {
+       protected function showCssOrJsPage() {
                global $wgOut;
 
                $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache'>\n$1\n</div>", 'clearyourcache' );
@@ -1072,19 +1097,6 @@ class Article {
                }
        }
 
-       /**
-        * Get the robot policy to be used for the current action=view request.
-        * @return String the policy that should be set
-        * @deprecated use getRobotPolicy() instead, which returns an associative
-        *    array
-        */
-       public function getRobotPolicyForView() {
-               wfDeprecated( __METHOD__ );
-               $policy = $this->getRobotPolicy( 'view' );
-
-               return $policy['index'] . ',' . $policy['follow'];
-       }
-
        /**
         * Get the robot policy to be used for the current view
         * @param $action String the action= GET parameter
@@ -1264,7 +1276,7 @@ class Article {
         * Show the footer section of an ordinary page view
         */
        public function showViewFooter() {
-               global $wgOut, $wgUseTrackbacks, $wgRequest;
+               global $wgOut, $wgUseTrackbacks;
 
                # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
                if ( $this->mTitle->getNamespace() == NS_USER_TALK && IP::isValid( $this->mTitle->getText() ) ) {
@@ -1296,6 +1308,7 @@ class Article {
                }
 
                $sk = $wgUser->getSkin();
+               $token = $wgUser->editToken();
 
                $wgOut->addHTML(
                        "<div class='patrollink'>" .
@@ -1307,7 +1320,8 @@ class Article {
                                                array(),
                                                array(
                                                        'action' => 'markpatrolled',
-                                                       'rcid' => $rcid
+                                                       'rcid' => $rcid,
+                                                       'token' => $token,
                                                ),
                                                array( 'known', 'noclasses' )
                                        )
@@ -1442,7 +1456,7 @@ class Article {
                global $wgUser, $wgEnableParserCache;
 
                return $wgEnableParserCache
-                       && intval( $wgUser->getOption( 'stubthreshold' ) ) == 0
+                       && $wgUser->getStubThreshold() == 0
                        && $this->exists()
                        && empty( $oldid )
                        && !$this->mTitle->isCssOrJsPage()
@@ -1457,15 +1471,20 @@ class Article {
 
                $oldid = $this->getOldID();
                $useParserCache = $this->useParserCache( $oldid );
-               $parserOptions = clone $this->getParserOptions();
+               $parserOptions = $this->getParserOptions();
 
                # Render printable version, use printable version cache
                $parserOptions->setIsPrintable( $wgOut->isPrintable() );
 
                # Don't show section-edit links on old revisions... this way lies madness.
-               $parserOptions->setEditSection( $this->isCurrent() );
+               if ( !$this->isCurrent() || $wgOut->isPrintable() ) {
+                       $parserOptions->setEditSection( false );
+               }
+               
                $useParserCache = $this->useParserCache( $oldid );
                $this->outputWikiText( $this->getContent(), $useParserCache, $parserOptions );
+               
+               return true;
        }
 
        /**
@@ -1477,11 +1496,15 @@ class Article {
         * @return boolean
         */
        public function tryDirtyCache() {
-
                global $wgOut;
                $parserCache = ParserCache::singleton();
-               $options = $this->getParserOptions();
-               $options->setIsPrintable( $wgOut->isPrintable() );
+               $options = clone $this->getParserOptions();
+               
+               if ( $wgOut->isPrintable() ) {
+                       $options->setIsPrintable( true );
+                       $options->setEditSection( false );
+               }
+               
                $output = $parserCache->getDirty( $this, $options );
 
                if ( $output ) {
@@ -1501,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
         *
@@ -1768,7 +1774,7 @@ class Article {
                wfProfileIn( __METHOD__ );
 
                $text = $revision->getText();
-               $rt = Title::newFromRedirect( $text );
+               $rt = Title::newFromRedirectRecurse( $text );
 
                $conditions = array( 'page_id' => $this->getId() );
 
@@ -1821,13 +1827,7 @@ class Article {
                if ( $isRedirect || is_null( $lastRevIsRedirect ) || $lastRevIsRedirect !== $isRedirect ) {
                        wfProfileIn( __METHOD__ );
                        if ( $isRedirect ) {
-                               // This title is a redirect, Add/Update row in the redirect table
-                               $set = array( /* SET */
-                                       'rd_namespace' => $redirectTitle->getNamespace(),
-                                       'rd_title'     => $redirectTitle->getDBkey(),
-                                       'rd_from'      => $this->getId(),
-                               );
-                               $dbw->replace( 'redirect', array( 'rd_from' ), $set, __METHOD__ );
+                               $this->insertRedirectEntry( $redirectTitle );
                        } else {
                                // This is not a redirect, remove row from redirect table
                                $where = array( 'rd_from' => $this->getId() );
@@ -1930,33 +1930,71 @@ class Article {
        }
 
        /**
-        * @deprecated use Article::doEdit()
+        * This function is not deprecated until somebody fixes the core not to use
+        * it. Nevertheless, use Article::doEdit() instead.
         */
        function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC = false, $comment = false, $bot = false ) {
-               wfDeprecated( __METHOD__ );
                $flags = EDIT_NEW | EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
                        ( $isminor ? EDIT_MINOR : 0 ) |
                        ( $suppressRC ? EDIT_SUPPRESS_RC : 0 ) |
                        ( $bot ? EDIT_FORCE_BOT : 0 );
 
-               $this->doEdit( $text, $summary, $flags, false, null, $watchthis, $comment, '', true );
+               # If this is a comment, add the summary as headline
+               if ( $comment && $summary != "" ) {
+                       $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $summary ) . "\n\n" . $text;
+               }
+               $this->doEdit( $text, $summary, $flags );
+
+               $dbw = wfGetDB( DB_MASTER );
+               if ( $watchthis ) {
+                       if ( !$this->mTitle->userIsWatching() ) {
+                               $dbw->begin();
+                               $this->doWatch();
+                               $dbw->commit();
+                       }
+               } else {
+                       if ( $this->mTitle->userIsWatching() ) {
+                               $dbw->begin();
+                               $this->doUnwatch();
+                               $dbw->commit();
+                       }
+               }
+               $this->doRedirect( $this->isRedirect( $text ) );
        }
 
        /**
         * @deprecated use Article::doEdit()
         */
        function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
-               wfDeprecated( __METHOD__ );
                $flags = EDIT_UPDATE | EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
                        ( $minor ? EDIT_MINOR : 0 ) |
                        ( $forceBot ? EDIT_FORCE_BOT : 0 );
 
-               $status = $this->doEdit( $text, $summary, $flags, false, null, $watchthis, false, $sectionanchor, true );
+               $status = $this->doEdit( $text, $summary, $flags );
 
                if ( !$status->isOK() ) {
                        return false;
                }
 
+               $dbw = wfGetDB( DB_MASTER );
+               if ( $watchthis ) {
+                       if ( !$this->mTitle->userIsWatching() ) {
+                               $dbw->begin();
+                               $this->doWatch();
+                               $dbw->commit();
+                       }
+               } else {
+                       if ( $this->mTitle->userIsWatching() ) {
+                               $dbw->begin();
+                               $this->doUnwatch();
+                               $dbw->commit();
+                       }
+               }
+
+               $extraQuery = ''; // Give extensions a chance to modify URL query on update
+               wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this, &$sectionanchor, &$extraQuery ) );
+
+               $this->doRedirect( $this->isRedirect( $text ), $sectionanchor, $extraQuery );
                return true;
        }
 
@@ -2011,11 +2049,6 @@ class Article {
         *
         * @param $baseRevId the revision ID this edit was based off, if any
         * @param $user Optional user object, $wgUser will be used if not passed
-        * @param $watchthis Watch the page if true, unwatch the page if false, do nothing if null
-        * @param $comment Boolean: whether the edit is a new section
-        * @param $sectionanchor The section anchor for the page; used for redirecting the user back to the page
-        *              after the edit is successfully committed
-        * @param $redirect If true, redirect the user back to the page after the edit is successfully committed
         *
         * @return Status object. Possible errors:
         *     edit-hook-aborted:       The ArticleSave hook aborted the edit but didn't set the fatal flag of $status
@@ -2032,8 +2065,7 @@ class Article {
         *
         *  Compatibility note: this function previously returned a boolean value indicating success/failure
         */
-       public function doEdit( $text, $summary, $flags = 0, $baseRevId = false, $user = null , $watchthis = null,
-                       $comment = false, $sectionanchor = '', $redirect = false) {
+       public function doEdit( $text, $summary, $flags = 0, $baseRevId = false, $user = null ) {
                global $wgUser, $wgDBtransactions, $wgUseAutomaticEditSummaries;
 
                # Low-level sanity check
@@ -2051,13 +2083,8 @@ class Article {
 
                $flags = $this->checkFlags( $flags );
 
-               # If this is a comment, add the summary as headline
-               if ( $comment && $summary != "" ) {
-                       $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $summary ) . "\n\n" . $text;
-               }
-
                if ( !wfRunHooks( 'ArticleSave', array( &$this, &$user, &$text, &$summary,
-                       $flags & EDIT_MINOR, &$watchthis, null, &$flags, &$status) ) )
+                       $flags & EDIT_MINOR, null, null, &$flags, &$status ) ) )
                {
                        wfDebug( __METHOD__ . ": ArticleSave hook aborted save!\n" );
                        wfProfileOut( __METHOD__ );
@@ -2262,7 +2289,7 @@ class Article {
                        Article::onArticleCreate( $this->mTitle );
 
                        wfRunHooks( 'ArticleInsertComplete', array( &$this, &$user, $text, $summary,
-                               $flags & EDIT_MINOR, &$watchthis, null, &$flags, $revision ) );
+                               $flags & EDIT_MINOR, null, null, &$flags, $revision ) );
                }
 
                # Do updates right now unless deferral was requested
@@ -2274,39 +2301,9 @@ class Article {
                $status->value['revision'] = $revision;
 
                wfRunHooks( 'ArticleSaveComplete', array( &$this, &$user, $text, $summary,
-                       $flags & EDIT_MINOR, &$watchthis, null, &$flags, $revision, &$status, $baseRevId,
-                       &$redirect) );
-
-               # Watch or unwatch the page
-               if ( $watchthis === true ) {
-                       if ( !$this->mTitle->userIsWatching() ) {
-                               $dbw->begin();
-                               $this->doWatch();
-                               $dbw->commit();
-                       }
-               } elseif ( $watchthis === false ) {
-                       if ( $this->mTitle->userIsWatching() ) {
-                               $dbw->begin();
-                               $this->doUnwatch();
-                               $dbw->commit();
-                       }
-               }
-
-               # Give extensions a chance to modify URL query on update
-               $extraQuery = '';
-
-               wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this, &$sectionanchor, &$extraQuery ) );
-
-               if ( $redirect ) {
-                       if ( $sectionanchor || $extraQuery ) {
-                               $this->doRedirect( $this->isRedirect( $text ), $sectionanchor, $extraQuery );
-                       } else {
-                               $this->doRedirect( $this->isRedirect( $text ) );
-                       }
-               }
+                       $flags & EDIT_MINOR, null, null, &$flags, $revision, &$status, $baseRevId ) );
 
                wfProfileOut( __METHOD__ );
-
                return $status;
        }
 
@@ -2344,12 +2341,18 @@ class Article {
         * Mark this particular edit/page as patrolled
         */
        public function markpatrolled() {
-               global $wgOut, $wgRequest, $wgUseRCPatrol, $wgUseNPPatrol, $wgUser;
+               global $wgOut, $wgUser, $wgRequest;
 
                $wgOut->setRobotPolicy( 'noindex,nofollow' );
 
                # If we haven't been given an rc_id value, we can't do anything
                $rcid = (int) $wgRequest->getVal( 'rcid' );
+
+               if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
+                       $wgOut->showErrorPage( 'sessionfailure-title', 'sessionfailure' );
+                       return;
+               }
+
                $rc = RecentChange::newFromId( $rcid );
 
                if ( is_null( $rc ) ) {
@@ -2361,7 +2364,6 @@ class Article {
                $returnto = $rc->getAttribute( 'rc_type' ) == RC_NEW ? 'Newpages' : 'Recentchanges';
                $return = SpecialPage::getTitleFor( $returnto );
 
-               $dbw = wfGetDB( DB_MASTER );
                $errors = $rc->doMarkPatrolled();
 
                if ( in_array( array( 'rcpatroldisabled' ), $errors ) ) {
@@ -2768,8 +2770,6 @@ class Article {
                        $onlyAuthor = false;
                }
 
-               $dbw->freeResult( $res );
-
                // Generate the summary with a '$1' placeholder
                if ( $blank ) {
                        // The current revision is blank and the one before is also
@@ -2913,7 +2913,6 @@ class Article {
 
                        if ( $bigHistory ) {
                                global $wgDeleteRevisionsLimit;
-
                                $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
                                        array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
                        }
@@ -3166,13 +3165,11 @@ class Article {
         * @return boolean true if successful
         */
        public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true ) {
-               global $wgUseSquid, $wgDeferredUpdateList;
-               global $wgUseTrackbacks;
+               global $wgDeferredUpdateList, $wgUseTrackbacks;
 
                wfDebug( __METHOD__ . "\n" );
 
                $dbw = wfGetDB( DB_MASTER );
-               $ns = $this->mTitle->getNamespace();
                $t = $this->mTitle->getDBkey();
                $id = $id ? $id : $this->mTitle->getArticleID( GAID_FOR_UPDATE );
 
@@ -3399,7 +3396,7 @@ class Article {
                if ( $s === false ) {
                        # No one else ever edited this page
                        return array( array( 'cantrollback' ) );
-               } else if ( $s->rev_deleted & REVISION::DELETED_TEXT || $s->rev_deleted & REVISION::DELETED_USER ) {
+               } else if ( $s->rev_deleted & Revision::DELETED_TEXT || $s->rev_deleted & Revision::DELETED_USER ) {
                        # Only admins can see this text
                        return array( array( 'notvisiblerev' ) );
                }
@@ -3478,7 +3475,7 @@ class Article {
         * User interface for rollback operations
         */
        public function rollback() {
-               global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
+               global $wgUser, $wgOut, $wgRequest;
 
                $details = null;
 
@@ -3596,8 +3593,8 @@ class Article {
                $edit->revid = $revid;
                $edit->newText = $text;
                $edit->pst = $this->preSaveTransform( $text );
-               $options = $this->getParserOptions();
-               $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $options, true, true, $revid );
+               $edit->popts = clone $this->getParserOptions();
+               $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $edit->popts, true, true, $revid );
                $edit->oldText = $this->getContent();
 
                $this->mPreparedEdit = $edit;
@@ -3636,9 +3633,8 @@ class Article {
 
                # Save it to the parser cache
                if ( $wgEnableParserCache ) {
-                       $popts = $this->getParserOptions();
                        $parserCache = ParserCache::singleton();
-                       $parserCache->save( $editInfo->output, $this, $popts );
+                       $parserCache->save( $editInfo->output, $this, $editInfo->popts );
                }
 
                # Update the links tables
@@ -3991,6 +3987,7 @@ class Article {
                $revision->insertOn( $dbw );
                $this->updateRevisionOn( $dbw, $revision );
 
+               global $wgUser;
                wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, false, $wgUser ) );
 
                wfProfileOut( __METHOD__ );
@@ -4292,8 +4289,6 @@ class Article {
                        }
                }
 
-               $dbr->freeResult( $res );
-
                return $result;
        }
 
@@ -4324,8 +4319,6 @@ class Article {
                        }
                }
 
-               $dbr->freeResult( $res );
-
                return $result;
        }
 
@@ -4337,6 +4330,8 @@ class Article {
        * @return string An appropriate autosummary, or an empty string.
        */
        public static function getAutosummary( $oldtext, $newtext, $flags ) {
+               global $wgContLang;
+               
                # Decide what kind of autosummary is needed.
 
                # Redirect autosummaries
@@ -4350,7 +4345,6 @@ class Article {
                # New page autosummaries
                if ( $flags & EDIT_NEW && strlen( $newtext ) ) {
                        # If they're making a new article, give its text, truncated, in the summary.
-                       global $wgContLang;
 
                        $truncatedtext = $wgContLang->truncate(
                                str_replace( "\n", ' ', $newtext ),
@@ -4364,7 +4358,6 @@ class Article {
                        return wfMsgForContent( 'autosumm-blank' );
                } elseif ( strlen( $oldtext ) > 10 * strlen( $newtext ) && strlen( $newtext ) < 500 ) {
                        # Removing more than 90% of the article
-                       global $wgContLang;
 
                        $truncatedtext = $wgContLang->truncate(
                                $newtext,
@@ -4405,10 +4398,10 @@ class Article {
         * @return string containing parsed output
         */
        public function getOutputFromWikitext( $text, $cache = true, $parserOptions = false ) {
-               global $wgParser, $wgOut, $wgEnableParserCache, $wgUseFileCache;
+               global $wgParser, $wgEnableParserCache, $wgUseFileCache;
 
                if ( !$parserOptions ) {
-                       $parserOptions = $this->getParserOptions();
+                       $parserOptions = clone $this->getParserOptions();
                }
 
                $time = - wfTime();
@@ -4452,7 +4445,9 @@ class Article {
                        $this->mParserOptions->enableLimitReport();
                }
 
-               return $this->mParserOptions;
+               // Clone to allow modifications of the return value without affecting 
+               // the cache
+               return clone $this->mParserOptions;
        }
 
        /**
@@ -4485,8 +4480,6 @@ class Article {
                        __METHOD__
                );
 
-               global $wgContLang;
-
                foreach ( $res as $row ) {
                        $tlTemplates["{$row->tl_namespace}:{$row->tl_title}"] = true;
                }
@@ -4578,20 +4571,22 @@ class Article {
         * and so on. Doesn't consider most of the stuff that Article::view is forced to
         * consider, so it's not appropriate to use there.
         *
+        * @since 1.16 (r52326) for LiquidThreads
+        * 
         * @param $oldid mixed integer Revision ID or null
         */
        public function getParserOutput( $oldid = null ) {
-               global $wgEnableParserCache, $wgUser, $wgOut;
+               global $wgEnableParserCache, $wgUser;
 
                // Should the parser cache be used?
                $useParserCache = $wgEnableParserCache &&
-                       intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
+                       $wgUser->getStubThreshold() == 0 &&
                        $this->exists() &&
                        $oldid === null;
 
                wfDebug( __METHOD__ . ': using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
 
-               if ( $wgUser->getOption( 'stubthreshold' ) ) {
+               if ( $wgUser->getStubThreshold() ) {
                        wfIncrStats( 'pcache_miss_stub' );
                }
 
@@ -4623,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;
+       }
+}