MediaWiki
REL1_19
|
00001 <?php 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"; 00032 $this->addOption( "sysop", "Grant the account sysop rights" ); 00033 $this->addOption( "bureaucrat", "Grant the account bureaucrat rights" ); 00034 $this->addArg( "username", "Username of new user" ); 00035 $this->addArg( "password", "Password to set" ); 00036 } 00037 00038 public function execute() { 00039 $username = $this->getArg( 0 ); 00040 $password = $this->getArg( 1 ); 00041 00042 $this->output( wfWikiID() . ": Creating and promoting User:{$username}..." ); 00043 00044 $user = User::newFromName( $username ); 00045 if ( !is_object( $user ) ) { 00046 $this->error( "invalid username.", true ); 00047 } elseif ( 0 != $user->idForName() ) { 00048 $this->error( "account exists.", true ); 00049 } 00050 00051 # Try to set the password 00052 try { 00053 $user->setPassword( $password ); 00054 } catch ( PasswordError $pwe ) { 00055 $this->error( $pwe->getText(), true ); 00056 } 00057 00058 # Insert the account into the database 00059 $user->addToDatabase(); 00060 $user->saveSettings(); 00061 00062 # Promote user 00063 if ( $this->hasOption( 'sysop' ) ) { 00064 $user->addGroup( 'sysop' ); 00065 } 00066 if ( $this->hasOption( 'bureaucrat' ) ) { 00067 $user->addGroup( 'bureaucrat' ); 00068 } 00069 00070 # Increment site_stats.ss_users 00071 $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 ); 00072 $ssu->doUpdate(); 00073 00074 $this->output( "done.\n" ); 00075 } 00076 } 00077 00078 $maintClass = "CreateAndPromote"; 00079 require_once( RUN_MAINTENANCE_IF_MAIN );