MediaWiki master
changePassword.php
Go to the documentation of this file.
1<?php
27require_once __DIR__ . '/Maintenance.php';
28
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;
60require_once RUN_MAINTENANCE_IF_MAIN;
$maintClass
Maintenance script to change the password of a given user.
execute()
Do the actual work.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
validateUserOption( $errorMsg)
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.