Merge "Improve timeouts in MultiHttpClient"
[lhc/web/wiklou.git] / includes / libs / CSSMin.php
index a6014b1..74e8b54 100644 (file)
@@ -19,7 +19,7 @@
  * @version 0.1.1 -- 2010-09-11
  * @author Trevor Parscal <tparscal@wikimedia.org>
  * @copyright Copyright 2010 Wikimedia Foundation
- * @license http://www.apache.org/licenses/LICENSE-2.0
+ * @license Apache-2.0
  */
 
 /**
@@ -40,7 +40,7 @@ class CSSMin {
        const EMBED_REGEX = '\/\*\s*\@embed\s*\*\/';
        const COMMENT_REGEX = '\/\*.*?\*\/';
 
-       /** @var array List of common image files extensions and MIME-types */
+       /** @var string[] List of common image files extensions and MIME-types */
        protected static $mimeTypes = [
                'gif' => 'image/gif',
                'jpe' => 'image/jpeg',
@@ -58,7 +58,7 @@ class CSSMin {
         *
         * @param string $source CSS stylesheet source to process
         * @param string $path File path where the source was read from
-        * @return array List of local file references
+        * @return string[] List of local file references
         */
        public static function getLocalFileReferences( $source, $path ) {
                $stripped = preg_replace( '/' . self::COMMENT_REGEX . '/s', '', $source );
@@ -100,7 +100,7 @@ class CSSMin {
         * @param bool $ie8Compat By default, a data URI will only be produced if it can be made short
         *     enough to fit in Internet Explorer 8 (and earlier) URI length limit (32,768 bytes). Pass
         *     `false` to remove this limitation.
-        * @return string|bool Image contents encoded as a data URI or false.
+        * @return string|false Image contents encoded as a data URI or false.
         */
        public static function encodeImageAsDataURI( $file, $type = null, $ie8Compat = true ) {
                // Fast-fail for files that definitely exceed the maximum data URI length
@@ -128,7 +128,7 @@ class CSSMin {
         * @param string $contents File contents to encode.
         * @param string $type File's MIME type.
         * @param bool $ie8Compat See encodeImageAsDataURI().
-        * @return string|bool Image contents encoded as a data URI or false.
+        * @return string|false Image contents encoded as a data URI or false.
         */
        public static function encodeStringAsDataURI( $contents, $type, $ie8Compat = true ) {
                // Try #1: Non-encoded data URI
@@ -173,13 +173,13 @@ class CSSMin {
 
        /**
         * Serialize a string (escape and quote) for use as a CSS string value.
-        * https://www.w3.org/TR/2016/WD-cssom-1-20160317/#serialize-a-string
+        * https://drafts.csswg.org/cssom/#serialize-a-string
         *
         * @param string $value
         * @return string
         */
        public static function serializeStringValue( $value ) {
-               $value = strtr( $value, [ "\0" => "\\fffd ", '\\' => '\\\\', '"' => '\\"' ] );
+               $value = strtr( $value, [ "\0" => "\u{FFFD}", '\\' => '\\\\', '"' => '\\"' ] );
                $value = preg_replace_callback( '/[\x01-\x1f\x7f]/', function ( $match ) {
                        return '\\' . base_convert( ord( $match[0] ), 10, 16 ) . ' ';
                }, $value );
@@ -387,10 +387,7 @@ class CSSMin {
         * @return bool
         */
        protected static function isLocalUrl( $maybeUrl ) {
-               if ( $maybeUrl !== '' && $maybeUrl[0] === '/' && !self::isRemoteUrl( $maybeUrl ) ) {
-                       return true;
-               }
-               return false;
+               return isset( $maybeUrl[1] ) && $maybeUrl[0] === '/' && $maybeUrl[1] !== '/';
        }
 
        /**
@@ -402,6 +399,7 @@ class CSSMin {
                        // Match these three variants separately to avoid broken urls when
                        // e.g. a double quoted url contains a parenthesis, or when a
                        // single quoted url contains a double quote, etc.
+                       // FIXME: Simplify now we only support PHP 7.0.0+
                        // Note: PCRE doesn't support multiple capture groups with the same name by default.
                        // - PCRE 6.7 introduced the "J" modifier (PCRE_INFO_JCHANGED for PCRE_DUPNAMES).
                        //   https://secure.php.net/manual/en/reference.pcre.pattern.modifiers.php
@@ -511,7 +509,7 @@ class CSSMin {
                                                return $data;
                                        }
                                }
-                               if ( method_exists( 'OutputPage', 'transformFilePath' ) ) {
+                               if ( class_exists( OutputPage::class ) ) {
                                        $url = OutputPage::transformFilePath( $remote, $local, $file );
                                } else {
                                        // Add version parameter as the first five hex digits