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