Abolished $wgDBname as a unique wiki identifier, it doesn't work with the new-fangled...
[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 echo( wfWikiID() . ": Creating and promoting User:{$username}..." );
22
23 # Validate username and check it doesn't exist
24 $user = User::newFromName( $username );
25 if( !is_object( $user ) ) {
26 echo( "invalid username.\n" );
27 die( 1 );
28 } elseif( 0 != $user->idForName() ) {
29 echo( "account exists.\n" );
30 die( 1 );
31 }
32
33 # Insert the account into the database
34 $user->addToDatabase();
35 $user->setPassword( $password );
36 $user->setToken();
37
38 # Promote user
39 $user->addGroup( 'sysop' );
40
41 # Increment site_stats.ss_users
42 $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
43 $ssu->doUpdate();
44
45 echo( "done.\n" );
46
47 ?>