00001 <?php 00002 00025 require_once( dirname(__FILE__) . '/Maintenance.php' ); 00026 00027 class CreateAndPromote extends Maintenance { 00028 00029 public function __construct() { 00030 parent::__construct(); 00031 $this->mDescription = "Create a new user account with administrator rights"; 00032 $this->addOption( "bureaucrat", "Grant the account bureaucrat rights" ); 00033 $this->addArg( "username", "Username of new user" ); 00034 $this->addArg( "password", "Password to set" ); 00035 } 00036 00037 public function execute() { 00038 $username = $this->getArg(0); 00039 $password = $this->getArg(1); 00040 00041 $this->output( wfWikiID() . ": Creating and promoting User:{$username}..." ); 00042 00043 $user = User::newFromName( $username ); 00044 if( !is_object( $user ) ) { 00045 $this->error( "invalid username.", true ); 00046 } elseif( 0 != $user->idForName() ) { 00047 $this->error( "account exists.", true ); 00048 } 00049 00050 # Try to set the password 00051 try { 00052 $user->setPassword( $password ); 00053 } catch( PasswordError $pwe ) { 00054 $this->error( $pwe->getText(), true ); 00055 } 00056 00057 # Insert the account into the database 00058 $user->addToDatabase(); 00059 $user->saveSettings(); 00060 00061 # Promote user 00062 $user->addGroup( 'sysop' ); 00063 if( $this->hasOption( 'bureaucrat' ) ) 00064 $user->addGroup( 'bureaucrat' ); 00065 00066 # Increment site_stats.ss_users 00067 $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 ); 00068 $ssu->doUpdate(); 00069 00070 $this->output( "done.\n" ); 00071 } 00072 } 00073 00074 $maintClass = "CreateAndPromote"; 00075 require_once( DO_MAINTENANCE );