r52003 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52002‎ | r52003 | r52004 >
Date:21:03, 16 June 2009
Author:aaron
Status:ok
Tags:
Comment:
(bug 19207) Bot autoreview works again
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -335,7 +335,7 @@
336336 if( $qal == FR_PRISTINE ) {
337337 $flags = self::quickTags( FR_PRISTINE );
338338 # If tags are available and user can set them, we are done...
339 - if( RevisionReview::userCanSetFlags( $flags, array(), $config ) ) {
 339+ if( self::userCanAutoSetFlags( $flags, array(), $config ) ) {
340340 return $flags;
341341 }
342342 $qal = FR_QUALITY; // try lower level
@@ -344,7 +344,7 @@
345345 if( $qal == FR_QUALITY ) {
346346 $flags = self::quickTags( FR_QUALITY );
347347 # If tags are available and user can set them, we are done...
348 - if( RevisionReview::userCanSetFlags( $flags, array(), $config ) ) {
 348+ if( self::userCanAutoSetFlags( $flags, array(), $config ) ) {
349349 return $flags;
350350 }
351351 $qal = FR_SIGHTED; // try lower level
@@ -353,13 +353,43 @@
354354 if( $qal == FR_SIGHTED ) {
355355 $flags = self::quickTags( FR_SIGHTED );
356356 # If tags are available and user can set them, we are done...
357 - if( RevisionReview::userCanSetFlags( $flags, array(), $config ) ) {
 357+ if( self::userCanAutoSetFlags( $flags, array(), $config ) ) {
358358 return $flags;
359359 }
360360 }
361361 return null;
362362 }
363363
 364+ /**
 365+ * Returns true if a user can auto-set $flags.
 366+ * This checks if the user has the right to autoreview
 367+ * to the given levels for each tag.
 368+ * @param array $flags, suggested flags
 369+ * @param array $oldflags, pre-existing flags
 370+ * @param array $config, visibility settings
 371+ * @returns bool
 372+ */
 373+ public static function userCanAutoSetFlags( $flags, $oldflags = array(), $config = array() ) {
 374+ global $wgUser;
 375+ if( !$wgUser->isAllowed('autoreview') ) {
 376+ return false;
 377+ }
 378+ # Check if all of the required site flags have a valid value
 379+ # that the user is allowed to set.
 380+ foreach( FlaggedRevs::getDimensions() as $qal => $levels ) {
 381+ $level = isset($flags[$qal]) ? $flags[$qal] : 0;
 382+ $highest = count($levels) - 1; // highest valid level
 383+ # Levels may not apply for some pages
 384+ if( $level > 0 && !RevisionReview::levelAvailable( $qal, $level, $config ) ) {
 385+ return false;
 386+ # Sanity check numeric range
 387+ } elseif( $level < 0 || $level > $highest ) {
 388+ return false;
 389+ }
 390+ }
 391+ return true;
 392+ }
 393+
364394 ################# Parsing functions #################
365395
366396 /**

Status & tagging log