X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FWebRequest.php;h=e39a576a7ac1c47c2e1aa82e5892625584d0c71a;hb=83e99164284773fec46fb8a417eba1f132807de3;hp=68a5cacf6febc62a739f211320ce002168b8228e;hpb=b62d5dbad7a5640402443f7530c2f5ac6cb6125d;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/WebRequest.php b/includes/WebRequest.php index 68a5cacf6f..e39a576a7a 100644 --- a/includes/WebRequest.php +++ b/includes/WebRequest.php @@ -22,14 +22,6 @@ # http://www.gnu.org/copyleft/gpl.html -/** - * Some entry points may use this file without first enabling the - * autoloader. - */ -if ( !function_exists( '__autoload' ) ) { - require_once( dirname(__FILE__) . '/normal/UtfNormal.php' ); -} - /** * The WebRequest class encapsulates getting at data passed in the * URL or via a POSTed form, handling remove of "magic quotes" slashes, @@ -435,19 +427,19 @@ class WebRequest { * @return Boolean */ public function checkSessionCookie() { - return isset( $_COOKIE[session_name()] ); + return isset( $_COOKIE[ session_name() ] ); } /** * Get a cookie from the $_COOKIE jar * * @param $key String: the name of the cookie - * @param $default Mixed: what to return if the value isn't found * @param $prefix String: a prefix to use for the cookie name, if not $wgCookiePrefix + * @param $default Mixed: what to return if the value isn't found * @return Mixed: cookie value or $default if the cookie not set */ - public function getCookie( $key, $default = null, $prefix = '' ) { - if( !$prefix ) { + public function getCookie( $key, $prefix = null, $default = null ) { + if( $prefix === null ) { global $wgCookiePrefix; $prefix = $wgCookiePrefix; } @@ -738,29 +730,39 @@ class WebRequest { /** * Parse the Accept-Language header sent by the client into an array * @return array( languageCode => q-value ) sorted by q-value in descending order + * May contain the "language" '*', which applies to languages other than those explicitly listed. + * This is aligned with rfc2616 section 14.4 */ public function getAcceptLang() { // Modified version of code found at http://www.thefutureoftheweb.com/blog/use-accept-language-header - if ( !isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) { + $acceptLang = $this->getHeader( 'Accept-Language' ); + if ( !$acceptLang ) { return array(); } + // Return the language codes in lower case + $acceptLang = strtolower( $acceptLang ); + // Break up string into pieces (languages and q factors) $lang_parse = null; - preg_match_all( '/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0(\.[0-9]+))?)?/i', - $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse ); + preg_match_all( '/([a-z]{1,8}(-[a-z]{1,8})?|\*)\s*(;\s*q\s*=\s*(1|0(\.[0-9]+)?)?)?/', + $acceptLang, $lang_parse ); if ( !count( $lang_parse[1] ) ) { return array(); } + // Create a list like "en" => 0.8 $langs = array_combine( $lang_parse[1], $lang_parse[4] ); // Set default q factor to 1 foreach ( $langs as $lang => $val ) { if ( $val === '' ) { $langs[$lang] = 1; + } else if ( $val == 0 ) { + unset($langs[$lang]); } } + // Sort list arsort( $langs, SORT_NUMERIC ); return $langs;