(bug 1150) Do not skip edit conflict and override just because editing user was the...
authorAaron Schulz <aaron@users.mediawiki.org>
Mon, 13 Oct 2008 14:48:17 +0000 (14:48 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Mon, 13 Oct 2008 14:48:17 +0000 (14:48 +0000)
includes/EditPage.php

index 4133c0f..bf43177 100644 (file)
@@ -914,7 +914,7 @@ class EditPage {
                }
 
                # Suppress edit conflict with self, except for section edits where merging is required.
-               if ( ( $this->section == '' ) && ( 0 != $userid ) && ( $this->mArticle->getUser() == $userid ) ) {
+               if ( $this->section == '' && $userid && $this->userWasLastToEdit($userid,$this->edittime) ) {
                        wfDebug( "EditPage::editForm Suppressing edit conflict, same user.\n" );
                        $this->isConflict = false;
                } else {
@@ -1022,6 +1022,27 @@ class EditPage {
                return self::AS_END;
        }
        
+       /**
+        * Check if no edits were made by other users since
+        * the time a user started editing the page. Limit to
+        * 20 revisions for the sake of sanity.
+        */
+       protected function userWasLastToEdit( $id, $edittime ) {
+               $dbw = wfGetDB( DB_MASTER );
+               $res = $dbw->select( 'revision',
+                       'rev_user',
+                       array( 'rev_page' => $this->mArticle->getId(),
+                               'rev_timestamp > '.$dbw->timestamp($edittime) ),
+                       __METHOD__,
+                       array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 20 ) );
+               while( $row = $res->fetchObject() ) {
+                       if( $row->rev_user != $id ) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+       
        /**
         * Check given input text against $wgSpamRegex, and return the text of the first match.
         * @return mixed -- matching string or false