r49053 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49052‎ | r49053 | r49054 >
Date:00:35, 31 March 2009
Author:aaron
Status:ok (Comments)
Tags:
Comment:
* Added $wgFlagAvailability
* Call static function statically
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticle.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.class.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.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.php
@@ -144,6 +144,14 @@
145145 'depth' => array( 'review' => 2 ),
146146 'style' => array( 'review' => 3 ),
147147 );
 148+# Use this to make levels of flags only appear if the page configured to
 149+# select the stable version in a certain way. Array of tags=>level=>config.
 150+$wgFlagAvailability = array();
 151+/* (example usage)
 152+$wgFlagAvailability = array(
 153+ 'style' => array( 1=>FLAGGED_VIS_LATEST, 2=>FLAGGED_VIS_QUALITY )
 154+);
 155+*/
148156
149157 # Restriction levels for auto-review right at Stabilization page
150158 $wgFlaggedRevsRestrictionLevels = array( '', 'sysop' );
Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -1300,6 +1300,7 @@
13011301 }
13021302 $skin = $wgUser->getSkin();
13031303
 1304+ $config = $this->getVisibilitySettings();
13041305 # Variable for sites with no flags, otherwise discarded
13051306 $approve = $wgRequest->getBool('wpApprove');
13061307 # See if the version being displayed is flagged...
@@ -1357,8 +1358,8 @@
13581359 # else collect all quality levels of a flag current user can set
13591360 } else {
13601361 foreach( $levels as $i => $name ) {
1361 - if( !RevisionReview::userCan($quality, $i) ) {
1362 - break;
 1362+ if( !RevisionReview::userCan($quality,$i,$config) ) {
 1363+ continue; // skip this level
13631364 }
13641365 $label[$i] = $name;
13651366 }
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -922,7 +922,7 @@
923923 return array( 'select' => $select, 'override' => $override,
924924 'autoreview' => '', 'expiry' => 'infinity' );
925925 }
926 - return array('select' => intval($row->fpc_select), 'override' => $row->fpc_override,
 926+ return array( 'select' => intval($row->fpc_select), 'override' => $row->fpc_override,
927927 'autoreview' => $row->fpc_level, 'expiry' => $row->fpc_expiry );
928928 }
929929
Index: trunk/extensions/FlaggedRevs/specialpages/RevisionReview_body.php
@@ -64,6 +64,7 @@
6565 $wgOut->addHTML( wfMsgExt('revreview-main',array('parse')) );
6666 return;
6767 }
 68+ # Get revision ID
6869 $this->oldid = $wgRequest->getIntOrNull( 'oldid' );
6970 if( !$this->oldid ) {
7071 $wgOut->showErrorPage( 'internalerror', 'revreview-revnotfound' );
@@ -104,8 +105,10 @@
105106 $this->dims[$tag] = 0;
106107 }
107108 }
 109+ $fa = FlaggedArticle::getTitleInstance( $this->page );
 110+ $this->config = $fa->getVisibilitySettings();
108111 # Check permissions and validate
109 - if( !$this->userCanSetFlags( $this->dims, $this->oflags ) ) {
 112+ if( !self::userCanSetFlags( $this->dims, $this->oflags, $this->config ) ) {
110113 $wgOut->permissionRequired( 'badaccess-group0' );
111114 return;
112115 }
@@ -247,10 +250,16 @@
248251 if( $form->validatedParams !== $k ) {
249252 return '<err#>';
250253 }
 254+ // User must be able to edit this page
 255+ if( !$form->page->quickUserCan('edit') ) {
 256+ return '<err#>';
 257+ }
 258+ $fa = FlaggedArticle::getTitleInstance( $form->page );
 259+ $form->config = $fa->getVisibilitySettings();
251260 # Get the revision's current flags, if any
252261 $form->oflags = FlaggedRevs::getRevisionTags( $form->page, $form->oldid );
253 - # Check permissions
254 - if( !$form->page->quickUserCan('edit') || !$form->userCanSetFlags($form->dims,$form->oflags) ) {
 262+ # Check tag permissions
 263+ if( !self::userCanSetFlags($form->dims,$form->oflags,$form->config) ) {
255264 return '<err#>';
256265 }
257266 list($approved,$status) = $form->submit();
@@ -382,7 +391,7 @@
383392 }
384393 }
385394 # Double-check permissions
386 - if( !$this->page->quickUserCan('edit') || !$this->userCanSetFlags($this->dims,$this->oflags) ) {
 395+ if( !$this->page->quickUserCan('edit') || !self::userCanSetFlags($this->dims,$this->oflags,$this->config) ) {
387396 return array($approved,false);
388397 }
389398 # We can only approve actual revisions...
@@ -750,8 +759,11 @@
751760 * @param int $value
752761 * @returns bool
753762 */
754 - public static function userCan( $tag, $value ) {
 763+ public static function userCan( $tag, $value, $config = array() ) {
755764 global $wgFlagRestrictions, $wgUser;
 765+ # Levels may not apply for some pages
 766+ if( !self::levelAvailable( $tag, $value, $config ) )
 767+ return false;
756768 # No restrictions -> full access
757769 if( !isset($wgFlagRestrictions[$tag]) )
758770 return true;
@@ -774,9 +786,10 @@
775787 * to the given levels for each tag.
776788 * @param array $flags, suggested flags
777789 * @param array $oldflags, pre-existing flags
 790+ * @param array $config, visibility settings
778791 * @returns bool
779792 */
780 - public static function userCanSetFlags( $flags, $oldflags = array() ) {
 793+ public static function userCanSetFlags( $flags, $oldflags = array(), $config = array() ) {
781794 global $wgUser;
782795 if( !$wgUser->isAllowed('review') ) {
783796 return false;
@@ -786,7 +799,7 @@
787800 foreach( FlaggedRevs::getDimensions() as $qal => $levels ) {
788801 $level = isset($flags[$qal]) ? $flags[$qal] : 0;
789802 $highest = count($levels) - 1; // highest valid level
790 - if( !self::userCan($qal,$level) ) {
 803+ if( !self::userCan($qal,$level,$config) ) {
791804 return false;
792805 } else if( isset($oldflags[$qal]) && !self::userCan($qal,$oldflags[$qal]) ) {
793806 return false;
@@ -797,6 +810,15 @@
798811 return true;
799812 }
800813
 814+ public static function levelAvailable( $tag, $val, $config ) {
 815+ global $wgFlagAvailability;
 816+ if( isset($wgFlagAvailability[$tag]) && isset($wgFlagAvailability[$tag][$val]) ) {
 817+ $precedence = $wgFlagAvailability[$tag][$val];
 818+ return ( $config['select'] === $precedence );
 819+ }
 820+ return true;
 821+ }
 822+
801823 public static function updateRecentChanges( $title, $revId, $rcId=false, $patrol=true ) {
802824 wfProfileIn( __METHOD__ );
803825 $revId = intval($revId);
Index: trunk/extensions/FlaggedRevs/api/ApiReview.php
@@ -78,7 +78,9 @@
7979
8080 // Check if user is even allowed to set the flags
8181 $form->oflags = FlaggedRevs::getRevisionTags( $title, $form->oldid );
82 - if( !$title->quickUserCan('edit') || !$form->userCanSetFlags( $form->dims, $form->oflags ) )
 82+ $fa = FlaggedArticle::getTitleInstance( $form->page );
 83+ $form->config = $fa->getVisibilitySettings();
 84+ if( !$title->quickUserCan('edit') || !RevisionReview::userCanSetFlags($form->dims,$form->oflags,$form->config) )
8385 $this->dieUsage( "You don't have the necessary rights to set the specified flags.", 'permissiondenied' );
8486
8587 // Now get the template and image parameters needed

Comments

#Comment by Aaron Schulz (talk | contribs)   01:14, 26 April 2009

Level 0 fix in r49054

Status & tagging log