Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php |
— | — | @@ -335,7 +335,7 @@ |
336 | 336 | if( $qal == FR_PRISTINE ) { |
337 | 337 | $flags = self::quickTags( FR_PRISTINE ); |
338 | 338 | # 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 ) ) { |
340 | 340 | return $flags; |
341 | 341 | } |
342 | 342 | $qal = FR_QUALITY; // try lower level |
— | — | @@ -344,7 +344,7 @@ |
345 | 345 | if( $qal == FR_QUALITY ) { |
346 | 346 | $flags = self::quickTags( FR_QUALITY ); |
347 | 347 | # 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 ) ) { |
349 | 349 | return $flags; |
350 | 350 | } |
351 | 351 | $qal = FR_SIGHTED; // try lower level |
— | — | @@ -353,13 +353,43 @@ |
354 | 354 | if( $qal == FR_SIGHTED ) { |
355 | 355 | $flags = self::quickTags( FR_SIGHTED ); |
356 | 356 | # 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 ) ) { |
358 | 358 | return $flags; |
359 | 359 | } |
360 | 360 | } |
361 | 361 | return null; |
362 | 362 | } |
363 | 363 | |
| 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 | + |
364 | 394 | ################# Parsing functions ################# |
365 | 395 | |
366 | 396 | /** |