r49220 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49219‎ | r49220 | r49221 >
Date:18:48, 5 April 2009
Author:purodha
Status:deferred
Tags:
Comment:
(Bug 11267) and (Bug 17612) part only. Add $wgUserFallbackLanguages to Defaultsettings.php
Users can select several languages labelled "fallback languages" in their preferences,
which are kept in the database.
Modified paths:
  • /branches/mutiple_languages_select/phase3/includes/DefaultSettings.php (modified) (history)
  • /branches/mutiple_languages_select/phase3/includes/User.php (modified) (history)
  • /branches/mutiple_languages_select/phase3/includes/Xml.php (modified) (history)
  • /branches/mutiple_languages_select/phase3/includes/specials/SpecialPreferences.php (modified) (history)
  • /branches/mutiple_languages_select/phase3/languages/messages/MessagesDe.php (modified) (history)
  • /branches/mutiple_languages_select/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /branches/mutiple_languages_select/phase3/languages/messages/MessagesKsh.php (modified) (history)
  • /branches/mutiple_languages_select/phase3/languages/messages/MessagesQqq.php (modified) (history)

Diff [purge]

Index: branches/mutiple_languages_select/phase3/includes/Xml.php
@@ -207,9 +207,10 @@
208208 *
209209 * @param $selected The language code of the selected language
210210 * @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
211212 * @return array of label and select
212213 */
213 - public static function languageSelector( $selected, $customisedOnly = true ) {
 214+ public static function languageSelector( $selected, $customisedOnly = true, $fallbackNum = false ) {
214215 global $wgContLanguageCode;
215216 /**
216217 * Make sure the site language is in the list; a custom language code
@@ -219,6 +220,12 @@
220221 if( !array_key_exists( $wgContLanguageCode, $languages ) ) {
221222 $languages[$wgContLanguageCode] = $wgContLanguageCode;
222223 }
 224+ $field = 'wpUserLanguage';
 225+ if($fallbackNum)
 226+ {
 227+ $field = 'wpUserFallbackLanguage['.strval($fallbackNum).']';
 228+ $languages['-'] = '';
 229+ }
223230 ksort( $languages );
224231
225232 /**
@@ -233,9 +240,11 @@
234241 }
235242
236243 return array(
237 - Xml::label( wfMsg('yourlanguage'), 'wpUserLanguage' ),
 244+ Xml::label( wfMsg($fallbackNum ? 'yourfallbacklanguage' : 'yourlanguage',
 245+ $fallbackNum),
 246+ 'wpUserLanguage' ),
238247 Xml::tags( 'select',
239 - array( 'id' => 'wpUserLanguage', 'name' => 'wpUserLanguage' ),
 248+ array( 'id' => 'wpUserLanguage', 'name' => $field ),
240249 $options
241250 )
242251 );
Index: branches/mutiple_languages_select/phase3/includes/User.php
@@ -996,6 +996,7 @@
997997 $variant = $wgContLang->getPreferredVariant( false );
998998 $defOpt['variant'] = $variant;
999999 $defOpt['language'] = $variant;
 1000+# $defopt['fallbacklang'] = ''; ## FIXME: fallbacklanguage is likely not used anywhere.
10001001
10011002 foreach( $wgNamespacesToBeSearchedDefault as $nsnum => $val ) {
10021003 $defOpt['searchNs'.$nsnum] = $val;
@@ -1894,9 +1895,8 @@
18951896 return (bool)$this->getOption( $oname );
18961897 }
18971898
1898 -
18991899 /**
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.
19011901 *
19021902 * @param $oname \string The option to check
19031903 * @param $defaultOverride \int A default value returned if the option does not exist
@@ -1912,12 +1912,35 @@
19131913 }
19141914
19151915 /**
 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+ /**
19161938 * Set the given option for a user.
19171939 *
19181940 * @param $oname \string The option to set
19191941 * @param $val \mixed New value to set
 1942+ * @param $eparator \string Used to serialize elements of $val if it's an array
19201943 */
1921 - function setOption( $oname, $val ) {
 1944+ function setOption( $oname, $val, $separator=':' ) {
19221945 $this->load();
19231946 if ( is_null( $this->mOptions ) ) {
19241947 $this->mOptions = User::getDefaultOptions();
@@ -1926,6 +1949,11 @@
19271950 # Clear cached skin, so the new one displays immediately in Special:Preferences
19281951 unset( $this->mSkin );
19291952 }
 1953+ if( is_array( $val ) )
 1954+ {
 1955+ $val = implode( $separator, $val );
 1956+# $wgUser->setOption( 'fallbacklang', implode(':', $this->mUserFallbackLanguage) );
 1957+ }
19301958 // Filter out any newlines that may have passed through input validation.
19311959 // Newlines are used to separate items in the options blob.
19321960 if( $val ) {
@@ -1940,7 +1968,7 @@
19411969 }
19421970 $this->mOptions[$oname] = $val;
19431971 }
1944 -
 1972+
19451973 /**
19461974 * Reset all options to the site defaults
19471975 */
Index: branches/mutiple_languages_select/phase3/includes/DefaultSettings.php
@@ -761,6 +761,8 @@
762762 #
763763 /** Site language code, should be one of ./languages/Language(.*).php */
764764 $wgLanguageCode = 'en';
 765+/** Number of fallback languages, a user can specify in preferences */
 766+$wgUserFallbackLanguages = 1;
765767
766768 /**
767769 * Some languages need different word forms, usually for different cases.
Index: branches/mutiple_languages_select/phase3/includes/specials/SpecialPreferences.php
@@ -26,7 +26,7 @@
2727 var $mUserLanguage, $mUserVariant;
2828 var $mSearch, $mRecent, $mRecentDays, $mTimeZone, $mHourDiff, $mSearchLines, $mSearchChars, $mAction;
2929 var $mReset, $mPosted, $mToggles, $mSearchNs, $mRealName, $mImageSize;
30 - var $mUnderline, $mWatchlistEdits, $mGender;
 30+ var $mUnderline, $mWatchlistEdits, $mGender, $mUserFallbackLanguage;
3131
3232 /**
3333 * Constructor
@@ -48,6 +48,7 @@
4949 $this->mNick = $request->getVal( 'wpNick' );
5050 $this->mUserLanguage = $request->getVal( 'wpUserLanguage' );
5151 $this->mUserVariant = $request->getVal( 'wpUserVariant' );
 52+ $this->mUserFallbackLanguage = $request->getArray( 'wpUserFallbackLanguage' );
5253 $this->mSearch = $request->getVal( 'wpSearch' );
5354 $this->mRecent = $request->getVal( 'wpRecent' );
5455 $this->mRecentDays = $request->getVal( 'wpRecentDays' );
@@ -99,6 +100,31 @@
100101 if ( !preg_match( '/^[a-z\-]*$/', $this->mUserLanguage ) ) {
101102 $this->mUserLanguage = 'nolanguage';
102103 }
 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+ }
103129
104130 wfRunHooks( 'InitPreferencesForm', array( $this, $request ) );
105131 }
@@ -256,6 +282,7 @@
257283
258284 $wgUser->setOption( 'language', $this->mUserLanguage );
259285 $wgUser->setOption( 'variant', $this->mUserVariant );
 286+ $wgUser->setOption( 'fallbacklang', $this->mUserFallbackLanguage );
260287 $wgUser->setOption( 'nickname', $this->mNick );
261288 $wgUser->setOption( 'quickbar', $this->mQuickbar );
262289 global $wgAllowUserSkin;
@@ -370,8 +397,8 @@
371398
372399 # language value might be blank, default to content language
373400 $this->mUserLanguage = $wgUser->getOption( 'language', $wgContLanguageCode );
374 -
375401 $this->mUserVariant = $wgUser->getOption( 'variant');
 402+ $this->mUserFallbackLanguage = $wgUser->getArrayOption( 'fallbacklang' );
376403 $this->mEmailFlag = $wgUser->getOption( 'disablemail' ) == 1 ? 1 : 0;
377404 $this->mNick = $wgUser->getOption( 'nickname' );
378405
@@ -562,6 +589,7 @@
563590 global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
564591 global $wgContLanguageCode, $wgDefaultSkin, $wgCookieExpiration;
565592 global $wgEmailConfirmToEdit, $wgEnableMWSuggest, $wgLocalTZoffset;
 593+ global $wgUserFallbackLanguages;
566594
567595 $wgOut->setPageTitle( wfMsg( 'preferences' ) );
568596 $wgOut->setArticleRelated( false );
@@ -762,12 +790,19 @@
763791 )
764792 );
765793
 794+ # language
 795+ if(!$wgDisableLangConversion || $wgUserFallbackLanguages>0)
 796+ {
 797+ $wgOut->addHTML(
 798+ $this->tableRow( Xml::element( 'h2', null, wfMsg( 'prefs-language' ) ) ) );
 799+ }
 800+
766801 list( $lsLabel, $lsSelect) = Xml::languageSelector( $this->mUserLanguage, false );
767802 $wgOut->addHTML(
768803 $this->tableRow( $lsLabel, $lsSelect )
769804 );
770805
771 - /* see if there are multiple language variants to choose from*/
 806+ /* see if there are multiple language variants to choose from */
772807 if(!$wgDisableLangConversion) {
773808 $variants = $wgContLang->getVariants();
774809 $variantArray = array();
@@ -810,6 +845,19 @@
811846 }
812847 }
813848
 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+
814862 # Password
815863 if( $wgAuth->allowPasswordChange() ) {
816864 $link = $wgUser->getSkin()->link( SpecialPage::getTitleFor( 'ResetPass' ), wfMsgHtml( 'prefs-resetpass' ),
Index: branches/mutiple_languages_select/phase3/languages/messages/MessagesQqq.php
@@ -524,14 +524,19 @@
525525 {{Identical|Log in}}',
526526 'youremail' => '{{Identical|E-mail}}',
527527 'username' => '{{Identical|Username}}',
528 -'uid' => '{{Identical|User ID}}',
 528+'uid' => 'Used in [[Special:Preferences]], first tab, {{Identical|User ID}}',
529529 'prefs-memberingroups' => 'This message is shown on [[Special:Preferences]], first tab, where it is follwed by a colon.',
530530 'yourrealname' => 'Used in [[Special:Preferences]], first tab.
531531 {{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.',
532533 'yourlanguage' => 'Used in [[Special:Preferences]], first tab.
533534 {{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]].
535537 {{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]]',
536541 'yournick' => 'Used in [[Special:Preferences]], first tab.',
537542 'badsig' => 'Error message displayed when entering invalid signature in user preferences',
538543 '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 @@
602602 'uid' => 'Metmaacher Nommer:',
603603 'prefs-memberingroups' => 'Bes en {{PLURAL:$1|de Metmaacherjrupp:|<strong>$1</strong> Metmaacherjruppe:|keijn Metmaacherjruppe.}}',
604604 'yourrealname' => 'Dinge richtije Name *',
 605+'prefs-language' => 'Shprooche',
605606 'yourlanguage' => 'Die Sproch, die et Wiki kalle soll:',
606607 'yourvariant' => 'Ding Variant',
 608+'yourfallbacklanguage' => 'Dem Wiki sing {{PLURAL:$2||$1.}} Ersatzshprooch:',
607609 'yournick' => 'Name för en Ding Ungerschreff:',
608610 'badsig' => 'Di Ungeschreff jëijd_esu nit — luer noh dem HTML do_dren un maach et rėshtėsh.',
609611 'badsiglength' => 'Ding „Unterschref“ es zoo lang.
Index: branches/mutiple_languages_select/phase3/languages/messages/MessagesEn.php
@@ -909,8 +909,10 @@
910910 'uid' => 'User ID:',
911911 'prefs-memberingroups' => 'Member of {{PLURAL:$1|group|groups}}:',
912912 'yourrealname' => 'Real name:',
 913+'prefs-language' => 'Language Settings',
913914 'yourlanguage' => 'Language:',
914915 'yourvariant' => 'Variant:', # only translate this message to other languages if you have to change it
 916+'yourfallbacklanguage' => 'Fallback language{{PLURAL:$2||&#32;number&nbsp;$1}}:',
915917 'yournick' => 'Signature:',
916918 'badsig' => 'Invalid raw signature.
917919 Check HTML tags.',
Index: branches/mutiple_languages_select/phase3/languages/messages/MessagesDe.php
@@ -712,8 +712,10 @@
713713 'uid' => 'Benutzer-ID:',
714714 'prefs-memberingroups' => 'Mitglied der {{PLURAL:$1|Benutzergruppe|Benutzergruppen}}:',
715715 'yourrealname' => 'Echter Name:',
 716+'prefs-language' => 'Spracheinstellungen',
716717 'yourlanguage' => 'Sprache der Benutzeroberfläche:',
717718 'yourvariant' => 'Variante',
 719+'yourfallbacklanguage' => '{{PLURAL:$2|Ersatzsprache|$1. Ersatzsprache}}:',
718720 'yournick' => 'Unterschrift:',
719721 'badsig' => 'Die Syntax der Unterschrift ist ungültig; bitte HTML überprüfen.',
720722 'badsiglength' => 'Die Unterschrift darf maximal $1 {{PLURAL:$1|Zeichen|Zeichen}} lang sein.',

Status & tagging log