tableName calls moved inside fieldInfoMulti and removed call that existed only for...
[lhc/web/wiklou.git] / maintenance / createAndPromote.php
1 <?php
2
3 /**
4 * Maintenance script to create an account and grant it administrator rights
5 *
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.
10 *
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.
15 *
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
20 *
21 * @ingroup Maintenance
22 * @author Rob Church <robchur@gmail.com>
23 */
24
25 require_once( dirname(__FILE__) . '/Maintenance.php' );
26
27 class CreateAndPromote extends Maintenance {
28
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" );
35 }
36
37 public function execute() {
38 $username = $this->getArg(0);
39 $password = $this->getArg(1);
40
41 $this->output( wfWikiID() . ": Creating and promoting User:{$username}..." );
42
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 );
48 }
49
50 # Try to set the password
51 try {
52 $user->setPassword( $password );
53 } catch( PasswordError $pwe ) {
54 $this->error( $pwe->getText(), true );
55 }
56
57 # Insert the account into the database
58 $user->addToDatabase();
59 $user->saveSettings();
60
61 # Promote user
62 $user->addGroup( 'sysop' );
63 if( $this->hasOption( 'bureaucrat' ) )
64 $user->addGroup( 'bureaucrat' );
65
66 # Increment site_stats.ss_users
67 $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
68 $ssu->doUpdate();
69
70 $this->output( "done.\n" );
71 }
72 }
73
74 $maintClass = "CreateAndPromote";
75 require_once( DO_MAINTENANCE );