Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php |
— | — | @@ -477,7 +477,7 @@ |
478 | 478 | * @return mixed array or null |
479 | 479 | */ |
480 | 480 | public static function getAutoReviewTags( $oldFlags, array $config = array() ) { |
481 | | - if ( !FlaggedRevs::autoReviewEdits() ) { |
| 481 | + if ( !self::autoReviewEdits() ) { |
482 | 482 | return null; // shouldn't happen |
483 | 483 | } |
484 | 484 | $flags = array(); |
— | — | @@ -486,7 +486,7 @@ |
487 | 487 | $val = isset( $oldFlags[$tag] ) ? $oldFlags[$tag] : 1; |
488 | 488 | $val = min( $val, self::maxAutoReviewLevel( $tag ) ); |
489 | 489 | # Dial down the level to one the user has permission to set |
490 | | - while ( !RevisionReview::userCan( $tag, $val ) ) { |
| 490 | + while ( !self::userCanSetTag( $tag, $val ) ) { |
491 | 491 | $val--; |
492 | 492 | if ( $val <= 0 ) { |
493 | 493 | return null; // all tags vals must be > 0 |
— | — | @@ -497,6 +497,69 @@ |
498 | 498 | return $flags; |
499 | 499 | } |
500 | 500 | |
| 501 | + /** |
| 502 | + * Returns true if a user can set $tag to $value. |
| 503 | + * @param string $tag |
| 504 | + * @param int $value |
| 505 | + * @param array $config (optional page config) |
| 506 | + * @returns bool |
| 507 | + */ |
| 508 | + public static function userCanSetTag( $tag, $value, $config = null ) { |
| 509 | + global $wgUser; |
| 510 | + # Sanity check tag and value |
| 511 | + $levels = self::getTagLevels( $tag ); |
| 512 | + $highest = count( $levels ) - 1; |
| 513 | + if( !$levels || $value < 0 || $value > $highest ) { |
| 514 | + return false; // flag range is invalid |
| 515 | + } |
| 516 | + $restrictions = self::getTagRestrictions(); |
| 517 | + # No restrictions -> full access |
| 518 | + if ( !isset( $restrictions[$tag] ) ) { |
| 519 | + return true; |
| 520 | + } |
| 521 | + # Validators always have full access |
| 522 | + if ( $wgUser->isAllowed( 'validate' ) ) { |
| 523 | + return true; |
| 524 | + } |
| 525 | + # Check if this user has any right that lets him/her set |
| 526 | + # up to this particular value |
| 527 | + foreach ( $restrictions[$tag] as $right => $level ) { |
| 528 | + if ( $value <= $level && $level > 0 && $wgUser->isAllowed( $right ) ) { |
| 529 | + return true; |
| 530 | + } |
| 531 | + } |
| 532 | + return false; |
| 533 | + } |
| 534 | + |
| 535 | + /** |
| 536 | + * Returns true if a user can set $flags. |
| 537 | + * This checks if the user has the right to review |
| 538 | + * to the given levels for each tag. |
| 539 | + * @param array $flags, suggested flags |
| 540 | + * @param array $oldflags, pre-existing flags |
| 541 | + * @param array $config, visibility settings |
| 542 | + * @returns bool |
| 543 | + */ |
| 544 | + public static function userCanSetFlags( $flags, $oldflags = array(), $config = null ) { |
| 545 | + global $wgUser; |
| 546 | + if ( !$wgUser->isAllowed( 'review' ) ) |
| 547 | + return false; // User is not able to review pages |
| 548 | + # Check if all of the required site flags have a valid value |
| 549 | + # that the user is allowed to set. |
| 550 | + foreach ( self::getDimensions() as $qal => $levels ) { |
| 551 | + $level = isset( $flags[$qal] ) ? $flags[$qal] : 0; |
| 552 | + $highest = count( $levels ) - 1; // highest valid level |
| 553 | + if ( !self::userCanSetTag( $qal, $level, $config ) ) { |
| 554 | + return false; // user cannot set proposed flag |
| 555 | + } elseif ( isset( $oldflags[$qal] ) |
| 556 | + && !self::userCanSetTag( $qal, $oldflags[$qal] ) ) |
| 557 | + { |
| 558 | + return false; // user cannot change old flag ($config is ignored here) |
| 559 | + } |
| 560 | + } |
| 561 | + return true; |
| 562 | + } |
| 563 | + |
501 | 564 | # ################ Parsing functions ################# |
502 | 565 | |
503 | 566 | /** |
— | — | @@ -510,7 +573,7 @@ |
511 | 574 | global $wgParser; |
512 | 575 | # Make our hooks trigger (force unstub so setting doesn't get lost) |
513 | 576 | $wgParser->firstCallInit(); |
514 | | - $wgParser->fr_isStable = ( FlaggedRevs::inclusionSetting() != FR_INCLUDES_CURRENT ); |
| 577 | + $wgParser->fr_isStable = ( self::inclusionSetting() != FR_INCLUDES_CURRENT ); |
515 | 578 | # Parse with default options |
516 | 579 | $options = self::makeParserOptions(); |
517 | 580 | $outputText = $wgParser->preprocess( $text, $title, $options, $id ); |
— | — | @@ -535,7 +598,7 @@ |
536 | 599 | $title = $article->getTitle(); // avoid pass-by-reference error |
537 | 600 | # Make our hooks trigger (force unstub so setting doesn't get lost) |
538 | 601 | $wgParser->firstCallInit(); |
539 | | - $wgParser->fr_isStable = ( FlaggedRevs::inclusionSetting() != FR_INCLUDES_CURRENT ); |
| 602 | + $wgParser->fr_isStable = ( self::inclusionSetting() != FR_INCLUDES_CURRENT ); |
540 | 603 | # Don't show section-edit links, they can be old and misleading |
541 | 604 | $options = self::makeParserOptions(); |
542 | 605 | # Parse the new body, wikitext -> html |
— | — | @@ -760,7 +823,7 @@ |
761 | 824 | } |
762 | 825 | } |
763 | 826 | # If using the current version of includes, there is nothing else to check. |
764 | | - if ( FlaggedRevs::inclusionSetting() == FR_INCLUDES_CURRENT ) { |
| 827 | + if ( self::inclusionSetting() == FR_INCLUDES_CURRENT ) { |
765 | 828 | return true; |
766 | 829 | } |
767 | 830 | # Try the cache... |
— | — | @@ -1238,7 +1301,7 @@ |
1239 | 1302 | if ( $right == '' ) { |
1240 | 1303 | return true; // no restrictions (none) |
1241 | 1304 | } |
1242 | | - return in_array( $right, FlaggedRevs::getRestrictionLevels(), true ); |
| 1305 | + return in_array( $right, self::getRestrictionLevels(), true ); |
1243 | 1306 | } |
1244 | 1307 | |
1245 | 1308 | /** |
— | — | @@ -1261,7 +1324,7 @@ |
1262 | 1325 | // If FlaggedRevs got "turned off" for this page (due to not |
1263 | 1326 | // having the stable version as the default), then clear it |
1264 | 1327 | // from the tracking tables... |
1265 | | - if ( !$config['override'] && FlaggedRevs::forDefaultVersionOnly() ) { |
| 1328 | + if ( !$config['override'] && self::forDefaultVersionOnly() ) { |
1266 | 1329 | $pagesClearTracking[] = $row->fpc_page_id; // no stable version |
1267 | 1330 | // Check if the new (default) config has a different way |
1268 | 1331 | // of selecting the stable version of this page... |
— | — | @@ -1590,7 +1653,7 @@ |
1591 | 1654 | # We can set the sync cache key already. |
1592 | 1655 | global $wgParserCacheExpireTime; |
1593 | 1656 | $key = wfMemcKey( 'flaggedrevs', 'includesSynced', $article->getId() ); |
1594 | | - $data = FlaggedRevs::makeMemcObj( "true" ); |
| 1657 | + $data = self::makeMemcObj( "true" ); |
1595 | 1658 | $wgMemc->set( $key, $data, $wgParserCacheExpireTime ); |
1596 | 1659 | } else if ( $sv ) { |
1597 | 1660 | # Update tracking table |
Index: trunk/extensions/FlaggedRevs/FlaggedRevision.php |
— | — | @@ -380,7 +380,7 @@ |
381 | 381 | * @returns bool |
382 | 382 | */ |
383 | 383 | public function userCanSetFlags() { |
384 | | - return RevisionReview::userCanSetFlags( $this->mTags ); |
| 384 | + return FlaggedRevs::userCanSetFlags( $this->mTags ); |
385 | 385 | } |
386 | 386 | |
387 | 387 | /** |
Index: trunk/extensions/FlaggedRevs/specialpages/RevisionReview_body.php |
— | — | @@ -132,7 +132,7 @@ |
133 | 133 | $fa = FlaggedArticle::getTitleInstance( $this->page ); |
134 | 134 | $this->config = $fa->getVisibilitySettings(); |
135 | 135 | # Check permissions and validate |
136 | | - if ( !self::userCanSetFlags( $this->dims, $this->oflags, $this->config ) ) { |
| 136 | + if ( !FlaggedRevs::userCanSetFlags( $this->dims, $this->oflags, $this->config ) ) { |
137 | 137 | $wgOut->permissionRequired( 'badaccess-group0' ); |
138 | 138 | return; |
139 | 139 | } |
— | — | @@ -294,7 +294,7 @@ |
295 | 295 | # Get the revision's current flags, if any |
296 | 296 | $form->oflags = FlaggedRevs::getRevisionTags( $form->page, $form->oldid ); |
297 | 297 | # Check tag permissions |
298 | | - if ( !self::userCanSetFlags( $form->dims, $form->oflags, $form->config ) ) { |
| 298 | + if ( !FlaggedRevs::userCanSetFlags( $form->dims, $form->oflags, $form->config ) ) { |
299 | 299 | return '<err#>' . wfMsgExt( 'revreview-failed', 'parseinline' ); |
300 | 300 | } |
301 | 301 | list( $approved, $status ) = $form->submit(); |
— | — | @@ -335,7 +335,7 @@ |
336 | 336 | } |
337 | 337 | # Double-check permissions |
338 | 338 | if ( !$this->page->quickUserCan( 'edit' ) |
339 | | - || !self::userCanSetFlags( $this->dims, $this->oflags, $this->config ) ) |
| 339 | + || !FlaggedRevs::userCanSetFlags( $this->dims, $this->oflags, $this->config ) ) |
340 | 340 | { |
341 | 341 | return array( $approved, false ); |
342 | 342 | } |
— | — | @@ -704,67 +704,6 @@ |
705 | 705 | return $p; |
706 | 706 | } |
707 | 707 | |
708 | | - /** |
709 | | - * Returns true if a user can set $tag to $value. |
710 | | - * @param string $tag |
711 | | - * @param int $value |
712 | | - * @param array $config (optional page config) |
713 | | - * @returns bool |
714 | | - */ |
715 | | - public static function userCan( $tag, $value, $config = null ) { |
716 | | - global $wgUser; |
717 | | - # Sanity check tag and value |
718 | | - $levels = FlaggedRevs::getTagLevels( $tag ); |
719 | | - $highest = count( $levels ) - 1; |
720 | | - if( !$levels || $value < 0 || $value > $highest ) { |
721 | | - return false; // flag range is invalid |
722 | | - } |
723 | | - $restrictions = FlaggedRevs::getTagRestrictions(); |
724 | | - # No restrictions -> full access |
725 | | - if ( !isset( $restrictions[$tag] ) ) { |
726 | | - return true; |
727 | | - } |
728 | | - # Validators always have full access |
729 | | - if ( $wgUser->isAllowed( 'validate' ) ) { |
730 | | - return true; |
731 | | - } |
732 | | - # Check if this user has any right that lets him/her set |
733 | | - # up to this particular value |
734 | | - foreach ( $restrictions[$tag] as $right => $level ) { |
735 | | - if ( $value <= $level && $level > 0 && $wgUser->isAllowed( $right ) ) { |
736 | | - return true; |
737 | | - } |
738 | | - } |
739 | | - return false; |
740 | | - } |
741 | | - |
742 | | - /** |
743 | | - * Returns true if a user can set $flags. |
744 | | - * This checks if the user has the right to review |
745 | | - * to the given levels for each tag. |
746 | | - * @param array $flags, suggested flags |
747 | | - * @param array $oldflags, pre-existing flags |
748 | | - * @param array $config, visibility settings |
749 | | - * @returns bool |
750 | | - */ |
751 | | - public static function userCanSetFlags( $flags, $oldflags = array(), $config = null ) { |
752 | | - global $wgUser; |
753 | | - if ( !$wgUser->isAllowed( 'review' ) ) |
754 | | - return false; // User is not able to review pages |
755 | | - # Check if all of the required site flags have a valid value |
756 | | - # that the user is allowed to set. |
757 | | - foreach ( FlaggedRevs::getDimensions() as $qal => $levels ) { |
758 | | - $level = isset( $flags[$qal] ) ? $flags[$qal] : 0; |
759 | | - $highest = count( $levels ) - 1; // highest valid level |
760 | | - if ( !self::userCan( $qal, $level, $config ) ) { |
761 | | - return false; // user cannot set proposed flag |
762 | | - } elseif ( isset( $oldflags[$qal] ) && !self::userCan( $qal, $oldflags[$qal] ) ) { |
763 | | - return false; // user cannot change old flag ($config is ignored here) |
764 | | - } |
765 | | - } |
766 | | - return true; |
767 | | - } |
768 | | - |
769 | 708 | public static function updateRecentChanges( $title, $revId, $rcId = false, $patrol = true ) { |
770 | 709 | wfProfileIn( __METHOD__ ); |
771 | 710 | $revId = intval( $revId ); |
Index: trunk/extensions/FlaggedRevs/FlaggedRevsXML.php |
— | — | @@ -470,7 +470,7 @@ |
471 | 471 | # Build up all levels available to user |
472 | 472 | foreach ( FlaggedRevs::getDimensions() as $tag => $levels ) { |
473 | 473 | if ( isset( $selected[$tag] ) && |
474 | | - !RevisionReview::userCan( $tag, $selected[$tag], $config ) ) |
| 474 | + !FlaggedRevs::userCanSetTag( $tag, $selected[$tag], $config ) ) |
475 | 475 | { |
476 | 476 | return array( false, false ); // form will have to be disabled |
477 | 477 | } |
— | — | @@ -478,7 +478,7 @@ |
479 | 479 | $minLevels[$tag] = false; // first non-zero level number |
480 | 480 | foreach ( $levels as $i => $msg ) { |
481 | 481 | # Some levels may be restricted or not applicable... |
482 | | - if ( !RevisionReview::userCan( $tag, $i, $config ) ) { |
| 482 | + if ( !FlaggedRevs::userCanSetTag( $tag, $i, $config ) ) { |
483 | 483 | continue; // skip this level |
484 | 484 | } else if ( $i > 0 && !$minLevels[$tag] ) { |
485 | 485 | $minLevels[$tag] = $i; // first non-zero level number |
— | — | @@ -651,7 +651,7 @@ |
652 | 652 | $flags = $srev->getTags(); |
653 | 653 | # Check if user is allowed to renew the stable version. |
654 | 654 | # If not, then get the flags for the new revision itself. |
655 | | - if ( !RevisionReview::userCanSetFlags( $oldFlags ) ) { |
| 655 | + if ( !FlaggedRevs::userCanSetFlags( $oldFlags ) ) { |
656 | 656 | $flags = $oldFlags; |
657 | 657 | } |
658 | 658 | $reviewNotes = $srev->getComment(); |
— | — | @@ -686,7 +686,7 @@ |
687 | 687 | |
688 | 688 | # Disable form for unprivileged users |
689 | 689 | $uneditable = !$article->getTitle()->quickUserCan( 'edit' ); |
690 | | - $disabled = !RevisionReview::userCanSetFlags( $flags ) || $uneditable; |
| 690 | + $disabled = !FlaggedRevs::userCanSetFlags( $flags ) || $uneditable; |
691 | 691 | if ( $disabled ) { |
692 | 692 | $form .= Xml::openElement( 'div', array( 'class' => 'fr-rating-controls-disabled', |
693 | 693 | 'id' => 'fr-rating-controls-disabled' ) ); |
Index: trunk/extensions/FlaggedRevs/api/ApiReview.php |
— | — | @@ -77,8 +77,12 @@ |
78 | 78 | $form->oflags = FlaggedRevs::getRevisionTags( $title, $form->oldid ); |
79 | 79 | $fa = FlaggedArticle::getTitleInstance( $form->page ); |
80 | 80 | $form->config = $fa->getVisibilitySettings(); |
81 | | - if ( !$title->quickUserCan( 'edit' ) || !RevisionReview::userCanSetFlags( $form->dims, $form->oflags, $form->config ) ) |
| 81 | + |
| 82 | + if ( !$title->quickUserCan( 'edit' ) |
| 83 | + || !FlaggedRevs::userCanSetFlags( $form->dims, $form->oflags, $form->config ) ) |
| 84 | + { |
82 | 85 | $this->dieUsage( "You don't have the necessary rights to set the specified flags.", 'permissiondenied' ); |
| 86 | + } |
83 | 87 | |
84 | 88 | if ( $form->isApproval() ) { |
85 | 89 | // Now get the template and image parameters needed |