Actually do what the documentation says (r21907)
[lhc/web/wiklou.git] / maintenance / createAndPromote.php
1 <?php
2
3 /**
4 * Maintenance script to create an account and grant it administrator rights
5 *
6 * @addtogroup Maintenance
7 * @author Rob Church <robchur@gmail.com>
8 */
9
10 require_once( 'commandLine.inc' );
11
12 if( !count( $args ) == 2 ) {
13 echo( "Please provide a username and password for the new account.\n" );
14 die( 1 );
15 }
16
17 $username = $args[0];
18 $password = $args[1];
19
20 echo( wfWikiID() . ": Creating and promoting User:{$username}..." );
21
22 # Validate username and check it doesn't exist
23 $user = User::newFromName( $username );
24 if( !is_object( $user ) ) {
25 echo( "invalid username.\n" );
26 die( 1 );
27 } elseif( 0 != $user->idForName() ) {
28 echo( "account exists.\n" );
29 die( 1 );
30 }
31
32 # Insert the account into the database
33 $user->addToDatabase();
34 $user->setPassword( $password );
35 $user->setToken();
36
37 # Promote user
38 $user->addGroup( 'sysop' );
39
40 # Increment site_stats.ss_users
41 $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
42 $ssu->doUpdate();
43
44 echo( "done.\n" );
45
46 ?>