Experimental patch to partially protect against simultaneous edit bug by
authorBrion Vibber <brion@users.mediawiki.org>
Sun, 17 Aug 2003 11:58:33 +0000 (11:58 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sun, 17 Aug 2003 11:58:33 +0000 (11:58 +0000)
adding the conflict check to the UPDATE on cur and moving it up before
the INSERT to old. Should throw edit conflict instead of overwriting
a different revision.

includes/Article.php
includes/DatabaseFunctions.php
includes/EditPage.php

index da63a4b..caf5773 100644 (file)
@@ -421,6 +421,23 @@ class Article {
                        $this->mCountAdjustment = $this->isCountable( $text )
                          - $this->isCountable( $oldtext );
 
+                       $now = wfTimestampNow();
+                       $won = wfInvertTimestamp( $now );
+                       $sql = "UPDATE cur SET cur_text='" . wfStrencode( $text ) .
+                         "',cur_comment='" .  wfStrencode( $summary ) .
+                         "',cur_minor_edit={$me2}, cur_user=" . $wgUser->getID() .
+                         ",cur_timestamp='{$now}',cur_user_text='" .
+                         wfStrencode( $wgUser->getName() ) .
+                         "',cur_is_redirect={$redir}, cur_is_new=0, cur_touched='{$now}', inverse_timestamp='{$won}' " .
+                         "WHERE cur_id=" . $this->getID() .
+                         " AND cur_timestamp='" . $this->getTimestamp() . "'";
+                       $res = wfQuery( $sql, $fname );
+                       
+                       if( wfAffectedRows() == 0 ) {
+                               /* Belated edit conflict! Run away!! */
+                               return false;
+                       }
+
                        $sql = "INSERT INTO old (old_namespace,old_title,old_text," .
                          "old_comment,old_user,old_user_text,old_timestamp," .
                          "old_minor_edit,inverse_timestamp) VALUES (" .
@@ -435,17 +452,6 @@ class Article {
                        $res = wfQuery( $sql, $fname );
                        $oldid = wfInsertID( $res );
 
-                       $now = wfTimestampNow();
-                       $won = wfInvertTimestamp( $now );
-                       $sql = "UPDATE cur SET cur_text='" . wfStrencode( $text ) .
-                         "',cur_comment='" .  wfStrencode( $summary ) .
-                         "',cur_minor_edit={$me2}, cur_user=" . $wgUser->getID() .
-                         ",cur_timestamp='{$now}',cur_user_text='" .
-                         wfStrencode( $wgUser->getName() ) .
-                         "',cur_is_redirect={$redir}, cur_is_new=0, cur_touched='{$now}', inverse_timestamp='{$won}' " .
-                         "WHERE cur_id=" . $this->getID();
-                       wfQuery( $sql, $fname );
-
                        $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time," .
                          "rc_namespace,rc_title,rc_new,rc_minor,rc_bot,rc_cur_id,rc_user," .
                          "rc_user_text,rc_comment,rc_this_oldid,rc_last_oldid) VALUES (" .
@@ -480,7 +486,8 @@ class Article {
                        }
                }
 
-               $this->showArticle( $text, wfMsg( "updated" ) ); 
+               $this->showArticle( $text, wfMsg( "updated" ) );
+               return true;
        }
 
        # After we've either updated or inserted the article, update
index bd767e8..a1c4388 100644 (file)
@@ -116,6 +116,7 @@ function wfInsertId() { return mysql_insert_id( wfGetDB() ); }
 function wfDataSeek( $res, $row ) { return mysql_data_seek( $res, $row ); }
 function wfLastErrno() { return mysql_errno(); }
 function wfLastError() { return mysql_error(); }
+function wfAffectedRows() { return mysql_affected_rows( wfGetDB() ); }
 
 function wfLastDBquery()
 {
index f529053..7f430d6 100644 (file)
@@ -153,8 +153,10 @@ class EditPage {
                        }
                        if ( ! $isConflict ) {
                                # All's well: update the article here
-                               $this->mArticle->updateArticle( $wpTextbox1, $wpSummary, $wpMinoredit, $wpWatchthis, $wpSection );
-                               return;
+                               if($this->mArticle->updateArticle( $wpTextbox1, $wpSummary, $wpMinoredit, $wpWatchthis, $wpSection ))
+                                       return;
+                               else
+                                       $isConflict = true;
                        }
                }
                # First time through: get contents, set time for conflict