r42034 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r42033 | r42034 (on ViewVC) | r42035 >
Date:14:48, 13 October 2008
Author:aaron
Status:ok (Comments)
Tags:
Comment:(bug 1150) Do not skip edit conflict and override just because editing user was the last to edit. This caused removal of edits if a user edit conflicts, merges/automerges, then presses back (such as fixing a typo) and saves again. Check all users since edit time instead. If they are *all* the editing user, then go ahead and skip.
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/EditPage.php
===================================================================
--- trunk/phase3/includes/EditPage.php	(revision 42033)
+++ trunk/phase3/includes/EditPage.php	(revision 42034)
@@ -914,7 +914,7 @@
 		}
 
 		# 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 {
@@ -1023,6 +1023,27 @@
 	}
 	
 	/**
+	 * 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
 	 */

Comments

#Comment by Brion VIBBER (Talk | contribs)   19:19, 13 October 2008

Think is is reasonably ok, though my head hurts from the edit conflict scenarios. ;)

DB escaping details for the timestamp have been fixed in later revs

#Comment by NerdyNSK (Talk | contribs)   09:32, 15 October 2008
Views
Toolbox