Index: trunk/extensions/UsabilityInitiative/DontSwitchMeOver/post-switchover.php |
— | — | @@ -0,0 +1,60 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +$IP = getenv( 'MW_INSTALL_PATH' ); |
| 5 | +if ( $IP === false ) { |
| 6 | + $IP = dirname( __FILE__ ) . '/../..'; |
| 7 | +} |
| 8 | +require( "$IP/maintenance/Maintenance.php" ); |
| 9 | + |
| 10 | +class PostSwitchover extends Maintenance { |
| 11 | + const REPORTING_INTERVAL = 1000; |
| 12 | + |
| 13 | + public function __construct() { |
| 14 | + parent::__construct(); |
| 15 | + $this->mDescription = "Migrate users that indicated they didn't want to be switched over back to the old defaults."; |
| 16 | + $this->addArg( 'start', "User ID to start from. Use this to resume an aborted run", false ); |
| 17 | + $this->addOption( 'maxlag', 'Maximum database slave lag in seconds (5 by default)', false, true ); |
| 18 | + } |
| 19 | + |
| 20 | + public function execute() { |
| 21 | + $start = intval( $this->getOption( 'start', 0 ) ); |
| 22 | + $maxlag = intval( $this->getOption( 'maxlag', 5 ) ); |
| 23 | + |
| 24 | + $dbr = wfGetDb( DB_SLAVE ); |
| 25 | + $maxUserID = $dbr->selectField( 'user', 'MAX(user_id)', false ); |
| 26 | + |
| 27 | + $this->output( "Starting from user_id $start of $maxUserID\n" ); |
| 28 | + for ( $i = $start; $i < $maxUserID; $i++ ) { |
| 29 | + $this->fixUser( $i ); |
| 30 | + if ( $i % self::REPORTING_INTERVAL == 0 ) { |
| 31 | + $this->output( "$i\n" ); |
| 32 | + wfWaitForSlaves( $maxlag ); |
| 33 | + } |
| 34 | + } |
| 35 | + $this->output( "All done\n" ); |
| 36 | + } |
| 37 | + |
| 38 | + private function fixUser( $i ) { |
| 39 | + global $wgDontSwitchMeOverPrefs; |
| 40 | + $user = User::newFromId( $i ); |
| 41 | + |
| 42 | + // If the user doesn't exist or doesn't have our preference enabled, skip |
| 43 | + if ( $user->isAnon() || !$user->getOption( 'dontswitchmeover' ) ) { |
| 44 | + return; |
| 45 | + } |
| 46 | + |
| 47 | + $changed = false; |
| 48 | + foreach ( $wgDontSwitchMeOverPrefs as $pref => $oldVal ) { |
| 49 | + if ( $user->getOption( $pref ) == User::getDefaultOption( $pref ) ) { |
| 50 | + $user->setOption( $pref, $oldVal ); |
| 51 | + $changed = true; |
| 52 | + } |
| 53 | + } |
| 54 | + if ( $changed ) { |
| 55 | + $user->saveSettings(); |
| 56 | + } |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +$maintClass = "PostSwitchover"; |
| 61 | +require_once( DO_MAINTENANCE ); |
Property changes on: trunk/extensions/UsabilityInitiative/DontSwitchMeOver/post-switchover.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 62 | + native |
Index: trunk/extensions/UsabilityInitiative/DontSwitchMeOver/DontSwitchMeOver.php |
— | — | @@ -19,7 +19,15 @@ |
20 | 20 | */ |
21 | 21 | |
22 | 22 | /* Configuration */ |
23 | | - |
| 23 | + |
| 24 | +// Preferences to switch back to. This has to be set because the old default |
| 25 | +// skin isn't remembered after a switchover. |
| 26 | +// You can also add more preferences here, and on wikis with PrefSwitch setting |
| 27 | +// $wgDontSwitchMeOverPrefs = $wgPrefSwitchPrefs['off']; is probably wise |
| 28 | +$wgDontSwitchMeOverPrefs = array( |
| 29 | + 'skin' => 'monobook' |
| 30 | +); |
| 31 | + |
24 | 32 | // Credits |
25 | 33 | $wgExtensionCredits['other'][] = array( |
26 | 34 | 'path' => __FILE__, |