r18496 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r18495 | r18496 (on ViewVC) | r18497 >
Date:19:43, 22 December 2006
Author:robchurch
Status:new
Tags:
Comment:Sort out user rights when patrolling. If a user has the "autopatrol" right, then their edits are auto-marked as patrolled. If a user *doesn't* have this right, then they can't mark their own edits as patrolled in the normal fashion.
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/Article.php
===================================================================
--- trunk/phase3/includes/Article.php	(revision 18495)
+++ trunk/phase3/includes/Article.php	(revision 18496)
@@ -1340,7 +1340,7 @@
 							$revisionId );
 							
 						# Mark as patrolled if the user can do so
-						if( $wgUser->isAllowed( 'patrol' ) ) {
+						if( $wgUser->isAllowed( 'autopatrol' ) ) {
 							RecentChange::markPatrolled( $rcid );
 						}
 					}
@@ -1401,7 +1401,7 @@
 				$rcid = RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary, $bot,
 				  '', strlen( $text ), $revisionId );
 				# Mark as patrolled if the user can
-				if( $wgUser->isAllowed( 'patrol' ) ) {
+				if( $wgUser->isAllowed( 'autopatrol' ) ) {
 					RecentChange::markPatrolled( $rcid );
 				}
 			}
@@ -1461,7 +1461,7 @@
 	 */
 	function markpatrolled() {
 		global $wgOut, $wgRequest, $wgUseRCPatrol, $wgUser;
-		$wgOut->setRobotpolicy( 'noindex,nofollow' );
+		$wgOut->setRobotPolicy( 'noindex,nofollow' );
 
 		# Check RC patrol config. option
 		if( !$wgUseRCPatrol ) {
@@ -1475,20 +1475,45 @@
 			return;
 		}
 		
+		# If we haven't been given an rc_id value, we can't do anything
 		$rcid = $wgRequest->getVal( 'rcid' );
-		if ( !is_null ( $rcid ) ) {
-			if( wfRunHooks( 'MarkPatrolled', array( &$rcid, &$wgUser, false ) ) ) {
-				RecentChange::markPatrolled( $rcid );
-				wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, false ) );
-				$wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
-				$wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
+		if( !$rcid ) {
+			$wgOut->errorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
+			return;
+		}
+		
+		# Handle the 'MarkPatrolled' hook
+		if( !wfRunHooks( 'MarkPatrolled', array( $rcid, &$wgUser, false ) ) ) {
+			return;
+		}
+		
+		$return = SpecialPage::getTitleFor( 'Recentchanges' );
+		# If it's left up to us, check that the user is allowed to patrol this edit
+		# If the user has the "autopatrol" right, then we'll assume there are no
+		# other conditions stopping them doing so
+		if( !$wgUser->isAllowed( 'autopatrol' ) ) {
+			$rc = RecentChange::newFromId( $rcid );
+			# Graceful error handling, as we've done before here...
+			# (If the recent change doesn't exist, then it doesn't matter whether
+			# the user is allowed to patrol it or not; nothing is going to happen
+			if( is_object( $rc ) && $wgUser->getName() == $rc->getAttribute( 'rc_user_text' ) ) {
+				# The user made this edit, and can't patrol it
+				# Tell them so, and then back off
+				$wgOut->setPageTitle( wfMsg( 'markedaspatrollederror' ) );
+				$wgOut->addWikiText( wfMsgNoTrans( 'markedaspatrollederror-noautopatrol' ) );
+				$wgOut->returnToMain( false, $return );
+				return;
 			}
-			$rcTitle = SpecialPage::getTitleFor( 'Recentchanges' );
-			$wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
 		}
-		else {
-			$wgOut->showErrorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
-		}
+		
+		# Mark the edit as patrolled
+		RecentChange::markPatrolled( $rcid );
+		wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, false ) );
+		
+		# Inform the user
+		$wgOut->setPageTitle( wfMsg( 'markedaspatrolled' ) );
+		$wgOut->addWikiText( wfMsgNoTrans( 'markedaspatrolledtext' ) );
+		$wgOut->returnToMain( false, $return );
 	}
 
 	/**
Index: trunk/phase3/includes/RecentChange.php
===================================================================
--- trunk/phase3/includes/RecentChange.php	(revision 18495)
+++ trunk/phase3/includes/RecentChange.php	(revision 18496)
@@ -64,6 +64,24 @@
 		$rc->numberofWatchingusers = false;
 		return $rc;
 	}
+	
+	/**
+	 * Obtain the recent change with a given rc_id value
+	 *
+	 * @param $rcid rc_id value to retrieve
+	 * @return RecentChange
+	 */
+	public static function newFromId( $rcid ) {
+		$dbr =& wfGetDB( DB_SLAVE );
+		$res = $dbr->select( 'recentchanges', '*', array( 'rc_id' => $rcid ), __METHOD__ );
+		if( $res && $dbr->numRows( $res ) > 0 ) {
+			$row = $dbr->fetchObject( $res );
+			$dbr->freeResult( $res );
+			return self::newFromRow( $row );
+		} else {
+			return NULL;
+		}
+	}
 
 	# Accessors
 
@@ -449,6 +467,15 @@
 		$this->mExtra = array();
 	}
 
+	/**
+	 * Get an attribute value
+	 *
+	 * @param $name Attribute name
+	 * @return mixed
+	 */
+	public function getAttribute( $name ) {
+		return isset( $this->mAttribs[$name] ) ? $this->mAttribs[$name] : NULL;
+	}
 
 	/**
 	 * Gets the end part of the diff URL associated with this object
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 18495)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 18496)
@@ -935,6 +935,7 @@
 $wgGroupPermissions['sysop']['importupload']    = true;
 $wgGroupPermissions['sysop']['move']            = true;
 $wgGroupPermissions['sysop']['patrol']          = true;
+$wgGroupPermissions['sysop']['autopatrol']		= true;
 $wgGroupPermissions['sysop']['protect']         = true;
 $wgGroupPermissions['sysop']['proxyunbannable'] = true;
 $wgGroupPermissions['sysop']['rollback']        = true;
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 18495)
+++ trunk/phase3/RELEASE-NOTES	(revision 18496)
@@ -345,8 +345,6 @@
 * Don't show "you can view and copy the source of this page" message for
   pages which don't exist
 * (bug 8310) Blank line added to top of 'post' when page is blank
-* (bug 5411) Remove autopatrol preference; users who can mark edits patrolled
-  will now have their edits marked as such regardless
 * (bug 8109) Template parameters ignored in "recentchangestext"
 * Gracefully skip redirect-to-fragment on WebKit versions less than 420;
   it messes up on current versions of Safari but is ok in the latest
@@ -373,6 +371,11 @@
 * (bug 7685) Use explicit values for ar_text and ar_flags when deleting,
   for better compatibility with MySQL's strict mode
 * Update default interwiki values to reflect changed location of ursine:
+* (bug 5411) Remove autopatrol preference
+* Users who have the "autopatrol" permission will have their edits marked as
+  patrolled automatically
+* Users who do not have the "autopatrol" permission will no longer be able
+  to mark their own edits as patrolled
 
 == Languages updated ==
 
Index: trunk/phase3/languages/messages/MessagesEn.php
===================================================================
--- trunk/phase3/languages/messages/MessagesEn.php	(revision 18495)
+++ trunk/phase3/languages/messages/MessagesEn.php	(revision 18496)
@@ -2117,6 +2117,7 @@
 'rcpatroldisabledtext'  => "The Recent Changes Patrol feature is currently disabled.",
 'markedaspatrollederror'  => "Cannot mark as patrolled",
 'markedaspatrollederrortext' => "You need to specify a revision to mark as patrolled.",
+'markedaspatrollederror-noautopatrol' => 'You are not allowed to mark your own changes as patrolled.',
 
 # Monobook.js: tooltips and access keys for monobook
 'Monobook.js' => '/* tooltips and access keys */
Views
Toolbox