r63827 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63826‎ | r63827 | r63828 >
Date:19:41, 16 March 2010
Author:aaron
Status:ok
Tags:
Comment:
* Removed $wgFlaggedRevsProtectLevels. Added simplified $wgFlaggedRevsProtection to be used instead.
* Removed getProtectLevels(), using getRestrictionLevels() instead
* Improved userCanSetAutoreviewLevel() validation
* Refactored FlaggedRevs::load() a bit
* Refactored 'none' restriction level code
* defineSpecialPages() cleanups
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.class.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/api/ApiStabilize.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -145,20 +145,16 @@
146146 # (FR_SIGHTED,FR_QUALITY,FR_PRISTINE)
147147 $wgFlaggedRevsPatrolLevel = FR_SIGHTED;
148148
149 -# Protection levels, defined below, that appear in protection form.
150 -# The stable version is the default for each level. A "none" level
151 -# will appear in the forms as well, to restore the default settings.
152 -$wgFlaggedRevsProtectLevels = array();
153 -/* (example usage)
154 -$wgFlaggedRevsProtectLevels = array(
155 - 'semi-review' => array('select' => FLAGGED_VIS_LATEST, 'autoreview' => ''),
156 - 'intm-review' => array('select' => FLAGGED_VIS_LATEST, 'autoreview' => 'review'),
157 -);
158 -*/
159 -
160 -# Restriction levels for auto-review right at Stabilization page
161 -# No effect if $wgFlaggedRevsProtectLevels is used.
 149+# Restriction levels for 'autoreview'/'review' rights.
 150+# When a level is selected for a page, an edit made by a user
 151+# requires approval unless that user has the specified permission.
 152+# Levels are set at the Stabilization special page.
162153 $wgFlaggedRevsRestrictionLevels = array( '', 'sysop' );
 154+# Set this to disable Stabilization and show the above restriction levels
 155+# on the protection form of pages. Each level has the stable version shown by default.
 156+# A "none" level will appear in the forms as well, to restore the default settings.
 157+# NOTE: The stable version precedence cannot be configured per page with this.
 158+$wgFlaggedRevsProtection = false;
163159
164160 # Please set these as something different. Any text will do, though it probably
165161 # shouldn't be very short (less secure) or very long (waste of resources).
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -18,7 +18,6 @@
1919 protected static $patrolNamespaces = array();
2020 # Restriction levels/config
2121 protected static $restrictionLevels = array();
22 - protected static $protectionLevels = array();
2322 # Temporary process cache variable
2423 protected static $includeVersionCache = array();
2524
@@ -26,7 +25,10 @@
2726
2827 public static function load() {
2928 global $wgFlaggedRevTags;
30 - if ( self::$loaded ) return true;
 29+ if ( self::$loaded ) {
 30+ return true;
 31+ }
 32+ self::$loaded = true;
3133 # Assume true, then set to false if needed
3234 if ( !empty( $wgFlaggedRevTags ) ) {
3335 self::$qualityVersions = true;
@@ -76,25 +78,10 @@
7779 self::$minPL[$tag] = max( $minPL, 1 );
7880 self::$minSL[$tag] = 1;
7981 }
80 - global $wgFlaggedRevsProtectLevels;
81 - $wgFlaggedRevsProtectLevels = (array)$wgFlaggedRevsProtectLevels;
82 - foreach ( $wgFlaggedRevsProtectLevels as $level => $config ) {
83 - # Sanity check that the config is complete
84 - if ( !isset( $config['select'] ) || !isset( $config['autoreview'] ) ) {
85 - throw new MWException( 'FlaggedRevs given incomplete $wgFlaggedRevsProtectLevels value!' );
86 - # Disallow reserved level names
87 - } else if ( $level == 'invalid' || $level == 'none' ) {
88 - throw new MWException( 'FlaggedRevs given reserved $wgFlaggedRevsProtectLevels key!' );
89 - }
90 - $config['override'] = 1; // stable is default
91 - self::$protectionLevels[$level] = $config;
92 - }
9382 global $wgFlaggedRevsRestrictionLevels;
94 - # Make sure that there is a "none" level
 83+ # Make sure that the levels are unique
9584 self::$restrictionLevels = array_unique( $wgFlaggedRevsRestrictionLevels );
96 - if ( !in_array( '', self::$restrictionLevels ) ) {
97 - self::$restrictionLevels = array( '' ) + self::$restrictionLevels;
98 - }
 85+ self::$restrictionLevels = array_filter( self::$restrictionLevels, 'strlen' );
9986 # Make sure no talk namespaces are in review namespace
10087 global $wgFlaggedRevsNamespaces, $wgFlaggedRevsPatrolNamespaces;
10188 foreach ( $wgFlaggedRevsNamespaces as $ns ) {
@@ -107,8 +94,6 @@
10895 self::$reviewNamespaces = $wgFlaggedRevsNamespaces;
10996 # Note: reviewable *pages* override patrollable ones
11097 self::$patrolNamespaces = $wgFlaggedRevsPatrolNamespaces;
111 -
112 - self::$loaded = true;
11398 }
11499
115100 # ################ Basic accessors #################
@@ -268,43 +253,37 @@
269254 global $wgFlaggedRevsLowProfile;
270255 return $wgFlaggedRevsLowProfile;
271256 }
272 -
273 - /**
274 - * Get the site defined protection levels for review
275 - * @returns array (associative)
276 - */
277 - public static function getProtectionLevels() {
278 - self::load(); // validates levels
279 - return self::$protectionLevels;
280 - }
281257
282258 /**
283259 * Are there site defined protection levels for review
284260 * @returns bool
285261 */
286262 public static function useProtectionLevels() {
287 - return ( count( self::getProtectionLevels() ) > 0 );
 263+ global $wgFlaggedRevsProtection;
 264+ return $wgFlaggedRevsProtection && self::getRestrictionLevels();
288265 }
289 -
 266+
290267 /**
291268 * Find what protection level a config is in
292269 * @param array $config
293 - * @returns mixed (array/string)
 270+ * @returns string
294271 */
295272 public static function getProtectionLevel( $config ) {
296 - $validLevels = self::getProtectionLevels();
 273+ if( !self::useProtectionLevels() ) {
 274+ throw new MWException('getProtectionLevel() called with $wgFlaggedRevsProtection off');
 275+ }
297276 $defaultConfig = self::getDefaultVisibilitySettings();
298 - # Remove expiry for quick comparisons
299 - unset( $defaultConfig['expiry'] );
300 - unset( $config['expiry'] );
301 - # Check if the page is not protected at all
302 - if ( $config == $defaultConfig ) {
303 - return "none";
 277+ # Check if the page is not protected at all...
 278+ if ( $config['override'] == $defaultConfig['override']
 279+ && $config['autoreview'] == $defaultConfig['autoreview'] )
 280+ {
 281+ return "none"; // not protected
304282 }
305 - # Otherwise, find the protection level
306 - foreach ( $validLevels as $level => $settings ) {
307 - if ( $config == $settings ) {
308 - return $level;
 283+ # All protection levels have 'override' on
 284+ if( $config['override'] ) {
 285+ # The levels are defined by the 'autoreview' settings
 286+ if( in_array( $config['autoreview'], self::getRestrictionLevels() ) ) {
 287+ return $config['autoreview'];
309288 }
310289 }
311290 return "invalid";
@@ -1157,10 +1136,10 @@
11581137 # ################ Page configuration functions #################
11591138
11601139 /**
1161 - * Get visibility restrictions on page
 1140+ * Get visibility settings/restrictions for a page
11621141 * @param Title $title, page title
11631142 * @param int $flags, FR_MASTER
1164 - * @returns Array (select,override)
 1143+ * @returns Array (associative) (select,override,autoreview,expiry)
11651144 */
11661145 public static function getPageVisibilitySettings( $title, $flags = 0 ) {
11671146 $db = ($flags & FR_MASTER) ?
@@ -1183,19 +1162,22 @@
11841163 }
11851164 // Is there a non-expired row?
11861165 if ( $row ) {
 1166+ $precedence = self::useProtectionLevels()
 1167+ ? self::getPrecedence() // site default; ignore fpc_select
 1168+ : $row->fpc_select;
11871169 $config = array(
1188 - 'select' => intval( $row->fpc_select ),
1189 - 'override' => $row->fpc_override,
 1170+ 'select' => intval( $precedence ),
 1171+ 'override' => $row->fpc_override ? 1 : 0,
11901172 'autoreview' => $row->fpc_level,
1191 - 'expiry' => Block::decodeExpiry( $row->fpc_expiry )
 1173+ 'expiry' => Block::decodeExpiry( $row->fpc_expiry ) // TS_MW
11921174 );
1193 - # If there are protection levels defined check if this is valid
 1175+ # If there are protection levels defined check if this is valid...
11941176 if ( self::useProtectionLevels() && self::getProtectionLevel( $config ) == 'invalid' ) {
1195 - return self::getDefaultVisibilitySettings(); // revert to none
 1177+ $config = self::getDefaultVisibilitySettings(); // revert to default (none)
11961178 }
11971179 } else {
11981180 # Return the default config if this page doesn't have its own
1199 - return self::getDefaultVisibilitySettings();
 1181+ $config = self::getDefaultVisibilitySettings();
12001182 }
12011183 return $config;
12021184 }
@@ -1217,7 +1199,7 @@
12181200 'expiry' => 'infinity'
12191201 );
12201202 }
1221 -
 1203+
12221204 /**
12231205 * Purge expired restrictions from the flaggedpage_config table.
12241206 * The stable version of pages may change and invalidation may be required.
Index: trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php
@@ -114,8 +114,9 @@
115115 // Custom expiry takes precedence
116116 $this->expiry = strlen( $this->expiry ) ?
117117 $this->expiry : $this->expirySelection;
118 - if ( $this->expiry == 'existing' )
 118+ if ( $this->expiry == 'existing' ) {
119119 $this->expiry = $this->oldExpiry;
 120+ }
120121 // Custom reason takes precedence
121122 if ( $this->reasonSelection != 'other' ) {
122123 $comment = $this->reasonSelection; // start with dropdown reason
@@ -157,13 +158,17 @@
158159
159160 /**
160161 * Check if a user can set the autoreview restiction level to $right
161 - * @param string $level
 162+ * @param string $right the level
162163 * @returns bool
163164 */
164165 public static function userCanSetAutoreviewLevel( $right ) {
165166 global $wgUser;
166 - if ( $right == '' )
167 - return true; // no restrictions
 167+ if ( $right == '' ) {
 168+ return true; // no restrictions (none)
 169+ }
 170+ if ( !in_array( $right, FlaggedRevs::getRestrictionLevels() ) ) {
 171+ return false; // invalid restriction level
 172+ }
168173 # Don't let them choose levels above their own rights
169174 if ( $right == 'sysop' ) {
170175 // special case, rewrite sysop to protect and editprotected
@@ -359,24 +364,26 @@
360365
361366 protected function buildSelector( $selected ) {
362367 global $wgUser;
363 - $levels = array();
364 - foreach ( FlaggedRevs::getRestrictionLevels() as $key ) {
 368+ $allowedLevels = array();
 369+ $levels = FlaggedRevs::getRestrictionLevels();
 370+ array_unshift( $levels, '' ); // Add a "none" level
 371+ foreach ( $levels as $key ) {
365372 # Don't let them choose levels they can't set,
366373 # but *show* them all when the form is disabled.
367374 if ( $this->isAllowed && !self::userCanSetAutoreviewLevel( $key ) ) {
368375 continue;
369376 }
370 - $levels[] = $key;
 377+ $allowedLevels[] = $key;
371378 }
372379 $id = 'mwProtect-level-autoreview';
373380 $attribs = array(
374381 'id' => $id,
375382 'name' => $id,
376 - 'size' => count( $levels ),
 383+ 'size' => count( $allowedLevels ),
377384 ) + $this->disabledAttrib;
378385
379386 $out = Xml::openElement( 'select', $attribs );
380 - foreach ( $levels as $key ) {
 387+ foreach ( $allowedLevels as $key ) {
381388 $out .= Xml::option( $this->getOptionLabel( $key ), $key, $key == $selected );
382389 }
383390 $out .= Xml::closeElement( 'select' );
@@ -395,50 +402,37 @@
396403 } else {
397404 $key = "protect-level-{$permission}";
398405 $msg = wfMsg( $key );
399 - if ( wfEmptyMsg( $key, $msg ) )
 406+ if ( wfEmptyMsg( $key, $msg ) ) {
400407 $msg = wfMsg( 'protect-fallback', $permission );
 408+ }
401409 return $msg;
402410 }
403411 }
404412
405413 public function submit() {
406414 global $wgUser, $wgContLang;
407 - $defaultPrecedence = FlaggedRevs::getPrecedence();
408 - $defaultOverride = FlaggedRevs::isStableShownByDefault();
409 - $reset = false;
410 - if ( $this->select == $defaultPrecedence && $this->override == $defaultOverride ) {
411 - $reset = ( $this->autoreview == '' ); // we are going back to site defaults
412 - }
413415 # Take this opportunity to purge out expired configurations
414416 FlaggedRevs::purgeExpiredConfigurations();
 417+ # Are we are going back to site defaults?
 418+ $reset = self::configIsReset( $this->select, $this->override, $this->autoreview );
415419 # Parse and cleanup the expiry time given...
416 - $expiry = $this->expiry; // save original input
417420 if ( $reset || $this->expiry == 'infinite' || $this->expiry == 'indefinite' ) {
418 - $this->expiry = Block::infinity();
 421+ $this->expiry = Block::infinity(); // normalize to 'infinity'
419422 } else {
420423 # Convert GNU-style date, on error returns -1 for PHP <5.1 and false for PHP >=5.1
421424 $this->expiry = strtotime( $this->expiry );
422425 if ( $this->expiry < 0 || $this->expiry === false ) {
423426 return 'stabilize_expiry_invalid';
424427 }
 428+ # Convert date to MW timestamp format
425429 $this->expiry = wfTimestamp( TS_MW, $this->expiry );
426430 if ( $this->expiry < wfTimestampNow() ) {
427431 return 'stabilize_expiry_old';
428432 }
429433 }
430 -
431 - $dbw = wfGetDB( DB_MASTER );
432 - # Get current config...
433 - $oldRow = $dbw->selectRow( 'flaggedpage_config',
434 - array( 'fpc_select', 'fpc_override', 'fpc_level', 'fpc_expiry' ),
435 - array( 'fpc_page_id' => $this->page->getArticleID() ),
436 - __METHOD__,
437 - 'FOR UPDATE'
438 - );
439434 # Update the DB row with the new config...
440 - $changed = $this->updateConfigRow( $oldRow, $reset );
441 -
442 - // Check if this actually changed anything...
 435+ $changed = $this->updateConfigRow( $reset );
 436+ # Log if this actually changed anything...
443437 if ( $changed ) {
444438 $article = new Article( $this->page );
445439 $latest = $this->page->getLatestRevID( GAID_FOR_UPDATE );
@@ -467,6 +461,7 @@
468462 $comment .= wfMsgForContent( 'colon-separator' ) . $reason;
469463 }
470464 # Insert a null revision...
 465+ $dbw = wfGetDB( DB_MASTER );
471466 $nullRev = Revision::newNullRevision( $dbw, $article->getId(), $comment, true );
472467 $nullRevId = $nullRev->insertOn( $dbw );
473468 # Update page record and touch page
@@ -504,33 +499,37 @@
505500 return true;
506501 }
507502
508 - protected function updateConfigRow( $oldRow, $reset ) {
 503+ protected function updateConfigRow( $reset ) {
509504 $changed = false;
510505 $dbw = wfGetDB( DB_MASTER );
511 - # If setting to site default values and there is a row...erase it
512 - if ( $oldRow && $reset ) {
 506+ # If setting to site default values and there is a row then erase it
 507+ if ( $reset ) {
513508 $dbw->delete( 'flaggedpage_config',
514509 array( 'fpc_page_id' => $this->page->getArticleID() ),
515510 __METHOD__
516511 );
517512 $changed = ( $dbw->affectedRows() != 0 ); // did this do anything?
518 - # Otherwise, add a row unless we are just setting it as the site default,
519 - # or it is the same the current one...
 513+ # Otherwise, add/replace row if we are not just setting it to the site default
520514 } elseif ( !$reset ) {
 515+ # Get current config...
 516+ $oldRow = $dbw->selectRow( 'flaggedpage_config',
 517+ array( 'fpc_select', 'fpc_override', 'fpc_level', 'fpc_expiry' ),
 518+ array( 'fpc_page_id' => $this->page->getArticleID() ),
 519+ __METHOD__,
 520+ 'FOR UPDATE'
 521+ );
521522 $dbExpiry = Block::encodeExpiry( $this->expiry, $dbw );
522 - if ( !$oldRow // no previous config, or...
523 - || $oldRow->fpc_select != $this->select // ...precedence changed, or...
524 - || $oldRow->fpc_override != $this->override // ...override changed, or...
525 - || $oldRow->fpc_level != $this->autoreview // ...autoreview level changed, or...
526 - || $oldRow->fpc_expiry != $dbExpiry // ...expiry changed
527 - ) {
528 - $changed = true;
 523+ # Check if this is not the same config as the existing row (if any)
 524+ $changed = self::configIsDifferent( $oldRow,
 525+ $this->select, $this->override, $this->autoreview, $dbExpiry );
 526+ # If the new config is different, replace the old row...
 527+ if ( $changed ) {
529528 $dbw->replace( 'flaggedpage_config',
530529 array( 'PRIMARY' ),
531530 array(
532531 'fpc_page_id' => $this->page->getArticleID(),
533 - 'fpc_select' => $this->select,
534 - 'fpc_override' => $this->override,
 532+ 'fpc_select' => intval( $this->select ),
 533+ 'fpc_override' => intval( $this->override ),
535534 'fpc_level' => $this->autoreview,
536535 'fpc_expiry' => $dbExpiry
537536 ),
@@ -540,19 +539,51 @@
541540 }
542541 return $changed;
543542 }
544 -
 543+
 544+ // Checks if new config is the same as the site default
 545+ protected function configIsReset( $select, $override, $autoreview ) {
 546+ # For protection config, just ignore the fpc_select column
 547+ if( FlaggedRevs::useProtectionLevels() ) {
 548+ return ( $override == FlaggedRevs::isStableShownByDefault()
 549+ && $autoreview == '' );
 550+ } else {
 551+ return ( $select == FlaggedRevs::getPrecedence()
 552+ && $override == FlaggedRevs::isStableShownByDefault()
 553+ && $autoreview == '' );
 554+ }
 555+ }
 556+
 557+ // Checks if new config is different than the existing row
 558+ protected function configIsDifferent( $oldRow, $select, $override, $autoreview, $dbExpiry ) {
 559+ if( !$oldRow ) {
 560+ return true; // no previous config
 561+ }
 562+ # For protection config, just ignore the fpc_select column
 563+ if( FlaggedRevs::useProtectionLevels() ) {
 564+ return ( $oldRow->fpc_override != $override // ...override changed, or...
 565+ || $oldRow->fpc_level != $autoreview // ...autoreview level changed, or...
 566+ || $oldRow->fpc_expiry != $dbExpiry // ...expiry changed
 567+ );
 568+ } else {
 569+ return ( $oldRow->fpc_select != $select // ...precedence changed, or...
 570+ || $oldRow->fpc_override != $override // ...override changed, or...
 571+ || $oldRow->fpc_level != $autoreview // ...autoreview level changed, or...
 572+ || $oldRow->fpc_expiry != $dbExpiry // ...expiry changed
 573+ );
 574+ }
 575+ }
 576+
545577 // @FIXME: do this better
546578 protected function getLogReason( $reset ) {
547579 global $wgContLang;
548 - # ID, accuracy, depth, style
549580 $set = array();
550 - // Precedence
551 - if ( FlaggedRevs::qualityVersions() ) {
 581+ // Precedence (ignored for protection-based configs)
 582+ if ( !FlaggedRevs::useProtectionLevels() && FlaggedRevs::qualityVersions() ) {
552583 $set[] = wfMsgForContent( 'stabilization-sel-short' ) .
553584 wfMsgForContent( 'colon-separator' ) .
554585 wfMsgForContent( "stabilization-sel-short-{$this->select}" );
555586 }
556 - // Default version
 587+ // Default version shown on page view
557588 $set[] = wfMsgForContent( 'stabilization-def-short' ) .
558589 wfMsgForContent( 'colon-separator' ) .
559590 wfMsgForContent( "stabilization-def-short-{$this->override}" );
@@ -563,17 +594,17 @@
564595 # Append comment with settings (other than for resets)
565596 $reason = $this->reason;
566597 if ( !$reset ) {
567 - $reason = $this->reason
568 - ? "{$this->reason} $settings"
569 - : "$settings";
 598+ $reason = ( $reason != '' )
 599+ ? "{$reason} {$settings}"
 600+ : $settings;
570601 $dbw = wfGetDB( DB_MASTER );
571 - $encodedExpiry = Block::encodeExpiry( $expiry, $dbw );
572 - if ( $encodedExpiry != 'infinity' ) {
573 - $expiry_description = ' (' . wfMsgForContent( 'stabilize-expiring',
574 - $wgContLang->timeanddate( $expiry, false, false ) ,
575 - $wgContLang->date( $expiry, false, false ) ,
576 - $wgContLang->time( $expiry, false, false ) ) . ')';
577 - $reason .= "$expiry_description";
 602+ # $this->expiry is a MW timestamp or 'infinity'
 603+ if ( $this->expiry != Block::infinity() ) {
 604+ $expiry_description = wfMsgForContent( 'stabilize-expiring',
 605+ $wgContLang->timeanddate( $this->expiry, false, false ) ,
 606+ $wgContLang->date( $this->expiry, false, false ) ,
 607+ $wgContLang->time( $this->expiry, false, false ) );
 608+ $reason .= " ($expiry_description)";
578609 }
579610 }
580611 return $reason;
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
@@ -7,15 +7,14 @@
88 */
99 public static function defineSpecialPages( &$list ) {
1010 global $wgSpecialPages, $wgUseTagFilter;
11 - global $wgFlaggedRevsNamespaces, $wgFlaggedRevsOverride, $wgFlaggedRevsProtectLevels;
1211 // Show special pages only if FlaggedRevs is enabled on some namespaces
13 - if ( empty( $wgFlaggedRevsNamespaces ) ) {
 12+ if ( !FlaggedRevs::getReviewNamespaces() ) {
1413 return true;
1514 }
1615 $list['RevisionReview'] = $wgSpecialPages['RevisionReview'] = 'RevisionReview';
1716 $list['ReviewedVersions'] = $wgSpecialPages['ReviewedVersions'] = 'ReviewedVersions';
1817 // Protect levels define allowed stability settings
19 - if ( empty( $wgFlaggedRevsProtectLevels ) ) {
 18+ if ( !FlaggedRevs::useProtectionLevels() ) {
2019 $list['Stabilization'] = $wgSpecialPages['Stabilization'] = 'Stabilization';
2120 }
2221 $list['UnreviewedPages'] = $wgSpecialPages['UnreviewedPages'] = 'UnreviewedPages';
@@ -29,7 +28,7 @@
3029 }
3130 $list['QualityOversight'] = $wgSpecialPages['QualityOversight'] = 'QualityOversight';
3231 $list['ValidationStatistics'] = $wgSpecialPages['ValidationStatistics'] = 'ValidationStatistics';
33 - if ( !$wgFlaggedRevsOverride ) {
 32+ if ( !FlaggedRevs::isStableShownByDefault() ) {
3433 $list['StablePages'] = $wgSpecialPages['StablePages'] = 'StablePages';
3534 } else {
3635 $list['UnstablePages'] = $wgSpecialPages['UnstablePages'] = 'UnstablePages';
@@ -2058,17 +2057,17 @@
20592058 }
20602059 # Can the user actually do anything?
20612060 $isAllowed = $wgUser->isAllowed( 'stablesettings' );
2062 - $disabledAttrib = !$isAllowed ? array( 'disabled' => 'disabled' ) : array();
 2061+ $disabledAttrib = !$isAllowed ?
 2062+ array( 'disabled' => 'disabled' ) : array();
20632063 # Get the current config/expiry
20642064 $config = FlaggedRevs::getPageVisibilitySettings( $article->getTitle(), FR_MASTER );
 2065+ # Convert expiry to a display form (GMT)
20652066 $oldExpiry = $config['expiry'] !== 'infinity' ?
20662067 wfTimestamp( TS_RFC2822, $config['expiry'] ) : 'infinite';
2067 - # Load request params...
 2068+ # Load requested restriction level, default to current level...
20682069 $selected = $wgRequest->getVal( 'wpStabilityConfig',
20692070 FlaggedRevs::getProtectionLevel( $config ) );
2070 - if ( $selected == 'invalid' ) {
2071 - throw new MWException( 'This page has an undefined stability configuration!' );
2072 - }
 2071+ # Load the requested expiry time
20732072 $expiry = $wgRequest->getText( 'mwStabilize-expiry' );
20742073 # Add some script for expiry dropdowns
20752074 $wgOut->addScript(
@@ -2088,29 +2087,28 @@
20892088 $output .= Xml::openElement( 'fieldset' );
20902089 $output .= Xml::element( 'legend', null, wfMsg( 'flaggedrevs-protect-legend' ) );
20912090 # Add a "no restrictions" level
2092 - $effectiveLevels = array( "none" => null );
2093 - $effectiveLevels += FlaggedRevs::getProtectionLevels();
2094 -
 2091+ $effectiveLevels = FlaggedRevs::getRestrictionLevels();
 2092+ array_unshift( $effectiveLevels, "none" );
 2093+ # Show all restriction levels in a select...
20952094 $attribs = array(
20962095 'id' => 'mwStabilityConfig',
20972096 'name' => 'mwStabilityConfig',
20982097 'size' => count( $effectiveLevels ),
20992098 ) + $disabledAttrib;
21002099 $output .= Xml::openElement( 'select', $attribs );
2101 - # Show all restriction levels in a select...
2102 - foreach ( $effectiveLevels as $level => $x ) {
2103 - if ( $level == 'none' ) {
 2100+ foreach ( $effectiveLevels as $limit ) {
 2101+ if ( $limit == 'none' ) {
21042102 $label = FlaggedRevs::stableOnlyIfConfigured()
21052103 ? wfMsg( 'flaggedrevs-protect-none' )
21062104 : wfMsg( 'flaggedrevs-protect-basic' );
21072105 } else {
2108 - $label = wfMsg( 'flaggedrevs-protect-' . $level );
 2106+ $label = wfMsg( 'flaggedrevs-protect-' . $limit );
21092107 }
21102108 // Default to the key itself if no UI message
2111 - if ( wfEmptyMsg( 'flaggedrevs-protect-' . $level, $label ) ) {
2112 - $label = 'flaggedrevs-protect-' . $level;
 2109+ if ( wfEmptyMsg( 'flaggedrevs-protect-' . $limit, $label ) ) {
 2110+ $label = 'flaggedrevs-protect-' . $limit;
21132111 }
2114 - $output .= Xml::option( $label, $level, $level == $selected );
 2112+ $output .= Xml::option( $label, $limit, $limit == $selected );
21152113 }
21162114 $output .= Xml::closeElement( 'select' );
21172115 # Get expiry dropdown
@@ -2198,15 +2196,15 @@
21992197 // Update stability config from request
22002198 public static function onProtectionSave( $article, &$errorMsg ) {
22012199 global $wgUser, $wgRequest;
2202 - $levels = FlaggedRevs::getProtectionLevels();
2203 - if ( empty( $levels ) || !$article->exists() )
 2200+ if ( !FlaggedRevs::useProtectionLevels() || !$article->exists() ) {
22042201 return true; // simple custom levels set for action=protect
2205 - if ( wfReadOnly() || !$wgUser->isAllowed( 'stablesettings' ) ) {
2206 - return true; // user cannot change anything
22072202 }
22082203 if ( !FlaggedRevs::inReviewNamespace( $article->getTitle() ) ) {
22092204 return true; // not a reviewable page
22102205 }
 2206+ if ( wfReadOnly() || !$wgUser->isAllowed( 'stablesettings' ) ) {
 2207+ return true; // user cannot change anything
 2208+ }
22112209 $form = new Stabilization();
22122210 $form->target = $article->getTitle(); # Our target page
22132211 $form->watchThis = null; # protection form already has a watch check
@@ -2215,17 +2213,17 @@
22162214 $form->expiry = $wgRequest->getText( 'mwStabilize-expiry' ); # Expiry
22172215 $form->expirySelection = $wgRequest->getVal( 'wpExpirySelection' ); # Expiry dropdown
22182216 # Fill in config from the protection level...
 2217+ $levels = FlaggedRevs::getRestrictionLevels();
22192218 $selected = $wgRequest->getVal( 'mwStabilityConfig' );
 2219+ $form->select = FlaggedRevs::getPrecedence(); // default
22202220 if ( $selected == "none" ) {
2221 - $form->select = FlaggedRevs::getPrecedence(); // default
22222221 $form->override = (int)FlaggedRevs::isStableShownByDefault(); // default
22232222 $form->autoreview = ''; // default
22242223 $form->reviewThis = false;
2225 - } else if ( isset( $levels[$selected] ) ) {
2226 - $form->select = $levels[$selected]['select'];
2227 - $form->override = $levels[$selected]['override'];
2228 - $form->autoreview = $levels[$selected]['autoreview'];
2229 - $form->reviewThis = true; // auto-review; protection-like
 2224+ } else if ( in_array( $selected, $levels ) ) {
 2225+ $form->override = 1; // stable page
 2226+ $form->autoreview = $selected; // autoreview restriction
 2227+ $form->reviewThis = true; // auto-review page; protection-like
22302228 } else {
22312229 return false; // bad level
22322230 }
Index: trunk/extensions/FlaggedRevs/api/ApiStabilize.php
@@ -62,20 +62,19 @@
6363 $form->reasonSelection = 'other'; # Reason dropdown
6464 $form->expiry = $params['expiry']; # Expiry
6565 $form->expirySelection = 'other'; # Expiry dropdown
66 -
67 - $levels = FlaggedRevs::getProtectionLevels();
 66+
6867 // Check if protection levels are enabled
69 - if( !empty($levels) ) {
 68+ if( FlaggedRevs::useProtectionLevels() ) {
 69+ $levels = FlaggedRevs::getRestrictionLevels();
7070 # Fill in config from the protection level...
7171 $selected = $params['protectlevel'];
 72+ $form->select = FlaggedRevs::getPrecedence(); // default
7273 if( $selected == "none" ) {
73 - $form->select = FlaggedRevs::getPrecedence(); // default
7474 $form->override = (int)FlaggedRevs::isStableShownByDefault(); // default
7575 $form->autoreview = ''; // default
76 - } else if( isset($levels[$selected]) ) {
77 - $form->select = $levels[$selected]['select'];
78 - $form->override = $levels[$selected]['override'];
79 - $form->autoreview = $levels[$selected]['autoreview'];
 76+ } else if( in_array( $selected, $levels ) ) {
 77+ $form->override = 1; // stable page
 78+ $form->autoreview = $selected; // autoreview restriction
8079 } else {
8180 $this->dieUsage( "Invalid protection level given.", 'badprotectlevel' );
8281 }
@@ -87,10 +86,10 @@
8887 } else {
8988 $form->override = $this->defaultFromKey( $params['default'] );
9089 }
91 - if( $params['autoreview'] != 'none' ) {
92 - $form->autoreview = $params['autoreview'];
93 - } else {
 90+ if( $params['autoreview'] == 'none' ) {
9491 $form->autoreview = ''; // 'none' -> ''
 92+ } else {
 93+ $form->autoreview = $params['autoreview'];
9594 }
9695 }
9796 $form->wasPosted = true; // already validated
@@ -105,7 +104,7 @@
106105 # Output success line with the title and config parameters
107106 $res = array();
108107 $res['title'] = $title->getPrefixedText();
109 - if( FlaggedRevs::getProtectionLevels() ) {
 108+ if( count($levels) ) {
110109 $res['protectlevel'] = $params['protectlevel'];
111110 } else {
112111 $res['default'] = $params['default'];
@@ -159,19 +158,17 @@
160159 }
161160
162161 public function getAllowedParams() {
 162+ // Replace '' with more readable 'none' in autoreview restiction levels
 163+ $autoreviewLevels = FlaggedRevs::getRestrictionLevels();
 164+ $autoreviewLevels[] = 'none';
163165 if( FlaggedRevs::useProtectionLevels() ) {
164 - $validLevels = array_keys( FlaggedRevs::getProtectionLevels() );
165 - $validLevels[] = 'none';
166166 $pars = array(
167167 'protectlevel' => array(
168 - ApiBase :: PARAM_TYPE => $validLevels,
 168+ ApiBase :: PARAM_TYPE => $autoreviewLevels,
169169 ApiBase :: PARAM_DFLT => 'none',
170170 )
171171 );
172172 } else {
173 - // Replace '' with more readable 'none' in autoreview restiction levels
174 - $autoreviewLevels = array_filter( FlaggedRevs::getRestrictionLevels() );
175 - $autoreviewLevels[] = 'none';
176173 $pars = array(
177174 'default' => array(
178175 ApiBase :: PARAM_TYPE => array( 'latest', 'stable' ),

Status & tagging log