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