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