resourceloader: Remove Grade C sniffs for WebOS <=1.4 and SymbianOS
[lhc/web/wiklou.git] / includes / WebRequest.php
index 76d94b2..defe07e 100644 (file)
@@ -395,18 +395,25 @@ class WebRequest {
                # https://www.php.net/variables.external#language.variables.external.dot-in-names
                # Work around PHP *feature* to avoid *bugs* elsewhere.
                $name = strtr( $name, '.', '_' );
-               if ( isset( $arr[$name] ) ) {
-                       $data = $arr[$name];
+
+               if ( !isset( $arr[$name] ) ) {
+                       return $default;
+               }
+
+               $data = $arr[$name];
+               # Optimisation: Skip UTF-8 normalization and legacy transcoding for simple ASCII strings.
+               $isAsciiStr = ( is_string( $data ) && preg_match( '/[^\x20-\x7E]/', $data ) === 0 );
+               if ( !$isAsciiStr ) {
                        if ( isset( $_GET[$name] ) && is_string( $data ) ) {
                                # Check for alternate/legacy character encoding.
-                               $contLang = MediaWikiServices::getInstance()->getContentLanguage();
-                               $data = $contLang->checkTitleEncoding( $data );
+                               $data = MediaWikiServices::getInstance()
+                                       ->getContentLanguage()
+                                       ->checkTitleEncoding( $data );
                        }
                        $data = $this->normalizeUnicode( $data );
-                       return $data;
-               } else {
-                       return $default;
                }
+
+               return $data;
        }
 
        /**
@@ -1140,7 +1147,7 @@ HTML;
        /**
         * Parse the Accept-Language header sent by the client into an array
         *
-        * @return array Array( languageCode => q-value ) sorted by q-value in
+        * @return 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