r66442 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66441‎ | r66442 | r66443 >
Date:21:22, 14 May 2010
Author:aaron
Status:ok
Tags:
Comment:
* Moved userCanSetAutoreviewLevel() to FlaggedRevs class
* Re-organized some FlaggedRevs functions a bit
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.class.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -96,7 +96,7 @@
9797 self::$patrolNamespaces = $wgFlaggedRevsPatrolNamespaces;
9898 }
9999
100 - # ################ Basic accessors #################
 100+ # ################ Basic config accessors #################
101101
102102 /**
103103 * Is there only one tag and it has only one level?
@@ -255,32 +255,6 @@
256256 }
257257
258258 /**
259 - * Find what protection level a config is in
260 - * @param array $config
261 - * @returns string
262 - */
263 - public static function getProtectionLevel( array $config ) {
264 - if ( !self::useProtectionLevels() ) {
265 - throw new MWException( 'getProtectionLevel() called with $wgFlaggedRevsProtection off' );
266 - }
267 - $defaultConfig = self::getDefaultVisibilitySettings();
268 - # Check if the page is not protected at all...
269 - if ( $config['override'] == $defaultConfig['override']
270 - && $config['autoreview'] == $defaultConfig['autoreview'] )
271 - {
272 - return "none"; // not protected
273 - }
274 - # All protection levels have 'override' on
275 - if ( $config['override'] ) {
276 - # The levels are defined by the 'autoreview' settings
277 - if ( in_array( $config['autoreview'], self::getRestrictionLevels() ) ) {
278 - return $config['autoreview'];
279 - }
280 - }
281 - return "invalid";
282 - }
283 -
284 - /**
285259 * Get the autoreview restriction levels available
286260 * @returns array
287261 */
@@ -419,85 +393,9 @@
420394 return str_replace( '$wgScriptPath', $wgScriptPath, $wgFlaggedRevsStylePath );
421395 }
422396
423 - /**
424 - * Get global revision status precedence setting
425 - * or a specific one if given a tag tier (e.g. FR_QUALITY).
426 - * Returns one of FLAGGED_VIS_PRISTINE, FLAGGED_VIS_QUALITY, FLAGGED_VIS_LATEST.
427 - *
428 - * @param int config tier, optional (FR_PRISTINE,FR_QUALITY,FR_SIGHTED)
429 - * @return int
430 - */
431 - public static function getPrecedence( $configTier = null ) {
432 - global $wgFlaggedRevsPrecedence;
433 - if ( is_null( $configTier ) ) {
434 - $configTier = (int)$wgFlaggedRevsPrecedence;
435 - }
436 - switch( $configTier )
437 - {
438 - case FR_PRISTINE:
439 - $select = FLAGGED_VIS_PRISTINE;
440 - break;
441 - case FR_QUALITY:
442 - $select = FLAGGED_VIS_QUALITY;
443 - break;
444 - default:
445 - $select = FLAGGED_VIS_LATEST;
446 - break;
447 - }
448 - return $select;
449 - }
 397+ # ################ Permission functions #################
450398
451399 /**
452 - * Get minimum level tags for a tier
453 - * @return array
454 - */
455 - public static function quickTags( $tier ) {
456 - self::load();
457 - switch( $tier ) // select reference levels
458 - {
459 - case FR_PRISTINE:
460 - $minLevels = self::$minPL;
461 - case FR_QUALITY:
462 - $minLevels = self::$minQL;
463 - default:
464 - $minLevels = self::$minSL;
465 - }
466 - $flags = array();
467 - foreach ( self::getDimensions() as $tag => $x ) {
468 - $flags[$tag] = $minLevels[$tag];
469 - }
470 - return $flags;
471 - }
472 -
473 - /**
474 - * Get minimum tags that are closest to $oldFlags
475 - * given the site, page, and user rights limitations.
476 - * @param array $oldFlags previous stable rev flags
477 - * @param array $config
478 - * @return mixed array or null
479 - */
480 - public static function getAutoReviewTags( $oldFlags, array $config = array() ) {
481 - if ( !self::autoReviewEdits() ) {
482 - return null; // shouldn't happen
483 - }
484 - $flags = array();
485 - foreach ( self::getDimensions() as $tag => $levels ) {
486 - # Try to keep this tag val the same as the stable rev's
487 - $val = isset( $oldFlags[$tag] ) ? $oldFlags[$tag] : 1;
488 - $val = min( $val, self::maxAutoReviewLevel( $tag ) );
489 - # Dial down the level to one the user has permission to set
490 - while ( !self::userCanSetTag( $tag, $val ) ) {
491 - $val--;
492 - if ( $val <= 0 ) {
493 - return null; // all tags vals must be > 0
494 - }
495 - }
496 - $flags[$tag] = $val;
497 - }
498 - return $flags;
499 - }
500 -
501 - /**
502400 * Returns true if a user can set $tag to $value.
503401 * @param string $tag
504402 * @param int $value
@@ -560,6 +458,31 @@
561459 return true;
562460 }
563461
 462+ /**
 463+ * Check if a user can set the autoreview restiction level to $right
 464+ * @param string $right the level
 465+ * @returns bool
 466+ */
 467+ public static function userCanSetAutoreviewLevel( $right ) {
 468+ global $wgUser;
 469+ if ( $right == '' ) {
 470+ return true; // no restrictions (none)
 471+ }
 472+ if ( !in_array( $right, FlaggedRevs::getRestrictionLevels() ) ) {
 473+ return false; // invalid restriction level
 474+ }
 475+ # Don't let them choose levels above their own rights
 476+ if ( $right == 'sysop' ) {
 477+ // special case, rewrite sysop to protect and editprotected
 478+ if ( !$wgUser->isAllowed( 'protect' ) && !$wgUser->isAllowed( 'editprotected' ) ) {
 479+ return false;
 480+ }
 481+ } else if ( !$wgUser->isAllowed( $right ) ) {
 482+ return false;
 483+ }
 484+ return true;
 485+ }
 486+
564487 # ################ Parsing functions #################
565488
566489 /**
@@ -1284,7 +1207,34 @@
12851208 );
12861209 }
12871210
 1211+
12881212 /**
 1213+ * Find what protection level a config is in
 1214+ * @param array $config
 1215+ * @returns string
 1216+ */
 1217+ public static function getProtectionLevel( array $config ) {
 1218+ if ( !self::useProtectionLevels() ) {
 1219+ throw new MWException( 'getProtectionLevel() called with $wgFlaggedRevsProtection off' );
 1220+ }
 1221+ $defaultConfig = self::getDefaultVisibilitySettings();
 1222+ # Check if the page is not protected at all...
 1223+ if ( $config['override'] == $defaultConfig['override']
 1224+ && $config['autoreview'] == $defaultConfig['autoreview'] )
 1225+ {
 1226+ return "none"; // not protected
 1227+ }
 1228+ # All protection levels have 'override' on
 1229+ if ( $config['override'] ) {
 1230+ # The levels are defined by the 'autoreview' settings
 1231+ if ( in_array( $config['autoreview'], self::getRestrictionLevels() ) ) {
 1232+ return $config['autoreview'];
 1233+ }
 1234+ }
 1235+ return "invalid";
 1236+ }
 1237+
 1238+ /**
12891239 * Check if an fpc_select value is valid
12901240 * @param int $select
12911241 */
@@ -1413,6 +1363,84 @@
14141364 }
14151365
14161366 /**
 1367+ * Get global revision status precedence setting
 1368+ * or a specific one if given a tag tier (e.g. FR_QUALITY).
 1369+ * Returns one of FLAGGED_VIS_PRISTINE, FLAGGED_VIS_QUALITY, FLAGGED_VIS_LATEST.
 1370+ *
 1371+ * @param int config tier, optional (FR_PRISTINE,FR_QUALITY,FR_SIGHTED)
 1372+ * @return int
 1373+ */
 1374+ public static function getPrecedence( $configTier = null ) {
 1375+ global $wgFlaggedRevsPrecedence;
 1376+ if ( is_null( $configTier ) ) {
 1377+ $configTier = (int)$wgFlaggedRevsPrecedence;
 1378+ }
 1379+ switch( $configTier )
 1380+ {
 1381+ case FR_PRISTINE:
 1382+ $select = FLAGGED_VIS_PRISTINE;
 1383+ break;
 1384+ case FR_QUALITY:
 1385+ $select = FLAGGED_VIS_QUALITY;
 1386+ break;
 1387+ default:
 1388+ $select = FLAGGED_VIS_LATEST;
 1389+ break;
 1390+ }
 1391+ return $select;
 1392+ }
 1393+
 1394+ /**
 1395+ * Get minimum level tags for a tier
 1396+ * @return array
 1397+ */
 1398+ public static function quickTags( $tier ) {
 1399+ self::load();
 1400+ switch( $tier ) // select reference levels
 1401+ {
 1402+ case FR_PRISTINE:
 1403+ $minLevels = self::$minPL;
 1404+ case FR_QUALITY:
 1405+ $minLevels = self::$minQL;
 1406+ default:
 1407+ $minLevels = self::$minSL;
 1408+ }
 1409+ $flags = array();
 1410+ foreach ( self::getDimensions() as $tag => $x ) {
 1411+ $flags[$tag] = $minLevels[$tag];
 1412+ }
 1413+ return $flags;
 1414+ }
 1415+
 1416+ /**
 1417+ * Get minimum tags that are closest to $oldFlags
 1418+ * given the site, page, and user rights limitations.
 1419+ * @param array $oldFlags previous stable rev flags
 1420+ * @param array $config
 1421+ * @return mixed array or null
 1422+ */
 1423+ public static function getAutoReviewTags( $oldFlags, array $config = array() ) {
 1424+ if ( !self::autoReviewEdits() ) {
 1425+ return null; // shouldn't happen
 1426+ }
 1427+ $flags = array();
 1428+ foreach ( self::getDimensions() as $tag => $levels ) {
 1429+ # Try to keep this tag val the same as the stable rev's
 1430+ $val = isset( $oldFlags[$tag] ) ? $oldFlags[$tag] : 1;
 1431+ $val = min( $val, self::maxAutoReviewLevel( $tag ) );
 1432+ # Dial down the level to one the user has permission to set
 1433+ while ( !self::userCanSetTag( $tag, $val ) ) {
 1434+ $val--;
 1435+ if ( $val <= 0 ) {
 1436+ return null; // all tags vals must be > 0
 1437+ }
 1438+ }
 1439+ $flags[$tag] = $val;
 1440+ }
 1441+ return $flags;
 1442+ }
 1443+
 1444+ /**
14171445 * Get the list of reviewable namespaces
14181446 * @return array
14191447 */
Index: trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php
@@ -142,7 +142,7 @@
143143 return false; // invalid precedence value
144144 }
145145 // Check autoreview restriction setting
146 - if ( !self::userCanSetAutoreviewLevel( $this->autoreview ) ) {
 146+ if ( !FlaggedRevs::userCanSetAutoreviewLevel( $this->autoreview ) ) {
147147 return false; // invalid value
148148 }
149149 }
@@ -182,31 +182,6 @@
183183 $this->reason = $comment;
184184 }
185185
186 - /**
187 - * Check if a user can set the autoreview restiction level to $right
188 - * @param string $right the level
189 - * @returns bool
190 - */
191 - public static function userCanSetAutoreviewLevel( $right ) {
192 - global $wgUser;
193 - if ( $right == '' ) {
194 - return true; // no restrictions (none)
195 - }
196 - if ( !in_array( $right, FlaggedRevs::getRestrictionLevels() ) ) {
197 - return false; // invalid restriction level
198 - }
199 - # Don't let them choose levels above their own rights
200 - if ( $right == 'sysop' ) {
201 - // special case, rewrite sysop to protect and editprotected
202 - if ( !$wgUser->isAllowed( 'protect' ) && !$wgUser->isAllowed( 'editprotected' ) ) {
203 - return false;
204 - }
205 - } else if ( !$wgUser->isAllowed( $right ) ) {
206 - return false;
207 - }
208 - return true;
209 - }
210 -
211186 protected function showSettings( $err = null ) {
212187 global $wgOut, $wgLang, $wgUser;
213188 # Add any error messages
@@ -400,7 +375,7 @@
401376 foreach ( $levels as $key ) {
402377 # Don't let them choose levels they can't set,
403378 # but *show* them all when the form is disabled.
404 - if ( $this->isAllowed && !self::userCanSetAutoreviewLevel( $key ) ) {
 379+ if ( $this->isAllowed && !FlaggedRevs::userCanSetAutoreviewLevel( $key ) ) {
405380 continue;
406381 }
407382 $allowedLevels[] = $key;

Status & tagging log