Page MenuHomePhabricator

maintenance-createUser.patch

Authored By
bzimport
Nov 21 2014, 11:00 PM
Size
1 KB
Referenced Files
None
Subscribers
None

maintenance-createUser.patch

diff -Naiur maintenance-original/createUser.php maintenance/createUser.php
--- a/maintenance/createUser.php 1970-01-01 10:00:00.000000000 +1000
+++ b/maintenance/createUser.php 2010-05-13 10:38:13.427824814 +1000
@@ -0,0 +1,68 @@
+<?php
+/**
+ * Create a user and assign groups
+ *
+ * @file
+ * @ingroup Maintenance
+ *
+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
+ */
+
+$optionsWithArgs = array( 'user', 'password' );
+require_once 'commandLine.inc';
+
+$USAGE =
+ "Usage: php createUser.php username password [groups ...] [--help]\n" .
+ "\toptions:\n" .
+ "\t\t--help show this message\n";
+
+if( in_array( '--help', $argv ) )
+ wfDie( $USAGE );
+
+$options = $argv;
+$username = array_shift($options);
+$password = array_shift($options);
+$groupnames = $options;
+if( !strlen( $username ) or !strlen( $password ) ) {
+ wfDie( $USAGE );
+}
+CreateUser::main( $username, $password, $groupnames );
+
+/**
+ * @ingroup Maintenance
+ */
+class CreateUser {
+ static function main($username, $password, $groupnames) {
+ echo( wfWikiID() . ": Creating and promoting User:{$username}..." );
+
+ # Validate groups, if any
+ $all_groups = User::getAllGroups();
+ foreach ($groupnames as $groupname) {
+ if(! in_array(strtolower($groupname), $all_groups)) {
+ die ( "Invalid group: $groupname\n" );
+ }
+ }
+
+ # 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 );
+ }
+ $user->addToDatabase();
+ $user->setPassword( $password );
+ foreach ($groupnames as $groupname) {
+ $user->addGroup($groupname);
+ }
+ $user->saveSettings();
+
+ # Increment site_stats.ss_users
+ $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
+ $ssu->doUpdate();
+
+ echo( "done.\n" );
+ }
+}

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6073
Default Alt Text
maintenance-createUser.patch (1 KB)

Event Timeline