clarify comment
[lhc/web/wiklou.git] / includes / Article.php
index e8c152c..efc4f65 100644 (file)
@@ -36,6 +36,18 @@ class Article {
        var $mUserText;                 //!<
        /**@}}*/
 
+       /**
+        * Constants used by internal components to get rollback results
+        */
+       const SUCCESS = 0;                      // Operation successful
+       const PERM_DENIED = 1;          // Permission denied
+       const BLOCKED = 2;                      // User has been blocked
+       const READONLY = 3;                     // Wiki is in read-only mode
+       const BAD_TOKEN = 4;            // Invalid token specified
+       const BAD_TITLE = 5;            // $this is not a valid Article
+       const ALREADY_ROLLED = 6;       // Someone else already rolled this back. $from and $summary will be set
+       const ONLY_AUTHOR = 7;          // User is the only author of the page
        /**
         * Constructor and clear the article
         * @param $title Reference to a Title object.
@@ -245,7 +257,7 @@ class Article {
         * @param array    $conditions
         * @private
         */
-       function pageData( &$dbr, $conditions ) {
+       function pageData( $dbr, $conditions ) {
                $fields = array(
                                'page_id',
                                'page_namespace',
@@ -271,7 +283,7 @@ class Article {
         * @param Database $dbr
         * @param Title $title
         */
-       function pageDataFromTitle( &$dbr, $title ) {
+       function pageDataFromTitle( $dbr, $title ) {
                return $this->pageData( $dbr, array(
                        'page_namespace' => $title->getNamespace(),
                        'page_title'     => $title->getDBkey() ) );
@@ -281,7 +293,7 @@ class Article {
         * @param Database $dbr
         * @param int $id
         */
-       function pageDataFromId( &$dbr, $id ) {
+       function pageDataFromId( $dbr, $id ) {
                return $this->pageData( $dbr, array( 'page_id' => $id ) );
        }
 
@@ -294,7 +306,7 @@ class Article {
         */
        function loadPageData( $data = 'fromdb' ) {
                if ( $data === 'fromdb' ) {
-                       $dbr =& $this->getDB();
+                       $dbr = $this->getDB();
                        $data = $this->pageDataFromId( $dbr, $this->getId() );
                }
 
@@ -332,7 +344,7 @@ class Article {
                        return $this->mContent;
                }
 
-               $dbr =& $this->getDB();
+               $dbr = $this->getDB();
 
                # Pre-fill content with error message so that if something
                # fails we'll have something telling us what we intended.
@@ -404,7 +416,7 @@ class Article {
         *
         * @return Database
         */
-       function &getDB() {
+       function getDB() {
                return wfGetDB( DB_MASTER );
        }
 
@@ -453,7 +465,7 @@ class Article {
                        if ( $id == 0 ) {
                                $this->mCounter = 0;
                        } else {
-                               $dbr =& wfGetDB( DB_SLAVE );
+                               $dbr = wfGetDB( DB_SLAVE );
                                $this->mCounter = $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
                                        'Article::getCount', $this->getSelectOptions() );
                        }
@@ -500,6 +512,10 @@ class Article {
         * @return bool
         */
        function isCurrent() {
+               # If no oldid, this is the current version.
+               if ($this->getOldID() == 0)
+                       return true;
+
                return $this->exists() &&
                        isset( $this->mRevision ) &&
                        $this->mRevision->isCurrent();
@@ -571,7 +587,7 @@ class Article {
                # XXX: this is expensive; cache this info somewhere.
 
                $contribs = array();
-               $dbr =& wfGetDB( DB_SLAVE );
+               $dbr = wfGetDB( DB_SLAVE );
                $revTable = $dbr->tableName( 'revision' );
                $userTable = $dbr->tableName( 'user' );
                $user = $this->getUser();
@@ -604,7 +620,7 @@ class Article {
        function view() {
                global $wgUser, $wgOut, $wgRequest, $wgContLang;
                global $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol, $wgParser;
-               global $wgUseTrackbacks, $wgNamespaceRobotPolicies;
+               global $wgUseTrackbacks, $wgNamespaceRobotPolicies, $wgArticleRobotPolicies;
                $sk = $wgUser->getSkin();
 
                wfProfileIn( __METHOD__ );
@@ -632,6 +648,8 @@ class Article {
                # Discourage indexing of printable versions, but encourage following
                if( $wgOut->isPrintable() ) {
                        $policy = 'noindex,follow';
+               } elseif ( isset( $wgArticleRobotPolicies[$this->mTitle->getPrefixedText()] ) ) {
+                       $policy = $wgArticleRobotPolicies[$this->mTitle->getPrefixedText()];
                } elseif( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
                        # Honour customised robot policies for this namespace
                        $policy = $wgNamespaceRobotPolicies[$ns];
@@ -678,10 +696,12 @@ class Article {
                }
 
                # Should the parser cache be used?
-               $pcache = $wgEnableParserCache &&
-                       intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
-                       $this->exists() &&
-                       empty( $oldid );
+               $pcache = $wgEnableParserCache
+                       && intval( $wgUser->getOption( 'stubthreshold' ) ) == 0
+                       && $this->exists()
+                       && empty( $oldid )
+                       && !$this->mTitle->isCssOrJsPage()
+                       && !$this->mTitle->isCssJsSubpage();
                wfDebug( 'Article::view using parser cache: ' . ($pcache ? 'yes' : 'no' ) . "\n" );
                if ( $wgUser->getOption( 'stubthreshold' ) ) {
                        wfIncrStats( 'pcache_miss_stub' );
@@ -718,9 +738,12 @@ class Article {
                }
 
                $outputDone = false;
+               wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$pcache ) );
                if ( $pcache ) {
                        if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
-                               wfRunHooks( 'ArticleViewHeader', array( &$this ) );
+                               // Ensure that UI elements requiring revision ID have
+                               // the correct version information.
+                               $wgOut->setRevisionId( $this->mLatest );
                                $outputDone = true;
                        }
                }
@@ -767,21 +790,24 @@ class Article {
                        }
                }
                if( !$outputDone ) {
-                       /**
-                        * @fixme: this hook doesn't work most of the time, as it doesn't
-                        * trigger when the parser cache is used.
-                        */
-                       wfRunHooks( 'ArticleViewHeader', array( &$this ) ) ;
                        $wgOut->setRevisionId( $this->getRevIdFetched() );
-                       # wrap user css and user js in pre and don't parse
-                       # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
-                       if (
-                               $ns == NS_USER &&
-                               preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle->getDBkey())
-                       ) {
-                               $wgOut->addWikiText( wfMsg('clearyourcache'));
-                               $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent)."\n</pre>" );
-                       } else if ( $rt = Title::newFromRedirect( $text ) ) {
+                       
+                        // Pages containing custom CSS or JavaScript get special treatment
+                       if( $this->mTitle->isCssOrJsPage() || $this->mTitle->isCssJsSubpage() ) {
+                               $wgOut->addHtml( wfMsgExt( 'clearyourcache', 'parse' ) );
+
+                               // Give hooks a chance to customise the output
+                               if( wfRunHooks( 'ShowRawCssJs', array( $this->mContent, $this->mTitle, $wgOut ) ) ) {
+                                       // Wrap the whole lot in a <pre> and don't parse
+                                       preg_match( '!\.(css|js)$!u', $this->mTitle->getText(), $m );
+                                       $wgOut->addHtml( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
+                                       $wgOut->addHtml( htmlspecialchars( $this->mContent ) );
+                                       $wgOut->addHtml( "\n</pre>\n" );
+                               }
+                       
+                       }
+                       
+                       elseif ( $rt = Title::newFromRedirect( $text ) ) {
                                # Display redirect
                                $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
                                $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
@@ -859,7 +885,7 @@ class Article {
        function addTrackbacks() {
                global $wgOut, $wgUser;
 
-               $dbr =& wfGetDB(DB_SLAVE);
+               $dbr = wfGetDB(DB_SLAVE);
                $tbs = $dbr->select(
                                /* FROM   */ 'trackbacks',
                                /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
@@ -874,8 +900,8 @@ class Article {
                        $rmvtxt = "";
                        if ($wgUser->isAllowed( 'trackback' )) {
                                $delurl = $this->mTitle->getFullURL("action=deletetrackback&tbid="
-                                               . $o->tb_id . "&token=" . $wgUser->editToken());
-                               $rmvtxt = wfMsg('trackbackremove', $delurl);
+                                               . $o->tb_id . "&token=" . urlencode( $wgUser->editToken() ) );
+                               $rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) );
                        }
                        $tbtext .= wfMsg(strlen($o->tb_ex) ? 'trackbackexcerpt' : 'trackback',
                                        $o->tb_title,
@@ -905,7 +931,7 @@ class Article {
                        return;
                }
 
-               $db =& wfGetDB(DB_MASTER);
+               $db = wfGetDB(DB_MASTER);
                $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
                $wgTitle->invalidateCache();
                $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
@@ -1139,7 +1165,7 @@ class Article {
                        if( is_null( $edittime ) ) {
                                $rev = Revision::newFromTitle( $this->mTitle );
                        } else {
-                               $dbw =& wfGetDB( DB_MASTER );
+                               $dbw = wfGetDB( DB_MASTER );
                                $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime );
                        }
                        if( is_null( $rev ) ) {
@@ -1182,7 +1208,7 @@ class Article {
 
                $this->doEdit( $text, $summary, $flags );
 
-               $dbw =& wfGetDB( DB_MASTER );
+               $dbw = wfGetDB( DB_MASTER );
                if ($watchthis) {
                        if (!$this->mTitle->userIsWatching()) {
                                $dbw->begin();
@@ -1209,7 +1235,7 @@ class Article {
 
                $good = $this->doEdit( $text, $summary, $flags );
                if ( $good ) {
-                       $dbw =& wfGetDB( DB_MASTER );
+                       $dbw = wfGetDB( DB_MASTER );
                        if ($watchthis) {
                                if (!$this->mTitle->userIsWatching()) {
                                        $dbw->begin();
@@ -1301,7 +1327,7 @@ class Article {
                $text = $this->preSaveTransform( $text );
                $newsize = strlen( $text );
 
-               $dbw =& wfGetDB( DB_MASTER );
+               $dbw = wfGetDB( DB_MASTER );
                $now = wfTimestampNow();
 
                if ( $flags & EDIT_UPDATE ) {
@@ -1634,7 +1660,7 @@ class Article {
         */
        function protect() {
                $form = new ProtectionForm( $this );
-               $form->show();
+               $form->execute();
        }
 
        /**
@@ -1682,25 +1708,54 @@ class Article {
 
                # If nothing's changed, do nothing
                if( $changed ) {
+                       global $wgGroupPermissions;
                        if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser, $limit, $reason ) ) ) {
 
-                               $dbw =& wfGetDB( DB_MASTER );
+                               $dbw = wfGetDB( DB_MASTER );
+
+                               $encodedExpiry = Block::encodeExpiry($expiry, $dbw );
+
+                               $expiry_description = '';
+                               if ( $encodedExpiry != 'infinity' ) {
+                                       $expiry_description = ' (' . wfMsgForContent( 'protect-expiring', $wgContLang->timeanddate( $expiry ) ).')';
+                               }
 
                                # Prepare a null revision to be added to the history
-                               $comment = $wgContLang->ucfirst( wfMsgForContent( $protect ? 'protectedarticle' : 'unprotectedarticle', $this->mTitle->getPrefixedText() ) );
+                               $modified = $current != '' && $protect;
+                               if ( $protect ) {
+                                       $comment_type = $modified ? 'modifiedarticleprotection' : 'protectedarticle';
+                               } else {
+                                       $comment_type = 'unprotectedarticle';
+                               }
+                               $comment = $wgContLang->ucfirst( wfMsgForContent( $comment_type, $this->mTitle->getPrefixedText() ) );
+
+                               foreach( $limit as $action => $restrictions ) {
+                                       # Check if the group level required to edit also can protect pages
+                                       # Otherwise, people who cannot normally protect can "protect" pages via transclusion
+                                       $cascade = ( $cascade && isset($wgGroupPermissions[$restrictions]['protect']) && $wgGroupPermissions[$restrictions]['protect'] );       
+                               }
+                               
+                               $cascade_description = '';
+                               if ($cascade) {
+                                       $cascade_description = ' ['.wfMsg('protect-summary-cascade').']';
+                               }
+
                                if( $reason )
                                        $comment .= ": $reason";
                                if( $protect )
                                        $comment .= " [$updated]";
+                               if ( $expiry_description && $protect )
+                                       $comment .= "$expiry_description";
+                               if ( $cascade )
+                                       $comment .= "$cascade_description";
+
                                $nullRevision = Revision::newNullRevision( $dbw, $id, $comment, true );
                                $nullRevId = $nullRevision->insertOn( $dbw );
 
                                # Update restrictions table
                                foreach( $limit as $action => $restrictions ) {
-                                       $encodedExpiry = Block::encodeExpiry($expiry, $dbw );
-
                                        if ($restrictions != '' ) {
-                                               $dbw->replace( 'page_restrictions', array( 'pr_pagetype'),
+                                               $dbw->replace( 'page_restrictions', array(array('pr_page', 'pr_type')),
                                                        array( 'pr_page' => $id, 'pr_type' => $action
                                                                , 'pr_level' => $restrictions, 'pr_cascade' => $cascade ? 1 : 0
                                                                , 'pr_expiry' => $encodedExpiry ), __METHOD__  );
@@ -1725,19 +1780,8 @@ class Article {
                                # Update the protection log
                                $log = new LogPage( 'protect' );
 
-                               $cascade_description = '';
-                               $expiry_description = '';
-
-                               if ($cascade) {
-                                       $cascade_description = ' ['.wfMsg('protect-summary-cascade').']';
-                               }
-
-                               if ( $encodedExpiry != 'infinity' ) {
-                                       $expiry_description = ' (' . wfMsgForContent( 'protect-expiring', $wgContLang->timeanddate( $expiry ) ).')';
-                               }
-
                                if( $protect ) {
-                                       $log->addEntry( 'protect', $this->mTitle, trim( $reason . " [$updated]$cascade_description$expiry_description" ) );
+                                       $log->addEntry( $modified ? 'modify' : 'protect', $this->mTitle, trim( $reason . " [$updated]$cascade_description$expiry_description" ) );
                                } else {
                                        $log->addEntry( 'unprotect', $this->mTitle, $reason );
                                }
@@ -1799,7 +1843,7 @@ class Article {
                $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
 
                # Better double-check that it hasn't been deleted yet!
-               $dbw =& wfGetDB( DB_MASTER );
+               $dbw = wfGetDB( DB_MASTER );
                $conds = $this->mTitle->pageCond();
                $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__ );
                if ( $latest === false ) {
@@ -1865,7 +1909,7 @@ class Article {
                                $reason = wfMsgForContent( 'exblank' );
                        }
 
-                       if( $length < 500 && $reason === '' ) {
+                       if( $reason === '' ) {
                                # comment field=255, let's grep the first 150 to have some user
                                # space left
                                global $wgContLang;
@@ -1901,7 +1945,7 @@ class Article {
                // First try the slave
                // If that doesn't have the latest revision, try the master
                $continue = 2;
-               $db =& wfGetDB( DB_SLAVE );
+               $db = wfGetDB( DB_SLAVE );
                do {
                        $res = $db->select( array( 'page', 'revision' ),
                                array( 'rev_id', 'rev_user_text' ),
@@ -1920,7 +1964,7 @@ class Article {
                        }
                        $row = $db->fetchObject( $res );
                        if ( $continue == 2 && $revLatest && $row->rev_id != $revLatest ) {
-                               $db =& wfGetDB( DB_MASTER );
+                               $db = wfGetDB( DB_MASTER );
                                $continue--;
                        } else {
                                $continue = 0;
@@ -1981,6 +2025,22 @@ class Article {
 </form>\n" );
 
                $wgOut->returnToMain( false );
+
+               $this->showLogExtract( $wgOut );
+       }
+
+
+       /**
+        * Show relevant lines from the deletion log
+        */
+       function showLogExtract( $out ) {
+               $out->addHtml( '<h2>' . htmlspecialchars( LogPage::logName( 'delete' ) ) . '</h2>' );
+               $logViewer = new LogViewer(
+                       new LogReader(
+                               new FauxRequest(
+                                       array( 'page' => $this->mTitle->getPrefixedText(),
+                                              'type' => 'delete' ) ) ) );
+               $logViewer->showList( $out );
        }
 
 
@@ -2021,7 +2081,7 @@ class Article {
 
                wfDebug( __METHOD__."\n" );
 
-               $dbw =& wfGetDB( DB_MASTER );
+               $dbw = wfGetDB( DB_MASTER );
                $ns = $this->mTitle->getNamespace();
                $t = $this->mTitle->getDBkey();
                $id = $this->mTitle->getArticleID();
@@ -2056,6 +2116,7 @@ class Article {
                                'ar_text_id'    => 'rev_text_id',
                                'ar_text'       => '\'\'', // Be explicit to appease
                                'ar_flags'      => '\'\'', // MySQL's "strict mode"...
+                               'ar_len'                => 'rev_len'
                        ), array(
                                'page_id' => $id,
                                'page_id = rev_page'
@@ -2107,60 +2168,52 @@ class Article {
        }
 
        /**
-        * Revert a modification
-        */
-       function rollback() {
-               global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
-
+        * Roll back the most recent consecutive set of edits to a page
+        * from the same user; fails if there are no eligible edits to
+        * roll back to, e.g. user is the sole contributor
+        *
+        * @param string $fromP - Name of the user whose edits to rollback. 
+        * @param string $summary - Custom summary. Set to default summary if empty.
+        * @param string $token - Rollback token.
+        * @param bool $bot - If true, mark all reverted edits as bot.
+        * 
+        * @param array $resultDetails contains result-specific dict of additional values
+        *    ALREADY_ROLLED : 'current' (rev)
+        *    SUCCESS        : 'summary' (str), 'current' (rev), 'target' (rev)
+        * 
+        * @return self::SUCCESS on succes, self::* on failure
+        */
+       public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails ) {
+               global $wgUser, $wgUseRCPatrol;
+               $resultDetails = null;
+               
                if( $wgUser->isAllowed( 'rollback' ) ) {
                        if( $wgUser->isBlocked() ) {
-                               $wgOut->blockedPage();
-                               return;
+                               return self::BLOCKED;
                        }
                } else {
-                       $wgOut->permissionRequired( 'rollback' );
-                       return;
+                       return self::PERM_DENIED;
                }
-
+                       
                if ( wfReadOnly() ) {
-                       $wgOut->readOnlyPage( $this->getContent() );
-                       return;
+                       return self::READONLY;
                }
-               if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
-                       array( $this->mTitle->getPrefixedText(),
-                               $wgRequest->getVal( 'from' ) )  ) ) {
-                       $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
-                       $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
-                       return;
-               }
-               $dbw =& wfGetDB( DB_MASTER );
-
-               # Enhanced rollback, marks edits rc_bot=1
-               $bot = $wgRequest->getBool( 'bot' );
+               if( !$wgUser->matchEditToken( $token, array( $this->mTitle->getPrefixedText(), $fromP ) ) )
+                       return self::BAD_TOKEN;
 
-               # Replace all this user's current edits with the next one down
+               $dbw = wfGetDB( DB_MASTER );
 
                # Get the last editor
                $current = Revision::newFromTitle( $this->mTitle );
                if( is_null( $current ) ) {
                        # Something wrong... no page?
-                       $wgOut->addHTML( wfMsg( 'notanarticle' ) );
-                       return;
+                       return self::BAD_TITLE;
                }
 
-               $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
+               $from = str_replace( '_', ' ', $fromP );
                if( $from != $current->getUserText() ) {
-                       $wgOut->setPageTitle( wfMsg('rollbackfailed') );
-                       $wgOut->addWikiText( wfMsg( 'alreadyrolled',
-                               htmlspecialchars( $this->mTitle->getPrefixedText()),
-                               htmlspecialchars( $from ),
-                               htmlspecialchars( $current->getUserText() ) ) );
-                       if( $current->getComment() != '') {
-                               $wgOut->addHTML(
-                                       wfMsg( 'editcomment',
-                                       htmlspecialchars( $current->getComment() ) ) );
-                       }
-                       return;
+                       $resultDetails = array( 'current' => $current );
+                       return self::ALREADY_ROLLED;
                }
 
                # Get the last edit not by this guy
@@ -2178,11 +2231,9 @@ class Article {
                        );
                if( $s === false ) {
                        # Something wrong
-                       $wgOut->setPageTitle(wfMsg('rollbackfailed'));
-                       $wgOut->addHTML( wfMsg( 'cantrollback' ) );
-                       return;
+                       return self::ONLY_AUTHOR;
                }
-
+       
                $set = array();
                if ( $bot ) {
                        # Mark all reverted edits as bot
@@ -2195,27 +2246,100 @@ class Article {
 
                if ( $set ) {
                        $dbw->update( 'recentchanges', $set,
-                               array( /* WHERE */
-                                       'rc_cur_id'    => $current->getPage(),
-                                       'rc_user_text' => $current->getUserText(),
-                                       "rc_timestamp > '{$s->rev_timestamp}'",
-                               ), __METHOD__
-                       );
+                                       array( /* WHERE */
+                                               'rc_cur_id' => $current->getPage(),
+                                               'rc_user_text' => $current->getUserText(),
+                                               "rc_timestamp > '{$s->rev_timestamp}'",
+                                       ), __METHOD__
+                               );
                }
 
                # Get the edit summary
                $target = Revision::newFromId( $s->rev_id );
-               $newComment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
-               $newComment = $wgRequest->getText( 'summary', $newComment );
+               if( empty( $summary ) )
+                       $summary = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
+
+               # Save
+               $flags = EDIT_UPDATE | EDIT_MINOR;
+               if( $bot )
+                       $flags |= EDIT_FORCE_BOT;
+               $this->doEdit( $target->getText(), $summary, $flags );
+
+               $resultDetails = array(
+                       'summary' => $summary,
+                       'current' => $current,
+                       'target' => $target,
+               );
+               return self::SUCCESS;
+       }
 
-               # Save it!
-               $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
-               $wgOut->setRobotpolicy( 'noindex,nofollow' );
-               $wgOut->addHTML( '<h2>' . htmlspecialchars( $newComment ) . "</h2>\n<hr />\n" );
+       /**
+        * User interface for rollback operations
+        */
+       function rollback() {
+               global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
 
-               $this->updateArticle( $target->getText(), $newComment, 1, $this->mTitle->userIsWatching(), $bot );
+               $details = null;
+               $result = $this->doRollback(
+                       $wgRequest->getVal( 'from' ),
+                       $wgRequest->getText( 'summary' ),
+                       $wgRequest->getVal( 'token' ),
+                       $wgRequest->getBool( 'bot' ),
+                       $details
+               );
+
+               switch( $result ) {
+                       case self::BLOCKED:
+                               $wgOut->blockedPage();
+                               break;
+                       case self::PERM_DENIED:
+                               $wgOut->permissionRequired( 'rollback' );
+                               break;
+                       case self::READONLY:
+                               $wgOut->readOnlyPage( $this->getContent() );
+                               break;
+                       case self::BAD_TOKEN:
+                               $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
+                               $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
+                               break;
+                       case self::BAD_TITLE:
+                               $wgOut->addHtml( wfMsg( 'notanarticle' ) );
+                               break;
+                       case self::ALREADY_ROLLED:
+                               $current = $details['current'];
+                               $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
+                               $wgOut->addWikiText(
+                                       wfMsg( 'alreadyrolled',
+                                               htmlspecialchars( $this->mTitle->getPrefixedText() ),
+                                               htmlspecialchars( $wgRequest->getVal( 'from' ) ),
+                                               htmlspecialchars( $current->getUserText() )
+                                       )
+                               );
+                               if( $current->getComment() != '' ) {
+                                       $wgOut->addHtml( wfMsg( 'editcomment',
+                                               $wgUser->getSkin()->formatComment( $current->getComment() ) ) );
+                               }
+                               break;
+                       case self::ONLY_AUTHOR:
+                               $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
+                               $wgOut->addHtml( wfMsg( 'cantrollback' ) );
+                               break;
+                       case self::SUCCESS:
+                               $current = $details['current'];
+                               $target = $details['target'];
+                               $wgOut->setPageTitle( wfMsg( 'actioncomplete' ) );
+                               $wgOut->setRobotPolicy( 'noindex,nofollow' );
+                               $old = $wgUser->getSkin()->userLink( $current->getUser(), $current->getUserText() )
+                                       . $wgUser->getSkin()->userToolLinks( $current->getUser(), $current->getUserText() );
+                               $new = $wgUser->getSkin()->userLink( $target->getUser(), $target->getUserText() )
+                                       . $wgUser->getSkin()->userToolLinks( $target->getUser(), $target->getUserText() );
+                               $wgOut->addHtml( wfMsgExt( 'rollback-success', array( 'parse', 'replaceafter' ), $old, $new ) );
+                               $wgOut->returnToMain( false, $this->mTitle );
+                               break;
+                       default:
+                               throw new MWException( __METHOD__ . ": Unknown return value `{$retval}`" );
+               }
 
-               $wgOut->returnToMain( false );
        }
 
 
@@ -2273,11 +2397,11 @@ class Article {
 
                if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
                        wfSeedRandom();
-                       if ( 0 == mt_rand( 0, 999 ) ) {
+                       if ( 0 == mt_rand( 0, 99 ) ) {
                                # Periodically flush old entries from the recentchanges table.
                                global $wgRCMaxAge;
 
-                               $dbw =& wfGetDB( DB_MASTER );
+                               $dbw = wfGetDB( DB_MASTER );
                                $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
                                $recentchanges = $dbw->tableName( 'recentchanges' );
                                $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
@@ -2330,7 +2454,7 @@ class Article {
         *
         * @param Revision $rev
         *
-        * @fixme This is a shitty interface function. Kill it and replace the
+        * @todo This is a shitty interface function. Kill it and replace the
         * other shitty functions like editUpdates and such so it's not needed
         * anymore.
         */
@@ -2385,7 +2509,12 @@ class Article {
                $userlinks = $sk->userLink( $revision->getUser(), $revision->getUserText() )
                                                . $sk->userToolLinks( $revision->getUser(), $revision->getUserText() );
 
-               $r = "\n\t\t\t\t<div id=\"mw-revision-info\">" . wfMsg( 'revision-info', $td, $userlinks ) . "</div>\n" .
+               $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 ) . "</div>\n" .
                     "\n\t\t\t\t<div id=\"mw-revision-nav\">" . wfMsg( 'revision-nav', $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>\n\t\t\t";
                $wgOut->setSubtitle( $r );
        }
@@ -2436,25 +2565,40 @@ class Article {
         * @return bool
         */
        function isFileCacheable() {
-               global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
+               global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest, $wgLang, $wgContLang;
                $action    = $wgRequest->getVal( 'action'    );
                $oldid     = $wgRequest->getVal( 'oldid'     );
                $diff      = $wgRequest->getVal( 'diff'      );
                $redirect  = $wgRequest->getVal( 'redirect'  );
                $printable = $wgRequest->getVal( 'printable' );
+               $page      = $wgRequest->getVal( 'page' );
+
+               //check for non-standard user language; this covers uselang, 
+               //and extensions for auto-detecting user language.
+               $ulang     = $wgLang->getCode(); 
+               $clang     = $wgContLang->getCode();
 
-               return $wgUseFileCache
-                       and (!$wgShowIPinHeader)
-                       and ($this->getID() != 0)
-                       and ($wgUser->isAnon())
-                       and (!$wgUser->getNewtalk())
-                       and ($this->mTitle->getNamespace() != NS_SPECIAL )
-                       and (empty( $action ) || $action == 'view')
-                       and (!isset($oldid))
-                       and (!isset($diff))
-                       and (!isset($redirect))
-                       and (!isset($printable))
-                       and (!$this->mRedirectedFrom);
+               $cacheable = $wgUseFileCache
+                       && (!$wgShowIPinHeader)
+                       && ($this->getID() != 0)
+                       && ($wgUser->isAnon())
+                       && (!$wgUser->getNewtalk())
+                       && ($this->mTitle->getNamespace() != NS_SPECIAL )
+                       && (empty( $action ) || $action == 'view')
+                       && (!isset($oldid))
+                       && (!isset($diff))
+                       && (!isset($redirect))
+                       && (!isset($printable))
+                       && !isset($page)
+                       && (!$this->mRedirectedFrom)
+                       && ($ulang === $clang);
+
+               if ( $cacheable ) {
+                       //extension may have reason to disable file caching on some pages.
+                       $cacheable = wfRunHooks( 'IsFileCacheable', array( $this ) );
+               }
+
+               return $cacheable;
        }
 
        /**
@@ -2501,7 +2645,7 @@ class Article {
        function quickEdit( $text, $comment = '', $minor = 0 ) {
                wfProfileIn( __METHOD__ );
 
-               $dbw =& wfGetDB( DB_MASTER );
+               $dbw = wfGetDB( DB_MASTER );
                $dbw->begin();
                $revision = new Revision( array(
                        'page'       => $this->getId(),
@@ -2526,7 +2670,7 @@ class Article {
                $id = intval( $id );
                global $wgHitcounterUpdateFreq, $wgDBtype;
 
-               $dbw =& wfGetDB( DB_MASTER );
+               $dbw = wfGetDB( DB_MASTER );
                $pageTable = $dbw->tableName( 'page' );
                $hitcounterTable = $dbw->tableName( 'hitcounter' );
                $acchitsTable = $dbw->tableName( 'acchits' );
@@ -2672,7 +2816,7 @@ class Article {
                                $wgOut->addHTML(wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' ) );
                        }
                } else {
-                       $dbr =& wfGetDB( DB_SLAVE );
+                       $dbr = wfGetDB( DB_SLAVE );
                        $wl_clause = array(
                                'wl_title'     => $page->getDBkey(),
                                'wl_namespace' => $page->getNamespace() );
@@ -2714,7 +2858,7 @@ class Article {
                        return false;
                }
 
-               $dbr =& wfGetDB( DB_SLAVE );
+               $dbr = wfGetDB( DB_SLAVE );
 
                $rev_clause = array( 'rev_page' => $id );
 
@@ -2748,7 +2892,7 @@ class Article {
                        return array();
                }
 
-               $dbr =& wfGetDB( DB_SLAVE );
+               $dbr = wfGetDB( DB_SLAVE );
                $res = $dbr->select( array( 'templatelinks' ),
                        array( 'tl_namespace', 'tl_title' ),
                        array( 'tl_from' => $id ),
@@ -2875,7 +3019,7 @@ class Article {
 
                        $tlTemplates = array();
 
-                       $dbr =& wfGetDB( DB_SLAVE );
+                       $dbr = wfGetDB( DB_SLAVE );
                        $res = $dbr->select( array( 'templatelinks' ),
                                array( 'tl_namespace', 'tl_title' ),
                                array( 'tl_from' => $id ),
@@ -2906,7 +3050,7 @@ class Article {
                                # Whee, link updates time.
                                $u = new LinksUpdate( $this->mTitle, $parserOutput );
 
-                               $dbw =& wfGetDb( DB_MASTER );
+                               $dbw = wfGetDb( DB_MASTER );
                                $dbw->begin();
 
                                $u->doUpdate();
@@ -2918,6 +3062,4 @@ class Article {
                $wgOut->addParserOutput( $parserOutput );
        }
 
-}
-
-?>
+}
\ No newline at end of file