MediaWiki REL1_28
Go to the documentation of this file.
27require_once __DIR__ . '/Maintenance.php';
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 }
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 $password = $this->getOption( 'password' );
55 try {
56 $status = $user->changeAuthenticationData( [
57 'username' => $user->getName(),
58 'password' => $password,
59 'retype' => $password,
60 ] );
61 if ( !$status->isGood() ) {
62 throw new PasswordError( $status->getWikiText( null, null, 'en' ) );
63 }
64 $user->saveSettings();
65 $this->output( "Password set for " . $user->getName() . "\n" );
66 } catch ( PasswordError $pwe ) {
67 $this->error( $pwe->getText(), true );
68 }
69 }
72$maintClass = "ChangePassword";
Maintenance script to change the password of a given user.
Do the actual work.
Default constructor.
Get the text to display when reporting the error on the command line.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
hasOption( $name)
Checks to see if a particular param exists.
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.
Show an error when any operation involving passwords fails to run.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition hooks.txt:1049
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 local account $user
Definition hooks.txt:249
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37