Sort out user rights when patrolling. If a user has the "autopatrol" right, then...
authorRob Church <robchurch@users.mediawiki.org>
Fri, 22 Dec 2006 19:43:20 +0000 (19:43 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Fri, 22 Dec 2006 19:43:20 +0000 (19:43 +0000)
RELEASE-NOTES
includes/Article.php
includes/DefaultSettings.php
includes/RecentChange.php
languages/messages/MessagesEn.php

index e6b7089..371fb34 100644 (file)
@@ -345,8 +345,6 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * 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 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (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 6576ccb..7332064 100644 (file)
@@ -1340,7 +1340,7 @@ class Article {
                                                        $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 @@ class Article {
                                $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 @@ class Article {
         */
        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 @@ class Article {
                        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' ) );
-                       }
-                       $rcTitle = SpecialPage::getTitleFor( 'Recentchanges' );
-                       $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
+               if( !$rcid ) {
+                       $wgOut->errorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
+                       return;
                }
-               else {
-                       $wgOut->showErrorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
+               
+               # 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;
+                       }
+               }
+               
+               # 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 dbe5937..3778bc1 100644 (file)
@@ -935,6 +935,7 @@ $wgGroupPermissions['sysop']['import']          = true;
 $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 68aeffe..998e5e4 100644 (file)
@@ -64,6 +64,24 @@ class RecentChange
                $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 @@ class RecentChange
                $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 f0d707a..9878c4b 100644 (file)
@@ -2117,6 +2117,7 @@ All transwiki import actions are logged at the [[Special:Log/import|import log]]
 '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 */