MediaWiki  1.23.8
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->mDescription = "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->error( "A \"user\" or \"userid\" must be set to change the password for", true );
50  }
51  if ( !$user || !$user->getId() ) {
52  $this->error( "No such user: " . $this->getOption( 'user' ), true );
53  }
54  try {
55  $user->setPassword( $this->getOption( 'password' ) );
56  $user->saveSettings();
57  $this->output( "Password set for " . $user->getName() . "\n" );
58  } catch ( PasswordError $pwe ) {
59  $this->error( $pwe->getText(), true );
60  }
61  }
62 }
63 
64 $maintClass = "ChangePassword";
65 require_once RUN_MAINTENANCE_IF_MAIN;
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:412
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
ChangePassword\execute
execute()
Do the actual work.
Definition: changePassword.php:43
PasswordError
Thrown by User::setPassword() on error.
Definition: User.php:45
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:389
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1530
ChangePassword
Maintenance script to change the password of a given user.
Definition: changePassword.php:34
MWException\getText
getText()
Get the text to display when reporting the error on the command line.
Definition: MWException.php:158
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:191
ChangePassword\__construct
__construct()
Default constructor.
Definition: changePassword.php:35
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:333
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular param exists.
Definition: Maintenance.php:181
$maintClass
$maintClass
Definition: changePassword.php:64