Merge "Disable transaction warnings for automatic trx."
[mediawiki.git] / maintenance / createAndPromote.php
blobad5333fcc7c6b1a9cbfc72ba319745ec5884c5fc
1 <?php
2 /**
3 * Creates 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( __DIR__ . '/Maintenance.php' );
27 /**
28 * Maintenance script to create an account and grant it administrator rights.
30 * @ingroup Maintenance
32 class CreateAndPromote extends Maintenance {
34 public function __construct() {
35 parent::__construct();
36 $this->mDescription = "Create a new user account";
37 $this->addOption( "sysop", "Grant the account sysop rights" );
38 $this->addOption( "bureaucrat", "Grant the account bureaucrat rights" );
39 $this->addArg( "username", "Username of new user" );
40 $this->addArg( "password", "Password to set" );
43 public function execute() {
44 $username = $this->getArg( 0 );
45 $password = $this->getArg( 1 );
47 $this->output( wfWikiID() . ": Creating and promoting User:{$username}..." );
49 $user = User::newFromName( $username );
50 if ( !is_object( $user ) ) {
51 $this->error( "invalid username.", true );
52 } elseif ( 0 != $user->idForName() ) {
53 $this->error( "account exists.", true );
56 # Try to set the password
57 try {
58 $user->setPassword( $password );
59 } catch ( PasswordError $pwe ) {
60 $this->error( $pwe->getText(), true );
63 # Insert the account into the database
64 $user->addToDatabase();
65 $user->saveSettings();
67 # Promote user
68 if ( $this->hasOption( 'sysop' ) ) {
69 $user->addGroup( 'sysop' );
71 if ( $this->hasOption( 'bureaucrat' ) ) {
72 $user->addGroup( 'bureaucrat' );
75 # Increment site_stats.ss_users
76 $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
77 $ssu->doUpdate();
79 $this->output( "done.\n" );
83 $maintClass = "CreateAndPromote";
84 require_once( RUN_MAINTENANCE_IF_MAIN );