Merge "Set initial language and variant user preferences to user's preferred variant...
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 18 Mar 2013 00:11:19 +0000 (00:11 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 18 Mar 2013 00:11:19 +0000 (00:11 +0000)
1  2 
includes/specials/SpecialUserlogin.php

@@@ -201,7 -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();
         * @return bool
         */
        function addNewAccount() {
-               global $wgUser, $wgEmailAuthentication, $wgLoginLanguageSelector;
+               global $wgContLang, $wgUser, $wgEmailAuthentication, $wgLoginLanguageSelector;
  
                # Create the account and abort if there's a problem doing so
                $status = $this->addNewAccountInternal();
  
                $u = $status->getValue();
  
-               # If we showed up language selection links, and one was in use, be
-               # smart (and sensible) and save that language as the user's preference
-               if( $wgLoginLanguageSelector && $this->mLanguage ) {
-                       $u->setOption( 'language', $this->mLanguage );
+               # Only save preferences if the user is not creating an account for someone else.
+               if ( $this->getUser()->isAnon() ) {
+                       # If we showed up language selection links, and one was in use, be
+                       # smart (and sensible) and save that language as the user's preference
+                       if( $wgLoginLanguageSelector && $this->mLanguage ) {
+                               $u->setOption( 'language', $this->mLanguage );
+                       } else {
+                               # Otherwise the user's language preference defaults to $wgContLang,
+                               # but it may be better to set it to their preferred $wgContLang variant,
+                               # based on browser preferences or URL parameters.
+                               $u->setOption( 'language', $wgContLang->getPreferredVariant() );
+                       }
+                       if ( $wgContLang->hasVariants() ) {
+                               $u->setOption( 'variant', $wgContLang->getPreferredVariant() );
+                       }
                }
  
                $out = $this->getOutput();
                        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' );
                }
  
                                // 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
        /**
         * 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 ) {
  
        /**
         * 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 ) {
                        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 {
                }
        }
  
 +      /**
 +       * @param $error string
 +       */
        function resetLoginForm( $error ) {
                $this->getOutput()->addHTML( Xml::element( 'p', array( 'class' => 'error' ), $error ) );
                $reset = new SpecialChangePassword();
        /**
         * @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' ) {
                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
        /**
         * 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
         */
         * 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
                        }
                }
  
 -              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 {
         * 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 ) {
                        $query
                );
        }
 +
 +      protected function getGroupName() {
 +              return 'login';
 +      }
  }