r48482 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48481‎ | r48482 | r48483 >
Date:09:02, 17 March 2009
Author:aaron
Status:ok (Comments)
Tags:
Comment:
* [schema change] Added ability to restrict autoreview per page
* Minor stable version log summary fix for 'other'
* Improved a few messages
* Other minor fixes
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/FlaggedRevs.sql (modified) (history)
  • /trunk/extensions/FlaggedRevs/archives/patch-fpc_level.sql (added) (history)
  • /trunk/extensions/FlaggedRevs/language/Stabilization.i18n.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -144,6 +144,9 @@
145145 'style' => array( 'review' => 3 ),
146146 );
147147
 148+# Restriction levels for auto-review right at Stabilization page
 149+$wgFlaggedRevsRestrictionLevels = array( '', 'sysop' );
 150+
148151 # Please set these as something different. Any text will do, though it probably
149152 # shouldn't be very short (less secure) or very long (waste of resources).
150153 # There must be two codes, and only the first two are checked.
@@ -549,6 +552,7 @@
550553 $wgExtNewFields[] = array( 'flaggedpages', 'fp_pending_since', "$base/archives/patch-fp_pending_since.sql" );
551554 $wgExtNewFields[] = array( 'reader_feedback', 'rfb_timestamp', "$base/archives/patch-rfb_timestamp.sql" );
552555 $wgExtNewFields[] = array( 'reader_feedback', 'rfb_ratings', "$base/archives/patch-rfb_ratings.sql" );
 556+ $wgExtNewFields[] = array( 'flaggedpage_config', 'fpc_level', "$base/archives/patch-fpc_level.sql" );
553557 } else if( $wgDBtype == 'postgres' ) {
554558 $wgExtNewTables[] = array( 'flaggedrevs', "$base/FlaggedRevs.pg.sql" ); // Initial install tables
555559 $wgExtPGNewFields[] = array('flaggedpage_config', 'fpc_expiry', "TIMESTAMPTZ NULL" );
@@ -559,6 +563,7 @@
560564 $wgExtNewTables[] = array( 'reader_feedback', "$base/postgres/patch-reader_feedback.sql" );
561565 $wgExtNewTables[] = array( 'flaggedrevs_tracking', "$base/postgres/patch-flaggedrevs_tracking.sql" );
562566 $wgExtNewIndexes[] = array('flaggedpages', 'fp_pending_since', "$base/postgres/patch-fp_pending_since.sql" );
 567+ $wgExtPGNewFields[] = array('flaggedpage_config', 'fpc_level', "TEXT NULL" );
563568 }
564569 return true;
565570 }
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -831,7 +831,7 @@
832832 public static function getPageVisibilitySettings( &$title, $forUpdate=false ) {
833833 $db = $forUpdate ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
834834 $row = $db->selectRow( 'flaggedpage_config',
835 - array( 'fpc_select', 'fpc_override', 'fpc_expiry' ),
 835+ array( 'fpc_select', 'fpc_override', 'fpc_level', 'fpc_expiry' ),
836836 array( 'fpc_page_id' => $title->getArticleID() ),
837837 __METHOD__
838838 );
@@ -855,10 +855,11 @@
856856 ## 1 = quality -> stable
857857 ## 0 = none
858858 $select = self::getPrecedence();
859 - return array( 'select' => $select, 'override' => $override, 'expiry' => 'infinity' );
 859+ return array( 'select' => $select, 'override' => $override,
 860+ 'autoreview' => '', 'expiry' => 'infinity' );
860861 }
861862 return array('select' => $row->fpc_select, 'override' => $row->fpc_override,
862 - 'expiry' => $row->fpc_expiry );
 863+ 'autoreview' => $row->fpc_level, 'expiry' => $row->fpc_expiry );
863864 }
864865
865866 /**
Index: trunk/extensions/FlaggedRevs/language/Stabilization.i18n.php
@@ -20,11 +20,13 @@
2121 'stabilization-leg' => 'Confirm stable version settings',
2222 'stabilization-select' => 'Stable version selection',
2323 'stabilization-select1' => 'The latest quality revision; if not present, then the latest sighted one',
24 - 'stabilization-select2' => 'The latest reviewed revision',
 24+ 'stabilization-select2' => 'The latest reviewed revision, regardless of validation level',
2525 'stabilization-select3' => 'The latest pristine revision; if not present, then the latest quality or sighted one',
2626 'stabilization-def' => 'Revision displayed on default page view',
2727 'stabilization-def1' => 'The stable revision; if not present, then the current one',
2828 'stabilization-def2' => 'The current revision',
 29+ 'stabilization-restrict' => 'Auto-review restrictions',
 30+ 'stabilization-restrict-none' => 'No extra restrictions',
2931 'stabilization-submit' => 'Confirm',
3032 'stabilization-notexists' => 'There is no page called "[[:$1|$1]]".
3133 No configuration is possible.',
@@ -41,6 +43,7 @@
4244 'stabilization-def-short' => 'Default',
4345 'stabilization-def-short-0' => 'Current',
4446 'stabilization-def-short-1' => 'Stable',
 47+ 'stabilization-rest-short' => 'autoreview=$1',
4548 'stabilize_expiry_invalid' => 'Invalid expiration date.',
4649 'stabilize_expiry_old' => 'This expiration time has already passed.',
4750 'stabilize-expiring' => 'expires $1 (UTC)',
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.sql
@@ -69,6 +69,8 @@
7070 fpc_select integer NOT NULL,
7171 -- Override the page?
7272 fpc_override bool NOT NULL,
 73+ -- The protection level (Sysop, etc) for autoreview
 74+ fpc_level varbinary(60) NULL,
7375 -- Field for time-limited settings
7476 fpc_expiry varbinary(14) NOT NULL default 'infinity',
7577
Index: trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php
@@ -64,6 +64,8 @@
6565 $this->config = FlaggedRevs::getPageVisibilitySettings( $this->page, true );
6666 $this->select = $this->config['select'];
6767 $this->override = $this->config['override'];
 68+ # Get autoreview restrictions...
 69+ $this->autoreview = $this->config['autoreview'];
6870 # Make user readable date for GET requests
6971 $this->oldExpiry = $this->config['expiry'] !== 'infinity' ?
7072 wfTimestamp( TS_RFC2822, $this->config['expiry'] ) : 'infinite';
@@ -71,11 +73,14 @@
7274 if( $wgRequest->wasPosted() ) {
7375 $this->select = $wgRequest->getInt( 'wpStableconfig-select' );
7476 $this->override = intval( $wgRequest->getBool( 'wpStableconfig-override' ) );
 77+ # Get autoreview restrictions...
 78+ $this->autoreview = $wgRequest->getVal( 'mwProtect-level-autoreview' );
7579 // Custom expiry takes precedence
7680 $this->expiry = strlen($this->expiry) ? $this->expiry : $this->expirySelection;
7781 if( $this->expiry == 'existing' ) $this->expiry = $this->oldExpiry;
7882 // Custom reason takes precedence
79 - $this->reason = strlen($this->reason) ? $this->reason : $this->reasonSelection;
 83+ $this->reason = strlen($this->reason) || $this->reasonSelection == 'other' ?
 84+ $this->reason : $this->reasonSelection;
8085 // Validate precedence setting
8186 $allowed = array(FLAGGED_VIS_QUALITY,FLAGGED_VIS_LATEST,FLAGGED_VIS_PRISTINE);
8287 if( $this->select && !in_array( $this->select, $allowed ) ) {
@@ -175,6 +180,10 @@
176181 Xml::radioLabel( wfMsg( 'stabilization-select2' ), 'wpStableconfig-select', FLAGGED_VIS_LATEST,
177182 'stable-select2', FLAGGED_VIS_LATEST == $this->select, $this->disabledAttrib ) . '<br />' . "\n" .
178183 Xml::closeElement( 'fieldset' ) .
 184+
 185+ Xml::fieldset( wfMsg( 'stabilization-restrict' ), false ) .
 186+ $this->buildSelector( $this->autoreview ) .
 187+ Xml::closeElement( 'fieldset' ) .
179188
180189 Xml::fieldset( wfMsg( 'stabilization-leg' ), false ) .
181190 Xml::openElement( 'table' );
@@ -256,18 +265,68 @@
257266 $wgOut->addHTML( Xml::element( 'h2', NULL, htmlspecialchars( LogPage::logName( 'stable' ) ) ) );
258267 LogEventsList::showLogExtract( $wgOut, 'stable', $this->page->getPrefixedText() );
259268 }
 269+
 270+ protected function buildSelector( $selected ) {
 271+ global $wgUser, $wgFlaggedRevsRestrictionLevels;
 272+ $levels = array();
 273+ foreach( $wgFlaggedRevsRestrictionLevels as $key ) {
 274+ # Don't let them choose levels above their own (aka so they can still unprotect and edit the page).
 275+ # but only when the form isn't disabled
 276+ if( $key == 'sysop' ) {
 277+ // special case, rewrite sysop to protect and editprotected
 278+ if( !$wgUser->isAllowed('protect') && !$wgUser->isAllowed('editprotected') && $this->isAllowed )
 279+ continue;
 280+ } else {
 281+ if( !$wgUser->isAllowed($key) && $this->isAllowed )
 282+ continue;
 283+ }
 284+ $levels[] = $key;
 285+ }
 286+ $id = 'mwProtect-level-autoreview';
 287+ $attribs = array(
 288+ 'id' => $id,
 289+ 'name' => $id,
 290+ 'size' => count( $levels ),
 291+ ) + $this->disabledAttrib;
260292
 293+ $out = Xml::openElement( 'select', $attribs );
 294+ foreach( $levels as $key ) {
 295+ $out .= Xml::option( $this->getOptionLabel( $key ), $key, $key == $selected );
 296+ }
 297+ $out .= Xml::closeElement( 'select' );
 298+ return $out;
 299+ }
 300+
 301+ /**
 302+ * Prepare the label for a protection selector option
 303+ *
 304+ * @param string $permission Permission required
 305+ * @return string
 306+ */
 307+ protected function getOptionLabel( $permission ) {
 308+ if( $permission == '' ) {
 309+ return wfMsg( 'stabilization-restrict-none' );
 310+ } else {
 311+ $key = "protect-level-{$permission}";
 312+ $msg = wfMsg( $key );
 313+ if( wfEmptyMsg( $key, $msg ) )
 314+ $msg = wfMsg( 'protect-fallback', $permission );
 315+ return $msg;
 316+ }
 317+ }
 318+
261319 protected function submit() {
262 - global $wgOut, $wgUser, $wgParser, $wgFlaggedRevsOverride;
 320+ global $wgOut, $wgUser, $wgParser;
263321
264322 $changed = $reset = false;
265323 $defaultPrecedence = FlaggedRevs::getPrecedence();
266 - if( $this->select == $defaultPrecedence && $this->override == $wgFlaggedRevsOverride ) {
 324+ $defaultOverride = FlaggedRevs::showStableByDefault();
 325+ if( $this->select == $defaultPrecedence && $this->override == $defaultOverride && !$this->autoreview ) {
267326 $reset = true; // we are going back to site defaults
268327 }
269328 # Take this opportunity to purge out expired configurations
270329 FlaggedRevs::purgeExpiredConfigurations();
271 -
 330+ # Parse expiry time given...
272331 if( $reset || $this->expiry == 'infinite' || $this->expiry == 'indefinite' ) {
273332 $expiry = Block::infinity();
274333 } else {
@@ -287,9 +346,10 @@
288347 $dbw = wfGetDB( DB_MASTER );
289348 # Get current config
290349 $row = $dbw->selectRow( 'flaggedpage_config',
291 - array( 'fpc_select', 'fpc_override', 'fpc_expiry' ),
 350+ array( 'fpc_select', 'fpc_override', 'fpc_level', 'fpc_expiry' ),
292351 array( 'fpc_page_id' => $this->page->getArticleID() ),
293 - __METHOD__ );
 352+ __METHOD__
 353+ );
294354 # If setting to site default values, erase the row if there is one...
295355 if( $row && $reset ) {
296356 $dbw->delete( 'flaggedpage_config',
@@ -297,14 +357,17 @@
298358 __METHOD__ );
299359 $changed = ($dbw->affectedRows() != 0); // did this do anything?
300360 # Otherwise, add a row unless we are just setting it as the site default, or it is the same the current one...
301 - } else if( $this->select !=0 || $this->override != $wgFlaggedRevsOverride ) {
302 - if( !$row || $row->fpc_select != $this->select || $row->fpc_override != $this->override || $row->fpc_expiry != $expiry ) {
 361+ } else if( !$reset ) {
 362+ if( !$row || $row->fpc_select != $this->select || $row->fpc_override != $this->override
 363+ || $row->fpc_level != $this->autoreview || $row->fpc_expiry != $expiry )
 364+ {
303365 $changed = true;
304366 $dbw->replace( 'flaggedpage_config',
305367 array( 'PRIMARY' ),
306368 array( 'fpc_page_id' => $this->page->getArticleID(),
307369 'fpc_select' => $this->select,
308370 'fpc_override' => $this->override,
 371+ 'fpc_level' => $this->autoreview,
309372 'fpc_expiry' => $expiry ),
310373 __METHOD__ );
311374 }
@@ -321,6 +384,9 @@
322385 wfMsgForContent("stabilization-sel-short-{$this->select}");
323386 $set[] = wfMsgForContent( "stabilization-def-short" ) . wfMsgForContent( 'colon-separator' ) .
324387 wfMsgForContent("stabilization-def-short-{$this->override}");
 388+ if( strlen($this->autoreview) ) {
 389+ $set[] = "autoreview={$this->autoreview}";
 390+ }
325391 $settings = '[' . implode(', ',$set). ']';
326392
327393 $reason = '';
@@ -373,7 +439,7 @@
374440 # Take the user to the diff to make sure an outdated version isn't
375441 # being set at the default. This is really an issue with configs
376442 # that only let certain pages be reviewed.
377 - if( $this->select != FLAGGED_VIS_LATEST ) {
 443+ if( $changed && $this->select != FLAGGED_VIS_LATEST ) {
378444 $frev = FlaggedRevision::newFromStable( $this->page, FR_MASTER );
379445 if( $frev && $frev->getRevId() != $latest ) {
380446 $query = "oldid={$frev->getRevId()}&diff=cur&diffonly=0"; // override diff-only
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
@@ -718,7 +718,18 @@
719719 $key = wfMemcKey( 'flaggedrevs', 'includesSynced', $rev->getPage() );
720720 global $wgMemc, $wgParserCacheExpireTime;
721721 # Auto-reviewing must be enabled and user must have the required permissions
722 - if( !$wgFlaggedRevsAutoReview || (!$user->isAllowed('autoreview') && !$user->isAllowed('bot')) ) {
 722+ if( !$wgFlaggedRevsAutoReview || !$user->isAllowed('autoreview') ) {
 723+ $isAllowed = false;
 724+ } else {
 725+ # Get autoreview restriction settings...
 726+ $config = FlaggedRevs::getPageVisibilitySettings( $title, true );
 727+ # Convert Sysop -> protect
 728+ $right = ($config['autoreview'] === 'sysop') ? 'protect' : $config['autoreview'];
 729+ # Check if the user has the required right, if any
 730+ $isAllowed = !$right || $user->isAllowed($right);
 731+ }
 732+ # Auto-reviewing must be enabled and user must have the required permissions
 733+ if( !$isAllowed ) {
723734 $wgMemc->set( $key, FlaggedRevs::makeMemcObj('false'), $wgParserCacheExpireTime );
724735 return true; // done! edit pending!
725736 }
@@ -894,8 +905,13 @@
895906 */
896907 public static function checkAutoPromote( $user, &$promote ) {
897908 global $wgFlaggedRevsAutopromote;
 909+ # Make sure bots always have autoreview
 910+ if( $user->isAllowed('bot') ) {
 911+ $promote[] = 'autoreview';
 912+ return true;
 913+ }
898914 if( empty($wgFlaggedRevsAutopromote) || !$user->getId() || $user->isAllowed('autoreview') ) {
899 - return true; // not needed
 915+ return true; // not needed or $wgFlaggedRevsAutopromote is off
900916 }
901917 # Check user email
902918 if( $wgFlaggedRevsAutopromote['email'] && !$user->isEmailConfirmed() ) {
Index: trunk/extensions/FlaggedRevs/archives/patch-fpc_level.sql
@@ -0,0 +1,3 @@
 2+-- The protection level (Sysop, autoconfirmed, etc) for autoreview
 3+ALTER TABLE /*$wgDBprefix*/flaggedpage_config
 4+ ADD fpc_level varbinary(60) NULL;
Property changes on: trunk/extensions/FlaggedRevs/archives/patch-fpc_level.sql
___________________________________________________________________
Name: svn:eol-style
15 + native

Comments

#Comment by 😂 (talk | contribs)   07:31, 8 February 2011

Has long since been deployed, not a scaptrap.

Status & tagging log