]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - maintenance/createAndPromote.php
MediaWiki 1.11.0
[autoinstallsdev/mediawiki.git] / maintenance / createAndPromote.php
1 <?php
2
3 /**
4  * Maintenance script to create an account and grant it administrator rights
5  *
6  * @addtogroup Maintenance
7  * @author Rob Church <robchur@gmail.com>
8  */
9
10 $options = array( 'help', 'bureaucrat' );
11 require_once( 'commandLine.inc' );
12
13 if( isset( $options['help'] ) ) {
14         showHelp();
15         exit( 1 );
16 }
17
18 if( count( $args ) < 2 ) {
19         echo( "Please provide a username and password for the new account.\n" );
20         die( 1 );
21 }
22
23 $username = $args[0];
24 $password = $args[1];
25
26 echo( wfWikiID() . ": Creating and promoting User:{$username}..." );
27
28 # Validate username and check it doesn't exist
29 $user = User::newFromName( $username );
30 if( !is_object( $user ) ) {
31         echo( "invalid username.\n" );
32         die( 1 );
33 } elseif( 0 != $user->idForName() ) {
34         echo( "account exists.\n" );
35         die( 1 );
36 }
37
38 # Insert the account into the database
39 $user->addToDatabase();
40 $user->setPassword( $password );
41 $user->setToken();
42
43 # Promote user
44 $user->addGroup( 'sysop' );
45 if( isset( $option['bureaucrat'] ) )
46         $user->addGroup( 'bureaucrat' );
47
48 # Increment site_stats.ss_users
49 $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
50 $ssu->doUpdate();
51
52 echo( "done.\n" );
53
54 function showHelp() {
55         echo( <<<EOT
56 Create a new user account with administrator rights
57
58 USAGE: php createAndPromote.php [--bureaucrat|--help] <username> <password>
59
60         --bureaucrat
61                 Grant the account bureaucrat rights
62         --help
63                 Show this help information
64
65 EOT
66         );
67 }