MediaWiki
REL1_22
|
00001 <?php 00027 require_once __DIR__ . '/Maintenance.php'; 00028 00034 class ChangePassword extends Maintenance { 00035 public function __construct() { 00036 parent::__construct(); 00037 $this->addOption( "user", "The username to operate on", false, true ); 00038 $this->addOption( "userid", "The user id to operate on", false, true ); 00039 $this->addOption( "password", "The password to use", true, true ); 00040 $this->mDescription = "Change a user's password"; 00041 } 00042 00043 public function execute() { 00044 if ( $this->hasOption( "user" ) ) { 00045 $user = User::newFromName( $this->getOption( 'user' ) ); 00046 } elseif ( $this->hasOption( "userid" ) ) { 00047 $user = User::newFromId( $this->getOption( 'userid' ) ); 00048 } else { 00049 $this->error( "A \"user\" or \"userid\" must be set to change the password for", true ); 00050 } 00051 if ( !$user || !$user->getId() ) { 00052 $this->error( "No such user: " . $this->getOption( 'user' ), true ); 00053 } 00054 try { 00055 $user->setPassword( $this->getOption( 'password' ) ); 00056 $user->saveSettings(); 00057 $this->output( "Password set for " . $user->getName() . "\n" ); 00058 } catch ( PasswordError $pwe ) { 00059 $this->error( $pwe->getText(), true ); 00060 } 00061 } 00062 } 00063 00064 $maintClass = "ChangePassword"; 00065 require_once RUN_MAINTENANCE_IF_MAIN;