Merge "Set initial language and variant user preferences to user's preferred variant...
[lhc/web/wiklou.git] / includes / specials / SpecialUserlogin.php
index 61a042d..eef6691 100644 (file)
@@ -201,7 +201,7 @@ class LoginForm extends SpecialPage {
                if( !$status->isGood() ) {
                        $error = $this->getOutput()->parse( $status->getWikiText() );
                        $this->mainLoginForm( $error );
-                       return false;
+                       return;
                }
 
                $u = $status->getValue();
@@ -385,32 +385,34 @@ class LoginForm extends SpecialPage {
                        return Status::newFatal( 'noname' );
                } elseif ( 0 != $u->idForName() ) {
                        return Status::newFatal( 'userexists' );
-               } elseif ( 0 != strcmp( $this->mPassword, $this->mRetype ) ) {
-                       return Status::newFatal( 'badretype' );
                }
 
-               # check for minimal password length
-               $valid = $u->getPasswordValidity( $this->mPassword );
-               if ( $valid !== true ) {
-                       if ( !$this->mCreateaccountMail ) {
+               if ( $this->mCreateaccountMail ) {
+                       # do not force a password for account creation by email
+                       # set invalid password, it will be replaced later by a random generated password
+                       $this->mPassword = null;
+               } else {
+                       if ( $this->mPassword !== $this->mRetype ) {
+                               return Status::newFatal( 'badretype' );
+                       }
+
+                       # check for minimal password length
+                       $valid = $u->getPasswordValidity( $this->mPassword );
+                       if ( $valid !== true ) {
                                if ( !is_array( $valid ) ) {
                                        $valid = array( $valid, $wgMinimalPasswordLength );
                                }
                                return call_user_func_array( 'Status::newFatal', $valid );
-                       } else {
-                               # do not force a password for account creation by email
-                               # set invalid password, it will be replaced later by a random generated password
-                               $this->mPassword = null;
                        }
                }
 
                # if you need a confirmed email address to edit, then obviously you
                # need an email address.
-               if ( $wgEmailConfirmToEdit && empty( $this->mEmail ) ) {
+               if ( $wgEmailConfirmToEdit && strval( $this->mEmail ) === '' ) {
                        return Status::newFatal( 'noemailtitle' );
                }
 
-               if( !empty( $this->mEmail ) && !Sanitizer::validateEmail( $this->mEmail ) ) {
+               if ( strval( $this->mEmail ) !== '' && !Sanitizer::validateEmail( $this->mEmail ) ) {
                        return Status::newFatal( 'invalidemailaddress' );
                }
 
@@ -614,7 +616,7 @@ class LoginForm extends SpecialPage {
                                // faces etc will probably just fail cleanly here.
                                $retval = self::RESET_PASS;
                        } else {
-                               $retval = ( $this->mPassword  == '' ) ? self::EMPTY_PASS : self::WRONG_PASS;
+                               $retval = ( $this->mPassword == '' ) ? self::EMPTY_PASS : self::WRONG_PASS;
                        }
                } elseif ( $wgBlockDisablesLogin && $u->isBlocked() ) {
                        // If we've enabled it, make it so that a blocked user cannot login
@@ -646,7 +648,7 @@ class LoginForm extends SpecialPage {
        /**
         * Increment the login attempt throttle hit count for the (username,current IP)
         * tuple unless the throttle was already reached.
-        * @param $username string The user name
+        * @param string $username The user name
         * @return Bool|Integer The integer hit count or True if it is already at the limit
         */
        public static function incLoginThrottle( $username ) {
@@ -674,7 +676,7 @@ class LoginForm extends SpecialPage {
 
        /**
         * Clear the login attempt throttle hit count for the (username,current IP) tuple.
-        * @param $username string The user name
+        * @param string $username The user name
         * @return void
         */
        public static function clearLoginThrottle( $username ) {
@@ -757,7 +759,7 @@ class LoginForm extends SpecialPage {
                        case self::SUCCESS:
                                # We've verified now, update the real record
                                $user = $this->getUser();
-                               if( (bool)$this->mRemember != (bool)$user->getOption( 'rememberpassword' ) ) {
+                               if( (bool)$this->mRemember != $user->getBoolOption( 'rememberpassword' ) ) {
                                        $user->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 );
                                        $user->saveSettings();
                                } else {
@@ -841,6 +843,9 @@ class LoginForm extends SpecialPage {
                }
        }
 
+       /**
+        * @param $error string
+        */
        function resetLoginForm( $error ) {
                $this->getOutput()->addHTML( Xml::element( 'p', array( 'class' => 'error' ), $error ) );
                $reset = new SpecialChangePassword();
@@ -851,8 +856,8 @@ class LoginForm extends SpecialPage {
        /**
         * @param $u User object
         * @param $throttle Boolean
-        * @param $emailTitle String: message name of email title
-        * @param $emailText String: message name of email text
+        * @param string $emailTitle message name of email title
+        * @param string $emailText message name of email text
         * @return Status object
         */
        function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) {
@@ -880,7 +885,6 @@ class LoginForm extends SpecialPage {
                return $result;
        }
 
-
        /**
         * Run any hooks registered for logins, then HTTP redirect to
         * $this->mReturnTo (or Main Page if that's undefined).  Formerly we had a
@@ -933,7 +937,7 @@ class LoginForm extends SpecialPage {
        /**
         * Display an "successful action" page.
         *
-        * @param $title string|Message page's title
+        * @param string|Message $title page's title
         * @param $msgname string
         * @param $injected_html string
         */
@@ -955,6 +959,7 @@ class LoginForm extends SpecialPage {
         * User::isBlockedFromCreateAccount(), which gets this block, ignores the 'hardblock'
         * setting on blocks (bug 13611).
         * @param $block Block the block causing this error
+        * @throws ErrorPageError
         */
        function userBlockedMessage( Block $block ) {
                # Let's be nice about this, it's likely that this feature will be used
@@ -1045,7 +1050,8 @@ class LoginForm extends SpecialPage {
                        }
                }
 
-               if ( $this->mUsername == '' ) {
+               // Pre-fill username (if not creating an account, bug 44775).
+               if ( $this->mUsername == '' && $this->mType != 'signup' ) {
                        if ( $user->isLoggedIn() ) {
                                $this->mUsername = $user->getName();
                        } else {
@@ -1343,8 +1349,8 @@ class LoginForm extends SpecialPage {
         * Create a language selector link for a particular language
         * Links back to this page preserving type and returnto
         *
-        * @param $text Link text
-        * @param $lang Language code
+        * @param string $text Link text
+        * @param string $lang Language code
         * @return string
         */
        function makeLanguageSelectorLink( $text, $lang ) {
@@ -1372,4 +1378,8 @@ class LoginForm extends SpecialPage {
                        $query
                );
        }
+
+       protected function getGroupName() {
+               return 'login';
+       }
 }