X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FcreateAndPromote.php;h=2072d7b54d6062ae60e43569c4ad0bac7704f844;hb=3ea30167fbbcb684370eb436a017cd42cc092fad;hp=848c2f7eda0654ccd4684bb41b8260dd74c4fa89;hpb=8eac2feedb7ee093d2c48504e1eb2b8a9dbc8452;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/createAndPromote.php b/maintenance/createAndPromote.php index 848c2f7eda..2072d7b54d 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 = [ '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 required!", false ); + $this->error( "Argument required!" ); $this->maybeHelp( true ); } elseif ( $exists ) { $inGroups = $user->getGroups(); @@ -120,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() ); } } @@ -143,5 +150,5 @@ class CreateAndPromote extends Maintenance { } } -$maintClass = "CreateAndPromote"; +$maintClass = CreateAndPromote::class; require_once RUN_MAINTENANCE_IF_MAIN;