Registered user can set their own language for the interface. See http://bugzilla...
authorAntoine Musso <hashar@users.mediawiki.org>
Wed, 8 Sep 2004 03:39:32 +0000 (03:39 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Wed, 8 Sep 2004 03:39:32 +0000 (03:39 +0000)
includes/Setup.php
includes/SpecialPreferences.php
includes/User.php

index 9511d7b..c48aa8e 100644 (file)
@@ -198,10 +198,37 @@ $wgLoadBalancer = LoadBalancer::newFromParams( $wgDBservers );
 $wgLoadBalancer->loadMasterPos();
 
 wfProfileOut( $fname.'-database' );
+wfProfileIn( $fname.'-User' );
+
+# Extension setup functions
+# Entries should be added to this variable during the inclusion 
+# of the extension file. This allows the extension to perform 
+# any necessary initialisation in the fully initialised environment
+foreach ( $wgSkinExtensionFunctions as $func ) {
+       $func();
+}
+
+if( $wgCommandLineMode ) {
+       # Used for some maintenance scripts; user session cookies can screw things up
+       # when the database is in an in-between state.
+       $wgUser = new User();
+} else {
+       $wgUser = User::loadFromSession();
+}
+
+// FIXME : we don't know what the user entered (see SpecialPreferences.php [AV])
+if(isset($wgUser->mOptions['language'])) {
+       // Change language of the site
+       $wgLanguageCode = $wgUser->mOptions['language'];
+       // we will load messages from file instead of from database
+       $wgUseDatabaseMessages = false;
+       }
+
+wfProfileOut( $fname.'-User' );
 wfProfileIn( $fname.'-language' );
 require_once( 'languages/Language.php' );
 
-$wgMessageCache = new MessageCache; 
+$wgMessageCache = new MessageCache;
 
 $wgLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
 if( ! class_exists( $wgLangClass ) || ($wgLanguageCode == 'en' && !$wgUseLatin1) ) {
@@ -222,6 +249,11 @@ if( $wgUseLatin1 && $wgLanguageCode != 'en' ) {
        unset( $wgLang );
        $wgLang = $xxx;
 }
+
+// now that we have a language object, set per language user defaults options
+// if we didn't grabbed them from database.
+if(!$wgUser->mDataLoaded) { $wgUser->loadDefaultFromLanguage(); }
+
 wfProfileOut( $fname.'-language' );
 wfProfileIn( $fname.'-MessageCache' );
 
@@ -248,25 +280,6 @@ wfProfileIn( $fname.'-BlockCache' );
 $wgBlockCache = new BlockCache( true );
 
 wfProfileOut( $fname.'-BlockCache' );
-wfProfileIn( $fname.'-User' );
-
-# Extension setup functions
-# Entries should be added to this variable during the inclusion 
-# of the extension file. This allows the extension to perform 
-# any necessary initialisation in the fully initialised environment
-foreach ( $wgSkinExtensionFunctions as $func ) {
-       $func();
-}
-
-if( $wgCommandLineMode ) {
-       # Used for some maintenance scripts; user session cookies can screw things up
-       # when the database is in an in-between state.
-       $wgUser = new User();
-} else {
-       $wgUser = User::loadFromSession();
-}
-
-wfProfileOut( $fname.'-User' );
 wfProfileIn( $fname.'-misc2' );
 
 $wgDeferredUpdateList = array();
index fead923..c06816e 100644 (file)
@@ -24,6 +24,7 @@ function wfSpecialPreferences() {
 class PreferencesForm {
        var $mQuickbar, $mOldpass, $mNewpass, $mRetypePass, $mStubs;
        var $mRows, $mCols, $mSkin, $mMath, $mDate, $mUserEmail, $mEmailFlag, $mNick;
+       var $mUserLanguage;
        var $mSearch, $mRecent, $mHourDiff, $mSearchLines, $mSearchChars, $mAction;
        var $mReset, $mPosted, $mToggles, $mSearchNs, $mRealName;
 
@@ -45,9 +46,10 @@ class PreferencesForm {
                $this->mMath = $request->getVal( 'wpMath' );
                $this->mDate = $request->getVal( 'wpDate' );
                $this->mUserEmail = $request->getVal( 'wpUserEmail' );
-               $this->mRealName = ($wgAllowRealName) ? $request->getVal( 'wpRealName' ) : '';
+               $this->mRealName = ($wgAllowRealName) ? $request->getVal( 'wpRealName' ) : '';
                $this->mEmailFlag = $request->getCheck( 'wpEmailFlag' ) ? 1 : 0;
                $this->mNick = $request->getVal( 'wpNick' );
+               $this->mUserLanguage = $request->getVal( 'wpUserLanguage' );
                $this->mSearch = $request->getVal( 'wpSearch' );
                $this->mRecent = $request->getVal( 'wpRecent' );
                $this->mHourDiff = $request->getVal( 'wpHourDiff' );
@@ -170,6 +172,7 @@ class PreferencesForm {
                }
                $wgUser->setEmail( $this->mUserEmail );
                $wgUser->setRealName( $this->mRealName );
+               $wgUser->setOption( 'language', $this->mUserLanguage );
                $wgUser->setOption( 'nickname', $this->mNick );
                $wgUser->setOption( 'quickbar', $this->mQuickbar );
                $wgUser->setOption( 'skin', $this->mSkin );
@@ -205,12 +208,14 @@ class PreferencesForm {
 
        /**
         * @access private
-        */ function resetPrefs() {
+        */
+       function resetPrefs() {
                global $wgUser, $wgLang, $wgAllowRealName;
 
                $this->mOldpass = $this->mNewpass = $this->mRetypePass = '';
                $this->mUserEmail = $wgUser->getEmail();
-               $this->mRealName = ($wgAllowRealName) ? $wgUser->getRealName() : '';
+               $this->mRealName = ($wgAllowRealName) ? $wgUser->getRealName() : '';
+               $this->mUserLanguage = $wgUser->getOption( 'language');
                if ( 1 == $wgUser->getOption( 'disablemail' ) ) { $this->mEmailFlag = 1; }
                else { $this->mEmailFlag = 0; }
                $this->mNick = $wgUser->getOption( 'nickname' );
@@ -340,7 +345,8 @@ class PreferencesForm {
                $tzGuess = wfMsg( 'guesstimezone' );
                $tzServerTime = wfMsg( 'servertime' );
                $yem = wfMsg( 'youremail' );
-               $yrn = ($wgAllowRealName) ? wfMsg( 'yourrealname' ) : '';
+               $yrn = ($wgAllowRealName) ? wfMsg( 'yourrealname' ) : '';
+               $yl  = wfMsg( 'yourlanguage' );
                $emf = wfMsg( 'emailflag' );
                $ynn = wfMsg( 'yournick' );
                $stt = wfMsg ( 'stubthreshold' ) ;
@@ -373,7 +379,8 @@ class PreferencesForm {
                $wgOut->addHTML("
                <div><label>$yem: <input type='text' name=\"wpUserEmail\" value=\"{$this->mUserEmail}\" size='20' /></label></div>
                <div><label><input type='checkbox' $emfc value=\"1\" name=\"wpEmailFlag\" /> $emf</label></div>
-               <div><label>$ynn: <input type='text' name=\"wpNick\" value=\"{$this->mNick}\" size='12' /></label></div>\n" );
+               <div><label>$ynn: <input type='text' name=\"wpNick\" value=\"{$this->mNick}\" size='12' /></label></div>
+               <div><label>$yl: <input type='text' name=\"wpUserLanguage\" value=\"{$this->mUserLanguage}\" size='8' /></label></div>\n" );
 
                # Fields for changing password
                #
index d6cd1b2..4bbaa18 100644 (file)
@@ -123,7 +123,8 @@ class User {
 
        /**
         * Set properties to default
-        * Used at construction.
+        * Used at construction. It will load per language default settings only
+        * if we have an available language object.
         */
        function loadDefaults() {
                global $wgLang, $wgIP;
@@ -134,10 +135,9 @@ class User {
                $this->mRealName = $this->mEmail = '';
                $this->mPassword = $this->mNewpassword = '';
                $this->mRights = array();
-               $defOpt = $wgLang->getDefaultUserOptions() ;
-               foreach ( $defOpt as $oname => $val ) {
-                       $this->mOptions[$oname] = $val;
-               }
+               // Getting user defaults only if we have an available language
+               if(isset($wgLang)) { $this->loadDefaultFromLanguage(); }
+               
                foreach ($wgNamespacesToBeSearchedDefault as $nsnum => $val) {
                        $this->mOptions['searchNs'.$nsnum] = $val;
                }
@@ -148,6 +148,19 @@ class User {
                $this->cookiePassword = '';
                $this->mHash = false;
        }
+       
+       /**
+        * Used to load user options from a language.
+        * This is not in loadDefault() cause we sometime create user before having
+        * a language object.
+        */     
+       function loadDefaultFromLanguage(){
+               global $wgLang;
+               $defOpt = $wgLang->getDefaultUserOptions() ;
+               foreach ( $defOpt as $oname => $val ) {
+                       $this->mOptions[$oname] = $val;
+               }               
+       }
 
        /**
         * Get blocking information
@@ -378,8 +391,7 @@ class User {
                return ( 0 != $this->mNewtalk );
        }
 
-       function setNewtalk( $val )
-       {
+       function setNewtalk( $val ) {
                $this->loadFromDatabase();
                $this->mNewtalk = $val;
                $this->invalidateCache();