MediaWiki master
changePassword.php
Go to the documentation of this file.
1<?php
27// @codeCoverageIgnoreStart
28require_once __DIR__ . '/Maintenance.php';
29// @codeCoverageIgnoreEnd
30
37 public function __construct() {
38 parent::__construct();
39 $this->addOption( "user", "The username to operate on", false, true );
40 $this->addOption( "userid", "The user id to operate on", false, true );
41 $this->addOption( "password", "The password to use", true, true );
42 $this->addDescription( "Change a user's password" );
43 }
44
45 public function execute() {
46 $user = $this->validateUserOption( "A \"user\" or \"userid\" must be set to change the password for" );
47 $password = $this->getOption( 'password' );
48 $status = $user->changeAuthenticationData( [
49 'username' => $user->getName(),
50 'password' => $password,
51 'retype' => $password,
52 ] );
53 if ( $status->isGood() ) {
54 $this->output( "Password set for " . $user->getName() . "\n" );
55 } else {
56 $this->fatalError( $status );
57 }
58 }
59}
60
61// @codeCoverageIgnoreStart
62$maintClass = ChangePassword::class;
63require_once RUN_MAINTENANCE_IF_MAIN;
64// @codeCoverageIgnoreEnd
$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.