Merge "jquery.client: Detect Internet Explorer 11"
[lhc/web/wiklou.git] / includes / specials / SpecialPasswordReset.php
index a166b56..69c4056 100644 (file)
@@ -27,7 +27,6 @@
  * @ingroup SpecialPage
  */
 class SpecialPasswordReset extends FormSpecialPage {
-
        /**
         * @var Message
         */
@@ -44,7 +43,7 @@ class SpecialPasswordReset extends FormSpecialPage {
        private $result;
 
        public function __construct() {
-               parent::__construct( 'PasswordReset' );
+               parent::__construct( 'PasswordReset', 'editmyprivateinfo' );
        }
 
        public function userCanExecute( User $user ) {
@@ -70,7 +69,8 @@ class SpecialPasswordReset extends FormSpecialPage {
                                'type' => 'text',
                                'label-message' => 'passwordreset-username',
                        );
-                       if( $this->getUser()->isLoggedIn() ) {
+
+                       if ( $this->getUser()->isLoggedIn() ) {
                                $a['Username']['default'] = $this->getUser()->getName();
                        }
                }
@@ -91,7 +91,7 @@ class SpecialPasswordReset extends FormSpecialPage {
                        );
                }
 
-               if( $this->getUser()->isAllowed( 'passwordreset' ) ) {
+               if ( $this->getUser()->isAllowed( 'passwordreset' ) ) {
                        $a['Capture'] = array(
                                'type' => 'check',
                                'label-message' => 'passwordreset-capture',
@@ -103,11 +103,8 @@ class SpecialPasswordReset extends FormSpecialPage {
        }
 
        public function alterForm( HTMLForm $form ) {
-               $form->setSubmitTextMsg( 'mailmypassword' );
-       }
-
-       protected function preText() {
                global $wgPasswordResetRoutes;
+
                $i = 0;
                if ( isset( $wgPasswordResetRoutes['username'] ) && $wgPasswordResetRoutes['username'] ) {
                        $i++;
@@ -118,7 +115,11 @@ class SpecialPasswordReset extends FormSpecialPage {
                if ( isset( $wgPasswordResetRoutes['domain'] ) && $wgPasswordResetRoutes['domain'] ) {
                        $i++;
                }
-               return $this->msg( 'passwordreset-pretext', $i )->parseAsBlock();
+
+               $message = ( $i > 1 ) ? 'passwordreset-text-many' : 'passwordreset-text-one';
+
+               $form->setHeaderText( $this->msg( $message, $i )->parseAsBlock() );
+               $form->setSubmitTextMsg( 'mailmypassword' );
        }
 
        /**
@@ -141,8 +142,9 @@ class SpecialPasswordReset extends FormSpecialPage {
                        }
                }
 
-               if( isset( $data['Capture'] ) && !$this->getUser()->isAllowed( 'passwordreset' ) ) {
-                       // The user knows they don't have the passwordreset permission, but they tried to spoof the form.  That's naughty
+               if ( isset( $data['Capture'] ) && !$this->getUser()->isAllowed( 'passwordreset' ) ) {
+                       // The user knows they don't have the passwordreset permission,
+                       // but they tried to spoof the form. That's naughty
                        throw new PermissionsError( 'passwordreset' );
                }
 
@@ -156,8 +158,8 @@ class SpecialPasswordReset extends FormSpecialPage {
                        $users = array( User::newFromName( $data['Username'] ) );
                } elseif ( isset( $data['Email'] )
                        && $data['Email'] !== ''
-                       && Sanitizer::validateEmail( $data['Email'] ) )
-               {
+                       && Sanitizer::validateEmail( $data['Email'] )
+               {
                        $method = 'email';
                        $res = wfGetDB( DB_SLAVE )->select(
                                'user',
@@ -165,9 +167,11 @@ class SpecialPasswordReset extends FormSpecialPage {
                                array( 'user_email' => $data['Email'] ),
                                __METHOD__
                        );
+
                        if ( $res ) {
                                $users = array();
-                               foreach( $res as $row ) {
+
+                               foreach ( $res as $row ) {
                                        $users[] = User::newFromRow( $row );
                                }
                        } else {
@@ -185,8 +189,8 @@ class SpecialPasswordReset extends FormSpecialPage {
                        return array( $error );
                }
 
-               if( count( $users ) == 0 ) {
-                       if( $method == 'email' ) {
+               if ( count( $users ) == 0 ) {
+                       if ( $method == 'email' ) {
                                // Don't reveal whether or not an email address is in use
                                return true;
                        } else {
@@ -209,9 +213,13 @@ class SpecialPasswordReset extends FormSpecialPage {
                foreach ( $users as $user ) {
                        if ( $user->isPasswordReminderThrottled() ) {
                                global $wgPasswordReminderResendTime;
+
                                # Round the time in hours to 3 d.p., in case someone is specifying
                                # minutes or seconds.
-                               return array( array( 'throttled-mailpassword', round( $wgPasswordReminderResendTime, 3 ) ) );
+                               return array( array(
+                                       'throttled-mailpassword',
+                                       round( $wgPasswordReminderResendTime, 3 )
+                               ) );
                        }
                }
 
@@ -244,8 +252,8 @@ class SpecialPasswordReset extends FormSpecialPage {
                        $password = $user->randomPassword();
                        $user->setNewpassword( $password );
                        $user->saveSettings();
-                       $passwords[] = $this->msg( 'passwordreset-emailelement', $user->getName(), $password
-                               )->inLanguage( $userLanguage )->text(); // We'll escape the whole thing later
+                       $passwords[] = $this->msg( 'passwordreset-emailelement', $user->getName(), $password )
+                               ->inLanguage( $userLanguage )->text(); // We'll escape the whole thing later
                }
                $passwordBlock = implode( "\n\n", $passwords );
 
@@ -262,7 +270,7 @@ class SpecialPasswordReset extends FormSpecialPage {
 
                $this->result = $firstUser->sendMail( $title->escaped(), $this->email->text() );
 
-               if( isset( $data['Capture'] ) && $data['Capture'] ) {
+               if ( isset( $data['Capture'] ) && $data['Capture'] ) {
                        // Save the user, will be used if an error occurs when sending the email
                        $this->firstUser = $firstUser;
                } else {
@@ -272,21 +280,22 @@ class SpecialPasswordReset extends FormSpecialPage {
 
                if ( $this->result->isGood() ) {
                        return true;
-               } elseif( isset( $data['Capture'] ) && $data['Capture'] ) {
+               } elseif ( isset( $data['Capture'] ) && $data['Capture'] ) {
                        // The email didn't send, but maybe they knew that and that's why they captured it
                        return true;
                } else {
-                       // @todo FIXME: The email didn't send, but we have already set the password throttle
-                       // timestamp, so they won't be able to try again until it expires...  :(
+                       // @todo FIXME: The email wasn't sent, but we have already set
+                       // the password throttle timestamp, so they won't be able to try
+                       // again until it expires...  :(
                        return array( array( 'mailerror', $this->result->getMessage() ) );
                }
        }
 
        public function onSuccess() {
-               if( $this->getUser()->isAllowed( 'passwordreset' ) && $this->email != null ) {
-                       // @todo: Logging
+               if ( $this->getUser()->isAllowed( 'passwordreset' ) && $this->email != null ) {
+                       // @todo Logging
 
-                       if( $this->result->isGood() ) {
+                       if ( $this->result->isGood() ) {
                                $this->getOutput()->addWikiMsg( 'passwordreset-emailsent-capture' );
                        } else {
                                $this->getOutput()->addWikiMsg( 'passwordreset-emailerror-capture',
@@ -305,8 +314,8 @@ class SpecialPasswordReset extends FormSpecialPage {
 
                // Maybe password resets are disabled, or there are no allowable routes
                if ( !is_array( $wgPasswordResetRoutes ) ||
-                        !in_array( true, array_values( $wgPasswordResetRoutes ) ) )
-               {
+                       !in_array( true, array_values( $wgPasswordResetRoutes ) )
+               {
                        return 'passwordreset-disabled';
                }