From: Antoine Musso Date: Wed, 8 Sep 2004 03:39:32 +0000 (+0000) Subject: Registered user can set their own language for the interface. See http://bugzilla... X-Git-Tag: 1.5.0alpha1~2058 X-Git-Url: http://git.cyclocoop.org/%22.%24h.%22?a=commitdiff_plain;h=f62712647b45b5bc5fcf8b2be69fb72882080037;p=lhc%2Fweb%2Fwiklou.git Registered user can set their own language for the interface. See bugzilla.wikipedia.org/show_bug.cgi?id=184 --- diff --git a/includes/Setup.php b/includes/Setup.php index 9511d7b1fd..c48aa8ed9a 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -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(); diff --git a/includes/SpecialPreferences.php b/includes/SpecialPreferences.php index fead9237c7..c06816ec89 100644 --- a/includes/SpecialPreferences.php +++ b/includes/SpecialPreferences.php @@ -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("
-
\n" ); +
+
\n" ); # Fields for changing password # diff --git a/includes/User.php b/includes/User.php index d6cd1b2f8a..4bbaa181f1 100644 --- a/includes/User.php +++ b/includes/User.php @@ -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();