summaryrefslogtreecommitdiff
path: root/maintenance/createAndPromote.php
blob: af4a1dab99c2f56c12a4384ea1e76305ddc2458a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php

/**
 * Maintenance script to create an account and grant it administrator rights
 *
 * @addtogroup Maintenance
 * @author Rob Church <robchur@gmail.com>
 */

$options = array( 'help', 'bureaucrat' );
require_once( 'commandLine.inc' );

if( isset( $options['help'] ) ) {
	showHelp();
	exit( 1 );
}

if( count( $args ) < 2 ) {
	echo( "Please provide a username and password for the new account.\n" );
	die( 1 );
}

$username = $args[0];
$password = $args[1];

echo( wfWikiID() . ": Creating and promoting User:{$username}..." );

# Validate username and check it doesn't exist
$user = User::newFromName( $username );
if( !is_object( $user ) ) {
	echo( "invalid username.\n" );
	die( 1 );
} elseif( 0 != $user->idForName() ) {
	echo( "account exists.\n" );
	die( 1 );
}

# Insert the account into the database
$user->addToDatabase();
$user->setPassword( $password );
$user->setToken();

# Promote user
$user->addGroup( 'sysop' );
if( isset( $option['bureaucrat'] ) )
	$user->addGroup( 'bureaucrat' );

# Increment site_stats.ss_users
$ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
$ssu->doUpdate();

echo( "done.\n" );

function showHelp() {
	echo( <<<EOT
Create a new user account with administrator rights

USAGE: php createAndPromote.php [--bureaucrat|--help] <username> <password>

	--bureaucrat
		Grant the account bureaucrat rights
	--help
		Show this help information

EOT
	);
}