Of course didn't mean to commit var_dump
[mediawiki.git] / maintenance / createAndPromote.php
blobbf20c97623762ac0c104c880f6d8264c2b11da5f
1 <?php
3 /**
4 * Maintenance script to create an account and grant it administrator rights
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
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( DO_MAINTENANCE );