Revert r52336 "Merge maintenance-work branch:"
[lhc/web/wiklou.git] / maintenance / createAndPromote.php
index a424336..a5a8f88 100644 (file)
@@ -8,53 +8,61 @@
  * @author Rob Church <robchur@gmail.com>
  */
 
-require_once( "Maintenance.php" );
-
-class CreateAndPromote extends Maintenance {
-
-       public function __construct() {
-               parent::__construct();
-               $this->mDescription = "Create a new user account with administrator rights";
-               $this->addParam( "bureaucrat", "Grant the account bureaucrat rights" );
-               $this->addArgs( array( "username", "password" ) );
-       }
-
-       public function execute() {
-               $username = $this->getArg(0);
-               $password = $this->getArg(1);
-               
-               $this->output( wfWikiID() . ": Creating and promoting User:{$username}..." );
-               
-               $user = User::newFromName( $username );
-               if( !is_object( $user ) ) {
-                       $this->error( "invalid username.\n", true );
-               } elseif( 0 != $user->idForName() ) {
-                       $this->error( "account exists.\n", true );
-               }
-
-               # Try to set the password
-               try {
-                       $user->setPassword( $password );
-               } catch( PasswordError $pwe ) {
-                       $this->error( $pwe->getText(), true );
-               }
-
-               # Insert the account into the database
-               $user->addToDatabase();
-               $user->saveSettings();
-       
-               # Promote user
-               $user->addGroup( 'sysop' );
-               if( $this->hasOption( 'bureaucrat' ) )
-                       $user->addGroup( 'bureaucrat' );
-       
-               # Increment site_stats.ss_users
-               $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
-               $ssu->doUpdate();
-       
-               $this->output( "done.\n" );
-       }
+$options = array( 'help', 'bureaucrat' );
+require_once( 'commandLine.inc' );
+
+if( isset( $options['help'] ) ) {
+       showHelp();
+       exit( 1 );
+}
+
+if( count( $args ) < 2 ) {
+       echo( "Please provide a username and password for the new account.\n" );
+       die( 1 );
+}
+
+$username = $args[0];
+$password = $args[1];
+
+echo( wfWikiID() . ": Creating and promoting User:{$username}..." );
+
+# Validate username and check it doesn't exist
+$user = User::newFromName( $username );
+if( !is_object( $user ) ) {
+       echo( "invalid username.\n" );
+       die( 1 );
+} elseif( 0 != $user->idForName() ) {
+       echo( "account exists.\n" );
+       die( 1 );
 }
 
-$maintClass = "CreateAndPromote";
-require_once( DO_MAINTENANCE );
+# Insert the account into the database
+$user->addToDatabase();
+$user->setPassword( $password );
+$user->saveSettings();
+
+# Promote user
+$user->addGroup( 'sysop' );
+if( isset( $option['bureaucrat'] ) )
+       $user->addGroup( 'bureaucrat' );
+
+# Increment site_stats.ss_users
+$ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
+$ssu->doUpdate();
+
+echo( "done.\n" );
+
+function showHelp() {
+       echo( <<<EOT
+Create a new user account with administrator rights
+
+USAGE: php createAndPromote.php [--bureaucrat|--help] <username> <password>
+
+       --bureaucrat
+               Grant the account bureaucrat rights
+       --help
+               Show this help information
+
+EOT
+       );
+}
\ No newline at end of file