Index: trunk/phase3/maintenance/cleanupSkin.php |
— | — | @@ -0,0 +1,93 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Script to change users skins on the fly. |
| 5 | + * This is for at least MediaWiki 1.10alpha (r19611) and have not been |
| 6 | + * tested with previous versions. It should probably work with 1.7+. |
| 7 | + * |
| 8 | + * Made on an original idea by Fooey (freenode) |
| 9 | + * |
| 10 | + * @author Ashar Voultoiz <hashar@altern.org> |
| 11 | + */ |
| 12 | + |
| 13 | +// Options we will use |
| 14 | +$options = array( 'quick' ); |
| 15 | +$optionsWithArgs = array( 'old', 'new' ); |
| 16 | + |
| 17 | +// This is a command line script, load tools and parse args |
| 18 | +require_once( 'commandLine.inc' ); |
| 19 | + |
| 20 | +// Check for mandatory options or print an usage message |
| 21 | +if( !(isset($options['old']) && isset($options['new']) ) ) { |
| 22 | +print <<<USAGE |
| 23 | +This script pass through all users and change their skins from 'oldSkinName' |
| 24 | +to 'newSkinName'. There is NO validation about the new skin existence! |
| 25 | + |
| 26 | +Usage: php cleanupSkin.php --old <oldSkinName> --new <newSkinName> |
| 27 | + [--quick] [--quiet] |
| 28 | + |
| 29 | +Options: |
| 30 | + --old <oldSkinName> : the old skin name |
| 31 | + --new <newSkinName> : new skin name to update users with |
| 32 | + --quick : hides the 5 seconds warning |
| 33 | + --quiet : do not print what is happening |
| 34 | + |
| 35 | + |
| 36 | +USAGE; |
| 37 | + exit(0); |
| 38 | +} |
| 39 | + |
| 40 | +// Load up the arguments: |
| 41 | +$oldSkinName = $options['old']; |
| 42 | +$newSkinName = $options['new']; |
| 43 | +$quick = isset($options['quick']); |
| 44 | +$quiet = isset($options['quiet']); |
| 45 | + |
| 46 | +// We list the user by user_id from one of the slave databases |
| 47 | +$dbr = wfGetDB( DB_SLAVE ); |
| 48 | +$result = $dbr->select( 'user', |
| 49 | + array( 'user_id' ), |
| 50 | + array(), |
| 51 | + __FILE__ |
| 52 | + ); |
| 53 | + |
| 54 | +// The warning message and countdown |
| 55 | +if( !$quick ) { |
| 56 | +print <<<WARN |
| 57 | +The script is about to change the skin for ALL USERS in the database. |
| 58 | +Users with skin '$oldSkinName' will be made to use '$newSkinName'. |
| 59 | + |
| 60 | +Abort with control-c in the next five seconds.... |
| 61 | +WARN; |
| 62 | + require('counter.php'); |
| 63 | + for ($i=6;$i>=1;) { |
| 64 | + print_c($i, --$i); |
| 65 | + sleep(1); |
| 66 | + } |
| 67 | + print "\n"; |
| 68 | +} |
| 69 | + |
| 70 | +// Iterate through the users |
| 71 | +while( $id = $dbr->fetchObject( $result ) ) { |
| 72 | + |
| 73 | + $user = User::newFromId( $id->user_id ); |
| 74 | + |
| 75 | + // We get this users informations |
| 76 | + $curSkinName = $user->getOption( 'skin' ); |
| 77 | + $username = $user->getName(); |
| 78 | + |
| 79 | + // Is he using the skin we want to migrate ? |
| 80 | + if( $curSkinName == $oldSkinName ) { |
| 81 | + |
| 82 | + if(!$quiet) print "Changing skin for $username ('$oldSkinName' -> '$newSkinName'):"; |
| 83 | + |
| 84 | + // Change skin and save it |
| 85 | + $user->setOption( 'skin', $newSkinName ); |
| 86 | + $user->saveSettings(); |
| 87 | + |
| 88 | + if(!$quiet) print " OK\n"; |
| 89 | + } elseif(!$quiet) { |
| 90 | + print "Not changing '$username' using skin '$curSkinName'\n"; |
| 91 | + } |
| 92 | +} |
| 93 | +print "Done.\n"; |
| 94 | +?> |
Property changes on: trunk/phase3/maintenance/cleanupSkin.php |
___________________________________________________________________ |
Added: eol-style |
1 | 95 | + native |