* @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();
$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();
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() );
}
}
}
}
-$maintClass = "CreateAndPromote";
+$maintClass = CreateAndPromote::class;
require_once RUN_MAINTENANCE_IF_MAIN;