Set initial language and variant user preferences to user's preferred variant on...
authorLiangent <liangent@gmail.com>
Sat, 9 Feb 2013 13:21:52 +0000 (21:21 +0800)
committerLiangent <liangent@gmail.com>
Fri, 15 Feb 2013 05:27:58 +0000 (13:27 +0800)
Change-Id: I7fffe7e96fe5139fe5d023bf9755882dc3efad6e

includes/specials/SpecialUserlogin.php

index 705f14f..61a042d 100644 (file)
@@ -230,7 +230,7 @@ class LoginForm extends SpecialPage {
         * @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();
@@ -242,10 +242,22 @@ class LoginForm extends SpecialPage {
 
                $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();