2006-06-17 23:07:16 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Maintenance script to create an account and grant it administrator rights
|
|
|
|
|
*
|
2009-08-02 19:35:17 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2010-10-03 09:25:28 +00:00
|
|
|
* @file
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Maintenance
|
2006-06-17 23:07:16 +00:00
|
|
|
* @author Rob Church <robchur@gmail.com>
|
|
|
|
|
*/
|
2007-07-06 23:24:10 +00:00
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
require_once( dirname( __FILE__ ) . '/Maintenance.php' );
|
2009-08-02 19:35:17 +00:00
|
|
|
|
|
|
|
|
class CreateAndPromote extends Maintenance {
|
|
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2011-05-05 05:11:50 +00:00
|
|
|
$this->mDescription = "Create a new user account";
|
|
|
|
|
$this->addOption( "sysop", "Grant the account sysop rights" );
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->addOption( "bureaucrat", "Grant the account bureaucrat rights" );
|
2009-08-18 23:06:24 +00:00
|
|
|
$this->addArg( "username", "Username of new user" );
|
|
|
|
|
$this->addArg( "password", "Password to set" );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
2010-05-22 16:50:39 +00:00
|
|
|
$username = $this->getArg( 0 );
|
|
|
|
|
$password = $this->getArg( 1 );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( wfWikiID() . ": Creating and promoting User:{$username}..." );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$user = User::newFromName( $username );
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( !is_object( $user ) ) {
|
2009-08-02 21:55:10 +00:00
|
|
|
$this->error( "invalid username.", true );
|
2010-05-22 16:50:39 +00:00
|
|
|
} elseif ( 0 != $user->idForName() ) {
|
2009-08-02 21:55:10 +00:00
|
|
|
$this->error( "account exists.", true );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Try to set the password
|
|
|
|
|
try {
|
|
|
|
|
$user->setPassword( $password );
|
2010-05-22 16:50:39 +00:00
|
|
|
} catch ( PasswordError $pwe ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->error( $pwe->getText(), true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Insert the account into the database
|
|
|
|
|
$user->addToDatabase();
|
|
|
|
|
$user->saveSettings();
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
# Promote user
|
2011-05-05 05:11:50 +00:00
|
|
|
if ( $this->hasOption( 'sysop' ) ) {
|
2011-05-14 14:20:18 +00:00
|
|
|
$user->addGroup( 'sysop' );
|
2011-05-05 05:11:50 +00:00
|
|
|
}
|
|
|
|
|
if ( $this->hasOption( 'bureaucrat' ) ) {
|
|
|
|
|
$user->addGroup( 'bureaucrat' );
|
|
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
# Increment site_stats.ss_users
|
|
|
|
|
$ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
|
|
|
|
|
$ssu->doUpdate();
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "done.\n" );
|
|
|
|
|
}
|
2006-06-17 23:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$maintClass = "CreateAndPromote";
|
2011-01-13 22:58:55 +00:00
|
|
|
require_once( RUN_MAINTENANCE_IF_MAIN );
|