MediaWiki  master
changePassword.php
Go to the documentation of this file.
1 <?php
27 require_once __DIR__ . '/Maintenance.php';
28 
34 class ChangePassword extends Maintenance {
35  public function __construct() {
36  parent::__construct();
37  $this->addOption( "user", "The username to operate on", false, true );
38  $this->addOption( "userid", "The user id to operate on", false, true );
39  $this->addOption( "password", "The password to use", true, true );
40  $this->addDescription( "Change a user's password" );
41  }
42 
43  public function execute() {
44  $user = $this->validateUserOption( "A \"user\" or \"userid\" must be set to change the password for" );
45  $password = $this->getOption( 'password' );
46  $status = $user->changeAuthenticationData( [
47  'username' => $user->getName(),
48  'password' => $password,
49  'retype' => $password,
50  ] );
51  if ( $status->isGood() ) {
52  $this->output( "Password set for " . $user->getName() . "\n" );
53  } else {
54  $this->fatalError( $status->getMessage( false, false, 'en' )->text() );
55  }
56  }
57 }
58 
59 $maintClass = ChangePassword::class;
60 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:489
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:329
ChangePassword\execute
execute()
Do the actual work.
Definition: changePassword.php:43
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:59
ChangePassword
Maintenance script to change the password of a given user.
Definition: changePassword.php:34
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:249
Maintenance\validateUserOption
validateUserOption( $errorMsg)
Definition: Maintenance.php:1672
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:286
ChangePassword\__construct
__construct()
Default constructor.
Definition: changePassword.php:35
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:435
$maintClass
$maintClass
Definition: changePassword.php:59