Index: trunk/phase3/includes/installer/WebInstaller.php |
— | — | @@ -444,28 +444,14 @@ |
445 | 445 | * @return string |
446 | 446 | */ |
447 | 447 | public function getAcceptLanguage() { |
448 | | - global $wgLanguageCode; |
| 448 | + global $wgLanguageCode, $wgRequest; |
449 | 449 | |
450 | 450 | $mwLanguages = Language::getLanguageNames(); |
451 | | - $langs = $_SERVER['HTTP_ACCEPT_LANGUAGE']; |
| 451 | + $headerLanguages = array_keys( $wgRequest->getAcceptLang() ); |
452 | 452 | |
453 | | - foreach ( explode( ';', $langs ) as $splitted ) { |
454 | | - foreach ( explode( ',', $splitted ) as $lang ) { |
455 | | - $lang = trim( strtolower( $lang ) ); |
456 | | - |
457 | | - if ( $lang == '' || $lang[0] == 'q' ) { |
458 | | - continue; |
459 | | - } |
460 | | - |
461 | | - if ( isset( $mwLanguages[$lang] ) ) { |
462 | | - return $lang; |
463 | | - } |
464 | | - |
465 | | - $lang = preg_replace( '/^(.*?)(?=-[^-]*)$/', '\\1', $lang ); |
466 | | - |
467 | | - if ( $lang != '' && isset( $mwLanguages[$lang] ) ) { |
468 | | - return $lang; |
469 | | - } |
| 453 | + foreach ( $headerLanguages as $lang ) { |
| 454 | + if ( isset( $mwLanguages[$lang] ) ) { |
| 455 | + return $lang; |
470 | 456 | } |
471 | 457 | } |
472 | 458 | |
Index: trunk/phase3/includes/WebRequest.php |
— | — | @@ -733,14 +733,15 @@ |
734 | 734 | */ |
735 | 735 | public function getAcceptLang() { |
736 | 736 | // Modified version of code found at http://www.thefutureoftheweb.com/blog/use-accept-language-header |
737 | | - if ( !isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) { |
| 737 | + $acceptLang = $this->getHeader( 'Accept-Language' ); |
| 738 | + if ( !$acceptLang ) { |
738 | 739 | return array(); |
739 | 740 | } |
740 | 741 | |
741 | 742 | // Break up string into pieces (languages and q factors) |
742 | 743 | $lang_parse = null; |
743 | 744 | preg_match_all( '/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0(\.[0-9]+))?)?/i', |
744 | | - $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse ); |
| 745 | + $acceptLang, $lang_parse ); |
745 | 746 | |
746 | 747 | if ( !count( $lang_parse[1] ) ) { |
747 | 748 | return array(); |
Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -233,29 +233,13 @@ |
234 | 234 | |
235 | 235 | // see if some supported language variant is set in the |
236 | 236 | // http header. |
237 | | - $acceptLanguage = $wgRequest->getHeader( 'Accept-Language' ); |
238 | | - if ( !$acceptLanguage ) { |
| 237 | + $languages = array_keys( $wgRequest->getAcceptLang() ); |
| 238 | + if ( empty( $languages ) ) { |
239 | 239 | return null; |
240 | 240 | } |
241 | 241 | |
242 | | - // explode by comma |
243 | | - $result = StringUtils::explode( ',', strtolower( $acceptLanguage ) ); |
244 | | - $languages = array(); |
245 | | - |
246 | | - foreach ( $result as $elem ) { |
247 | | - // if $elem likes 'zh-cn;q=0.9' |
248 | | - if ( ( $posi = strpos( $elem, ';' ) ) !== false ) { |
249 | | - // get the real language code likes 'zh-cn' |
250 | | - $languages[] = substr( $elem, 0, $posi ); |
251 | | - } else { |
252 | | - $languages[] = $elem; |
253 | | - } |
254 | | - } |
255 | | - |
256 | 242 | $fallback_languages = array(); |
257 | 243 | foreach ( $languages as $language ) { |
258 | | - // strip whitespace |
259 | | - $language = trim( $language ); |
260 | 244 | $this->mHeaderVariant = $this->validateVariant( $language ); |
261 | 245 | if ( $this->mHeaderVariant ) { |
262 | 246 | break; |