jenkins-bot has submitted this change and it was merged.

Change subject: Change Special:ChangePassword to use OOUI
......................................................................


Change Special:ChangePassword to use OOUI

In order to work with OOUI properly, SpecialChangePassword::attemptReset() 
doesn't
throw PasswordErrors anymore. It now returns a Status object which
is set to fatal, if some requirement doesn't meet.

In OOUIHTMLForm: Handle Message objects as errors correctly. It's a valid 
parameter
for fatal to use a Message object instead of a message key, so OOUIHTMLForm 
needs
to handle Mesage objects as Message objects (can be parsed directly) instead of 
using
it as a message key (which usually doesn't exist).

Bug: T78373
Change-Id: Id768833bbd966cdeadd5a13fdb64b636ea2062ef
---
M includes/htmlform/OOUIHTMLForm.php
M includes/specials/SpecialChangePassword.php
2 files changed, 34 insertions(+), 25 deletions(-)

Approvals:
  Jdlrobson: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/htmlform/OOUIHTMLForm.php 
b/includes/htmlform/OOUIHTMLForm.php
index 60f02a1..d328ecc 100644
--- a/includes/htmlform/OOUIHTMLForm.php
+++ b/includes/htmlform/OOUIHTMLForm.php
@@ -160,7 +160,12 @@
                                $msg = $error;
                                $error = array();
                        }
-                       $error = $this->msg( $msg, $error )->parse();
+                       // if the error is already a message object, don't use 
it as a message key
+                       if ( !$msg instanceof Message ) {
+                               $error = $this->msg( $msg, $error )->parse();
+                       } else {
+                               $error = $msg->parse();
+                       }
                        $error = new OOUI\HtmlSnippet( $error );
                }
 
diff --git a/includes/specials/SpecialChangePassword.php 
b/includes/specials/SpecialChangePassword.php
index df68b12..91ac4e0 100644
--- a/includes/specials/SpecialChangePassword.php
+++ b/includes/specials/SpecialChangePassword.php
@@ -190,20 +190,16 @@
                        return true;
                }
 
-               try {
-                       $this->mUserName = $request->getVal( 'wpName', 
$this->getUser()->getName() );
-                       $this->mDomain = $wgAuth->getDomain();
+               $this->mUserName = $request->getVal( 'wpName', 
$this->getUser()->getName() );
+               $this->mDomain = $wgAuth->getDomain();
 
-                       if ( !$wgAuth->allowPasswordChange() ) {
-                               throw new ErrorPageError( 'changepassword', 
'resetpass_forbidden' );
-                       }
-
-                       $this->attemptReset( $data['Password'], 
$data['NewPassword'], $data['Retype'] );
-
-                       return true;
-               } catch ( PasswordError $e ) {
-                       return $e->getMessage();
+               if ( !$wgAuth->allowPasswordChange() ) {
+                       throw new ErrorPageError( 'changepassword', 
'resetpass_forbidden' );
                }
+
+               $status = $this->attemptReset( $data['Password'], 
$data['NewPassword'], $data['Retype'] );
+
+               return $status;
        }
 
        public function onSuccess() {
@@ -231,10 +227,14 @@
        }
 
        /**
-        * @param string $oldpass
-        * @param string $newpass
-        * @param string $retype
-        * @throws PasswordError When cannot set the new password because 
requirements not met.
+        * Checks the new password if it meets the requirements for passwords 
and set
+        * it as a current password, otherwise set the passed Status object to 
fatal
+        * and doesn't change anything
+        *
+        * @param string $oldpass The current (temporary) password.
+        * @param string $newpass The password to set.
+        * @param string $retype The string of the retype password field to 
check with newpass
+        * @return Status
         */
        protected function attemptReset( $oldpass, $newpass, $retype ) {
                $isSelf = ( $this->mUserName === $this->getUser()->getName() );
@@ -245,33 +245,32 @@
                }
 
                if ( !$user || $user->isAnon() ) {
-                       throw new PasswordError( $this->msg( 'nosuchusershort', 
$this->mUserName )->text() );
+                       return Status::newFatal( $this->msg( 'nosuchusershort', 
$this->mUserName ) );
                }
 
                if ( $newpass !== $retype ) {
                        Hooks::run( 'PrefsPasswordAudit', array( $user, 
$newpass, 'badretype' ) );
-                       throw new PasswordError( $this->msg( 'badretype' 
)->text() );
+                       return Status::newFatal( $this->msg( 'badretype' ) );
                }
 
                $throttleCount = LoginForm::incLoginThrottle( $this->mUserName 
);
                if ( $throttleCount === true ) {
                        $lang = $this->getLanguage();
                        $throttleInfo = $this->getConfig()->get( 
'PasswordAttemptThrottle' );
-                       throw new PasswordError( $this->msg( 
'changepassword-throttled' )
+                       return Status::newFatal( $this->msg( 
'changepassword-throttled' )
                                ->params( $lang->formatDuration( 
$throttleInfo['seconds'] ) )
-                               ->text()
                        );
                }
 
                // @todo Make these separate messages, since the message is 
written for both cases
                if ( !$user->checkTemporaryPassword( $oldpass ) && 
!$user->checkPassword( $oldpass ) ) {
                        Hooks::run( 'PrefsPasswordAudit', array( $user, 
$newpass, 'wrongpassword' ) );
-                       throw new PasswordError( $this->msg( 
'resetpass-wrong-oldpass' )->text() );
+                       return Status::newFatal( $this->msg( 
'resetpass-wrong-oldpass' ) );
                }
 
                // User is resetting their password to their old password
                if ( $oldpass === $newpass ) {
-                       throw new PasswordError( $this->msg( 
'resetpass-recycled' )->text() );
+                       return Status::newFatal( $this->msg( 
'resetpass-recycled' ) );
                }
 
                // Do AbortChangePassword after checking mOldpass, so we don't 
leak information
@@ -279,7 +278,7 @@
                $abortMsg = 'resetpass-abort-generic';
                if ( !Hooks::run( 'AbortChangePassword', array( $user, 
$oldpass, $newpass, &$abortMsg ) ) ) {
                        Hooks::run( 'PrefsPasswordAudit', array( $user, 
$newpass, 'abortreset' ) );
-                       throw new PasswordError( $this->msg( $abortMsg 
)->text() );
+                       return Status::newFatal( $this->msg( $abortMsg ) );
                }
 
                // Please reset throttle for successful logins, thanks!
@@ -292,7 +291,7 @@
                        Hooks::run( 'PrefsPasswordAudit', array( $user, 
$newpass, 'success' ) );
                } catch ( PasswordError $e ) {
                        Hooks::run( 'PrefsPasswordAudit', array( $user, 
$newpass, 'error' ) );
-                       throw new PasswordError( $e->getMessage() );
+                       return Status::newFatal( new RawMessage( 
$e->getMessage() ) );
                }
 
                if ( $isSelf ) {
@@ -303,6 +302,7 @@
                }
                $user->saveSettings();
                $this->resetPasswordExpiration( $user );
+               return Status::newGood();
        }
 
        public function requiresUnblock() {
@@ -336,4 +336,8 @@
                        __METHOD__
                );
        }
+
+       protected function getDisplayFormat() {
+               return 'ooui';
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/238505
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id768833bbd966cdeadd5a13fdb64b636ea2062ef
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Bartosz DziewoƄski <[email protected]>
Gerrit-Reviewer: Daniel Friesen <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Glaisher <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to