r55415 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55414‎ | r55415 | r55416 >
Date:16:00, 21 August 2009
Author:philip
Status:ok (Comments)
Tags:
Comment:
1. Revert my revision r55371. Since it may override logged user's settings.
2. Patch for situations that some wikis like zhwikisource may disabled some language variants. We should treat these disabled variants unacceptable in LanguageConverter.
Modified paths:
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)
  • /trunk/phase3/languages/classes/LanguageZh.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/LanguageConverter.php
@@ -183,7 +183,7 @@
184184 // explode by comma
185185 $result = explode(',', $acceptLanguage);
186186
187 - $languages = array();
 187+ $languages = array();
188188
189189 foreach( $result as $elem ) {
190190 // if $elem likes 'zh-cn;q=0.9'
@@ -196,14 +196,32 @@
197197 }
198198 }
199199
 200+ $fallback_languages = array();
200201 foreach( $languages as $language ) {
201202 // strip whitespace
202203 $language = trim( $language );
203204 if( in_array( $language, $this->mVariants ) ) {
204 - $this->mPreferredVariant = $language;
205 - return $this->mPreferredVariant;
 205+ return $language;
206206 }
 207+ else {
 208+ // To see if there are fallbacks of current language.
 209+ // We record these fallback variants, and process
 210+ // them later.
 211+ $fallbacks = $this->getVariantFallbacks( $language );
 212+ if( is_string( $fallbacks ) )
 213+ $fallback_languages[] = $fallbacks;
 214+ elseif( is_array( $fallbacks ) )
 215+ $fallback_languages = array_merge( $fallback_languages, $fallbacks );
 216+ }
207217 }
 218+
 219+ // process fallback languages now
 220+ $fallback_languages = array_unique( $fallback_languages );
 221+ foreach( $fallback_languages as $language ) {
 222+ if( in_array( $language, $this->mVariants ) ) {
 223+ return $language;
 224+ }
 225+ }
208226 }
209227 }
210228
Index: trunk/phase3/languages/classes/LanguageZh.php
@@ -132,7 +132,17 @@
133133 global $wgHooks;
134134 parent::__construct();
135135
136 - $variants = array('zh','zh-hans','zh-hant','zh-cn','zh-hk','zh-mo','zh-my','zh-sg','zh-tw');
 136+ $variants_all = array('zh','zh-hans','zh-hant','zh-cn','zh-hk','zh-mo','zh-my','zh-sg','zh-tw');
 137+ $variants = array();
 138+
 139+ // If a wiki disabled some variants,
 140+ // LanguageConverter shouldn't process them
 141+ foreach( $variants_all as $variant ) {
 142+ $status = wfMsgExt( "variantname-$variant", array( 'parsemag', 'language' => $this ) );
 143+ if( trim($status) != 'disable' )
 144+ $variants[] = $variant;
 145+ }
 146+
137147 $variantfallbacks = array(
138148 'zh' => array('zh-hans','zh-hant','zh-cn','zh-tw','zh-hk','zh-sg','zh-mo','zh-my'),
139149 'zh-hans' => array('zh-cn','zh-sg','zh-my'),

Follow-up revisions

RevisionCommit summaryAuthorDate
r56458Partial revert of r55415, calling wfMsg in Language object constructor causes...werdna23:50, 16 September 2009
r56459Fix E_NOTICE in r55415 breaking Zh variantswerdna23:53, 16 September 2009
r56560Follow up on r55415 and r56458. Use another way to disable variants. Server a...philip19:51, 17 September 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r55371Save the variant find from HTTP_ACCEPT_LANGUAGE to $mPreferredVariant, so we ...philip11:11, 20 August 2009

Comments

#Comment by Lepetitcool07 (talk | contribs)   23:49, 16 September 2009

okay

Status & tagging log