Add option to populateChangeTagDef not to update the count
[lhc/web/wiklou.git] / maintenance / createAndPromote.php
index 9abc297..2072d7b 100644 (file)
@@ -31,7 +31,7 @@ require_once __DIR__ . '/Maintenance.php';
  * @ingroup Maintenance
  */
 class CreateAndPromote extends Maintenance {
-       private static $permitRoles = [ 'sysop', 'bureaucrat', 'bot' ];
+       private static $permitRoles = [ 'sysop', 'bureaucrat', 'interface-admin', 'bot' ];
 
        public function __construct() {
                parent::__construct();
@@ -63,15 +63,15 @@ class CreateAndPromote extends Maintenance {
 
                $user = User::newFromName( $username );
                if ( !is_object( $user ) ) {
-                       $this->error( "invalid username.", true );
+                       $this->fatalError( "invalid username." );
                }
 
                $exists = ( 0 !== $user->idForName() );
 
                if ( $exists && !$force ) {
-                       $this->error( "Account exists. Perhaps you want the --force option?", true );
+                       $this->fatalError( "Account exists. Perhaps you want the --force option?" );
                } elseif ( !$exists && !$password ) {
-                       $this->error( "Argument <password> required!", false );
+                       $this->error( "Argument <password> required!" );
                        $this->maybeHelp( true );
                } elseif ( $exists ) {
                        $inGroups = $user->getGroups();
@@ -79,11 +79,16 @@ class CreateAndPromote extends Maintenance {
 
                $groups = array_filter( self::$permitRoles, [ $this, 'hasOption' ] );
                if ( $this->hasOption( 'custom-groups' ) ) {
+                       $allGroups = array_flip( User::getAllGroups() );
                        $customGroupsText = $this->getOption( 'custom-groups' );
                        if ( $customGroupsText !== '' ) {
                                $customGroups = explode( ',', $customGroupsText );
                                foreach ( $customGroups as $customGroup ) {
-                                       $groups[] = trim( $customGroup );
+                                       if ( isset( $allGroups[$customGroup] ) ) {
+                                               $groups[] = trim( $customGroup );
+                                       } else {
+                                               $this->output( "$customGroup is not a valid group, ignoring!\n" );
+                                       }
                                }
                        }
                }
@@ -115,13 +120,20 @@ class CreateAndPromote extends Maintenance {
                if ( $password ) {
                        # Try to set the password
                        try {
-                               $user->setPassword( $password );
+                               $status = $user->changeAuthenticationData( [
+                                       'username' => $user->getName(),
+                                       'password' => $password,
+                                       'retype' => $password,
+                               ] );
+                               if ( !$status->isGood() ) {
+                                       throw new PasswordError( $status->getWikiText( null, null, 'en' ) );
+                               }
                                if ( $exists ) {
                                        $this->output( "Password set.\n" );
                                        $user->saveSettings();
                                }
                        } catch ( PasswordError $pwe ) {
-                               $this->error( $pwe->getText(), true );
+                               $this->fatalError( $pwe->getText() );
                        }
                }
 
@@ -138,5 +150,5 @@ class CreateAndPromote extends Maintenance {
        }
 }
 
-$maintClass = "CreateAndPromote";
+$maintClass = CreateAndPromote::class;
 require_once RUN_MAINTENANCE_IF_MAIN;