r59544 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59543‎ | r59544 | r59545 >
Date:10:53, 29 November 2009
Author:philip
Status:deferred
Tags:
Comment:
follow-up r59541. Fix the problem reported on [[Special:Code/MediaWiki/59541#c4540]]. Partly patched by Liangent.
Modified paths:
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/LanguageConverter.php
@@ -130,7 +130,7 @@
131131 * @public
132132 */
133133 function getPreferredVariant( $fromUser = true ) {
134 - global $wgUser, $wgRequest, $wgVariantArticlePath, $wgDefaultLanguageVariant;
 134+ global $wgUser, $wgRequest, $wgVariantArticlePath, $wgDefaultLanguageVariant, $wgOut;
135135
136136 if($this->mPreferredVariant)
137137 return $this->mPreferredVariant;
@@ -185,7 +185,19 @@
186186 // variable in case this is called before the user's
187187 // preference is loaded
188188 if( array_key_exists( 'HTTP_ACCEPT_LANGUAGE', $_SERVER ) ) {
189 -
 189+
 190+ // bug 21672: Add Accept-Language to Vary and XVO headers
 191+ // to help Squid to determine user's perferred local language
 192+ // ONLY add Accept-Language when a variant has been found out
 193+ // patched by Liangent
 194+ $aloption = array();
 195+ foreach ( $this->mVariants as $variant ) {
 196+ if( $variant === $this->mMainLanguageCode )
 197+ continue;
 198+ $aloption[] = "string-contains=$variant";
 199+ }
 200+ $wgOut->addVaryHeader( 'Accept-Language', $aloption );
 201+
190202 $acceptLanguage = strtolower( $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
191203 // explode by comma
192204 $result = explode(',', $acceptLanguage);
@@ -204,13 +216,11 @@
205217 }
206218
207219 $fallback_languages = array();
208 - $ret_language = null;
209220 foreach( $languages as $language ) {
210221 // strip whitespace
211222 $language = trim( $language );
212223 if( in_array( $language, $this->mVariants ) ) {
213 - $ret_language = $language;
214 - break;
 224+ return $language;
215225 }
216226 else {
217227 // To see if there are fallbacks of current language.
@@ -223,27 +233,14 @@
224234 $fallback_languages = array_merge( $fallback_languages, $fallbacks );
225235 }
226236 }
227 -
 237+
228238 // process fallback languages now
229 - if( $ret_language === null ) {
230 - $fallback_languages = array_unique( $fallback_languages );
231 - foreach( $fallback_languages as $language ) {
232 - if( in_array( $language, $this->mVariants ) ) {
233 - $ret_language = $language;
234 - break;
235 - }
 239+ $fallback_languages = array_unique( $fallback_languages );
 240+ foreach( $fallback_languages as $language ) {
 241+ if( in_array( $language, $this->mVariants ) ) {
 242+ return $language;
236243 }
237244 }
238 -
239 - // bug 21672: Add Accept-Language to Vary and XVO headers
240 - // to help Squid to determine user's perferred local language
241 - // ONLY add Accept-Language when a variant has been found out
242 - // thanks to Liangent's help
243 - if( $ret_language !== $this->mMainLanguageCode ) {
244 - global $wgOut;
245 - $wgOut->addVaryHeader( 'Accept-Language', array('string-contains=' .$ret_language) );
246 - }
247 - return $ret_language;
248245 }
249246 }
250247

Follow-up revisions

RevisionCommit summaryAuthorDate
r59559follow-up r59544. more comments added.philip18:38, 29 November 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r59541follow-up r59522, r59523, r59527, r59529, r59530....philip06:47, 29 November 2009

Status & tagging log