Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php |
— | — | @@ -145,20 +145,16 @@ |
146 | 146 | # (FR_SIGHTED,FR_QUALITY,FR_PRISTINE) |
147 | 147 | $wgFlaggedRevsPatrolLevel = FR_SIGHTED; |
148 | 148 | |
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. |
162 | 153 | $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; |
163 | 159 | |
164 | 160 | # Please set these as something different. Any text will do, though it probably |
165 | 161 | # shouldn't be very short (less secure) or very long (waste of resources). |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php |
— | — | @@ -18,7 +18,6 @@ |
19 | 19 | protected static $patrolNamespaces = array(); |
20 | 20 | # Restriction levels/config |
21 | 21 | protected static $restrictionLevels = array(); |
22 | | - protected static $protectionLevels = array(); |
23 | 22 | # Temporary process cache variable |
24 | 23 | protected static $includeVersionCache = array(); |
25 | 24 | |
— | — | @@ -26,7 +25,10 @@ |
27 | 26 | |
28 | 27 | public static function load() { |
29 | 28 | global $wgFlaggedRevTags; |
30 | | - if ( self::$loaded ) return true; |
| 29 | + if ( self::$loaded ) { |
| 30 | + return true; |
| 31 | + } |
| 32 | + self::$loaded = true; |
31 | 33 | # Assume true, then set to false if needed |
32 | 34 | if ( !empty( $wgFlaggedRevTags ) ) { |
33 | 35 | self::$qualityVersions = true; |
— | — | @@ -76,25 +78,10 @@ |
77 | 79 | self::$minPL[$tag] = max( $minPL, 1 ); |
78 | 80 | self::$minSL[$tag] = 1; |
79 | 81 | } |
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 | | - } |
93 | 82 | global $wgFlaggedRevsRestrictionLevels; |
94 | | - # Make sure that there is a "none" level |
| 83 | + # Make sure that the levels are unique |
95 | 84 | 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' ); |
99 | 86 | # Make sure no talk namespaces are in review namespace |
100 | 87 | global $wgFlaggedRevsNamespaces, $wgFlaggedRevsPatrolNamespaces; |
101 | 88 | foreach ( $wgFlaggedRevsNamespaces as $ns ) { |
— | — | @@ -107,8 +94,6 @@ |
108 | 95 | self::$reviewNamespaces = $wgFlaggedRevsNamespaces; |
109 | 96 | # Note: reviewable *pages* override patrollable ones |
110 | 97 | self::$patrolNamespaces = $wgFlaggedRevsPatrolNamespaces; |
111 | | - |
112 | | - self::$loaded = true; |
113 | 98 | } |
114 | 99 | |
115 | 100 | # ################ Basic accessors ################# |
— | — | @@ -268,43 +253,37 @@ |
269 | 254 | global $wgFlaggedRevsLowProfile; |
270 | 255 | return $wgFlaggedRevsLowProfile; |
271 | 256 | } |
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 | | - } |
281 | 257 | |
282 | 258 | /** |
283 | 259 | * Are there site defined protection levels for review |
284 | 260 | * @returns bool |
285 | 261 | */ |
286 | 262 | public static function useProtectionLevels() { |
287 | | - return ( count( self::getProtectionLevels() ) > 0 ); |
| 263 | + global $wgFlaggedRevsProtection; |
| 264 | + return $wgFlaggedRevsProtection && self::getRestrictionLevels(); |
288 | 265 | } |
289 | | - |
| 266 | + |
290 | 267 | /** |
291 | 268 | * Find what protection level a config is in |
292 | 269 | * @param array $config |
293 | | - * @returns mixed (array/string) |
| 270 | + * @returns string |
294 | 271 | */ |
295 | 272 | public static function getProtectionLevel( $config ) { |
296 | | - $validLevels = self::getProtectionLevels(); |
| 273 | + if( !self::useProtectionLevels() ) { |
| 274 | + throw new MWException('getProtectionLevel() called with $wgFlaggedRevsProtection off'); |
| 275 | + } |
297 | 276 | $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 |
304 | 282 | } |
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']; |
309 | 288 | } |
310 | 289 | } |
311 | 290 | return "invalid"; |
— | — | @@ -1157,10 +1136,10 @@ |
1158 | 1137 | # ################ Page configuration functions ################# |
1159 | 1138 | |
1160 | 1139 | /** |
1161 | | - * Get visibility restrictions on page |
| 1140 | + * Get visibility settings/restrictions for a page |
1162 | 1141 | * @param Title $title, page title |
1163 | 1142 | * @param int $flags, FR_MASTER |
1164 | | - * @returns Array (select,override) |
| 1143 | + * @returns Array (associative) (select,override,autoreview,expiry) |
1165 | 1144 | */ |
1166 | 1145 | public static function getPageVisibilitySettings( $title, $flags = 0 ) { |
1167 | 1146 | $db = ($flags & FR_MASTER) ? |
— | — | @@ -1183,19 +1162,22 @@ |
1184 | 1163 | } |
1185 | 1164 | // Is there a non-expired row? |
1186 | 1165 | if ( $row ) { |
| 1166 | + $precedence = self::useProtectionLevels() |
| 1167 | + ? self::getPrecedence() // site default; ignore fpc_select |
| 1168 | + : $row->fpc_select; |
1187 | 1169 | $config = array( |
1188 | | - 'select' => intval( $row->fpc_select ), |
1189 | | - 'override' => $row->fpc_override, |
| 1170 | + 'select' => intval( $precedence ), |
| 1171 | + 'override' => $row->fpc_override ? 1 : 0, |
1190 | 1172 | 'autoreview' => $row->fpc_level, |
1191 | | - 'expiry' => Block::decodeExpiry( $row->fpc_expiry ) |
| 1173 | + 'expiry' => Block::decodeExpiry( $row->fpc_expiry ) // TS_MW |
1192 | 1174 | ); |
1193 | | - # If there are protection levels defined check if this is valid |
| 1175 | + # If there are protection levels defined check if this is valid... |
1194 | 1176 | if ( self::useProtectionLevels() && self::getProtectionLevel( $config ) == 'invalid' ) { |
1195 | | - return self::getDefaultVisibilitySettings(); // revert to none |
| 1177 | + $config = self::getDefaultVisibilitySettings(); // revert to default (none) |
1196 | 1178 | } |
1197 | 1179 | } else { |
1198 | 1180 | # Return the default config if this page doesn't have its own |
1199 | | - return self::getDefaultVisibilitySettings(); |
| 1181 | + $config = self::getDefaultVisibilitySettings(); |
1200 | 1182 | } |
1201 | 1183 | return $config; |
1202 | 1184 | } |
— | — | @@ -1217,7 +1199,7 @@ |
1218 | 1200 | 'expiry' => 'infinity' |
1219 | 1201 | ); |
1220 | 1202 | } |
1221 | | - |
| 1203 | + |
1222 | 1204 | /** |
1223 | 1205 | * Purge expired restrictions from the flaggedpage_config table. |
1224 | 1206 | * The stable version of pages may change and invalidation may be required. |
Index: trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php |
— | — | @@ -114,8 +114,9 @@ |
115 | 115 | // Custom expiry takes precedence |
116 | 116 | $this->expiry = strlen( $this->expiry ) ? |
117 | 117 | $this->expiry : $this->expirySelection; |
118 | | - if ( $this->expiry == 'existing' ) |
| 118 | + if ( $this->expiry == 'existing' ) { |
119 | 119 | $this->expiry = $this->oldExpiry; |
| 120 | + } |
120 | 121 | // Custom reason takes precedence |
121 | 122 | if ( $this->reasonSelection != 'other' ) { |
122 | 123 | $comment = $this->reasonSelection; // start with dropdown reason |
— | — | @@ -157,13 +158,17 @@ |
158 | 159 | |
159 | 160 | /** |
160 | 161 | * Check if a user can set the autoreview restiction level to $right |
161 | | - * @param string $level |
| 162 | + * @param string $right the level |
162 | 163 | * @returns bool |
163 | 164 | */ |
164 | 165 | public static function userCanSetAutoreviewLevel( $right ) { |
165 | 166 | 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 | + } |
168 | 173 | # Don't let them choose levels above their own rights |
169 | 174 | if ( $right == 'sysop' ) { |
170 | 175 | // special case, rewrite sysop to protect and editprotected |
— | — | @@ -359,24 +364,26 @@ |
360 | 365 | |
361 | 366 | protected function buildSelector( $selected ) { |
362 | 367 | 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 ) { |
365 | 372 | # Don't let them choose levels they can't set, |
366 | 373 | # but *show* them all when the form is disabled. |
367 | 374 | if ( $this->isAllowed && !self::userCanSetAutoreviewLevel( $key ) ) { |
368 | 375 | continue; |
369 | 376 | } |
370 | | - $levels[] = $key; |
| 377 | + $allowedLevels[] = $key; |
371 | 378 | } |
372 | 379 | $id = 'mwProtect-level-autoreview'; |
373 | 380 | $attribs = array( |
374 | 381 | 'id' => $id, |
375 | 382 | 'name' => $id, |
376 | | - 'size' => count( $levels ), |
| 383 | + 'size' => count( $allowedLevels ), |
377 | 384 | ) + $this->disabledAttrib; |
378 | 385 | |
379 | 386 | $out = Xml::openElement( 'select', $attribs ); |
380 | | - foreach ( $levels as $key ) { |
| 387 | + foreach ( $allowedLevels as $key ) { |
381 | 388 | $out .= Xml::option( $this->getOptionLabel( $key ), $key, $key == $selected ); |
382 | 389 | } |
383 | 390 | $out .= Xml::closeElement( 'select' ); |
— | — | @@ -395,50 +402,37 @@ |
396 | 403 | } else { |
397 | 404 | $key = "protect-level-{$permission}"; |
398 | 405 | $msg = wfMsg( $key ); |
399 | | - if ( wfEmptyMsg( $key, $msg ) ) |
| 406 | + if ( wfEmptyMsg( $key, $msg ) ) { |
400 | 407 | $msg = wfMsg( 'protect-fallback', $permission ); |
| 408 | + } |
401 | 409 | return $msg; |
402 | 410 | } |
403 | 411 | } |
404 | 412 | |
405 | 413 | public function submit() { |
406 | 414 | 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 | | - } |
413 | 415 | # Take this opportunity to purge out expired configurations |
414 | 416 | FlaggedRevs::purgeExpiredConfigurations(); |
| 417 | + # Are we are going back to site defaults? |
| 418 | + $reset = self::configIsReset( $this->select, $this->override, $this->autoreview ); |
415 | 419 | # Parse and cleanup the expiry time given... |
416 | | - $expiry = $this->expiry; // save original input |
417 | 420 | if ( $reset || $this->expiry == 'infinite' || $this->expiry == 'indefinite' ) { |
418 | | - $this->expiry = Block::infinity(); |
| 421 | + $this->expiry = Block::infinity(); // normalize to 'infinity' |
419 | 422 | } else { |
420 | 423 | # Convert GNU-style date, on error returns -1 for PHP <5.1 and false for PHP >=5.1 |
421 | 424 | $this->expiry = strtotime( $this->expiry ); |
422 | 425 | if ( $this->expiry < 0 || $this->expiry === false ) { |
423 | 426 | return 'stabilize_expiry_invalid'; |
424 | 427 | } |
| 428 | + # Convert date to MW timestamp format |
425 | 429 | $this->expiry = wfTimestamp( TS_MW, $this->expiry ); |
426 | 430 | if ( $this->expiry < wfTimestampNow() ) { |
427 | 431 | return 'stabilize_expiry_old'; |
428 | 432 | } |
429 | 433 | } |
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 | | - ); |
439 | 434 | # 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... |
443 | 437 | if ( $changed ) { |
444 | 438 | $article = new Article( $this->page ); |
445 | 439 | $latest = $this->page->getLatestRevID( GAID_FOR_UPDATE ); |
— | — | @@ -467,6 +461,7 @@ |
468 | 462 | $comment .= wfMsgForContent( 'colon-separator' ) . $reason; |
469 | 463 | } |
470 | 464 | # Insert a null revision... |
| 465 | + $dbw = wfGetDB( DB_MASTER ); |
471 | 466 | $nullRev = Revision::newNullRevision( $dbw, $article->getId(), $comment, true ); |
472 | 467 | $nullRevId = $nullRev->insertOn( $dbw ); |
473 | 468 | # Update page record and touch page |
— | — | @@ -504,33 +499,37 @@ |
505 | 500 | return true; |
506 | 501 | } |
507 | 502 | |
508 | | - protected function updateConfigRow( $oldRow, $reset ) { |
| 503 | + protected function updateConfigRow( $reset ) { |
509 | 504 | $changed = false; |
510 | 505 | $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 ) { |
513 | 508 | $dbw->delete( 'flaggedpage_config', |
514 | 509 | array( 'fpc_page_id' => $this->page->getArticleID() ), |
515 | 510 | __METHOD__ |
516 | 511 | ); |
517 | 512 | $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 |
520 | 514 | } 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 | + ); |
521 | 522 | $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 ) { |
529 | 528 | $dbw->replace( 'flaggedpage_config', |
530 | 529 | array( 'PRIMARY' ), |
531 | 530 | array( |
532 | 531 | '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 ), |
535 | 534 | 'fpc_level' => $this->autoreview, |
536 | 535 | 'fpc_expiry' => $dbExpiry |
537 | 536 | ), |
— | — | @@ -540,19 +539,51 @@ |
541 | 540 | } |
542 | 541 | return $changed; |
543 | 542 | } |
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 | + |
545 | 577 | // @FIXME: do this better |
546 | 578 | protected function getLogReason( $reset ) { |
547 | 579 | global $wgContLang; |
548 | | - # ID, accuracy, depth, style |
549 | 580 | $set = array(); |
550 | | - // Precedence |
551 | | - if ( FlaggedRevs::qualityVersions() ) { |
| 581 | + // Precedence (ignored for protection-based configs) |
| 582 | + if ( !FlaggedRevs::useProtectionLevels() && FlaggedRevs::qualityVersions() ) { |
552 | 583 | $set[] = wfMsgForContent( 'stabilization-sel-short' ) . |
553 | 584 | wfMsgForContent( 'colon-separator' ) . |
554 | 585 | wfMsgForContent( "stabilization-sel-short-{$this->select}" ); |
555 | 586 | } |
556 | | - // Default version |
| 587 | + // Default version shown on page view |
557 | 588 | $set[] = wfMsgForContent( 'stabilization-def-short' ) . |
558 | 589 | wfMsgForContent( 'colon-separator' ) . |
559 | 590 | wfMsgForContent( "stabilization-def-short-{$this->override}" ); |
— | — | @@ -563,17 +594,17 @@ |
564 | 595 | # Append comment with settings (other than for resets) |
565 | 596 | $reason = $this->reason; |
566 | 597 | if ( !$reset ) { |
567 | | - $reason = $this->reason |
568 | | - ? "{$this->reason} $settings" |
569 | | - : "$settings"; |
| 598 | + $reason = ( $reason != '' ) |
| 599 | + ? "{$reason} {$settings}" |
| 600 | + : $settings; |
570 | 601 | $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)"; |
578 | 609 | } |
579 | 610 | } |
580 | 611 | return $reason; |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php |
— | — | @@ -7,15 +7,14 @@ |
8 | 8 | */ |
9 | 9 | public static function defineSpecialPages( &$list ) { |
10 | 10 | global $wgSpecialPages, $wgUseTagFilter; |
11 | | - global $wgFlaggedRevsNamespaces, $wgFlaggedRevsOverride, $wgFlaggedRevsProtectLevels; |
12 | 11 | // Show special pages only if FlaggedRevs is enabled on some namespaces |
13 | | - if ( empty( $wgFlaggedRevsNamespaces ) ) { |
| 12 | + if ( !FlaggedRevs::getReviewNamespaces() ) { |
14 | 13 | return true; |
15 | 14 | } |
16 | 15 | $list['RevisionReview'] = $wgSpecialPages['RevisionReview'] = 'RevisionReview'; |
17 | 16 | $list['ReviewedVersions'] = $wgSpecialPages['ReviewedVersions'] = 'ReviewedVersions'; |
18 | 17 | // Protect levels define allowed stability settings |
19 | | - if ( empty( $wgFlaggedRevsProtectLevels ) ) { |
| 18 | + if ( !FlaggedRevs::useProtectionLevels() ) { |
20 | 19 | $list['Stabilization'] = $wgSpecialPages['Stabilization'] = 'Stabilization'; |
21 | 20 | } |
22 | 21 | $list['UnreviewedPages'] = $wgSpecialPages['UnreviewedPages'] = 'UnreviewedPages'; |
— | — | @@ -29,7 +28,7 @@ |
30 | 29 | } |
31 | 30 | $list['QualityOversight'] = $wgSpecialPages['QualityOversight'] = 'QualityOversight'; |
32 | 31 | $list['ValidationStatistics'] = $wgSpecialPages['ValidationStatistics'] = 'ValidationStatistics'; |
33 | | - if ( !$wgFlaggedRevsOverride ) { |
| 32 | + if ( !FlaggedRevs::isStableShownByDefault() ) { |
34 | 33 | $list['StablePages'] = $wgSpecialPages['StablePages'] = 'StablePages'; |
35 | 34 | } else { |
36 | 35 | $list['UnstablePages'] = $wgSpecialPages['UnstablePages'] = 'UnstablePages'; |
— | — | @@ -2058,17 +2057,17 @@ |
2059 | 2058 | } |
2060 | 2059 | # Can the user actually do anything? |
2061 | 2060 | $isAllowed = $wgUser->isAllowed( 'stablesettings' ); |
2062 | | - $disabledAttrib = !$isAllowed ? array( 'disabled' => 'disabled' ) : array(); |
| 2061 | + $disabledAttrib = !$isAllowed ? |
| 2062 | + array( 'disabled' => 'disabled' ) : array(); |
2063 | 2063 | # Get the current config/expiry |
2064 | 2064 | $config = FlaggedRevs::getPageVisibilitySettings( $article->getTitle(), FR_MASTER ); |
| 2065 | + # Convert expiry to a display form (GMT) |
2065 | 2066 | $oldExpiry = $config['expiry'] !== 'infinity' ? |
2066 | 2067 | wfTimestamp( TS_RFC2822, $config['expiry'] ) : 'infinite'; |
2067 | | - # Load request params... |
| 2068 | + # Load requested restriction level, default to current level... |
2068 | 2069 | $selected = $wgRequest->getVal( 'wpStabilityConfig', |
2069 | 2070 | 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 |
2073 | 2072 | $expiry = $wgRequest->getText( 'mwStabilize-expiry' ); |
2074 | 2073 | # Add some script for expiry dropdowns |
2075 | 2074 | $wgOut->addScript( |
— | — | @@ -2088,29 +2087,28 @@ |
2089 | 2088 | $output .= Xml::openElement( 'fieldset' ); |
2090 | 2089 | $output .= Xml::element( 'legend', null, wfMsg( 'flaggedrevs-protect-legend' ) ); |
2091 | 2090 | # 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... |
2095 | 2094 | $attribs = array( |
2096 | 2095 | 'id' => 'mwStabilityConfig', |
2097 | 2096 | 'name' => 'mwStabilityConfig', |
2098 | 2097 | 'size' => count( $effectiveLevels ), |
2099 | 2098 | ) + $disabledAttrib; |
2100 | 2099 | $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' ) { |
2104 | 2102 | $label = FlaggedRevs::stableOnlyIfConfigured() |
2105 | 2103 | ? wfMsg( 'flaggedrevs-protect-none' ) |
2106 | 2104 | : wfMsg( 'flaggedrevs-protect-basic' ); |
2107 | 2105 | } else { |
2108 | | - $label = wfMsg( 'flaggedrevs-protect-' . $level ); |
| 2106 | + $label = wfMsg( 'flaggedrevs-protect-' . $limit ); |
2109 | 2107 | } |
2110 | 2108 | // 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; |
2113 | 2111 | } |
2114 | | - $output .= Xml::option( $label, $level, $level == $selected ); |
| 2112 | + $output .= Xml::option( $label, $limit, $limit == $selected ); |
2115 | 2113 | } |
2116 | 2114 | $output .= Xml::closeElement( 'select' ); |
2117 | 2115 | # Get expiry dropdown |
— | — | @@ -2198,15 +2196,15 @@ |
2199 | 2197 | // Update stability config from request |
2200 | 2198 | public static function onProtectionSave( $article, &$errorMsg ) { |
2201 | 2199 | global $wgUser, $wgRequest; |
2202 | | - $levels = FlaggedRevs::getProtectionLevels(); |
2203 | | - if ( empty( $levels ) || !$article->exists() ) |
| 2200 | + if ( !FlaggedRevs::useProtectionLevels() || !$article->exists() ) { |
2204 | 2201 | return true; // simple custom levels set for action=protect |
2205 | | - if ( wfReadOnly() || !$wgUser->isAllowed( 'stablesettings' ) ) { |
2206 | | - return true; // user cannot change anything |
2207 | 2202 | } |
2208 | 2203 | if ( !FlaggedRevs::inReviewNamespace( $article->getTitle() ) ) { |
2209 | 2204 | return true; // not a reviewable page |
2210 | 2205 | } |
| 2206 | + if ( wfReadOnly() || !$wgUser->isAllowed( 'stablesettings' ) ) { |
| 2207 | + return true; // user cannot change anything |
| 2208 | + } |
2211 | 2209 | $form = new Stabilization(); |
2212 | 2210 | $form->target = $article->getTitle(); # Our target page |
2213 | 2211 | $form->watchThis = null; # protection form already has a watch check |
— | — | @@ -2215,17 +2213,17 @@ |
2216 | 2214 | $form->expiry = $wgRequest->getText( 'mwStabilize-expiry' ); # Expiry |
2217 | 2215 | $form->expirySelection = $wgRequest->getVal( 'wpExpirySelection' ); # Expiry dropdown |
2218 | 2216 | # Fill in config from the protection level... |
| 2217 | + $levels = FlaggedRevs::getRestrictionLevels(); |
2219 | 2218 | $selected = $wgRequest->getVal( 'mwStabilityConfig' ); |
| 2219 | + $form->select = FlaggedRevs::getPrecedence(); // default |
2220 | 2220 | if ( $selected == "none" ) { |
2221 | | - $form->select = FlaggedRevs::getPrecedence(); // default |
2222 | 2221 | $form->override = (int)FlaggedRevs::isStableShownByDefault(); // default |
2223 | 2222 | $form->autoreview = ''; // default |
2224 | 2223 | $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 |
2230 | 2228 | } else { |
2231 | 2229 | return false; // bad level |
2232 | 2230 | } |
Index: trunk/extensions/FlaggedRevs/api/ApiStabilize.php |
— | — | @@ -62,20 +62,19 @@ |
63 | 63 | $form->reasonSelection = 'other'; # Reason dropdown |
64 | 64 | $form->expiry = $params['expiry']; # Expiry |
65 | 65 | $form->expirySelection = 'other'; # Expiry dropdown |
66 | | - |
67 | | - $levels = FlaggedRevs::getProtectionLevels(); |
| 66 | + |
68 | 67 | // Check if protection levels are enabled |
69 | | - if( !empty($levels) ) { |
| 68 | + if( FlaggedRevs::useProtectionLevels() ) { |
| 69 | + $levels = FlaggedRevs::getRestrictionLevels(); |
70 | 70 | # Fill in config from the protection level... |
71 | 71 | $selected = $params['protectlevel']; |
| 72 | + $form->select = FlaggedRevs::getPrecedence(); // default |
72 | 73 | if( $selected == "none" ) { |
73 | | - $form->select = FlaggedRevs::getPrecedence(); // default |
74 | 74 | $form->override = (int)FlaggedRevs::isStableShownByDefault(); // default |
75 | 75 | $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 |
80 | 79 | } else { |
81 | 80 | $this->dieUsage( "Invalid protection level given.", 'badprotectlevel' ); |
82 | 81 | } |
— | — | @@ -87,10 +86,10 @@ |
88 | 87 | } else { |
89 | 88 | $form->override = $this->defaultFromKey( $params['default'] ); |
90 | 89 | } |
91 | | - if( $params['autoreview'] != 'none' ) { |
92 | | - $form->autoreview = $params['autoreview']; |
93 | | - } else { |
| 90 | + if( $params['autoreview'] == 'none' ) { |
94 | 91 | $form->autoreview = ''; // 'none' -> '' |
| 92 | + } else { |
| 93 | + $form->autoreview = $params['autoreview']; |
95 | 94 | } |
96 | 95 | } |
97 | 96 | $form->wasPosted = true; // already validated |
— | — | @@ -105,7 +104,7 @@ |
106 | 105 | # Output success line with the title and config parameters |
107 | 106 | $res = array(); |
108 | 107 | $res['title'] = $title->getPrefixedText(); |
109 | | - if( FlaggedRevs::getProtectionLevels() ) { |
| 108 | + if( count($levels) ) { |
110 | 109 | $res['protectlevel'] = $params['protectlevel']; |
111 | 110 | } else { |
112 | 111 | $res['default'] = $params['default']; |
— | — | @@ -159,19 +158,17 @@ |
160 | 159 | } |
161 | 160 | |
162 | 161 | public function getAllowedParams() { |
| 162 | + // Replace '' with more readable 'none' in autoreview restiction levels |
| 163 | + $autoreviewLevels = FlaggedRevs::getRestrictionLevels(); |
| 164 | + $autoreviewLevels[] = 'none'; |
163 | 165 | if( FlaggedRevs::useProtectionLevels() ) { |
164 | | - $validLevels = array_keys( FlaggedRevs::getProtectionLevels() ); |
165 | | - $validLevels[] = 'none'; |
166 | 166 | $pars = array( |
167 | 167 | 'protectlevel' => array( |
168 | | - ApiBase :: PARAM_TYPE => $validLevels, |
| 168 | + ApiBase :: PARAM_TYPE => $autoreviewLevels, |
169 | 169 | ApiBase :: PARAM_DFLT => 'none', |
170 | 170 | ) |
171 | 171 | ); |
172 | 172 | } else { |
173 | | - // Replace '' with more readable 'none' in autoreview restiction levels |
174 | | - $autoreviewLevels = array_filter( FlaggedRevs::getRestrictionLevels() ); |
175 | | - $autoreviewLevels[] = 'none'; |
176 | 173 | $pars = array( |
177 | 174 | 'default' => array( |
178 | 175 | ApiBase :: PARAM_TYPE => array( 'latest', 'stable' ), |