* Converted to Unix newlines
[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 * @package MediaWiki
7 * @subpackage Maintenance
8 * @author Rob Church <robchur@gmail.com>
9 */
10
11 require_once( 'commandLine.inc' );
12
13 if( !count( $args ) == 2 ) {
14 echo( "Please provide a username and password for the new account.\n" );
15 die( 1 );
16 }
17
18 $username = $args[0];
19 $password = $args[1];
20
21 global $wgDBname;
22 echo( "{$wgDBname}: Creating and promoting User:{$username}..." );
23
24 # Validate username and check it doesn't exist
25 $user = User::newFromName( $username );
26 if( !is_object( $user ) ) {
27 echo( "invalid username.\n" );
28 die( 1 );
29 } elseif( 0 != $user->idForName() ) {
30 echo( "account exists.\n" );
31 die( 1 );
32 }
33
34 # Insert the account into the database
35 $user->addToDatabase();
36 $user->setPassword( $password );
37 $user->setToken();
38
39 # Promote user
40 $user->addGroup( 'sysop' );
41
42 # Increment site_stats.ss_users
43 $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
44 $ssu->doUpdate();
45
46 echo( "done.\n" );
47
48 ?>