Merge maintenance-work branch:
[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 * @file
7 * @ingroup Maintenance
8 * @author Rob Church <robchur@gmail.com>
9 */
10
11 require_once( "Maintenance.php" );
12
13 class CreateAndPromote extends Maintenance {
14
15 public function __construct() {
16 parent::__construct();
17 $this->mDescription = "Create a new user account with administrator rights";
18 $this->addParam( "bureaucrat", "Grant the account bureaucrat rights" );
19 $this->addArgs( array( "username", "password" ) );
20 }
21
22 public function execute() {
23 $username = $this->getArg(0);
24 $password = $this->getArg(1);
25
26 $this->output( wfWikiID() . ": Creating and promoting User:{$username}..." );
27
28 $user = User::newFromName( $username );
29 if( !is_object( $user ) ) {
30 $this->error( "invalid username.\n", true );
31 } elseif( 0 != $user->idForName() ) {
32 $this->error( "account exists.\n", true );
33 }
34
35 # Try to set the password
36 try {
37 $user->setPassword( $password );
38 } catch( PasswordError $pwe ) {
39 $this->error( $pwe->getText(), true );
40 }
41
42 # Insert the account into the database
43 $user->addToDatabase();
44 $user->saveSettings();
45
46 # Promote user
47 $user->addGroup( 'sysop' );
48 if( $this->hasOption( 'bureaucrat' ) )
49 $user->addGroup( 'bureaucrat' );
50
51 # Increment site_stats.ss_users
52 $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
53 $ssu->doUpdate();
54
55 $this->output( "done.\n" );
56 }
57 }
58
59 $maintClass = "CreateAndPromote";
60 require_once( DO_MAINTENANCE );