X-Git-Url: https://git.cyclocoop.org/%7B%7B%20url_for%28?a=blobdiff_plain;f=maintenance%2FcreateAndPromote.php;h=3591b9ce2456f0728c3c058571e88120c2b327d3;hb=79806e91e7512ae0122be81e3c84721f5d4f09e1;hp=e7d666a56271a3d09701d5d72ebe117fc783451b;hpb=e2a7988178698b4369c7963d20610ee622db3ee7;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/createAndPromote.php b/maintenance/createAndPromote.php index e7d666a562..3591b9ce24 100644 --- a/maintenance/createAndPromote.php +++ b/maintenance/createAndPromote.php @@ -31,7 +31,7 @@ require_once __DIR__ . '/Maintenance.php'; * @ingroup Maintenance */ class CreateAndPromote extends Maintenance { - private static $permitRoles = array( 'sysop', 'bureaucrat', 'bot' ); + private static $permitRoles = [ 'sysop', 'bureaucrat', 'bot' ]; public function __construct() { parent::__construct(); @@ -56,10 +56,12 @@ class CreateAndPromote extends Maintenance { } public function execute() { + global $wgDisableAuthManager; + $username = $this->getArg( 0 ); $password = $this->getArg( 1 ); $force = $this->hasOption( 'force' ); - $inGroups = array(); + $inGroups = []; $user = User::newFromName( $username ); if ( !is_object( $user ) ) { @@ -77,13 +79,18 @@ class CreateAndPromote extends Maintenance { $inGroups = $user->getGroups(); } - $groups = array_filter( self::$permitRoles, array( $this, 'hasOption' ) ); + $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,7 +122,18 @@ class CreateAndPromote extends Maintenance { if ( $password ) { # Try to set the password try { - $user->setPassword( $password ); + if ( $wgDisableAuthManager ) { + $user->setPassword( $password ); + } else { + $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(); @@ -126,7 +144,7 @@ class CreateAndPromote extends Maintenance { } # Promote user - array_map( array( $user, 'addGroup' ), $promotions ); + array_map( [ $user, 'addGroup' ], $promotions ); if ( !$exists ) { # Increment site_stats.ss_users