Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -185,15 +185,8 @@ |
186 | 186 | // variable in case this is called before the user's |
187 | 187 | // preference is loaded |
188 | 188 | 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 | + |
196 | 190 | $acceptLanguage = strtolower( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ); |
197 | | - |
198 | 191 | // explode by comma |
199 | 192 | $result = explode(',', $acceptLanguage); |
200 | 193 | |
— | — | @@ -211,11 +204,13 @@ |
212 | 205 | } |
213 | 206 | |
214 | 207 | $fallback_languages = array(); |
| 208 | + $ret_language = null; |
215 | 209 | foreach( $languages as $language ) { |
216 | 210 | // strip whitespace |
217 | 211 | $language = trim( $language ); |
218 | 212 | if( in_array( $language, $this->mVariants ) ) { |
219 | | - return $language; |
| 213 | + $ret_language = $language; |
| 214 | + break; |
220 | 215 | } |
221 | 216 | else { |
222 | 217 | // To see if there are fallbacks of current language. |
— | — | @@ -228,14 +223,30 @@ |
229 | 224 | $fallback_languages = array_merge( $fallback_languages, $fallbacks ); |
230 | 225 | } |
231 | 226 | } |
232 | | - |
| 227 | + |
233 | 228 | // 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 | + } |
238 | 236 | } |
239 | 237 | } |
| 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; |
240 | 251 | } |
241 | 252 | } |
242 | 253 | |