From b025e068713da202af834e699fe4d3cdb94fe0b1 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sun, 17 Aug 2003 11:58:33 +0000 Subject: [PATCH] Experimental patch to partially protect against simultaneous edit bug by 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 | 31 +++++++++++++++++++------------ includes/DatabaseFunctions.php | 1 + includes/EditPage.php | 6 ++++-- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index da63a4b9be..caf57735a4 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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 diff --git a/includes/DatabaseFunctions.php b/includes/DatabaseFunctions.php index bd767e8ed6..a1c438818e 100644 --- a/includes/DatabaseFunctions.php +++ b/includes/DatabaseFunctions.php @@ -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() { diff --git a/includes/EditPage.php b/includes/EditPage.php index f52905335f..7f430d6204 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -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 -- 2.20.1