From 1ea18dfaf2d106c0b119e6d07a8bf83686b5c931 Mon Sep 17 00:00:00 2001 From: Platonides Date: Mon, 28 May 2012 18:23:53 +0200 Subject: [PATCH] Minor changes to Ic50d01f5 Accept-Language code. Minor improvments to commit 894c5c1 Change-Id: I8cc63cb1ba2c3aa74ca9e225022d5be75e75ad23 --- includes/WebRequest.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/includes/WebRequest.php b/includes/WebRequest.php index 7d0dd4a13f..87526fcc03 100644 --- a/includes/WebRequest.php +++ b/includes/WebRequest.php @@ -985,6 +985,7 @@ HTML; * appearing time in the header in ascending order. * May contain the "language" '*', which applies to languages other than those explicitly listed. * This is aligned with rfc2616 section 14.4 + * Preference for earlier languages appears in rfc3282 as an extension to HTTP/1.1. */ public function getAcceptLang() { // Modified version of code found at http://www.thefutureoftheweb.com/blog/use-accept-language-header @@ -1008,22 +1009,22 @@ HTML; $langcodes = $lang_parse[1]; $qvalues = $lang_parse[4]; $indices = range( 0, count( $lang_parse[1] ) - 1 ); + // Set default q factor to 1 foreach ( $indices as $index ) { if ( $qvalues[$index] === '' ) { $qvalues[$index] = 1; } elseif ( $qvalues[$index] == 0 ) { - $langcodes[$index] = ''; + unset( $langcodes[$index], $qvalues[$index], $indices[$index] ); } } - // Sort list + // Sort list. First by $qvalues, then by order. Reorder $langcodes the same way array_multisort( $qvalues, SORT_DESC, SORT_NUMERIC, $indices, $langcodes ); + // Create a list like "en" => 0.8 $langs = array_combine( $langcodes, $qvalues ); - if ( isset( $langs[''] ) ) { - unset( $langs[''] ); - } + return $langs; } -- 2.20.1