dépôts
/
lhc
/
web
/
wiklou.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge "Use Xml::languageSelector in SpecialAllmessages"
[lhc/web/wiklou.git]
/
includes
/
WebRequest.php
diff --git
a/includes/WebRequest.php
b/includes/WebRequest.php
index
39c1b1b
..
766db46
100644
(file)
--- a/
includes/WebRequest.php
+++ b/
includes/WebRequest.php
@@
-504,9
+504,9
@@
class WebRequest {
* Fetch a text string from the given array or return $default if it's not
* set. Carriage returns are stripped from the text, and with some language
* modules there is an input transliteration applied. This should generally
* Fetch a text string from the given array or return $default if it's not
* set. Carriage returns are stripped from the text, and with some language
* modules there is an input transliteration applied. This should generally
- * be used for form
<textarea> and <input> fields. Used for user-supplied
- *
freeform text input (for which input transformations may be required - e.g.
- * Esperanto x-coding).
+ * be used for form
"<textarea>" and "<input>" fields. Used for
+ *
user-supplied freeform text input (for which input transformations may
+ *
be required - e.g.
Esperanto x-coding).
*
* @param $name String
* @param $default String: optional
*
* @param $name String
* @param $default String: optional
@@
-981,9
+981,11
@@
HTML;
/**
* Parse the Accept-Language header sent by the client into an array
/**
* Parse the Accept-Language header sent by the client into an array
- * @return array array( languageCode => q-value ) sorted by q-value in descending order
+ * @return array array( languageCode => q-value ) sorted by q-value in descending order then
+ * 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
* 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
*/
public function getAcceptLang() {
// Modified version of code found at http://www.thefutureoftheweb.com/blog/use-accept-language-header
@@
-1004,19
+1006,25
@@
HTML;
return array();
}
return array();
}
- // Create a list like "en" => 0.8
- $langs = array_combine( $lang_parse[1], $lang_parse[4] );
+ $langcodes = $lang_parse[1];
+ $qvalues = $lang_parse[4];
+ $indices = range( 0, count( $lang_parse[1] ) - 1 );
+
// Set default q factor to 1
// Set default q factor to 1
- foreach ( $
langs as $lang => $val
) {
- if ( $
val
=== '' ) {
- $
langs[$lang
] = 1;
- } elseif ( $
val
== 0 ) {
- unset(
$langs[$lang]
);
+ foreach ( $
indices as $index
) {
+ if ( $
qvalues[$index]
=== '' ) {
+ $
qvalues[$index
] = 1;
+ } elseif ( $
qvalues[$index]
== 0 ) {
+ unset(
$langcodes[$index], $qvalues[$index], $indices[$index]
);
}
}
}
}
- // Sort list
- arsort( $langs, SORT_NUMERIC );
+ // 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 );
+
return $langs;
}
return $langs;
}