Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php |
— | — | @@ -187,14 +187,9 @@ |
188 | 188 | # namespaces autopatrolled. |
189 | 189 | $wgGroupPermissions['autoconfirmed']['autopatrol'] = true; |
190 | 190 | |
191 | | -# Implicit autoreview group |
192 | | -$wgGroupPermissions['autoreview']['autoreview'] = true; |
193 | | -# Don't show the 'autoreview' group everywhere |
194 | | -$wgImplicitGroups[] = 'autoreview'; |
195 | | - |
196 | 191 | # Define when users get automatically promoted to Editors. Set as false to disable. |
197 | 192 | # '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. |
199 | 194 | $wgFlaggedRevsAutopromote = array( |
200 | 195 | 'days' => 60, # days since registration |
201 | 196 | 'edits' => 250, # total edit count |
— | — | @@ -214,10 +209,9 @@ |
215 | 210 | 'maxRevertedEdits' => 5, # Max edits the user could have had rolled back? |
216 | 211 | ); |
217 | 212 | |
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. |
219 | 214 | # This can be used for newer, semi-trusted users to improve workflow. |
220 | 215 | # It is done by granting some users the implicit 'autoreview' group. |
221 | | -# Set to false to disable. |
222 | 216 | $wgFlaggedRevsAutoconfirm = false; |
223 | 217 | /* (example usage) |
224 | 218 | $wgFlaggedRevsAutoconfirm = array( |
— | — | @@ -553,6 +547,9 @@ |
554 | 548 | # Save stability settings |
555 | 549 | $wgHooks['ProtectionForm::save'][] = 'FlaggedRevsHooks::onProtectionSave'; |
556 | 550 | } |
| 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'; |
557 | 554 | } |
558 | 555 | |
559 | 556 | # ####### END HOOK TRIGGERED FUNCTIONS ######### |
— | — | @@ -591,7 +588,7 @@ |
592 | 589 | } |
593 | 590 | |
594 | 591 | function efSetFlaggedRevsConditionalRights() { |
595 | | - global $wgGroupPermissions; |
| 592 | + global $wgGroupPermissions, $wgImplicitGroups, $wgFlaggedRevsAutoconfirm; |
596 | 593 | if ( FlaggedRevs::stableOnlyIfConfigured() ) { |
597 | 594 | // Removes sp:ListGroupRights cruft |
598 | 595 | if ( isset( $wgGroupPermissions['editor'] ) ) { |
— | — | @@ -601,6 +598,12 @@ |
602 | 599 | unset( $wgGroupPermissions['reviewer']['unreviewedpages'] ); |
603 | 600 | } |
604 | 601 | } |
| 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 | + } |
605 | 608 | } |
606 | 609 | |
607 | 610 | function efSetFlaggedRevsConditionalPreferences() { |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php |
— | — | @@ -438,8 +438,9 @@ |
439 | 439 | */ |
440 | 440 | public static function userCanSetFlags( $flags, $oldflags = array() ) { |
441 | 441 | global $wgUser; |
442 | | - if ( !$wgUser->isAllowed( 'review' ) ) |
| 442 | + if ( !$wgUser->isAllowed( 'review' ) ) { |
443 | 443 | return false; // User is not able to review pages |
| 444 | + } |
444 | 445 | # Check if all of the required site flags have a valid value |
445 | 446 | # that the user is allowed to set. |
446 | 447 | foreach ( self::getDimensions() as $qal => $levels ) { |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php |
— | — | @@ -176,16 +176,17 @@ |
177 | 177 | } |
178 | 178 | |
179 | 179 | // 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; |
184 | 184 | # Set a key to note when someone is reviewing this. |
185 | 185 | # NOTE: diff-to-stable views already handled elsewhere. |
186 | 186 | 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 | + } |
190 | 191 | } |
191 | 192 | return true; |
192 | 193 | } |
— | — | @@ -260,13 +261,16 @@ |
261 | 262 | * Update pending revision table |
262 | 263 | * Autoreview pages moved into content NS |
263 | 264 | */ |
264 | | - public static function onTitleMoveComplete( &$otitle, &$ntitle, $user, $pageId ) { |
| 265 | + public static function onTitleMoveComplete( |
| 266 | + Title $otitle, Title $ntitle, User $user, $pageId |
| 267 | + ) { |
265 | 268 | $fa = FlaggedArticle::getTitleInstance( $ntitle ); |
266 | 269 | // Re-validate NS/config (new title may not be reviewable) |
267 | 270 | if ( $fa->isReviewable( FR_MASTER ) ) { |
268 | 271 | // 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' ) ) |
271 | 275 | { |
272 | 276 | $rev = Revision::newFromTitle( $ntitle ); |
273 | 277 | // Treat this kind of like a new page... |
— | — | @@ -883,7 +887,7 @@ |
884 | 888 | * Note: RC items not inserted yet, RecentChange_save hook does rc_patrolled bit... |
885 | 889 | */ |
886 | 890 | public static function maybeMakeEditReviewed( |
887 | | - $article, $rev, $baseRevId = false, $user = null |
| 891 | + Article $article, $rev, $baseRevId = false, $user = null |
888 | 892 | ) { |
889 | 893 | global $wgRequest; |
890 | 894 | # Edit must be non-null, and to a reviewable page |
— | — | @@ -894,7 +898,7 @@ |
895 | 899 | if ( !$user ) { |
896 | 900 | $user = User::newFromId( $rev->getUser() ); |
897 | 901 | } |
898 | | - $title = $article->getTitle(); |
| 902 | + $title = $article->getTitle(); // convenience |
899 | 903 | $title->resetArticleID( $rev->getPage() ); // Avoid extra DB hit and lag issues |
900 | 904 | # Get what was just the current revision ID |
901 | 905 | $prevRevId = $rev->getParentId(); |
— | — | @@ -904,7 +908,7 @@ |
905 | 909 | # Is the page manually checked off to be reviewed? |
906 | 910 | if ( $editTimestamp |
907 | 911 | && $wgRequest->getCheck( 'wpReviewEdit' ) |
908 | | - && $user->isAllowed( 'review' ) ) |
| 912 | + && $title->userCan( 'review' ) ) |
909 | 913 | { |
910 | 914 | if ( self::editCheckReview( $article, $rev, $user, $editTimestamp ) ) { |
911 | 915 | return true; // reviewed...done! |
— | — | @@ -1072,7 +1076,7 @@ |
1073 | 1077 | # Is the page checked off to be reviewed? |
1074 | 1078 | if ( $editTimestamp |
1075 | 1079 | && $wgRequest->getCheck( 'wpReviewEdit' ) |
1076 | | - && $user->isAllowed( 'review' ) ) |
| 1080 | + && $title->userCan( 'review' ) ) |
1077 | 1081 | { |
1078 | 1082 | # Check wpEdittime against current revision's time. |
1079 | 1083 | # If an edit was auto-merged in between, review only up to what |
— | — | @@ -1217,38 +1221,45 @@ |
1218 | 1222 | } |
1219 | 1223 | |
1220 | 1224 | /** |
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 | + * |
1226 | 1240 | * Note: some unobtrusive caching is used to avoid DB hits. |
1227 | 1241 | */ |
1228 | | - public static function checkAutoPromote( $user, &$promote ) { |
| 1242 | + public static function checkAutoPromote( User $user, array &$promote ) { |
1229 | 1243 | 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 | | - } |
1235 | 1244 | # Check if $wgFlaggedRevsAutoconfirm is actually enabled |
1236 | 1245 | # and that this is a logged-in user that doesn't already |
1237 | 1246 | # have the 'autoreview' permission |
1238 | | - if ( !$user->getId() || $user->isAllowed( 'autoreview' ) |
1239 | | - || empty( $wgFlaggedRevsAutoconfirm ) ) |
1240 | | - { |
| 1247 | + if ( !$user->getId() || empty( $wgFlaggedRevsAutoconfirm ) ) { |
1241 | 1248 | return true; |
1242 | 1249 | } |
1243 | 1250 | # Check if results are cached to avoid DB queries. |
1244 | 1251 | # Checked basic, already available, promotion heuristics first... |
1245 | 1252 | $APSkipKey = wfMemcKey( 'flaggedrevs', 'autoreview-skip', $user->getId() ); |
1246 | 1253 | $value = $wgMemc->get( $APSkipKey ); |
1247 | | - if ( $value === 'true' ) return true; |
| 1254 | + if ( $value === 'true' ) { |
| 1255 | + return true; |
| 1256 | + } |
1248 | 1257 | # Check $wgFlaggedRevsAutoconfirm settings... |
1249 | 1258 | $now = time(); |
1250 | 1259 | $userCreation = wfTimestampOrNull( TS_UNIX, $user->getRegistration() ); |
1251 | 1260 | # 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; |
1253 | 1264 | $p = FlaggedRevs::getUserParams( $user->getId() ); |
1254 | 1265 | # Check if user edited enough content pages |
1255 | 1266 | $totalCheckedEditsNeeded = false; |