r59527 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59526‎ | r59527 | r59528 >
Date:20:00, 28 November 2009
Author:philip
Status:deferred (Comments)
Tags:
Comment:
follow-up r59522. ONLY add Accept-Language when a valid variant has been found out.
Modified paths:
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/LanguageConverter.php
@@ -185,15 +185,8 @@
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 - // bug 21672: Add Accept-Language to Vary and XVO headers
190 - // to help Squid to determine user's perferred local language
191 - // thanks to Liangent's help
192 - global $wgOut, $wgUseXVO;
193 - $wgOut->addVaryHeader( 'Accept-Language' );
194 - if( $wgUseXVO )
195 - $wgOut->addXVOHeader( 'Accept-Language' );
 189+
196190 $acceptLanguage = strtolower( $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
197 -
198191 // explode by comma
199192 $result = explode(',', $acceptLanguage);
200193
@@ -211,11 +204,13 @@
212205 }
213206
214207 $fallback_languages = array();
 208+ $ret_language = null;
215209 foreach( $languages as $language ) {
216210 // strip whitespace
217211 $language = trim( $language );
218212 if( in_array( $language, $this->mVariants ) ) {
219 - return $language;
 213+ $ret_language = $language;
 214+ break;
220215 }
221216 else {
222217 // To see if there are fallbacks of current language.
@@ -228,14 +223,30 @@
229224 $fallback_languages = array_merge( $fallback_languages, $fallbacks );
230225 }
231226 }
232 -
 227+
233228 // process fallback languages now
234 - $fallback_languages = array_unique( $fallback_languages );
235 - foreach( $fallback_languages as $language ) {
236 - if( in_array( $language, $this->mVariants ) ) {
237 - return $language;
 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+ }
238236 }
239237 }
 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, $wgUseXVO;
 245+ $wgOut->addVaryHeader( 'Accept-Language' );
 246+ if( $wgUseXVO )
 247+ $wgOut->addXVOHeader( 'Accept-Language' );
 248+
 249+ }
 250+ return $ret_language;
240251 }
241252 }
242253

Follow-up revisions

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

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r59522bug 21672: Add Accept-Language to Vary and XVO headers to help Squid to deter...philip19:13, 28 November 2009

Comments

#Comment by Tim Starling (talk | contribs)   04:19, 21 December 2009

This is incorrect, see comments on r59522.

Status & tagging log