Cleanup for r43315 (per aaron's comment): remove extra set of parenthesis
[lhc/web/wiklou.git] / includes / Article.php
index 7b41a08..f64e9f4 100644 (file)
@@ -448,7 +448,7 @@ class Article {
 
                // FIXME: Horrible, horrible! This content-loading interface just plain sucks.
                // We should instead work with the Revision object when we need it...
-               $this->mContent   = $revision->revText(); // Loads if user is allowed
+               $this->mContent   = $revision->getText( Revision::FOR_THIS_USER ); // Loads if user is allowed
 
                $this->mUser      = $revision->getUser();
                $this->mUserText  = $revision->getUserText();
@@ -813,15 +813,26 @@ class Article {
                        if ($this->getID() == 0) {
                                $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut );
                                $pager = new LogPager( $loglist, 'delete', false, $this->mTitle->getPrefixedText() );
-                               if( $pager->getNumRows() > 0 ) {
-                                       $wgOut->addHtml( '<div id="mw-deleted-notice">' );
+                               $count = $pager->getNumRows();
+                               if( $count > 0 ) {
+                                       $pager->mLimit = 10;
+                                       $wgOut->addHTML( '<div class="mw-warning-with-logexcerpt">' );
                                        $wgOut->addWikiMsg( 'deleted-notice' );
                                        $wgOut->addHTML(
                                                $loglist->beginLogEventsList() .
                                                $pager->getBody() .
                                                $loglist->endLogEventsList()
                                        );
-                                       $wgOut->addHtml( '</div>' );
+                                       if($count > 10){
+                                               $wgOut->addHTML( $wgUser->getSkin()->link(
+                                                       SpecialPage::getTitleFor( 'Log' ),
+                                                       wfMsgHtml( 'deletelog-fulllog' ),
+                                                       array(),
+                                                       array(
+                                                               'type' => 'delete',
+                                                               'page' => $this->mTitle->getPrefixedText() ) ) );
+                                       }
+                                       $wgOut->addHTML( '</div>' );
                                }
                        }
                        $text = $this->getContent();
@@ -869,15 +880,15 @@ class Article {
 
                         // Pages containing custom CSS or JavaScript get special treatment
                        if( $this->mTitle->isCssOrJsPage() || $this->mTitle->isCssJsSubpage() ) {
-                               $wgOut->addHtml( wfMsgExt( 'clearyourcache', 'parse' ) );
+                               $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
                                        $m = array();
                                        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" );
+                                       $wgOut->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
+                                       $wgOut->addHTML( htmlspecialchars( $this->mContent ) );
+                                       $wgOut->addHTML( "\n</pre>\n" );
                                }
                        } else if ( $rt = Title::newFromRedirect( $text ) ) {
                                # Don't append the subtitle if this was an old revision
@@ -1064,17 +1075,16 @@ class Article {
                                $this->view();
                        }
                } else {
-                       $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
-                       $action = htmlspecialchars( $_SERVER['REQUEST_URI'] );
-                       $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) );
-                       $msg = str_replace( '$1',
-                               "<form method=\"post\" action=\"$action\">\n" .
-                               "<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" .
-                               "</form>\n", $msg );
-
+                       $action = htmlspecialchars( $wgRequest->getRequestURL() );
+                       $button = wfMsgExt( 'confirm_purge_button', array('escapenoentities') );
+                       $form = "<form method=\"post\" action=\"$action\">\n" .
+                                       "<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" .
+                                       "</form>\n";
+                       $top = wfMsgExt( 'confirm-purge-top', array('parse') );
+                       $bottom = wfMsgExt( 'confirm-purge-bottom', array('parse') );
                        $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
                        $wgOut->setRobotPolicy( 'noindex,nofollow' );
-                       $wgOut->addHTML( $msg );
+                       $wgOut->addHTML( $top . $form . $bottom );
                }
        }
 
@@ -1114,7 +1124,7 @@ class Article {
         * Best if all done inside a transaction.
         *
         * @param Database $dbw
-        * @return int     The newly created page_id key
+        * @return int     The newly created page_id key, or false if the title already existed
         * @private
         */
        function insertOn( $dbw ) {
@@ -1133,13 +1143,15 @@ class Article {
                        'page_touched'      => $dbw->timestamp(),
                        'page_latest'       => 0, # Fill this in shortly...
                        'page_len'          => 0, # Fill this in shortly...
-               ), __METHOD__ );
-               $newid = $dbw->insertId();
-
-               $this->mTitle->resetArticleId( $newid );
+               ), __METHOD__, 'IGNORE' );
 
+               $affected = $dbw->affectedRows();
+               if ( $affected ) {
+                       $newid = $dbw->insertId();
+                       $this->mTitle->resetArticleId( $newid );
+               }
                wfProfileOut( __METHOD__ );
-               return $newid;
+               return $affected ? $newid : false;
        }
 
        /**
@@ -1352,29 +1364,31 @@ class Article {
                        ( $minor ? EDIT_MINOR : 0 ) |
                        ( $forceBot ? EDIT_FORCE_BOT : 0 );
 
-               $good = $this->doEdit( $text, $summary, $flags );
-               if ( $good ) {
-                       $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();
-                               }
+               $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 ) );
+               $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 $good;
+               $this->doRedirect( $this->isRedirect( $text ), $sectionanchor, $extraQuery );
+               return true;
        }
 
        /**
@@ -1404,13 +1418,27 @@ class Article {
         *          Fill in blank summaries with generated text where possible
         *
         * If neither EDIT_NEW nor EDIT_UPDATE is specified, the status of the article will be detected.
-        * If EDIT_UPDATE is specified and the article doesn't exist, the function will return false. If
-        * EDIT_NEW is specified and the article does exist, a duplicate key error will cause an exception
-        * to be thrown from the Database. These two conditions are also possible with auto-detection due
-        * to MediaWiki's performance-optimised locking strategy.
+        * If EDIT_UPDATE is specified and the article doesn't exist, the function will an 
+        * edit-gone-missing error. If EDIT_NEW is specified and the article does exist, an 
+        * edit-already-exists error will be returned. These two conditions are also possible with 
+        * auto-detection due to MediaWiki's performance-optimised locking strategy.
+        *
         * @param $baseRevId, the revision ID this edit was based off, if any
         *
-        * @return bool success
+        * @return Status object. Possible errors:
+        *     edit-hook-aborted:       The ArticleSave hook aborted the edit but didn't set the fatal flag of $status
+        *     edit-gone-missing:       In update mode, but the article didn't exist
+        *     edit-conflict:           In update mode, the article changed unexpectedly
+        *     edit-no-change:          Warning that the text was the same as before
+        *     edit-already-exists:     In creation mode, but the article already exists
+        *
+        *  Extensions may define additional errors.
+        *
+        *  $return->value will contain an associative array with members as follows:
+        *     new:                     Boolean indicating if the function attempted to create a new article
+        *     revision:                The revision object for the inserted revision, or null
+        *
+        *  Compatibility note: this function previously returned a boolean value indicating success/failure
         */
        function doEdit( $text, $summary, $flags = 0, $baseRevId = false, $user = null ) {
                global $wgUser, $wgDBtransactions, $wgUseAutomaticEditSummaries;
@@ -1425,10 +1453,13 @@ class Article {
                if ($user == null) {
                        $user = $wgUser;
                }
-               $good = true;
+               $status = Status::newGood( array() );
+
+               # Load $this->mTitle->getArticleID() and $this->mLatest if it's not already
+               $this->loadPageData(); 
 
                if ( !($flags & EDIT_NEW) && !($flags & EDIT_UPDATE) ) {
-                       $aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE );
+                       $aid = $this->mTitle->getArticleID();
                        if ( $aid ) {
                                $flags |= EDIT_UPDATE;
                        } else {
@@ -1438,11 +1469,14 @@ class Article {
 
                if( !wfRunHooks( 'ArticleSave', array( &$this, &$user, &$text,
                        &$summary, $flags & EDIT_MINOR,
-                       null, null, &$flags ) ) )
+                       null, null, &$flags, &$status ) ) )
                {
                        wfDebug( __METHOD__ . ": ArticleSave hook aborted save!\n" );
                        wfProfileOut( __METHOD__ );
-                       return false;
+                       if ( $status->isOK() ) {
+                               $status->fatal( 'edit-hook-aborted');
+                       }
+                       return $status;
                }
 
                # Silently ignore EDIT_MINOR if not allowed
@@ -1466,13 +1500,13 @@ class Article {
 
                if ( $flags & EDIT_UPDATE ) {
                        # Update article, but only if changed.
+                       $status->value['new'] = false;
 
                        # Make sure the revision is either completely inserted or not inserted at all
                        if( !$wgDBtransactions ) {
                                $userAbort = ignore_user_abort( true );
                        }
 
-                       $lastRevision = 0;
                        $revisionId = 0;
 
                        $changed = ( strcmp( $text, $oldtext ) != 0 );
@@ -1482,14 +1516,12 @@ class Article {
                                  - (int)$this->isCountable( $oldtext );
                                $this->mTotalAdjustment = 0;
 
-                               $lastRevision = $dbw->selectField(
-                                       'page', 'page_latest', array( 'page_id' => $this->getId() ) );
-
-                               if ( !$lastRevision ) {
+                               if ( !$this->mLatest ) {
                                        # Article gone missing
                                        wfDebug( __METHOD__.": EDIT_UPDATE specified but article doesn't exist\n" );
+                                       $status->fatal( 'edit-gone-missing' );
                                        wfProfileOut( __METHOD__ );
-                                       return false;
+                                       return $status;
                                }
 
                                $revision = new Revision( array(
@@ -1497,7 +1529,7 @@ class Article {
                                        'comment'    => $summary,
                                        'minor_edit' => $isminor,
                                        'text'       => $text,
-                                       'parent_id'  => $lastRevision,
+                                       'parent_id'  => $this->mLatest,
                                        'user'       => $user->getId(),
                                        'user_text'  => $user->getName(),
                                        ) );
@@ -1506,11 +1538,22 @@ class Article {
                                $revisionId = $revision->insertOn( $dbw );
 
                                # Update page
-                               $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
+                               #
+                               # Note that we use $this->mLatest instead of fetching a value from the master DB 
+                               # during the course of this function. This makes sure that EditPage can detect 
+                               # edit conflicts reliably, either by $ok here, or by $article->getTimestamp() 
+                               # before this function is called. A previous function used a separate query, this
+                               # creates a window where concurrent edits can cause an ignored edit conflict.
+                               $ok = $this->updateRevisionOn( $dbw, $revision, $this->mLatest );
 
                                if( !$ok ) {
                                        /* Belated edit conflict! Run away!! */
-                                       $good = false;
+                                       $status->fatal( 'edit-conflict' );
+                                       # Delete the invalid revision if the DB is not transactional
+                                       if ( !$wgDBtransactions ) {
+                                               $dbw->delete( 'revision', array( 'rev_id' => $revisionId ), __METHOD__ );
+                                       }
+                                       $revisionId = 0;
                                        $dbw->rollback();
                                } else {
                                        wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, $baseRevId ) );
@@ -1518,7 +1561,7 @@ class Article {
                                        # Update recentchanges
                                        if( !( $flags & EDIT_SUPPRESS_RC ) ) {
                                                $rc = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $user, $summary,
-                                                       $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
+                                                       $this->mLatest, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
                                                        $revisionId );
 
                                                # Mark as patrolled if the user can do so
@@ -1530,6 +1573,7 @@ class Article {
                                        $dbw->commit();
                                }
                        } else {
+                               $status->warning( 'edit-no-change' );
                                $revision = null;
                                // Keep the same revision ID, but do some updates on it
                                $revisionId = $this->getRevIdFetched();
@@ -1541,16 +1585,20 @@ class Article {
                        if( !$wgDBtransactions ) {
                                ignore_user_abort( $userAbort );
                        }
-
-                       if ( $good ) {
-                               # Invalidate cache of this article and all pages using this article
-                               # as a template. Partly deferred.
-                               Article::onArticleEdit( $this->mTitle, false ); // leave templatelinks for editUpdates()
-                               # Update links tables, site stats, etc.
-                               $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, $changed );
+                       // Now that ignore_user_abort is restored, we can respond to fatal errors
+                       if ( !$status->isOK() ) {
+                               wfProfileOut( __METHOD__ );
+                               return $status;
                        }
+
+                       # Invalidate cache of this article and all pages using this article
+                       # as a template. Partly deferred. Leave templatelinks for editUpdates().
+                       Article::onArticleEdit( $this->mTitle, 'skiptransclusions' );
+                       # Update links tables, site stats, etc.
+                       $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, $changed );
                } else {
                        # Create new article
+                       $status->value['new'] = true;
 
                        # Set statistics members
                        # We work out if it's countable after PST to avoid counter drift
@@ -1558,10 +1606,19 @@ class Article {
                        $this->mGoodAdjustment = (int)$this->isCountable( $text );
                        $this->mTotalAdjustment = 1;
 
+                       $dbw->begin();
+
                        # Add the page record; stake our claim on this title!
-                       # This will fail with a database query exception if the article already exists
+                       # This will return false if the article already exists
                        $newid = $this->insertOn( $dbw );
 
+                       if ( $newid === false ) {
+                               $dbw->rollback();
+                               $status->fatal( 'edit-already-exists' );
+                               wfProfileOut( __METHOD__ );
+                               return $status;
+                       }
+
                        # Save the revision text...
                        $revision = new Revision( array(
                                'page'       => $newid,
@@ -1589,6 +1646,7 @@ class Article {
                                }
                        }
                        $user->incEditCount();
+                       $dbw->commit();
 
                        # Update links, etc.
                        $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, true );
@@ -1600,17 +1658,19 @@ class Article {
                                $flags & EDIT_MINOR, null, null, &$flags, $revision ) );
                }
 
-               if ( $good && !( $flags & EDIT_DEFER_UPDATES ) ) {
+               # Do updates right now unless deferral was requested
+               if ( !( $flags & EDIT_DEFER_UPDATES ) ) {
                        wfDoUpdates();
                }
 
-               if ( $good ) {
-                       wfRunHooks( 'ArticleSaveComplete', array( &$this, &$user, $text, $summary,
-                               $flags & EDIT_MINOR, null, null, &$flags, $revision ) );
-               }
+               // Return the new revision (or null) to the caller
+               $status->value['revision'] = $revision;
+
+               wfRunHooks( 'ArticleSaveComplete', array( &$this, &$user, $text, $summary,
+                       $flags & EDIT_MINOR, null, null, &$flags, $revision, &$status ) );
 
                wfProfileOut( __METHOD__ );
-               return $good;
+               return $status;
        }
 
        /**
@@ -2137,7 +2197,7 @@ class Article {
         * @return int approximate revision count
         */
        function estimateRevisionCount() {
-               $dbr = wfGetDB();
+               $dbr = wfGetDB( DB_SLAVE );
                // For an exact count...
                //return $dbr->selectField( 'revision', 'COUNT(*)',
                //      array( 'rev_page' => $this->getId() ), __METHOD__ );
@@ -2196,8 +2256,7 @@ class Article {
         * @param $reason string Prefilled reason
         */
        function confirmDelete( $reason ) {
-               global $wgOut, $wgUser, $wgContLang;
-               $align = $wgContLang->isRtl() ? 'left' : 'right';
+               global $wgOut, $wgUser;
 
                wfDebug( "Article::confirmDelete\n" );
 
@@ -2206,46 +2265,55 @@ class Article {
                $wgOut->addWikiMsg( 'confirmdeletetext' );
 
                if( $wgUser->isAllowed( 'suppressrevision' ) ) {
-                       $suppress = "<tr id=\"wpDeleteSuppressRow\" name=\"wpDeleteSuppressRow\"><td></td><td>";
-                       $suppress .= Xml::checkLabel( wfMsg( 'revdelete-suppress' ), 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '2' ) );
-                       $suppress .= "</td></tr>";
+                       $suppress = "<tr id=\"wpDeleteSuppressRow\" name=\"wpDeleteSuppressRow\">
+                                       <td></td>
+                                       <td class='mw-input'>" .
+                                               Xml::checkLabel( wfMsg( 'revdelete-suppress' ),
+                                                       'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
+                                       "</td>
+                               </tr>";
                } else {
                        $suppress = '';
                }
+               $checkWatch = $wgUser->getBoolOption( 'watchdeletion' ) || $this->mTitle->userIsWatching();
 
-               $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->mTitle->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
+               $form = Xml::openElement( 'form', array( 'method' => 'post', 
+                       'action' => $this->mTitle->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
                        Xml::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
                        Xml::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
-                       Xml::openElement( 'table' ) .
+                       Xml::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
                        "<tr id=\"wpDeleteReasonListRow\">
-                               <td align='$align'>" .
+                               <td class='mw-label'>" .
                                        Xml::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
                                "</td>
-                               <td>" .
+                               <td class='mw-input'>" .
                                        Xml::listDropDown( 'wpDeleteReasonList',
                                                wfMsgForContent( 'deletereason-dropdown' ),
                                                wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
                                "</td>
                        </tr>
                        <tr id=\"wpDeleteReasonRow\">
-                               <td align='$align'>" .
+                               <td class='mw-label'>" .
                                        Xml::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
                                "</td>
-                               <td>" .
-                                       Xml::input( 'wpReason', 60, $reason, array( 'type' => 'text', 'maxlength' => '255', 'tabindex' => '2', 'id' => 'wpReason' ) ) .
+                               <td class='mw-input'>" .
+                                       Xml::input( 'wpReason', 60, $reason, array( 'type' => 'text', 'maxlength' => '255', 
+                                               'tabindex' => '2', 'id' => 'wpReason' ) ) .
                                "</td>
                        </tr>
                        <tr>
                                <td></td>
-                               <td>" .
-                                       Xml::checkLabel( wfMsg( 'watchthis' ), 'wpWatch', 'wpWatch', $wgUser->getBoolOption( 'watchdeletion' ) || $this->mTitle->userIsWatching(), array( 'tabindex' => '3' ) ) .
+                               <td class='mw-input'>" .
+                                       Xml::checkLabel( wfMsg( 'watchthis' ),
+                                               'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
                                "</td>
                        </tr>
                        $suppress
                        <tr>
                                <td></td>
-                               <td>" .
-                                       Xml::submitButton( wfMsg( 'deletepage' ), array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '4' ) ) .
+                               <td class='mw-submit'>" .
+                                       Xml::submitButton( wfMsg( 'deletepage' ),
+                                               array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
                                "</td>
                        </tr>" .
                        Xml::closeElement( 'table' ) .
@@ -2268,7 +2336,7 @@ class Article {
         * Show relevant lines from the deletion log
         */
        function showLogExtract( $out ) {
-               $out->addHtml( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
+               $out->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
                LogEventsList::showLogExtract( $out, 'delete', $this->mTitle->getPrefixedText() );
        }
 
@@ -2297,7 +2365,7 @@ class Article {
                                $wgOut->returnToMain( false );
                                wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason, $id));
                        } else {
-                               if ($error = '')
+                               if ($error == '')
                                        $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
                                else
                                        $wgOut->showFatalError( $error );
@@ -2404,6 +2472,11 @@ class Article {
                # If using cleanup triggers, we can skip some manual deletes
                if ( !$dbw->cleanupTriggers() ) {
                        # Clean up recentchanges entries...
+                       $dbw->delete( 'recentchanges',
+                               array( 'rc_type != '.RC_LOG, 
+                                       'rc_namespace' => $this->mTitle->getNamespace(),
+                                       'rc_title' => $this->mTitle->getDBKey() ),
+                               __METHOD__ );
                        $dbw->delete( 'recentchanges',
                                array( 'rc_type != '.RC_LOG, 'rc_cur_id' => $id ),
                                __METHOD__ );
@@ -2463,7 +2536,7 @@ class Article {
 
                # Check permissions
                $errors = array_merge( $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser ),
-                                               $this->mTitle->getUserPermissionsErrors( 'rollback', $wgUser ) );
+                       $this->mTitle->getUserPermissionsErrors( 'rollback', $wgUser ) );
                if( !$wgUser->matchEditToken( $token, array( $this->mTitle->getPrefixedText(), $fromP ) ) )
                        $errors[] = array( 'sessionfailure' );
 
@@ -2567,12 +2640,18 @@ class Article {
                # Save
                $flags = EDIT_UPDATE;
 
-               if ($wgUser->isAllowed('minoredit'))
+               if( $wgUser->isAllowed('minoredit') )
                        $flags |= EDIT_MINOR;
 
                if( $bot && ($wgUser->isAllowed('markbotedits') || $wgUser->isAllowed('bot')) )
                        $flags |= EDIT_FORCE_BOT;
-               $this->doEdit( $target->getText(), $summary, $flags, $target->getId() );
+               # Actually store the edit
+               $status = $this->doEdit( $target->getText(), $summary, $flags, $target->getId() );
+               if ( !empty( $status->value['revision'] ) ) {
+                       $revId = $status->value['revision']->getId();
+               } else {
+                       $revId = false;
+               }
 
                wfRunHooks( 'ArticleRollbackComplete', array( $this, $wgUser, $target ) );
 
@@ -2580,6 +2659,7 @@ class Article {
                        'summary' => $summary,
                        'current' => $current,
                        'target' => $target,
+                       'newid' => $revId
                );
                return array();
        }
@@ -2607,7 +2687,7 @@ class Article {
                        $wgOut->rateLimited();
                        return;
                }
-               if( isset( $result[0][0] ) && ( $result[0][0] == 'alreadyrolled' || $result[0][0] == 'cantrollback' ) ){
+               if( isset( $result[0][0] ) && ( $result[0][0] == 'alreadyrolled' || $result[0][0] == 'cantrollback' ) ) {
                        $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
                        $errArray = $result[0];
                        $errMsg = array_shift( $errArray );
@@ -2615,7 +2695,8 @@ class Article {
                        if( isset( $details['current'] ) ){
                                $current = $details['current'];
                                if( $current->getComment() != '' ) {
-                                       $wgOut->addWikiMsgArray( 'editcomment', array( $wgUser->getSkin()->formatComment( $current->getComment() ) ), array( 'replaceafter' ) );
+                                       $wgOut->addWikiMsgArray( 'editcomment', array( 
+                                               $wgUser->getSkin()->formatComment( $current->getComment() ) ), array( 'replaceafter' ) );
                                }
                        }
                        return;
@@ -2642,17 +2723,18 @@ class Article {
 
                $current = $details['current'];
                $target = $details['target'];
+               $newId = $details['newid'];
                $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->addHTML( wfMsgExt( 'rollback-success', array( 'parse', 'replaceafter' ), $old, $new ) );
                $wgOut->returnToMain( false, $this->mTitle );
 
-               if( !$wgRequest->getBool( 'hidediff', false ) ) {
-                       $de = new DifferenceEngine( $this->mTitle, $current->getId(), 'next', false, true );
+               if( !$wgRequest->getBool( 'hidediff', false ) && !$wgUser->getBoolOption( 'norollbackdiff', false ) ) {
+                       $de = new DifferenceEngine( $this->mTitle, $current->getId(), $newId, false, true );
                        $de->showDiff( '', '' );
                }
        }
@@ -2741,6 +2823,8 @@ class Article {
                $u = new LinksUpdate( $this->mTitle, $editInfo->output, false );
                $u->setRecursiveTouch( $changed ); // refresh/invalidate including pages too
                $u->doUpdate();
+               
+               wfRunHooks( 'ArticleEditUpdates', array( &$this, &$editInfo, $changed ) );
 
                if( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
                        if ( 0 == mt_rand( 0, 99 ) ) {
@@ -2883,7 +2967,7 @@ class Article {
                        ? 'revision-info-current'
                        : 'revision-info';
 
-               $r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" . wfMsg( $infomsg, $td, $userlinks ) . "</div>\n" .
+               $r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" . wfMsg( $infomsg, $td, $userlinks, $revision->getID() ) . "</div>\n" .
 
                     "\n\t\t\t\t<div id=\"mw-revision-nav\">" . $cdel . wfMsg( 'revision-nav', $prevdiff, 
                                $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>\n\t\t\t";
@@ -2912,13 +2996,13 @@ class Article {
                static $called = false;
                if( $called ) {
                        wfDebug( "Article::tryFileCache(): called twice!?\n" );
-                       return;
+                       return false;
                }
                $called = true;
-               if($this->isFileCacheable()) {
+               if( $this->isFileCacheable() ) {
                        $touched = $this->mTouched;
                        $cache = new HTMLFileCache( $this->mTitle );
-                       if($cache->isFileCacheGood( $touched )) {
+                       if( $cache->isFileCacheGood( $touched ) ) {
                                wfDebug( "Article::tryFileCache(): about to load file\n" );
                                $cache->loadFromFileCache();
                                return true;
@@ -2929,6 +3013,7 @@ class Article {
                } else {
                        wfDebug( "Article::tryFileCache(): not cacheable\n" );
                }
+               return false;
        }
 
        /**
@@ -2937,40 +3022,31 @@ class Article {
         */
        function isFileCacheable() {
                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' );
-               $useskin   = $wgRequest->getVal( 'useskin' );
-
-               //check for non-standard user language; this covers uselang,
-               //and extensions for auto-detecting user language.
-               $ulang     = $wgLang->getCode();
-               $clang     = $wgContLang->getCode();
+               // Get all query values
+               $queryVals = $wgRequest->getValues();
+               foreach( $queryVals as $query => $val ) {
+                       if( $query == 'title' || ($query == 'action' && $val == 'view') ) {
+                               // Normal page view in query form
+                       } else {
+                               return false;
+                       }
+               }
+               // 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)
+                       && ($this->getID() > 0)
                        && ($wgUser->isAnon())
                        && (!$wgUser->getNewtalk())
-                       && ($this->mTitle->getNamespace() != NS_SPECIAL )
-                       && (!isset($useskin))
-                       && (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.
+               // Extension may have reason to disable file caching on some pages.
+               if( $cacheable ) {
                        $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
                }
-
                return $cacheable;
        }
 
@@ -3162,11 +3238,11 @@ class Article {
        /**
         * Purge caches on page update etc
         */
-       public static function onArticleEdit( $title, $touchTemplates = true ) {
+       public static function onArticleEdit( $title, $transclusions = 'transclusions' ) {
                global $wgDeferredUpdateList, $wgUseFileCache;
 
                // Invalidate caches of articles which include this page
-               if( $touchTemplates )
+               if( $transclusions !== 'skiptransclusions' )
                        $wgDeferredUpdateList[] = new HTMLCacheUpdate( $title, 'templatelinks' );
 
                // Invalidate the caches of all pages which redirect here
@@ -3214,18 +3290,18 @@ class Article {
                $wgOut->setSubtitle( wfMsg( 'infosubtitle' ) );
 
                if( !$this->mTitle->exists() ) {
-                       $wgOut->addHtml( '<div class="noarticletext">' );
+                       $wgOut->addHTML( '<div class="noarticletext">' );
                        if( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
                                // This doesn't quite make sense; the user is asking for
                                // information about the _page_, not the message... -- RC
-                               $wgOut->addHtml( htmlspecialchars( wfMsgWeirdKey( $this->mTitle->getText() ) ) );
+                               $wgOut->addHTML( htmlspecialchars( wfMsgWeirdKey( $this->mTitle->getText() ) ) );
                        } else {
                                $msg = $wgUser->isLoggedIn()
                                        ? 'noarticletext'
                                        : 'noarticletextanon';
-                               $wgOut->addHtml( wfMsgExt( $msg, 'parse' ) );
+                               $wgOut->addHTML( wfMsgExt( $msg, 'parse' ) );
                        }
-                       $wgOut->addHtml( '</div>' );
+                       $wgOut->addHTML( '</div>' );
                } else {
                        $dbr = wfGetDB( DB_SLAVE );
                        $wl_clause = array(
@@ -3356,8 +3432,9 @@ class Article {
                # Decide what kind of autosummary is needed.
 
                # Redirect autosummaries
+               $ot = Title::newFromRedirect( $oldtext );
                $rt = Title::newFromRedirect( $newtext );
-               if( is_object( $rt ) ) {
+               if( is_object( $rt ) && ( !is_object( $ot ) || !$rt->equals( $ot ) || $ot->getFragment() != $rt->getFragment() ) ) {
                        return wfMsgForContent( 'autoredircomment', $rt->getFullText() );
                }
 
@@ -3367,14 +3444,14 @@ class Article {
                        global $wgContLang;
                        $truncatedtext = $wgContLang->truncate(
                                str_replace("\n", ' ', $newtext),
-                               max( 0, 200 - strlen( wfMsgForContent( 'autosumm-new') ) ),
+                               max( 0, 200 - strlen( wfMsgForContent( 'autosumm-new' ) ) ),
                                '...' );
                        return wfMsgForContent( 'autosumm-new', $truncatedtext );
                }
 
                # Blanking autosummaries
                if( $oldtext != '' && $newtext == '' ) {
-                       return wfMsgForContent('autosumm-blank');
+                       return wfMsgForContent( 'autosumm-blank' );
                } elseif( strlen( $oldtext ) > 10 * strlen( $newtext ) && strlen( $newtext ) < 500) {
                        # Removing more than 90% of the article
                        global $wgContLang;
@@ -3400,7 +3477,7 @@ class Article {
         * @param bool    $cache
         */
        public function outputWikiText( $text, $cache = true ) {
-               global $wgParser, $wgUser, $wgOut, $wgEnableParserCache;
+               global $wgParser, $wgUser, $wgOut, $wgEnableParserCache, $wgUseFileCache;
 
                $popts = $wgOut->parserOptions();
                $popts->setTidy(true);
@@ -3413,8 +3490,14 @@ class Article {
                        $parserCache = ParserCache::singleton();
                        $parserCache->save( $parserOutput, $this, $wgUser );
                }
+               // Make sure file cache is not used on uncacheable content.
+               // Output that has magic words in it can still use the parser cache
+               // (if enabled), though it will generally expire sooner.
+               if( $parserOutput->getCacheTime() == -1 || $parserOutput->containsOldMagic() ) {
+                       $wgUseFileCache = false;
+               }
 
-               if ( !wfReadOnly() && $this->mTitle->areRestrictionsCascading() ) {
+               if ( $this->isCurrent() && !wfReadOnly() && $this->mTitle->areRestrictionsCascading() ) {
                        // templatelinks table may have become out of sync,
                        // especially if using variable-based transclusions.
                        // For paranoia, check if things have changed and if