a424336ebddd5ab10398398dbb2602f2e998b6e9
4 * Maintenance script to create an account and grant it administrator rights
8 * @author Rob Church <robchur@gmail.com>
11 require_once( "Maintenance.php" );
13 class CreateAndPromote
extends Maintenance
{
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" ) );
22 public function execute() {
23 $username = $this->getArg(0);
24 $password = $this->getArg(1);
26 $this->output( wfWikiID() . ": Creating and promoting User:{$username}..." );
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 );
35 # Try to set the password
37 $user->setPassword( $password );
38 } catch( PasswordError
$pwe ) {
39 $this->error( $pwe->getText(), true );
42 # Insert the account into the database
43 $user->addToDatabase();
44 $user->saveSettings();
47 $user->addGroup( 'sysop' );
48 if( $this->hasOption( 'bureaucrat' ) )
49 $user->addGroup( 'bureaucrat' );
51 # Increment site_stats.ss_users
52 $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
55 $this->output( "done.\n" );
59 $maintClass = "CreateAndPromote";
60 require_once( DO_MAINTENANCE
);