r67393 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67392‎ | r67393 | r67394 >
Date:07:45, 5 June 2010
Author:aaron
Status:deferred
Tags:
Comment:
* Create autoreview group only when $wgFlaggedRevsAutoconfirm is set
* Grant 'autoreview' right to bots via UserGetRights
* Removed circular-looking isAllowed() checks from checkAutoPromote function
* Use more correct userCan() in places of isAllowed() in some places
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.class.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -187,14 +187,9 @@
188188 # namespaces autopatrolled.
189189 $wgGroupPermissions['autoconfirmed']['autopatrol'] = true;
190190
191 -# Implicit autoreview group
192 -$wgGroupPermissions['autoreview']['autoreview'] = true;
193 -# Don't show the 'autoreview' group everywhere
194 -$wgImplicitGroups[] = 'autoreview';
195 -
196191 # Define when users get automatically promoted to Editors. Set as false to disable.
197192 # 'spacing' and 'benchmarks' require edits to be spread out. Users must have X (benchmark)
198 -# edits Y (spacing) days apart. Set to false to disable.
 193+# edits Y (spacing) days apart.
199194 $wgFlaggedRevsAutopromote = array(
200195 'days' => 60, # days since registration
201196 'edits' => 250, # total edit count
@@ -214,10 +209,9 @@
215210 'maxRevertedEdits' => 5, # Max edits the user could have had rolled back?
216211 );
217212
218 -# Define when users get to have their own edits auto-reviewed.
 213+# Define when users get to have their own edits auto-reviewed. Set to false to disable.
219214 # This can be used for newer, semi-trusted users to improve workflow.
220215 # It is done by granting some users the implicit 'autoreview' group.
221 -# Set to false to disable.
222216 $wgFlaggedRevsAutoconfirm = false;
223217 /* (example usage)
224218 $wgFlaggedRevsAutoconfirm = array(
@@ -553,6 +547,9 @@
554548 # Save stability settings
555549 $wgHooks['ProtectionForm::save'][] = 'FlaggedRevsHooks::onProtectionSave';
556550 }
 551+ # Give bots the 'autoreview' right (here so it triggers after CentralAuth)
 552+ # @TODO: better way to ensure hook order
 553+ $wgHooks['UserGetRights'][] = 'FlaggedRevsHooks::onUserGetRights';
557554 }
558555
559556 # ####### END HOOK TRIGGERED FUNCTIONS #########
@@ -591,7 +588,7 @@
592589 }
593590
594591 function efSetFlaggedRevsConditionalRights() {
595 - global $wgGroupPermissions;
 592+ global $wgGroupPermissions, $wgImplicitGroups, $wgFlaggedRevsAutoconfirm;
596593 if ( FlaggedRevs::stableOnlyIfConfigured() ) {
597594 // Removes sp:ListGroupRights cruft
598595 if ( isset( $wgGroupPermissions['editor'] ) ) {
@@ -601,6 +598,12 @@
602599 unset( $wgGroupPermissions['reviewer']['unreviewedpages'] );
603600 }
604601 }
 602+ if ( !empty( $wgFlaggedRevsAutoconfirm ) ) {
 603+ # Implicit autoreview group
 604+ $wgGroupPermissions['autoreview']['autoreview'] = true;
 605+ # Don't show the 'autoreview' group everywhere
 606+ $wgImplicitGroups[] = 'autoreview';
 607+ }
605608 }
606609
607610 function efSetFlaggedRevsConditionalPreferences() {
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -438,8 +438,9 @@
439439 */
440440 public static function userCanSetFlags( $flags, $oldflags = array() ) {
441441 global $wgUser;
442 - if ( !$wgUser->isAllowed( 'review' ) )
 442+ if ( !$wgUser->isAllowed( 'review' ) ) {
443443 return false; // User is not able to review pages
 444+ }
444445 # Check if all of the required site flags have a valid value
445446 # that the user is allowed to set.
446447 foreach ( self::getDimensions() as $qal => $levels ) {
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
@@ -176,16 +176,17 @@
177177 }
178178
179179 // Mark when an unreviewed page is being reviewed
180 - public static function maybeMarkUnderReview( $article, $user, $request ) {
181 - if ( !$user->isAllowed( 'review' ) ) {
182 - return true; // user cannot review
183 - }
 180+ public static function maybeMarkUnderReview(
 181+ Article $article, User $user, WebRequest $request
 182+ ) {
 183+ global $wgMemc;
184184 # Set a key to note when someone is reviewing this.
185185 # NOTE: diff-to-stable views already handled elsewhere.
186186 if ( $request->getInt( 'reviewing' ) || $request->getInt( 'rcid' ) ) {
187 - global $wgMemc;
188 - $key = wfMemcKey( 'unreviewedPages', 'underReview', $article->getId() );
189 - $wgMemc->set( $key, '1', 20 * 60 ); // 20 min
 187+ if ( $article->getTitle()->userCan( 'review' ) ) {
 188+ $key = wfMemcKey( 'unreviewedPages', 'underReview', $article->getId() );
 189+ $wgMemc->set( $key, '1', 20 * 60 ); // 20 min
 190+ }
190191 }
191192 return true;
192193 }
@@ -260,13 +261,16 @@
261262 * Update pending revision table
262263 * Autoreview pages moved into content NS
263264 */
264 - public static function onTitleMoveComplete( &$otitle, &$ntitle, $user, $pageId ) {
 265+ public static function onTitleMoveComplete(
 266+ Title $otitle, Title $ntitle, User $user, $pageId
 267+ ) {
265268 $fa = FlaggedArticle::getTitleInstance( $ntitle );
266269 // Re-validate NS/config (new title may not be reviewable)
267270 if ( $fa->isReviewable( FR_MASTER ) ) {
268271 // Moved from non-reviewable to reviewable NS?
269 - if ( FlaggedRevs::autoReviewNewPages() && $user->isAllowed( 'autoreview' )
270 - && !FlaggedRevs::inReviewNamespace( $otitle ) )
 272+ if ( !FlaggedRevs::inReviewNamespace( $otitle )
 273+ && FlaggedRevs::autoReviewNewPages()
 274+ && $ntitle->userCan( 'autoreview' ) )
271275 {
272276 $rev = Revision::newFromTitle( $ntitle );
273277 // Treat this kind of like a new page...
@@ -883,7 +887,7 @@
884888 * Note: RC items not inserted yet, RecentChange_save hook does rc_patrolled bit...
885889 */
886890 public static function maybeMakeEditReviewed(
887 - $article, $rev, $baseRevId = false, $user = null
 891+ Article $article, $rev, $baseRevId = false, $user = null
888892 ) {
889893 global $wgRequest;
890894 # Edit must be non-null, and to a reviewable page
@@ -894,7 +898,7 @@
895899 if ( !$user ) {
896900 $user = User::newFromId( $rev->getUser() );
897901 }
898 - $title = $article->getTitle();
 902+ $title = $article->getTitle(); // convenience
899903 $title->resetArticleID( $rev->getPage() ); // Avoid extra DB hit and lag issues
900904 # Get what was just the current revision ID
901905 $prevRevId = $rev->getParentId();
@@ -904,7 +908,7 @@
905909 # Is the page manually checked off to be reviewed?
906910 if ( $editTimestamp
907911 && $wgRequest->getCheck( 'wpReviewEdit' )
908 - && $user->isAllowed( 'review' ) )
 912+ && $title->userCan( 'review' ) )
909913 {
910914 if ( self::editCheckReview( $article, $rev, $user, $editTimestamp ) ) {
911915 return true; // reviewed...done!
@@ -1072,7 +1076,7 @@
10731077 # Is the page checked off to be reviewed?
10741078 if ( $editTimestamp
10751079 && $wgRequest->getCheck( 'wpReviewEdit' )
1076 - && $user->isAllowed( 'review' ) )
 1080+ && $title->userCan( 'review' ) )
10771081 {
10781082 # Check wpEdittime against current revision's time.
10791083 # If an edit was auto-merged in between, review only up to what
@@ -1217,38 +1221,45 @@
12181222 }
12191223
12201224 /**
1221 - * (a) Grant implicit 'autoreview' group for users meeting $wgFlaggedRevsAutoconfirm
1222 - * requirements that don't already have the 'autoreview' right. This lets people
1223 - * who opt-out as Editors still have their own edits automatically reviewed.
1224 - * (b) Grant implicit 'autoreview' group for user with the 'bot' right that don't
1225 - * already have the 'autoreview' right.
 1225+ * Grant 'autoreview' rights to users with the 'bot' right
 1226+ */
 1227+ public static function onUserGetRights( User $user, array &$rights ) {
 1228+ # Make sure bots always have the 'autoreview' right
 1229+ if ( in_array( 'bot', $rights ) && !in_array( 'autoreview', $rights ) ) {
 1230+ $rights[] = 'autoreview';
 1231+ }
 1232+ return true;
 1233+ }
 1234+
 1235+ /**
 1236+ * Grant implicit 'autoreview' group to users meeting the
 1237+ * $wgFlaggedRevsAutoconfirm requirements. This lets people who
 1238+ * opt-out as Editors still have their own edits automatically reviewed.
 1239+ *
12261240 * Note: some unobtrusive caching is used to avoid DB hits.
12271241 */
1228 - public static function checkAutoPromote( $user, &$promote ) {
 1242+ public static function checkAutoPromote( User $user, array &$promote ) {
12291243 global $wgFlaggedRevsAutoconfirm, $wgMemc;
1230 - # Make sure bots always have autoreview
1231 - if ( $user->isAllowed( 'bot' ) ) {
1232 - $promote[] = 'autoreview'; // add the group
1233 - return true;
1234 - }
12351244 # Check if $wgFlaggedRevsAutoconfirm is actually enabled
12361245 # and that this is a logged-in user that doesn't already
12371246 # have the 'autoreview' permission
1238 - if ( !$user->getId() || $user->isAllowed( 'autoreview' )
1239 - || empty( $wgFlaggedRevsAutoconfirm ) )
1240 - {
 1247+ if ( !$user->getId() || empty( $wgFlaggedRevsAutoconfirm ) ) {
12411248 return true;
12421249 }
12431250 # Check if results are cached to avoid DB queries.
12441251 # Checked basic, already available, promotion heuristics first...
12451252 $APSkipKey = wfMemcKey( 'flaggedrevs', 'autoreview-skip', $user->getId() );
12461253 $value = $wgMemc->get( $APSkipKey );
1247 - if ( $value === 'true' ) return true;
 1254+ if ( $value === 'true' ) {
 1255+ return true;
 1256+ }
12481257 # Check $wgFlaggedRevsAutoconfirm settings...
12491258 $now = time();
12501259 $userCreation = wfTimestampOrNull( TS_UNIX, $user->getRegistration() );
12511260 # User registration was not always tracked in DB...use null for such cases
1252 - $userage = $userCreation ? floor( ( $now - $userCreation ) / 86400 ) : null;
 1261+ $userage = $userCreation
 1262+ ? floor( ( $now - $userCreation ) / 86400 )
 1263+ : null;
12531264 $p = FlaggedRevs::getUserParams( $user->getId() );
12541265 # Check if user edited enough content pages
12551266 $totalCheckedEditsNeeded = false;

Status & tagging log