Index: branches/mutiple_languages_select/phase3/includes/Xml.php |
— | — | @@ -207,9 +207,10 @@ |
208 | 208 | * |
209 | 209 | * @param $selected The language code of the selected language |
210 | 210 | * @param $customisedOnly If true only languages which have some content are listed |
| 211 | + * @param $fallbackNum Not used unless a user fallback language, then 1..$wgUserFallbackLanguages |
211 | 212 | * @return array of label and select |
212 | 213 | */ |
213 | | - public static function languageSelector( $selected, $customisedOnly = true ) { |
| 214 | + public static function languageSelector( $selected, $customisedOnly = true, $fallbackNum = false ) { |
214 | 215 | global $wgContLanguageCode; |
215 | 216 | /** |
216 | 217 | * Make sure the site language is in the list; a custom language code |
— | — | @@ -219,6 +220,12 @@ |
220 | 221 | if( !array_key_exists( $wgContLanguageCode, $languages ) ) { |
221 | 222 | $languages[$wgContLanguageCode] = $wgContLanguageCode; |
222 | 223 | } |
| 224 | + $field = 'wpUserLanguage'; |
| 225 | + if($fallbackNum) |
| 226 | + { |
| 227 | + $field = 'wpUserFallbackLanguage['.strval($fallbackNum).']'; |
| 228 | + $languages['-'] = ''; |
| 229 | + } |
223 | 230 | ksort( $languages ); |
224 | 231 | |
225 | 232 | /** |
— | — | @@ -233,9 +240,11 @@ |
234 | 241 | } |
235 | 242 | |
236 | 243 | return array( |
237 | | - Xml::label( wfMsg('yourlanguage'), 'wpUserLanguage' ), |
| 244 | + Xml::label( wfMsg($fallbackNum ? 'yourfallbacklanguage' : 'yourlanguage', |
| 245 | + $fallbackNum), |
| 246 | + 'wpUserLanguage' ), |
238 | 247 | Xml::tags( 'select', |
239 | | - array( 'id' => 'wpUserLanguage', 'name' => 'wpUserLanguage' ), |
| 248 | + array( 'id' => 'wpUserLanguage', 'name' => $field ), |
240 | 249 | $options |
241 | 250 | ) |
242 | 251 | ); |
Index: branches/mutiple_languages_select/phase3/includes/User.php |
— | — | @@ -996,6 +996,7 @@ |
997 | 997 | $variant = $wgContLang->getPreferredVariant( false ); |
998 | 998 | $defOpt['variant'] = $variant; |
999 | 999 | $defOpt['language'] = $variant; |
| 1000 | +# $defopt['fallbacklang'] = ''; ## FIXME: fallbacklanguage is likely not used anywhere. |
1000 | 1001 | |
1001 | 1002 | foreach( $wgNamespacesToBeSearchedDefault as $nsnum => $val ) { |
1002 | 1003 | $defOpt['searchNs'.$nsnum] = $val; |
— | — | @@ -1894,9 +1895,8 @@ |
1895 | 1896 | return (bool)$this->getOption( $oname ); |
1896 | 1897 | } |
1897 | 1898 | |
1898 | | - |
1899 | 1899 | /** |
1900 | | - * Get the user's current setting for a given option, as a boolean value. |
| 1900 | + * Get the user's current setting for a given option, as an integer value. |
1901 | 1901 | * |
1902 | 1902 | * @param $oname \string The option to check |
1903 | 1903 | * @param $defaultOverride \int A default value returned if the option does not exist |
— | — | @@ -1912,12 +1912,35 @@ |
1913 | 1913 | } |
1914 | 1914 | |
1915 | 1915 | /** |
| 1916 | + * Get the user's current setting for an option, as an array value. |
| 1917 | + * |
| 1918 | + * @param $oname \string The option to check |
| 1919 | + * @param $defaultOverride \array A default value returned if the option does not exist |
| 1920 | + * @param $eparator \string Used to unserialize the array elements |
| 1921 | + * @return \array User's current value for the option |
| 1922 | + * @see getOption() |
| 1923 | + */ |
| 1924 | + function getArrayOption( $oname, $defaultOverride=array(), $separator=':' ) { |
| 1925 | + $val = $this->getOption( $oname ); |
| 1926 | + if( $val == '' ) |
| 1927 | + { |
| 1928 | + $val = $defaultOverride; |
| 1929 | + } |
| 1930 | + else |
| 1931 | + { |
| 1932 | + $val = explode( $separator, $val ); |
| 1933 | + } |
| 1934 | + return ( $val ); |
| 1935 | + } |
| 1936 | + |
| 1937 | + /** |
1916 | 1938 | * Set the given option for a user. |
1917 | 1939 | * |
1918 | 1940 | * @param $oname \string The option to set |
1919 | 1941 | * @param $val \mixed New value to set |
| 1942 | + * @param $eparator \string Used to serialize elements of $val if it's an array |
1920 | 1943 | */ |
1921 | | - function setOption( $oname, $val ) { |
| 1944 | + function setOption( $oname, $val, $separator=':' ) { |
1922 | 1945 | $this->load(); |
1923 | 1946 | if ( is_null( $this->mOptions ) ) { |
1924 | 1947 | $this->mOptions = User::getDefaultOptions(); |
— | — | @@ -1926,6 +1949,11 @@ |
1927 | 1950 | # Clear cached skin, so the new one displays immediately in Special:Preferences |
1928 | 1951 | unset( $this->mSkin ); |
1929 | 1952 | } |
| 1953 | + if( is_array( $val ) ) |
| 1954 | + { |
| 1955 | + $val = implode( $separator, $val ); |
| 1956 | +# $wgUser->setOption( 'fallbacklang', implode(':', $this->mUserFallbackLanguage) ); |
| 1957 | + } |
1930 | 1958 | // Filter out any newlines that may have passed through input validation. |
1931 | 1959 | // Newlines are used to separate items in the options blob. |
1932 | 1960 | if( $val ) { |
— | — | @@ -1940,7 +1968,7 @@ |
1941 | 1969 | } |
1942 | 1970 | $this->mOptions[$oname] = $val; |
1943 | 1971 | } |
1944 | | - |
| 1972 | + |
1945 | 1973 | /** |
1946 | 1974 | * Reset all options to the site defaults |
1947 | 1975 | */ |
Index: branches/mutiple_languages_select/phase3/includes/DefaultSettings.php |
— | — | @@ -761,6 +761,8 @@ |
762 | 762 | # |
763 | 763 | /** Site language code, should be one of ./languages/Language(.*).php */ |
764 | 764 | $wgLanguageCode = 'en'; |
| 765 | +/** Number of fallback languages, a user can specify in preferences */ |
| 766 | +$wgUserFallbackLanguages = 1; |
765 | 767 | |
766 | 768 | /** |
767 | 769 | * Some languages need different word forms, usually for different cases. |
Index: branches/mutiple_languages_select/phase3/includes/specials/SpecialPreferences.php |
— | — | @@ -26,7 +26,7 @@ |
27 | 27 | var $mUserLanguage, $mUserVariant; |
28 | 28 | var $mSearch, $mRecent, $mRecentDays, $mTimeZone, $mHourDiff, $mSearchLines, $mSearchChars, $mAction; |
29 | 29 | var $mReset, $mPosted, $mToggles, $mSearchNs, $mRealName, $mImageSize; |
30 | | - var $mUnderline, $mWatchlistEdits, $mGender; |
| 30 | + var $mUnderline, $mWatchlistEdits, $mGender, $mUserFallbackLanguage; |
31 | 31 | |
32 | 32 | /** |
33 | 33 | * Constructor |
— | — | @@ -48,6 +48,7 @@ |
49 | 49 | $this->mNick = $request->getVal( 'wpNick' ); |
50 | 50 | $this->mUserLanguage = $request->getVal( 'wpUserLanguage' ); |
51 | 51 | $this->mUserVariant = $request->getVal( 'wpUserVariant' ); |
| 52 | + $this->mUserFallbackLanguage = $request->getArray( 'wpUserFallbackLanguage' ); |
52 | 53 | $this->mSearch = $request->getVal( 'wpSearch' ); |
53 | 54 | $this->mRecent = $request->getVal( 'wpRecent' ); |
54 | 55 | $this->mRecentDays = $request->getVal( 'wpRecentDays' ); |
— | — | @@ -99,6 +100,31 @@ |
100 | 101 | if ( !preg_match( '/^[a-z\-]*$/', $this->mUserLanguage ) ) { |
101 | 102 | $this->mUserLanguage = 'nolanguage'; |
102 | 103 | } |
| 104 | + # Validate fallback languages |
| 105 | + if ( is_array( $this->mUserFallbackLanguage ) ) |
| 106 | + { |
| 107 | + $mUFLseen = array(); |
| 108 | + foreach($this->mUserFallbackLanguage as $i => $mUFL) |
| 109 | + { |
| 110 | + if ( ( !preg_match( '/^[a-z\-]*$/', $mUFL ) ) || // nonsential |
| 111 | + ( !preg_match( '/[a-z]/', $mUFL ) ) || // not min 1 char |
| 112 | + ( $mUFL == $this->mUserLanguage ) || // user language |
| 113 | + isset( $mUFLseen[$mUFL] ) ) // duplicate |
| 114 | + { |
| 115 | + unset($this->mUserFallbackLanguage[$i]); |
| 116 | + } |
| 117 | + else |
| 118 | + { |
| 119 | + $mUFLseen[$mUFL] = TRUE; |
| 120 | + } |
| 121 | + } |
| 122 | + unset($mUFLseen); |
| 123 | + $this->mUserFallbackLanguage = explode( ':', ':'.implode(':', $this->mUserFallbackLanguage ) ); |
| 124 | + } |
| 125 | + else |
| 126 | + { |
| 127 | + $this->mUserFallbackLanguage = array( $this->mUserFallbackLanguage ); |
| 128 | + } |
103 | 129 | |
104 | 130 | wfRunHooks( 'InitPreferencesForm', array( $this, $request ) ); |
105 | 131 | } |
— | — | @@ -256,6 +282,7 @@ |
257 | 283 | |
258 | 284 | $wgUser->setOption( 'language', $this->mUserLanguage ); |
259 | 285 | $wgUser->setOption( 'variant', $this->mUserVariant ); |
| 286 | + $wgUser->setOption( 'fallbacklang', $this->mUserFallbackLanguage ); |
260 | 287 | $wgUser->setOption( 'nickname', $this->mNick ); |
261 | 288 | $wgUser->setOption( 'quickbar', $this->mQuickbar ); |
262 | 289 | global $wgAllowUserSkin; |
— | — | @@ -370,8 +397,8 @@ |
371 | 398 | |
372 | 399 | # language value might be blank, default to content language |
373 | 400 | $this->mUserLanguage = $wgUser->getOption( 'language', $wgContLanguageCode ); |
374 | | - |
375 | 401 | $this->mUserVariant = $wgUser->getOption( 'variant'); |
| 402 | + $this->mUserFallbackLanguage = $wgUser->getArrayOption( 'fallbacklang' ); |
376 | 403 | $this->mEmailFlag = $wgUser->getOption( 'disablemail' ) == 1 ? 1 : 0; |
377 | 404 | $this->mNick = $wgUser->getOption( 'nickname' ); |
378 | 405 | |
— | — | @@ -562,6 +589,7 @@ |
563 | 590 | global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication; |
564 | 591 | global $wgContLanguageCode, $wgDefaultSkin, $wgCookieExpiration; |
565 | 592 | global $wgEmailConfirmToEdit, $wgEnableMWSuggest, $wgLocalTZoffset; |
| 593 | + global $wgUserFallbackLanguages; |
566 | 594 | |
567 | 595 | $wgOut->setPageTitle( wfMsg( 'preferences' ) ); |
568 | 596 | $wgOut->setArticleRelated( false ); |
— | — | @@ -762,12 +790,19 @@ |
763 | 791 | ) |
764 | 792 | ); |
765 | 793 | |
| 794 | + # language |
| 795 | + if(!$wgDisableLangConversion || $wgUserFallbackLanguages>0) |
| 796 | + { |
| 797 | + $wgOut->addHTML( |
| 798 | + $this->tableRow( Xml::element( 'h2', null, wfMsg( 'prefs-language' ) ) ) ); |
| 799 | + } |
| 800 | + |
766 | 801 | list( $lsLabel, $lsSelect) = Xml::languageSelector( $this->mUserLanguage, false ); |
767 | 802 | $wgOut->addHTML( |
768 | 803 | $this->tableRow( $lsLabel, $lsSelect ) |
769 | 804 | ); |
770 | 805 | |
771 | | - /* see if there are multiple language variants to choose from*/ |
| 806 | + /* see if there are multiple language variants to choose from */ |
772 | 807 | if(!$wgDisableLangConversion) { |
773 | 808 | $variants = $wgContLang->getVariants(); |
774 | 809 | $variantArray = array(); |
— | — | @@ -810,6 +845,19 @@ |
811 | 846 | } |
812 | 847 | } |
813 | 848 | |
| 849 | + # Fallback Languages |
| 850 | + for( $i=1; $i<=$wgUserFallbackLanguages; ++$i) |
| 851 | + { |
| 852 | + if ( ! isset( $this->mUserFallbackLanguage[$i] ) ) |
| 853 | + { |
| 854 | + $this->mUserFallbackLanguage[$i] = ( '-' ); |
| 855 | + } |
| 856 | + list( $lsLabel, $lsSelect) = Xml::languageSelector( $this->mUserFallbackLanguage[$i], false , $i); |
| 857 | + $wgOut->addHTML( |
| 858 | + $this->tableRow( $lsLabel, $lsSelect ) |
| 859 | + ); |
| 860 | + } |
| 861 | + |
814 | 862 | # Password |
815 | 863 | if( $wgAuth->allowPasswordChange() ) { |
816 | 864 | $link = $wgUser->getSkin()->link( SpecialPage::getTitleFor( 'ResetPass' ), wfMsgHtml( 'prefs-resetpass' ), |
Index: branches/mutiple_languages_select/phase3/languages/messages/MessagesQqq.php |
— | — | @@ -524,14 +524,19 @@ |
525 | 525 | {{Identical|Log in}}', |
526 | 526 | 'youremail' => '{{Identical|E-mail}}', |
527 | 527 | 'username' => '{{Identical|Username}}', |
528 | | -'uid' => '{{Identical|User ID}}', |
| 528 | +'uid' => 'Used in [[Special:Preferences]], first tab, {{Identical|User ID}}', |
529 | 529 | 'prefs-memberingroups' => 'This message is shown on [[Special:Preferences]], first tab, where it is follwed by a colon.', |
530 | 530 | 'yourrealname' => 'Used in [[Special:Preferences]], first tab. |
531 | 531 | {{Identical|Real name}}', |
| 532 | +'prefs-language' => 'Used in [[Special:Preferences]], first tab, as section title, only when the wiki has language variants, or users can specify fallback languages.', |
532 | 533 | 'yourlanguage' => 'Used in [[Special:Preferences]], first tab. |
533 | 534 | {{Identical|Language}}', |
534 | | -'yourvariant' => 'Used in [[Special:Preferences]], first tab, when the wiki content language has variants only. |
| 535 | +'yourvariant' => 'Used in [[Special:Preferences]], first tab, when the wiki content language has variants, only. |
| 536 | +See: [[:me:Manual:$wgUserContentLanguage]]. |
535 | 537 | {{optional}}', |
| 538 | +'yourfallbacklanguage' => 'Used in [[Special:Preferences]], |
| 539 | +$1 = the ordinal number (1..$wgUserFallbackLangauges) of this fallback language, |
| 540 | +$2 = the maximum number of fallback languages for this wiki, see [[:mw:Manual:$wgUserFallbackLanguages]]', |
536 | 541 | 'yournick' => 'Used in [[Special:Preferences]], first tab.', |
537 | 542 | 'badsig' => 'Error message displayed when entering invalid signature in user preferences', |
538 | 543 | 'badsiglength' => 'Warning message that is displayed on [[Special:Preferences]] when trying to save a signature that is too long. Parameter $1 is the maximum number of characters that is allowed in a signature (multi-byte characters are counted as one character).', |
Index: branches/mutiple_languages_select/phase3/languages/messages/MessagesKsh.php |
— | — | @@ -601,8 +601,10 @@ |
602 | 602 | 'uid' => 'Metmaacher Nommer:', |
603 | 603 | 'prefs-memberingroups' => 'Bes en {{PLURAL:$1|de Metmaacherjrupp:|<strong>$1</strong> Metmaacherjruppe:|keijn Metmaacherjruppe.}}', |
604 | 604 | 'yourrealname' => 'Dinge richtije Name *', |
| 605 | +'prefs-language' => 'Shprooche', |
605 | 606 | 'yourlanguage' => 'Die Sproch, die et Wiki kalle soll:', |
606 | 607 | 'yourvariant' => 'Ding Variant', |
| 608 | +'yourfallbacklanguage' => 'Dem Wiki sing {{PLURAL:$2||$1.}} Ersatzshprooch:', |
607 | 609 | 'yournick' => 'Name för en Ding Ungerschreff:', |
608 | 610 | 'badsig' => 'Di Ungeschreff jëijd_esu nit — luer noh dem HTML do_dren un maach et rėshtėsh.', |
609 | 611 | 'badsiglength' => 'Ding „Unterschref“ es zoo lang. |
Index: branches/mutiple_languages_select/phase3/languages/messages/MessagesEn.php |
— | — | @@ -909,8 +909,10 @@ |
910 | 910 | 'uid' => 'User ID:', |
911 | 911 | 'prefs-memberingroups' => 'Member of {{PLURAL:$1|group|groups}}:', |
912 | 912 | 'yourrealname' => 'Real name:', |
| 913 | +'prefs-language' => 'Language Settings', |
913 | 914 | 'yourlanguage' => 'Language:', |
914 | 915 | 'yourvariant' => 'Variant:', # only translate this message to other languages if you have to change it |
| 916 | +'yourfallbacklanguage' => 'Fallback language{{PLURAL:$2|| number $1}}:', |
915 | 917 | 'yournick' => 'Signature:', |
916 | 918 | 'badsig' => 'Invalid raw signature. |
917 | 919 | Check HTML tags.', |
Index: branches/mutiple_languages_select/phase3/languages/messages/MessagesDe.php |
— | — | @@ -712,8 +712,10 @@ |
713 | 713 | 'uid' => 'Benutzer-ID:', |
714 | 714 | 'prefs-memberingroups' => 'Mitglied der {{PLURAL:$1|Benutzergruppe|Benutzergruppen}}:', |
715 | 715 | 'yourrealname' => 'Echter Name:', |
| 716 | +'prefs-language' => 'Spracheinstellungen', |
716 | 717 | 'yourlanguage' => 'Sprache der Benutzeroberfläche:', |
717 | 718 | 'yourvariant' => 'Variante', |
| 719 | +'yourfallbacklanguage' => '{{PLURAL:$2|Ersatzsprache|$1. Ersatzsprache}}:', |
718 | 720 | 'yournick' => 'Unterschrift:', |
719 | 721 | 'badsig' => 'Die Syntax der Unterschrift ist ungültig; bitte HTML überprüfen.', |
720 | 722 | 'badsiglength' => 'Die Unterschrift darf maximal $1 {{PLURAL:$1|Zeichen|Zeichen}} lang sein.', |