00001 <?php
00002
00011 $options = array( 'help', 'bureaucrat' );
00012 require_once( 'commandLine.inc' );
00013
00014 if( isset( $options['help'] ) ) {
00015 showHelp();
00016 exit( 1 );
00017 }
00018
00019 if( count( $args ) < 2 ) {
00020 echo( "Please provide a username and password for the new account.\n" );
00021 die( 1 );
00022 }
00023
00024 $username = $args[0];
00025 $password = $args[1];
00026
00027 echo( wfWikiID() . ": Creating and promoting User:{$username}..." );
00028
00029 # Validate username and check it doesn't exist
00030 $user = User::newFromName( $username );
00031 if( !is_object( $user ) ) {
00032 echo( "invalid username.\n" );
00033 die( 1 );
00034 } elseif( 0 != $user->idForName() ) {
00035 echo( "account exists.\n" );
00036 die( 1 );
00037 }
00038
00039 # Insert the account into the database
00040 $user->addToDatabase();
00041 $user->setPassword( $password );
00042 $user->saveSettings();
00043
00044 # Promote user
00045 $user->addGroup( 'sysop' );
00046 if( isset( $option['bureaucrat'] ) )
00047 $user->addGroup( 'bureaucrat' );
00048
00049 # Increment site_stats.ss_users
00050 $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
00051 $ssu->doUpdate();
00052
00053 echo( "done.\n" );
00054
00055 function showHelp() {
00056 echo( <<<EOT
00057 Create a new user account with administrator rights
00058
00059 USAGE: php createAndPromote.php [--bureaucrat|--help] <username> <password>
00060
00061 --bureaucrat
00062 Grant the account bureaucrat rights
00063 --help
00064 Show this help information
00065
00066 EOT
00067 );
00068 }