Apply changes made live on Wikimedia cluster related to preprocessor caching to subve...
[lhc/web/wiklou.git] / includes / Article.php
index 15ca8c5..5c33c75 100644 (file)
@@ -135,7 +135,7 @@ class Article {
         * @return mixed false, Title of in-wiki target, or string with URL
         */
        public function followRedirectText( $text ) {
-               $rt = Title::newFromRedirect( $text );
+               $rt = Title::newFromRedirectRecurse( $text ); // recurse through to only get the final target
                # process if title object is valid and not special:userlogout
                if( $rt ) {
                        if( $rt->getInterwiki() != '' ) {
@@ -218,7 +218,7 @@ class Article {
                                if( wfEmptyMsg( $message, $text ) )
                                        $text = '';
                        } else {
-                               $text = wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' );
+                               $text = wfMsgExt( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon', 'parsemag' );
                        }
                        wfProfileOut( __METHOD__ );
                        return $text;
@@ -228,6 +228,21 @@ class Article {
                        return $this->mContent;
                }
        }
+       
+       /**
+        * Get the text of the current revision. No side-effects...
+        *
+        * @return Return the text of the current revision
+       */
+       public function getRawText() {
+               // Check process cache for current revision
+               if( $this->mContentLoaded && $this->mOldId == 0 ) {
+                       return $this->mContent;
+               }
+               $rev = Revision::newFromTitle( $this->mTitle );
+               $text = $rev ? $rev->getRawText() : false;
+               return $text;
+       }
 
        /**
         * This function returns the text of a section, specified by a number ($section).
@@ -245,6 +260,28 @@ class Article {
                global $wgParser;
                return $wgParser->getSection( $text, $section );
        }
+       
+       /**
+        * Get the text that needs to be saved in order to undo all revisions
+        * between $undo and $undoafter. Revisions must belong to the same page,
+        * must exist and must not be deleted
+        * @param $undo Revision 
+        * @param $undoafter Revision Must be an earlier revision than $undo
+        * @return mixed string on success, false on failure
+        */
+       public function getUndoText( Revision $undo, Revision $undoafter = null ) {
+               $undo_text = $undo->getText();
+               $undoafter_text = $undoafter->getText();
+               $cur_text = $this->getContent();
+               if ( $cur_text == $undo_text ) {
+                       # No use doing a merge if it's just a straight revert.
+                       return $undoafter_text;
+               }
+               $undone_text = '';
+               if ( !wfMerge( $undo_text, $undoafter_text, $cur_text, $undone_text ) )
+                       return false;
+               return $undone_text;
+       }
 
        /**
         * @return int The oldid of the article that is to be shown, 0 for the
@@ -508,6 +545,18 @@ class Article {
        public function exists() {
                return $this->getId() > 0;
        }
+       
+       /**
+        * Check if this page is something we're going to be showing
+        * some sort of sensible content for. If we return false, page
+        * views (plain action=view) will return an HTTP 404 response,
+        * so spiders and robots can know they're following a bad link.
+        *
+        * @return bool
+        */
+       public function hasViewableContent() {
+               return $this->exists() || $this->mTitle->isAlwaysKnown();
+       }
 
        /**
         * @return int The view count for the page
@@ -557,7 +606,7 @@ class Article {
                        }
                        // Apparently loadPageData was never called
                        $this->loadContent();
-                       $titleObj = Title::newFromRedirect( $this->fetchContent() );
+                       $titleObj = Title::newFromRedirectRecurse( $this->fetchContent() );
                } else {
                        $titleObj = Title::newFromRedirect( $text );
                }
@@ -687,7 +736,7 @@ class Article {
                                $parserCache = ParserCache::singleton();
                                $wgOut->setETag( $parserCache->getETag($this,$wgUser) );
                        }
-                       if( $wgOut->checkLastModified( $this->getTouched() ) ){
+                       if( $wgOut->checkLastModified( $this->getTouched() ) ) {
                                wfProfileOut( __METHOD__ );
                                return;
                        } else if( $this->tryFileCache() ) {
@@ -714,6 +763,7 @@ class Article {
                $rdfrom = $wgRequest->getVal( 'rdfrom' );
                $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
                $purge = $wgRequest->getVal( 'action' ) == 'purge';
+               $return404 = false;
 
                $wgOut->setArticleFlag( true );
 
@@ -730,15 +780,17 @@ class Article {
                }
                $wgOut->setRobotPolicy( $policy );
 
+               # Allow admins to see deleted content if explicitly requested
+               $delId = $diff ? $diff : $oldid;
+               $unhide = $wgRequest->getInt('unhide') == 1 && $wgUser->matchEditToken( $wgRequest->getVal('token'), $delId );
                # If we got diff and oldid in the query, we want to see a
                # diff page instead of the article.
 
                if( !is_null( $diff ) ) {
                        $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
 
-                       $diff = $wgRequest->getVal( 'diff' );
                        $htmldiff = $wgRequest->getVal( 'htmldiff' , false);
-                       $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid, $purge, $htmldiff);
+                       $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid, $purge, $htmldiff, $unhide );
                        // DifferenceEngine directly fetched the revision:
                        $this->mRevIdFetched = $de->mNewid;
                        $de->showDiffPage( $diffOnly );
@@ -752,6 +804,16 @@ class Article {
                        wfProfileOut( __METHOD__ );
                        return;
                }
+               
+               if( $ns == NS_USER || $ns == NS_USER_TALK ) {
+                       # User/User_talk subpages are not modified. (bug 11443)
+                       if( !$this->mTitle->isSubpage() ) {
+                               $block = new Block();
+                               if( $block->load( $this->mTitle->getBaseText() ) ) {
+                                       $wgOut->setRobotpolicy( 'noindex,nofollow' );
+                               }
+                       }
+               }
 
                # Should the parser cache be used?
                $pcache = $this->useParserCache( $oldid );
@@ -766,7 +828,7 @@ class Article {
                        // We'll need a backlink to the source page for navigation.
                        if( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
                                $redir = $sk->makeKnownLinkObj( $this->mRedirectedFrom, '', 'redirect=no' );
-                               $s = wfMsg( 'redirectedfrom', $redir );
+                               $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
                                $wgOut->setSubtitle( $s );
 
                                // Set the fragment if one was specified in the redirect
@@ -782,7 +844,7 @@ class Article {
                        global $wgRedirectSources;
                        if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
                                $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
-                               $s = wfMsg( 'redirectedfrom', $redir );
+                               $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
                                $wgOut->setSubtitle( $s );
                                $wasRedirected = true;
                        }
@@ -803,29 +865,48 @@ class Article {
                                $this->showDeletionLog();
                        }
                        $text = $this->getContent();
-                       if( $text === false ) {
+                       // For now, check also for ID until getContent actually returns
+                       // false for pages that do not exists
+                       if( $text === false || $this->getID() === 0 ) {
                                # Failed to load, replace text with error message
                                $t = $this->mTitle->getPrefixedText();
                                if( $oldid ) {
-                                       $d = wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid );
-                                       $text = wfMsg( 'missing-article', $t, $d );
-                               } else {
-                                       $text = wfMsg( 'noarticletext' );
+                                       $d = wfMsgExt( 'missingarticle-rev', 'escape', $oldid );
+                                       $text = wfMsgExt( 'missing-article', 'parsemag', $t, $d );
+                               // Always use page content for pages in the MediaWiki namespace
+                               // since it contains the default message
+                               } elseif ( $this->mTitle->getNamespace() != NS_MEDIAWIKI ) {
+                                       $text = wfMsgExt( 'noarticletext', 'parsemag' );
                                }
                        }
+                       
                        # Non-existent pages
                        if( $this->getID() === 0 ) {
                                $wgOut->setRobotPolicy( 'noindex,nofollow' );
                                $text = "<div class='noarticletext'>\n$text\n</div>";
-                       } 
+                               if( !$this->hasViewableContent() ) {
+                                       // If there's no backing content, send a 404 Not Found
+                                       // for better machine handling of broken links.
+                                       $return404 = true;
+                               }
+                       }
+
+                       if( $return404 ) {
+                               $wgRequest->response()->header( "HTTP/1.x 404 Not Found" );
+                       }
 
                        # Another whitelist check in case oldid is altering the title
                        if( !$this->mTitle->userCanRead() ) {
                                $wgOut->loginToUse();
                                $wgOut->output();
+                               $wgOut->disable();
                                wfProfileOut( __METHOD__ );
-                               exit;
+                               return;
                        }
+                       
+                       # For ?curid=x urls, disallow indexing
+                       if( $wgRequest->getInt('curid') )
+                               $wgOut->setRobotPolicy( 'noindex,follow' );
 
                        # We're looking at an old revision
                        if( !empty( $oldid ) ) {
@@ -834,8 +915,9 @@ class Article {
                                        // FIXME: This would be a nice place to load the 'no such page' text.
                                } else {
                                        $this->setOldSubtitle( isset($this->mOldId) ? $this->mOldId : $oldid );
+                                       # Allow admins to see deleted content if explicitly requested
                                        if( $this->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
-                                               if( !$this->mRevision->userCan( Revision::DELETED_TEXT ) ) {
+                                               if( !$unhide || !$this->mRevision->userCan(Revision::DELETED_TEXT) ) {
                                                        $wgOut->addWikiMsg( 'rev-deleted-text-permission' );
                                                        $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
                                                        wfProfileOut( __METHOD__ );
@@ -862,7 +944,7 @@ class Article {
                                        $wgOut->addHTML( htmlspecialchars( $this->mContent ) );
                                        $wgOut->addHTML( "\n</pre>\n" );
                                }
-                       } else if( $rt = Title::newFromRedirect( $text ) ) {
+                       } else if( $rt = Title::newFromRedirectArray( $text ) ) { # get an array of redirect targets
                                # Don't append the subtitle if this was an old revision
                                $wgOut->addHTML( $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() ) );
                                $parseout = $wgParser->parse($text, $this->mTitle, ParserOptions::newFromUser($wgUser));
@@ -914,7 +996,7 @@ class Article {
 
                # If we have been passed an &rcid= parameter, we want to give the user a
                # chance to mark this new article as patrolled.
-               if( !is_null( $rcid ) && $rcid != 0 && $wgUser->isAllowed( 'patrol' ) && $this->mTitle->exists() ) {
+               if( !empty($rcid) && $this->mTitle->exists() && $this->mTitle->quickUserCan('patrol') ) {
                        $wgOut->addHTML(
                                "<div class='patrollink'>" .
                                        wfMsgHtml( 'markaspatrolledlink',
@@ -975,24 +1057,41 @@ class Article {
 
        /**
         * View redirect
-        * @param $target Title object of destination to redirect
+        * @param $target Title object or Array of destination(s) to redirect
         * @param $appendSubtitle Boolean [optional]
         * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
         */
        public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
                global $wgParser, $wgOut, $wgContLang, $wgStylePath, $wgUser;
                # Display redirect
+               if( !is_array( $target ) ) {
+                       $target = array( $target );
+               }
                $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
-               $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
-
+               $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
+               $imageUrl2 = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
+               $alt2 = $wgContLang->isRTL() ? '&larr;' : '&rarr;'; // should -> and <- be used instead of entities?
+               
                if( $appendSubtitle ) {
                        $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
                }
                $sk = $wgUser->getSkin();
+               // the loop prepends the arrow image before the link, so the first case needs to be outside
+               $title = array_shift( $target );
                if( $forceKnown ) {
-                       $link = $sk->makeKnownLinkObj( $target, htmlspecialchars( $target->getFullText() ) );
+                       $link = $sk->makeKnownLinkObj( $title, htmlspecialchars( $title->getFullText() ) );
                } else {
-                       $link = $sk->makeLinkObj( $target, htmlspecialchars( $target->getFullText() ) );
+                       $link = $sk->makeLinkObj( $title, htmlspecialchars( $title->getFullText() ) );
+               }
+               // automatically append redirect=no to each link, since most of them are redirect pages themselves
+               foreach( $target as $rt ) {
+                       if( $forceKnown ) {
+                               $link .= '<img src="'.$imageUrl2.'" alt="'.$alt2.' " />'
+                                       . $sk->makeKnownLinkObj( $rt, htmlspecialchars( $rt->getFullText() ) );
+                       } else {
+                               $link .= '<img src="'.$imageUrl2.'" alt="'.$alt2.' " />'
+                                       . $sk->makeLinkObj( $rt, htmlspecialchars( $rt->getFullText() ) );
+                       }
                }
                return '<img src="'.$imageUrl.'" alt="#REDIRECT " />' .
                        '<span class="redirectText">'.$link.'</span>';
@@ -1100,7 +1199,7 @@ class Article {
                        if( $this->getID() == 0 ) {
                                $text = false;
                        } else {
-                               $text = $this->getContent();
+                               $text = $this->getRawText();
                        }
                        $wgMessageCache->replace( $this->mTitle->getDBkey(), $text );
                }
@@ -1265,11 +1364,12 @@ class Article {
        }
 
        /**
+        * @param $section empty/null/false or a section number (0, 1, 2, T1, T2...)
         * @return string Complete article text, or null if error
         */
        public function replaceSection( $section, $text, $summary = '', $edittime = NULL ) {
                wfProfileIn( __METHOD__ );
-               if( $section === '' ) {
+               if( strval( $section ) == '' ) {
                        // Whole-page edit; let the whole text through
                } else {
                        if( is_null($edittime) ) {
@@ -1461,7 +1561,7 @@ class Article {
                $isminor = ( $flags & EDIT_MINOR ) && $user->isAllowed('minoredit');
                $bot = $flags & EDIT_FORCE_BOT;
 
-               $oldtext = $this->getContent();
+               $oldtext = $this->getRawText(); // current revision
                $oldsize = strlen( $oldtext );
 
                # Provide autosummaries if one is not provided and autosummaries are enabled.
@@ -1538,7 +1638,7 @@ class Article {
                                        # Update recentchanges
                                        if( !( $flags & EDIT_SUPPRESS_RC ) ) {
                                                # Mark as patrolled if the user can do so
-                                               $patrolled = $wgUseRCPatrol && $user->isAllowed('autopatrol');
+                                               $patrolled = $wgUseRCPatrol && $this->mTitle->userCan('autopatrol');
                                                # Add RC row to the DB
                                                $rc = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $user, $summary,
                                                        $this->mLatest, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
@@ -1620,7 +1720,7 @@ class Article {
                        if( !( $flags & EDIT_SUPPRESS_RC ) ) {
                                global $wgUseRCPatrol, $wgUseNPPatrol;
                                # Mark as patrolled if the user can do so
-                               $patrolled = ($wgUseRCPatrol || $wgUseNPPatrol) && $user->isAllowed('autopatrol');
+                               $patrolled = ($wgUseRCPatrol || $wgUseNPPatrol) && $this->mTitle->userCan('autopatrol');
                                # Add RC row to the DB
                                $rc = RecentChange::notifyNew( $now, $this->mTitle, $isminor, $user, $summary, $bot,
                                        '', strlen($text), $revisionId, $patrolled );
@@ -1701,8 +1801,8 @@ class Article {
                }
 
                #It would be nice to see where the user had actually come from, but for now just guess
-               $returnto = $rc->getAttribute( 'rc_type' ) == RC_NEW ? 'Newpages' : 'Recentchanges';
-               $return = Title::makeTitle( NS_SPECIAL, $returnto );
+               $returnto = $rc->getAttribute( 'rc_type' ) == RC_NEW ? 'newpages' : 'recentchanges';
+               $return = SpecialPage::getTitleFor( $returnto );
 
                $dbw = wfGetDB( DB_MASTER );
                $errors = $rc->doMarkPatrolled();
@@ -1856,14 +1956,23 @@ class Article {
                $changed = false;
                foreach( $wgRestrictionTypes as $action ) {
                        if( isset( $expiry[$action] ) ) {
-                               $current[$action] = implode( '', $this->mTitle->getRestrictions( $action ) );
-                               $changed = ($changed || ($this->mTitle->mRestrictionsExpiry[$action] != $expiry[$action]) );
+                               # Get current restrictions on $action
+                               $aLimits = $this->mTitle->getRestrictions( $action );
+                               $current[$action] = implode( '', $aLimits );
+                               # Are any actual restrictions being dealt with here?
+                               $aRChanged = count($aLimits) || !empty($limit[$action]);
+                               # If something changed, we need to log it. Checking $aRChanged
+                               # assures that "unprotecting" a page that is not protected does
+                               # not log just because the expiry was "changed".
+                               if( $aRChanged && $this->mTitle->mRestrictionsExpiry[$action] != $expiry[$action] ) {
+                                       $changed = true;
+                               }
                        }
                }
 
                $current = Article::flattenRestrictions( $current );
 
-               $changed = ($changed || ( $current != $updated ) );
+               $changed = ($changed || $current != $updated );
                $changed = $changed || ($updated && $this->mTitle->areRestrictionsCascading() != $cascade);
                $protect = ( $updated != '' );
 
@@ -1884,13 +1993,10 @@ class Article {
 
                                # Only restrictions with the 'protect' right can cascade...
                                # Otherwise, people who cannot normally protect can "protect" pages via transclusion
-                               foreach( $limit as $action => $restriction ) {
-                                       # FIXME: can $restriction be an array or what? (same as fixme above)
-                                       if( $restriction != 'protect' && $restriction != 'sysop' ) {
-                                               $cascade = false;
-                                               break;
-                                       }
-                               }
+                               $editrestriction = isset( $limit['edit'] ) ? array( $limit['edit'] ) : $this->mTitle->getRestrictions( 'edit' );
+                               # The schema allows multiple restrictions
+                               if(!in_array('protect', $editrestriction) && !in_array('sysop', $editrestriction))
+                                       $cascade = false;
                                $cascade_description = '';       
                                if( $cascade ) {
                                        $cascade_description = ' ['.wfMsgForContent('protect-summary-cascade').']';      
@@ -1908,7 +2014,9 @@ class Article {
                                                $protect_description .= "[$action=$restrictions] (";
                                                if( $encodedExpiry[$action] != 'infinity' ) {
                                                        $protect_description .= wfMsgForContent( 'protect-expiring', 
-                                                               $wgContLang->timeanddate( $expiry[$action], false, false ) );    
+                                                               $wgContLang->timeanddate( $expiry[$action], false, false ) ,
+                                                               $wgContLang->date( $expiry[$action], false, false ) ,
+                                                               $wgContLang->time( $expiry[$action], false, false ) );   
                                                } else {
                                                        $protect_description .= wfMsgForContent( 'protect-expiry-indefinite' );
                                                }
@@ -2085,14 +2193,14 @@ class Article {
 
                $reason = $this->DeleteReasonList;
 
-               if( $reason != 'other' && $this->DeleteReason != '') {
+               if( $reason != 'other' && $this->DeleteReason != '' ) {
                        // Entry from drop down menu + additional comment
-                       $reason .= ': ' . $this->DeleteReason;
+                       $reason .= wfMsgForContent( 'colon-separator' ) . $this->DeleteReason;
                } elseif( $reason == 'other' ) {
                        $reason = $this->DeleteReason;
                }
                # Flag to hide all contents of the archived revisions
-               $suppress = $wgRequest->getVal( 'wpSuppress' ) && $wgUser->isAllowed('suppressrevision');
+               $suppress = $wgRequest->getVal( 'wpSuppress' ) && $wgUser->isAllowed( 'suppressrevision' );
 
                # This code desperately needs to be totally rewritten
 
@@ -2105,7 +2213,7 @@ class Article {
                # Check permissions
                $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgUser );
 
-               if(count($permission_errors)>0) {
+               if( count( $permission_errors ) > 0 ) {
                        $wgOut->showPermissionsErrorPage( $permission_errors );
                        return;
                }
@@ -2117,7 +2225,9 @@ class Article {
                $conds = $this->mTitle->pageCond();
                $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__ );
                if( $latest === false ) {
-                       $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
+                       $wgOut->showFatalError( wfMsgExt( 'cannotdelete', array( 'parse' ) ) );
+                       $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
+                       LogEventsList::showLogExtract( $wgOut, 'delete', $this->mTitle->getPrefixedText() );
                        return;
                }
 
@@ -2146,8 +2256,8 @@ class Article {
 
                // If the page has a history, insert a warning
                if( $hasHistory && !$confirm ) {
-                       $skin=$wgUser->getSkin();
-                       $wgOut->addHTML( '<strong>' . wfMsg( 'historywarning' ) . ' ' . $skin->historyLink() . '</strong>' );
+                       $skin = $wgUser->getSkin();
+                       $wgOut->addHTML( '<strong>' . wfMsgExt( 'historywarning', array( 'parseinline' ) ) . ' ' . $skin->historyLink() . '</strong>' );
                        if( $bigHistory ) {
                                global $wgLang, $wgDeleteRevisionsLimit;
                                $wgOut->wrapWikiMsg( "<div class='error'>\n$1</div>\n",
@@ -2236,7 +2346,7 @@ class Article {
 
                wfDebug( "Article::confirmDelete\n" );
 
-               $wgOut->setSubtitle( wfMsg( 'delete-backlink', $wgUser->getSkin()->makeKnownLinkObj( $this->mTitle ) ) );
+               $wgOut->setSubtitle( wfMsgHtml( 'delete-backlink', $wgUser->getSkin()->makeKnownLinkObj( $this->mTitle ) ) );
                $wgOut->setRobotPolicy( 'noindex,nofollow' );
                $wgOut->addWikiMsg( 'confirmdeletetext' );
 
@@ -2328,10 +2438,13 @@ class Article {
                                $wgOut->returnToMain( false );
                                wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason, $id));
                        } else {
-                               if( $error == '' )
-                                       $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
-                               else
+                               if( $error == '' ) {
+                                       $wgOut->showFatalError( wfMsgExt( 'cannotdelete', array( 'parse' ) ) );
+                                       $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
+                                       LogEventsList::showLogExtract( $wgOut, 'delete', $this->mTitle->getPrefixedText() );
+                               } else {
                                        $wgOut->showFatalError( $error );
+                               }
                        }
                }
        }
@@ -2356,7 +2469,7 @@ class Article {
                        return false;
                }
 
-               $u = new SiteStatsUpdate( 0, 1, -(int)$this->isCountable( $this->getContent() ), -1 );
+               $u = new SiteStatsUpdate( 0, 1, -(int)$this->isCountable( $this->getRawText() ), -1 );
                array_push( $wgDeferredUpdateList, $u );
 
                // Bitfields to further suppress the content
@@ -2618,7 +2731,7 @@ class Article {
                        $revId = false;
                }
 
-               wfRunHooks( 'ArticleRollbackComplete', array( $this, $wgUser, $target ) );
+               wfRunHooks( 'ArticleRollbackComplete', array( $this, $wgUser, $target, $current ) );
 
                $resultDetails = array(
                        'summary' => $summary,
@@ -2704,16 +2817,13 @@ class Article {
        /**
         * Do standard deferred updates after page view
         */
-       protected function viewUpdates() {
-               global $wgDeferredUpdateList, $wgUser;
-               if( 0 != $this->getID() ) {
-                       # Don't update page view counters on views from bot users (bug 14044)
-                       global $wgDisableCounters;
-                       if( !$wgDisableCounters && !$wgUser->isAllowed( 'bot' ) ) {
-                               Article::incViewCount( $this->getID() );
-                               $u = new SiteStatsUpdate( 1, 0, 0 );
-                               array_push( $wgDeferredUpdateList, $u );
-                       }
+       public function viewUpdates() {
+               global $wgDeferredUpdateList, $wgDisableCounters, $wgUser;
+               # Don't update page view counters on views from bot users (bug 14044)
+               if( !$wgDisableCounters && !$wgUser->isAllowed('bot') && $this->getID() ) {
+                       Article::incViewCount( $this->getID() );
+                       $u = new SiteStatsUpdate( 1, 0, 0 );
+                       array_push( $wgDeferredUpdateList, $u );
                }
                # Update newtalk / watchlist notification status
                $wgUser->clearNotification( $this->mTitle );
@@ -2863,10 +2973,10 @@ class Article {
         *
         * @param $oldid String: revision ID of this article revision
         */
-       public function setOldSubtitle( $oldid=0 ) {
-               global $wgLang, $wgOut, $wgUser;
+       public function setOldSubtitle( $oldid = 0 ) {
+               global $wgLang, $wgOut, $wgUser, $wgRequest;
 
-               if( !wfRunHooks( 'DisplayOldSubtitle', array(&$this, &$oldid) ) ) {
+               if( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
                        return;
                }
 
@@ -2876,34 +2986,34 @@ class Article {
                $td = $wgLang->timeanddate( $this->mTimestamp, true );
                $sk = $wgUser->getSkin();
                $lnk = $current
-                       ? wfMsg( 'currentrevisionlink' )
-                       : $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'currentrevisionlink' ) );
+                       ? wfMsgHtml( 'currentrevisionlink' )
+                       : $sk->makeKnownLinkObj( $this->mTitle, wfMsgHtml( 'currentrevisionlink' ) );
                $curdiff = $current
-                       ? wfMsg( 'diff' )
-                       : $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'diff' ), 'diff=cur&oldid='.$oldid );
+                       ? wfMsgHtml( 'diff' )
+                       : $sk->makeKnownLinkObj( $this->mTitle, wfMsgHtml( 'diff' ), 'diff=cur&oldid='.$oldid );
                $prev = $this->mTitle->getPreviousRevisionID( $oldid ) ;
                $prevlink = $prev
-                       ? $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid )
-                       : wfMsg( 'previousrevision' );
+                       ? $sk->makeKnownLinkObj( $this->mTitle, wfMsgHtml( 'previousrevision' ), 'direction=prev&oldid='.$oldid )
+                       : wfMsgHtml( 'previousrevision' );
                $prevdiff = $prev
-                       ? $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'diff' ), 'diff=prev&oldid='.$oldid )
-                       : wfMsg( 'diff' );
+                       ? $sk->makeKnownLinkObj( $this->mTitle, wfMsgHtml( 'diff' ), 'diff=prev&oldid='.$oldid )
+                       : wfMsgHtml( 'diff' );
                $nextlink = $current
-                       ? wfMsg( 'nextrevision' )
-                       : $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
+                       ? wfMsgHtml( 'nextrevision' )
+                       : $sk->makeKnownLinkObj( $this->mTitle, wfMsgHtml( 'nextrevision' ), 'direction=next&oldid='.$oldid );
                $nextdiff = $current
-                       ? wfMsg( 'diff' )
-                       : $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'diff' ), 'diff=next&oldid='.$oldid );
+                       ? wfMsgHtml( 'diff' )
+                       : $sk->makeKnownLinkObj( $this->mTitle, wfMsgHtml( 'diff' ), 'diff=next&oldid='.$oldid );
 
                $cdel='';
                if( $wgUser->isAllowed( 'deleterevision' ) ) {
                        $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
                        if( $revision->isCurrent() ) {
                        // We don't handle top deleted edits too well
-                               $cdel = wfMsgHtml('rev-delundel');
+                               $cdel = wfMsgHtml( 'rev-delundel' );
                        } else if( !$revision->userCan( Revision::DELETED_RESTRICTED ) ) {
                        // If revision was hidden from sysops
-                               $cdel = wfMsgHtml('rev-delundel');
+                               $cdel = wfMsgHtml( 'rev-delundel' );
                        } else {
                                $cdel = $sk->makeKnownLinkObj( $revdel,
                                        wfMsgHtml('rev-delundel'),
@@ -2915,18 +3025,19 @@ class Article {
                        }
                        $cdel = "(<small>$cdel</small>) ";
                }
-               # Show user links if allowed to see them. Normally they
-               # are hidden regardless, but since we can already see the text here...
-               $userlinks = $sk->revUserTools( $revision, false );
+               $unhide = $wgRequest->getInt('unhide') == 1 && $wgUser->matchEditToken( $wgRequest->getVal('token'), $oldid );
+               # Show user links if allowed to see them. If hidden, then show them only if requested...
+               $userlinks = $sk->revUserTools( $revision, !$unhide );
 
                $m = wfMsg( 'revision-info-current' );
                $infomsg = $current && !wfEmptyMsg( 'revision-info-current', $m ) && $m != '-'
                        ? 'revision-info-current'
                        : 'revision-info';
 
-               $r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" . wfMsg( $infomsg, $td, $userlinks, $revision->getID() ) . "</div>\n" .
+               $r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" . wfMsgExt( $infomsg, array( 'parseinline', 'replaceafter' ), 
+                       $td, $userlinks, $revision->getID() ) . "</div>\n" .
 
-                    "\n\t\t\t\t<div id=\"mw-revision-nav\">" . $cdel . wfMsg( 'revision-nav', $prevdiff, 
+                    "\n\t\t\t\t<div id=\"mw-revision-nav\">" . $cdel . wfMsgHtml( 'revision-nav', $prevdiff, 
                                $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>\n\t\t\t";
                $wgOut->setSubtitle( $r );
        }
@@ -2977,31 +3088,14 @@ class Article {
         * @return bool
         */
        public function isFileCacheable() {
-               global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest, $wgLang, $wgContLang;
-               // Get all query values
-               $queryVals = $wgRequest->getValues();
-               foreach( $queryVals as $query => $val ) {
-                       // Normal page view in query form can have action=view
-                       if( $query !== 'title' && $query !== 'curid' && !($query == 'action' && $val == 'view') ) {
-                               return false;
+               $cacheable = false;
+               if( HTMLFileCache::useFileCache() ) {
+                       $cacheable = $this->getID() && !$this->mRedirectedFrom;
+                       // Extension may have reason to disable file caching on some pages.
+                       if( $cacheable ) {
+                               $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
                        }
                }
-               // Check for non-standard user language; this covers uselang,
-               // and extensions for auto-detecting user language.
-               $ulang = $wgLang->getCode();
-               $clang = $wgContLang->getCode();
-
-               $cacheable = $wgUseFileCache
-                       && !$wgShowIPinHeader
-                       && $this->getID() > 0
-                       && $wgUser->isAnon()
-                       && !$wgUser->getNewtalk()
-                       && !$this->mRedirectedFrom
-                       && $ulang === $clang;
-               // Extension may have reason to disable file caching on some pages.
-               if( $cacheable ) {
-                       $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
-               }
                return $cacheable;
        }
 
@@ -3154,7 +3248,7 @@ class Article {
        }
 
        public static function onArticleDelete( $title ) {
-               global $wgUseFileCache, $wgMessageCache;
+               global $wgMessageCache;
                # Update existence markers on article/talk tabs...
                if( $title->isTalkPage() ) {
                        $other = $title->getSubjectPage();
@@ -3168,10 +3262,7 @@ class Article {
                $title->purgeSquid();
 
                # File cache
-               if( $wgUseFileCache ) {
-                       $cm = new HTMLFileCache( $title );
-                       @unlink( $cm->fileCacheName() );
-               }
+               HTMLFileCache::clearFileCache( $title );
 
                # Messages
                if( $title->getNamespace() == NS_MEDIAWIKI ) {
@@ -3193,7 +3284,7 @@ class Article {
         * Purge caches on page update etc
         */
        public static function onArticleEdit( $title, $transclusions = 'transclusions' ) {
-               global $wgDeferredUpdateList, $wgUseFileCache;
+               global $wgDeferredUpdateList;
 
                // Invalidate caches of articles which include this page
                if( $transclusions !== 'skiptransclusions' )
@@ -3206,10 +3297,7 @@ class Article {
                $title->purgeSquid();
 
                # Clear file cache for this page only
-               if( $wgUseFileCache ) {
-                       $cm = new HTMLFileCache( $title );
-                       @unlink( $cm->fileCacheName() );
-               }
+               HTMLFileCache::clearFileCache( $title );
        }
 
        /**#@-*/
@@ -3239,7 +3327,7 @@ class Article {
 
                $wgOut->setPagetitle( $page->getPrefixedText() );
                $wgOut->setPageTitleActionText( wfMsg( 'info_short' ) );
-               $wgOut->setSubtitle( wfMsg( 'infosubtitle' ) );
+               $wgOut->setSubtitle( wfMsgHtml( 'infosubtitle' ) );
 
                if( !$this->mTitle->exists() ) {
                        $wgOut->addHTML( '<div class="noarticletext">' );