Fix typo in description
[mediawiki.git] / maintenance / createAndPromote.php
blob8bff284a1171617d1b820856fe6960f64bff9ac5
1 <?php
2 /**
3 * Maintenance script to create an account and grant it administrator rights
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Maintenance
22 * @author Rob Church <robchur@gmail.com>
25 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
27 class CreateAndPromote extends Maintenance {
29 public function __construct() {
30 parent::__construct();
31 $this->mDescription = "Create a new user account with administrator rights";
32 $this->addOption( "bureaucrat", "Grant the account bureaucrat rights" );
33 $this->addArg( "username", "Username of new user" );
34 $this->addArg( "password", "Password to set" );
37 public function execute() {
38 $username = $this->getArg( 0 );
39 $password = $this->getArg( 1 );
41 $this->output( wfWikiID() . ": Creating and promoting User:{$username}..." );
43 $user = User::newFromName( $username );
44 if ( !is_object( $user ) ) {
45 $this->error( "invalid username.", true );
46 } elseif ( 0 != $user->idForName() ) {
47 $this->error( "account exists.", true );
50 # Try to set the password
51 try {
52 $user->setPassword( $password );
53 } catch ( PasswordError $pwe ) {
54 $this->error( $pwe->getText(), true );
57 # Insert the account into the database
58 $user->addToDatabase();
59 $user->saveSettings();
61 # Promote user
62 $user->addGroup( 'sysop' );
63 if ( $this->hasOption( 'bureaucrat' ) )
64 $user->addGroup( 'bureaucrat' );
66 # Increment site_stats.ss_users
67 $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
68 $ssu->doUpdate();
70 $this->output( "done.\n" );
74 $maintClass = "CreateAndPromote";
75 require_once( RUN_MAINTENANCE_IF_MAIN );