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