r66384 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66383‎ | r66384 | r66385 >
Date:19:51, 13 May 2010
Author:aaron
Status:ok
Tags:
Comment:
Refactored userCanSetTag/userCanSetFlags functions into FlaggedRevs class
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevision.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.class.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevsXML.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/api/ApiReview.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/specialpages/RevisionReview_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -477,7 +477,7 @@
478478 * @return mixed array or null
479479 */
480480 public static function getAutoReviewTags( $oldFlags, array $config = array() ) {
481 - if ( !FlaggedRevs::autoReviewEdits() ) {
 481+ if ( !self::autoReviewEdits() ) {
482482 return null; // shouldn't happen
483483 }
484484 $flags = array();
@@ -486,7 +486,7 @@
487487 $val = isset( $oldFlags[$tag] ) ? $oldFlags[$tag] : 1;
488488 $val = min( $val, self::maxAutoReviewLevel( $tag ) );
489489 # Dial down the level to one the user has permission to set
490 - while ( !RevisionReview::userCan( $tag, $val ) ) {
 490+ while ( !self::userCanSetTag( $tag, $val ) ) {
491491 $val--;
492492 if ( $val <= 0 ) {
493493 return null; // all tags vals must be > 0
@@ -497,6 +497,69 @@
498498 return $flags;
499499 }
500500
 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+
501564 # ################ Parsing functions #################
502565
503566 /**
@@ -510,7 +573,7 @@
511574 global $wgParser;
512575 # Make our hooks trigger (force unstub so setting doesn't get lost)
513576 $wgParser->firstCallInit();
514 - $wgParser->fr_isStable = ( FlaggedRevs::inclusionSetting() != FR_INCLUDES_CURRENT );
 577+ $wgParser->fr_isStable = ( self::inclusionSetting() != FR_INCLUDES_CURRENT );
515578 # Parse with default options
516579 $options = self::makeParserOptions();
517580 $outputText = $wgParser->preprocess( $text, $title, $options, $id );
@@ -535,7 +598,7 @@
536599 $title = $article->getTitle(); // avoid pass-by-reference error
537600 # Make our hooks trigger (force unstub so setting doesn't get lost)
538601 $wgParser->firstCallInit();
539 - $wgParser->fr_isStable = ( FlaggedRevs::inclusionSetting() != FR_INCLUDES_CURRENT );
 602+ $wgParser->fr_isStable = ( self::inclusionSetting() != FR_INCLUDES_CURRENT );
540603 # Don't show section-edit links, they can be old and misleading
541604 $options = self::makeParserOptions();
542605 # Parse the new body, wikitext -> html
@@ -760,7 +823,7 @@
761824 }
762825 }
763826 # 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 ) {
765828 return true;
766829 }
767830 # Try the cache...
@@ -1238,7 +1301,7 @@
12391302 if ( $right == '' ) {
12401303 return true; // no restrictions (none)
12411304 }
1242 - return in_array( $right, FlaggedRevs::getRestrictionLevels(), true );
 1305+ return in_array( $right, self::getRestrictionLevels(), true );
12431306 }
12441307
12451308 /**
@@ -1261,7 +1324,7 @@
12621325 // If FlaggedRevs got "turned off" for this page (due to not
12631326 // having the stable version as the default), then clear it
12641327 // from the tracking tables...
1265 - if ( !$config['override'] && FlaggedRevs::forDefaultVersionOnly() ) {
 1328+ if ( !$config['override'] && self::forDefaultVersionOnly() ) {
12661329 $pagesClearTracking[] = $row->fpc_page_id; // no stable version
12671330 // Check if the new (default) config has a different way
12681331 // of selecting the stable version of this page...
@@ -1590,7 +1653,7 @@
15911654 # We can set the sync cache key already.
15921655 global $wgParserCacheExpireTime;
15931656 $key = wfMemcKey( 'flaggedrevs', 'includesSynced', $article->getId() );
1594 - $data = FlaggedRevs::makeMemcObj( "true" );
 1657+ $data = self::makeMemcObj( "true" );
15951658 $wgMemc->set( $key, $data, $wgParserCacheExpireTime );
15961659 } else if ( $sv ) {
15971660 # Update tracking table
Index: trunk/extensions/FlaggedRevs/FlaggedRevision.php
@@ -380,7 +380,7 @@
381381 * @returns bool
382382 */
383383 public function userCanSetFlags() {
384 - return RevisionReview::userCanSetFlags( $this->mTags );
 384+ return FlaggedRevs::userCanSetFlags( $this->mTags );
385385 }
386386
387387 /**
Index: trunk/extensions/FlaggedRevs/specialpages/RevisionReview_body.php
@@ -132,7 +132,7 @@
133133 $fa = FlaggedArticle::getTitleInstance( $this->page );
134134 $this->config = $fa->getVisibilitySettings();
135135 # Check permissions and validate
136 - if ( !self::userCanSetFlags( $this->dims, $this->oflags, $this->config ) ) {
 136+ if ( !FlaggedRevs::userCanSetFlags( $this->dims, $this->oflags, $this->config ) ) {
137137 $wgOut->permissionRequired( 'badaccess-group0' );
138138 return;
139139 }
@@ -294,7 +294,7 @@
295295 # Get the revision's current flags, if any
296296 $form->oflags = FlaggedRevs::getRevisionTags( $form->page, $form->oldid );
297297 # Check tag permissions
298 - if ( !self::userCanSetFlags( $form->dims, $form->oflags, $form->config ) ) {
 298+ if ( !FlaggedRevs::userCanSetFlags( $form->dims, $form->oflags, $form->config ) ) {
299299 return '<err#>' . wfMsgExt( 'revreview-failed', 'parseinline' );
300300 }
301301 list( $approved, $status ) = $form->submit();
@@ -335,7 +335,7 @@
336336 }
337337 # Double-check permissions
338338 if ( !$this->page->quickUserCan( 'edit' )
339 - || !self::userCanSetFlags( $this->dims, $this->oflags, $this->config ) )
 339+ || !FlaggedRevs::userCanSetFlags( $this->dims, $this->oflags, $this->config ) )
340340 {
341341 return array( $approved, false );
342342 }
@@ -704,67 +704,6 @@
705705 return $p;
706706 }
707707
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 -
769708 public static function updateRecentChanges( $title, $revId, $rcId = false, $patrol = true ) {
770709 wfProfileIn( __METHOD__ );
771710 $revId = intval( $revId );
Index: trunk/extensions/FlaggedRevs/FlaggedRevsXML.php
@@ -470,7 +470,7 @@
471471 # Build up all levels available to user
472472 foreach ( FlaggedRevs::getDimensions() as $tag => $levels ) {
473473 if ( isset( $selected[$tag] ) &&
474 - !RevisionReview::userCan( $tag, $selected[$tag], $config ) )
 474+ !FlaggedRevs::userCanSetTag( $tag, $selected[$tag], $config ) )
475475 {
476476 return array( false, false ); // form will have to be disabled
477477 }
@@ -478,7 +478,7 @@
479479 $minLevels[$tag] = false; // first non-zero level number
480480 foreach ( $levels as $i => $msg ) {
481481 # Some levels may be restricted or not applicable...
482 - if ( !RevisionReview::userCan( $tag, $i, $config ) ) {
 482+ if ( !FlaggedRevs::userCanSetTag( $tag, $i, $config ) ) {
483483 continue; // skip this level
484484 } else if ( $i > 0 && !$minLevels[$tag] ) {
485485 $minLevels[$tag] = $i; // first non-zero level number
@@ -651,7 +651,7 @@
652652 $flags = $srev->getTags();
653653 # Check if user is allowed to renew the stable version.
654654 # If not, then get the flags for the new revision itself.
655 - if ( !RevisionReview::userCanSetFlags( $oldFlags ) ) {
 655+ if ( !FlaggedRevs::userCanSetFlags( $oldFlags ) ) {
656656 $flags = $oldFlags;
657657 }
658658 $reviewNotes = $srev->getComment();
@@ -686,7 +686,7 @@
687687
688688 # Disable form for unprivileged users
689689 $uneditable = !$article->getTitle()->quickUserCan( 'edit' );
690 - $disabled = !RevisionReview::userCanSetFlags( $flags ) || $uneditable;
 690+ $disabled = !FlaggedRevs::userCanSetFlags( $flags ) || $uneditable;
691691 if ( $disabled ) {
692692 $form .= Xml::openElement( 'div', array( 'class' => 'fr-rating-controls-disabled',
693693 'id' => 'fr-rating-controls-disabled' ) );
Index: trunk/extensions/FlaggedRevs/api/ApiReview.php
@@ -77,8 +77,12 @@
7878 $form->oflags = FlaggedRevs::getRevisionTags( $title, $form->oldid );
7979 $fa = FlaggedArticle::getTitleInstance( $form->page );
8080 $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+ {
8285 $this->dieUsage( "You don't have the necessary rights to set the specified flags.", 'permissiondenied' );
 86+ }
8387
8488 if ( $form->isApproval() ) {
8589 // Now get the template and image parameters needed

Follow-up revisions

RevisionCommit summaryAuthorDate
r66704MFT r66384-r66669aaron19:27, 20 May 2010

Status & tagging log