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