Merge "Add date format for Latvian language"
[lhc/web/wiklou.git] / maintenance / createAndPromote.php
index 5681d41..861b364 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Creates an account and grant it administrator rights.
+ * Creates an account and grants it rights.
  *
  * 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
  * @author Pablo Castellano <pablo@anche.no>
  */
 
-require_once( __DIR__ . '/Maintenance.php' );
+require_once __DIR__ . '/Maintenance.php';
 
 /**
- * Maintenance script to create an account and grant it administrator rights.
+ * Maintenance script to create an account and grant it rights.
  *
  * @ingroup Maintenance
  */
 class CreateAndPromote extends Maintenance {
-
-       static $permitRoles = array( 'sysop', 'bureaucrat' );
+       private static $permitRoles = array( 'sysop', 'bureaucrat', 'bot' );
 
        public function __construct() {
                parent::__construct();
                $this->mDescription = "Create a new user account and/or grant it additional rights";
-               $this->addOption( "force", "If acccount exists already, just grant it rights or change password." );
+               $this->addOption(
+                       'force',
+                       'If acccount exists already, just grant it rights or change password.'
+               );
                foreach ( self::$permitRoles as $role ) {
                        $this->addOption( $role, "Add the account to the {$role} group" );
                }
+
+               $this->addOption(
+                       'custom-groups',
+                       'Comma-separated list of groups to add the user to',
+                       false,
+                       true
+               );
+
                $this->addArg( "username", "Username of new user" );
                $this->addArg( "password", "Password to set (not required if --force is used)", false );
        }
@@ -67,10 +77,25 @@ class CreateAndPromote extends Maintenance {
                        $inGroups = $user->getGroups();
                }
 
-               $promotions = array_diff( array_filter( self::$permitRoles, array( $this, 'hasOption' ) ), $inGroups );
+               $groups = array_filter( self::$permitRoles, array( $this, 'hasOption' ) );
+               if ( $this->hasOption( 'custom-groups' ) ) {
+                       $customGroupsText = $this->getOption( 'custom-groups' );
+                       if ( $customGroupsText !== '' ) {
+                               $customGroups = explode( ',', $customGroupsText );
+                               foreach ( $customGroups as $customGroup ) {
+                                       $groups[] = trim( $customGroup );
+                               }
+                       }
+               }
+
+               $promotions = array_diff(
+                       $groups,
+                       $inGroups
+               );
 
                if ( $exists && !$password && count( $promotions ) === 0 ) {
                        $this->output( "Account exists and nothing to do.\n" );
+
                        return;
                } elseif ( count( $promotions ) !== 0 ) {
                        $promoText = "User:{$username} into " . implode( ', ', $promotions ) . "...\n";
@@ -114,4 +139,4 @@ class CreateAndPromote extends Maintenance {
 }
 
 $maintClass = "CreateAndPromote";
-require_once( RUN_MAINTENANCE_IF_MAIN );
+require_once RUN_MAINTENANCE_IF_MAIN;