MediaWiki fundraising/REL1_35
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 if ( $this->hasOption( "user" ) ) {
45 $user = User::newFromName( $this->getOption( 'user' ) );
46 } elseif ( $this->hasOption( "userid" ) ) {
47 $user = User::newFromId( $this->getOption( 'userid' ) );
48 } else {
49 $this->fatalError( "A \"user\" or \"userid\" must be set to change the password for" );
50 }
51 if ( !$user || !$user->getId() ) {
52 $this->fatalError( "No such user: " . $this->getOption( 'user' ) );
53 }
54 $password = $this->getOption( 'password' );
55 $status = $user->changeAuthenticationData( [
56 'username' => $user->getName(),
57 'password' => $password,
58 'retype' => $password,
59 ] );
60 if ( $status->isGood() ) {
61 $this->output( "Password set for " . $user->getName() . "\n" );
62 } else {
63 $this->fatalError( $status->getMessage( false, false, 'en' )->text() );
64 }
65 }
66}
67
68$maintClass = ChangePassword::class;
69require_once RUN_MAINTENANCE_IF_MAIN;
const 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.
hasOption( $name)
Checks to see if a particular option was set.
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.