24 require_once __DIR__ .
'/Maintenance.php';
34 parent::__construct();
38 $this->
addArg(
'user',
'Username or user ID, if starts with #' );
39 $this->
addArg(
'email',
'Email to assign' );
41 $this->
addOption(
'no-reset-password',
'Don\'t reset the user\'s password' );
45 $userName = $this->
getArg( 0 );
46 if ( preg_match(
'/^#\d+$/', $userName ) ) {
51 if ( !$user || !$user->isRegistered() || !$user->loadFromId() ) {
52 $this->
fatalError(
"Error: user '$userName' does not exist\n" );
55 $email = $this->
getArg( 1,
'' );
57 $this->
fatalError(
"Error: email '$email' is not valid\n" );
61 $user->setEmail( $email );
63 $user->saveSettings();
65 if ( !$this->
hasOption(
'no-reset-password' ) ) {
68 $status = $user->changeAuthenticationData( [
69 'username' => $user->getName(),
70 'password' => $password,
71 'retype' => $password,
73 if ( !$status->isGood() ) {
74 $this->
error(
"Password couldn't be reset because:\n"
75 . $status->getMessage(
false,
false,
'en' )->text() );
78 $this->
output(
"Done!\n" );
83 require_once RUN_MAINTENANCE_IF_MAIN;
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
static generateRandomPasswordString(int $minLength=10)
Generate a random string suitable for a password.
Maintenance script that resets user email.
__construct()
Default constructor.
execute()
Do the actual work.
static validateEmail( $addr)
Does a string look like an e-mail address?
static newFromName( $name, $validate='valid')
static newFromId( $id)
Static factory method for creation from a given user ID.