Merge "Fix some omitted colons in Spanish magic word l10n"
[lhc/web/wiklou.git] / includes / libs / CSSMin.php
index 318448a..e3a3e2c 100644 (file)
@@ -61,23 +61,38 @@ class CSSMin {
        /**
         * Gets a list of local file paths which are referenced in a CSS style sheet
         *
+        * This function will always return an empty array if the second parameter is not given or null
+        * for backwards-compatibility.
+        *
         * @param string $source CSS data to remap
         * @param string $path File path where the source was read from (optional)
         * @return array List of local file references
         */
        public static function getLocalFileReferences( $source, $path = null ) {
+               if ( $path === null ) {
+                       return array();
+               }
+
+               $path = rtrim( $path, '/' ) . '/';
                $files = array();
+
                $rFlags = PREG_OFFSET_CAPTURE | PREG_SET_ORDER;
                if ( preg_match_all( '/' . self::URL_REGEX . '/', $source, $matches, $rFlags ) ) {
                        foreach ( $matches as $match ) {
-                               $file = ( isset( $path )
-                                       ? rtrim( $path, '/' ) . '/'
-                                       : '' ) . "{$match['file'][0]}";
+                               $url = $match['file'][0];
 
-                               // Only proceed if we can access the file
-                               if ( !is_null( $path ) && file_exists( $file ) ) {
-                                       $files[] = $file;
+                               // Skip fully-qualified and protocol-relative URLs and data URIs
+                               if ( substr( $url, 0, 2 ) === '//' || parse_url( $url, PHP_URL_SCHEME ) ) {
+                                       break;
                                }
+
+                               $file = $path . $url;
+                               // Skip non-existent files
+                               if ( file_exists( $file ) ) {
+                                       break;
+                               }
+
+                               $files[] = $file;
                        }
                }
                return $files;
@@ -223,8 +238,6 @@ class CSSMin {
                                return $ruleWithRemapped;
                        }
                }, $source );
-
-               return $source;
        }
 
        /**
@@ -242,8 +255,7 @@ class CSSMin {
                $url = $file . $query;
 
                // Skip fully-qualified and protocol-relative URLs and data URIs
-               $urlScheme = substr( $url, 0, 2 ) === '//' || parse_url( $url, PHP_URL_SCHEME );
-               if ( $urlScheme ) {
+               if ( substr( $url, 0, 2 ) === '//' || parse_url( $url, PHP_URL_SCHEME ) ) {
                        return $url;
                }