From cb8b609a39c1a2fc4441c6c30b13bf6c86647c34 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Fri, 22 Dec 2006 19:43:20 +0000 Subject: [PATCH] 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. --- RELEASE-NOTES | 7 ++-- includes/Article.php | 53 +++++++++++++++++++++++-------- includes/DefaultSettings.php | 1 + includes/RecentChange.php | 27 ++++++++++++++++ languages/messages/MessagesEn.php | 1 + 5 files changed, 73 insertions(+), 16 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index e6b70897c1..371fb34b00 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 == diff --git a/includes/Article.php b/includes/Article.php index 6576ccbc3d..7332064d99 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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 ); } /** diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index dbe5937dc3..3778bc197a 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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; diff --git a/includes/RecentChange.php b/includes/RecentChange.php index 68aeffef0e..998e5e45a4 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -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 diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index f0d707aa8c..9878c4b448 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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 */ -- 2.20.1