Merge "Added point in release notes about added ORM stuffs"
[lhc/web/wiklou.git] / includes / WikiPage.php
index 6d9170a..1378ce1 100644 (file)
@@ -540,7 +540,14 @@ class WikiPage extends Page {
                        return; // page doesn't exist or is missing page_latest info
                }
 
-               $revision = Revision::newFromPageId( $this->getId(), $latest );
+               // Bug 37225: if session S1 loads the page row FOR UPDATE, the result always includes the
+               // latest changes committed. This is true even within REPEATABLE-READ transactions, where
+               // S1 normally only sees changes committed before the first S1 SELECT. Thus we need S1 to
+               // also gets the revision row FOR UPDATE; otherwise, it may not find it since a page row
+               // UPDATE and revision row INSERT by S2 may have happened after the first S1 SELECT.
+               // http://dev.mysql.com/doc/refman/5.0/en/set-transaction.html#isolevel_repeatable-read.
+               $flags = ( $this->mDataLoadedFrom == self::DATA_FOR_UPDATE ) ? Revision::LOCKING_READ : 0;
+               $revision = Revision::newFromPageId( $this->getId(), $latest, $flags );
                if ( $revision ) { // sanity
                        $this->setLastEdit( $revision );
                }
@@ -1421,7 +1428,7 @@ class WikiPage extends Page {
         *  Compatibility note: this function previously returned a boolean value indicating success/failure
         */
        public function doEdit( $text, $summary, $flags = 0, $baseRevId = false, $user = null ) {
-               global $wgUser, $wgUseAutomaticEditSummaries;
+               global $wgUser, $wgUseAutomaticEditSummaries, $wgUseRCPatrol, $wgUseNPPatrol;
 
                # Low-level sanity check
                if ( $this->mTitle->getText() === '' ) {
@@ -1523,45 +1530,40 @@ class WikiPage extends Page {
                                $ok = $this->updateRevisionOn( $dbw, $revision, $oldid, $oldIsRedirect );
 
                                if ( !$ok ) {
-                                       /* Belated edit conflict! Run away!! */
+                                       # Belated edit conflict! Run away!!
                                        $status->fatal( 'edit-conflict' );
 
-                                       $revisionId = 0;
                                        $dbw->rollback( __METHOD__ );
-                               } else {
-                                       global $wgUseRCPatrol;
-                                       wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, $baseRevId, $user ) );
-                                       # Update recentchanges
-                                       if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
-                                               # Mark as patrolled if the user can do so
-                                               $patrolled = $wgUseRCPatrol && !count(
-                                                       $this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
-                                               # Add RC row to the DB
-                                               $rc = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $user, $summary,
-                                                       $oldid, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
-                                                       $revisionId, $patrolled
-                                               );
-
-                                               # Log auto-patrolled edits
-                                               if ( $patrolled ) {
-                                                       PatrolLog::record( $rc, true, $user );
-                                               }
+
+                                       wfProfileOut( __METHOD__ );
+                                       return $status;
+                               }
+
+                               wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, $baseRevId, $user ) );
+                               # Update recentchanges
+                               if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
+                                       # Mark as patrolled if the user can do so
+                                       $patrolled = $wgUseRCPatrol && !count(
+                                               $this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
+                                       # Add RC row to the DB
+                                       $rc = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $user, $summary,
+                                               $oldid, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
+                                               $revisionId, $patrolled
+                                       );
+
+                                       # Log auto-patrolled edits
+                                       if ( $patrolled ) {
+                                               PatrolLog::record( $rc, true, $user );
                                        }
-                                       $user->incEditCount();
-                                       $dbw->commit( __METHOD__ );
                                }
+                               $user->incEditCount();
+                               $dbw->commit( __METHOD__ );
                        } else {
                                // Bug 32948: revision ID must be set to page {{REVISIONID}} and
                                // related variables correctly
                                $revision->setId( $this->getLatest() );
                        }
 
-                       // Now that ignore_user_abort is restored, we can respond to fatal errors
-                       if ( !$status->isOK() ) {
-                               wfProfileOut( __METHOD__ );
-                               return $status;
-                       }
-
                        # Update links tables, site stats, etc.
                        $this->doEditUpdates( $revision, $user, array( 'changed' => $changed,
                                'oldcountable' => $oldcountable ) );
@@ -1613,8 +1615,6 @@ class WikiPage extends Page {
 
                        # Update recentchanges
                        if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
-                               global $wgUseRCPatrol, $wgUseNPPatrol;
-
                                # Mark as patrolled if the user can do so
                                $patrolled = ( $wgUseRCPatrol || $wgUseNPPatrol ) && !count(
                                        $this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );