SpecialMyLanguage: Use page language instead of wiki language for redirect target...
[lhc/web/wiklou.git] / maintenance / changePassword.php
index f276fc1..9fa6632 100644 (file)
@@ -24,7 +24,7 @@
  * @ingroup Maintenance
  */
 
-require_once( __DIR__ . '/Maintenance.php' );
+require_once __DIR__ . '/Maintenance.php';
 
 /**
  * Maintenance script to change the password of a given user.
@@ -37,7 +37,7 @@ class ChangePassword extends Maintenance {
                $this->addOption( "user", "The username to operate on", false, true );
                $this->addOption( "userid", "The user id to operate on", false, true );
                $this->addOption( "password", "The password to use", true, true );
-               $this->mDescription = "Change a user's password";
+               $this->addDescription( "Change a user's password" );
        }
 
        public function execute() {
@@ -46,13 +46,21 @@ class ChangePassword extends Maintenance {
                } elseif ( $this->hasOption( "userid" ) ) {
                        $user = User::newFromId( $this->getOption( 'userid' ) );
                } else {
-                       $this->error( "A \"user\" or \"userid\" must be set to change the password for" , true );
+                       $this->error( "A \"user\" or \"userid\" must be set to change the password for", true );
                }
                if ( !$user || !$user->getId() ) {
                        $this->error( "No such user: " . $this->getOption( 'user' ), true );
                }
+               $password = $this->getOption( 'password' );
                try {
-                       $user->setPassword( $this->getOption( 'password' ) );
+                       $status = $user->changeAuthenticationData( [
+                               'username' => $user->getName(),
+                               'password' => $password,
+                               'retype' => $password,
+                       ] );
+                       if ( !$status->isGood() ) {
+                               throw new PasswordError( $status->getWikiText( null, null, 'en' ) );
+                       }
                        $user->saveSettings();
                        $this->output( "Password set for " . $user->getName() . "\n" );
                } catch ( PasswordError $pwe ) {
@@ -62,4 +70,4 @@ class ChangePassword extends Maintenance {
 }
 
 $maintClass = "ChangePassword";
-require_once( RUN_MAINTENANCE_IF_MAIN );
+require_once RUN_MAINTENANCE_IF_MAIN;