Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -130,7 +130,7 @@ |
131 | 131 | * @public |
132 | 132 | */ |
133 | 133 | function getPreferredVariant( $fromUser = true ) { |
134 | | - global $wgUser, $wgRequest, $wgVariantArticlePath, $wgDefaultLanguageVariant; |
| 134 | + global $wgUser, $wgRequest, $wgVariantArticlePath, $wgDefaultLanguageVariant, $wgOut; |
135 | 135 | |
136 | 136 | if($this->mPreferredVariant) |
137 | 137 | return $this->mPreferredVariant; |
— | — | @@ -185,7 +185,19 @@ |
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 | | - |
| 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 | + |
190 | 202 | $acceptLanguage = strtolower( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ); |
191 | 203 | // explode by comma |
192 | 204 | $result = explode(',', $acceptLanguage); |
— | — | @@ -204,13 +216,11 @@ |
205 | 217 | } |
206 | 218 | |
207 | 219 | $fallback_languages = array(); |
208 | | - $ret_language = null; |
209 | 220 | foreach( $languages as $language ) { |
210 | 221 | // strip whitespace |
211 | 222 | $language = trim( $language ); |
212 | 223 | if( in_array( $language, $this->mVariants ) ) { |
213 | | - $ret_language = $language; |
214 | | - break; |
| 224 | + return $language; |
215 | 225 | } |
216 | 226 | else { |
217 | 227 | // To see if there are fallbacks of current language. |
— | — | @@ -223,27 +233,14 @@ |
224 | 234 | $fallback_languages = array_merge( $fallback_languages, $fallbacks ); |
225 | 235 | } |
226 | 236 | } |
227 | | - |
| 237 | + |
228 | 238 | // 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; |
236 | 243 | } |
237 | 244 | } |
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; |
248 | 245 | } |
249 | 246 | } |
250 | 247 | |