From 87c6f7ad2b6b1f8adb7fa5272051a743142f3be2 Mon Sep 17 00:00:00 2001 From: Trevor Parscal Date: Sat, 11 Sep 2010 10:20:26 +0000 Subject: [PATCH] Made CSSMin::remap take both local and remote directory parameters, allowing more felxible configuration. Also made ResourceLoaderFileModule use $wgScriptPath as the base of the remote directory parameter. --- includes/ResourceLoaderModule.php | 9 +++++++-- includes/libs/CSSMin.php | 11 ++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/includes/ResourceLoaderModule.php b/includes/ResourceLoaderModule.php index 8ea392b963..93813ba0a5 100644 --- a/includes/ResourceLoaderModule.php +++ b/includes/ResourceLoaderModule.php @@ -684,8 +684,13 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { * @return string Remapped CSS */ protected static function remapStyle( $file ) { - global $wgUseDataURLs; - return CSSMin::remap( file_get_contents( self::remapFilename( $file ) ), dirname( $file ), $wgUseDataURLs ); + global $wgUseDataURLs, $wgScriptPath; + return CSSMin::remap( + file_get_contents( self::remapFilename( $file ) ), + dirname( $file ), + $wgScriptPath . '/' . dirname( $file ), + $wgUseDataURLs + ); } } diff --git a/includes/libs/CSSMin.php b/includes/libs/CSSMin.php index 05314a713c..bc361150fb 100644 --- a/includes/libs/CSSMin.php +++ b/includes/libs/CSSMin.php @@ -18,7 +18,7 @@ * This class provides minification, URL remapping, URL extracting, and data-URL embedding. * * @file - * @version 0.1.0 -- 2010-09-09 + * @version 0.1.1 -- 2010-09-11 * @author Trevor Parscal * @copyright Copyright 2010 Wikimedia Foundation * @license http://www.apache.org/licenses/LICENSE-2.0 @@ -81,7 +81,7 @@ class CSSMin { * @param $path string File path where the source was read from * @return string Remapped CSS data */ - public static function remap( $source, $path, $embed = true ) { + public static function remap( $source, $local, $remote, $embed = true ) { $pattern = '/((?\s*\/\*\s*\@embed\s*\*\/)(?
[^\;\}]*))?' . self::URL_REGEX . '(?[^;]*)[\;]?/';
 		$offset = 0;
 		while ( preg_match( $pattern, $source, $match, PREG_OFFSET_CAPTURE, $offset ) ) {
@@ -89,11 +89,12 @@ class CSSMin {
 			$embed = $match['embed'][0];
 			$pre = $match['pre'][0];
 			$post = $match['post'][0];
-			$file = "{$path}/{$match['file'][0]}";
-			// Only proceed if we can access the file
+			$file = "{$local}/{$match['file'][0]}";
+			$url = "{$remote}/{$match['file'][0]}";
+			// Only proceed if we can access the fill
 			if ( file_exists( $file ) ) {
 				// Add version parameter as a time-stamp in ISO 8601 format, using Z for the timezone, meaning GMT
-				$url = "{$file}?" . gmdate( 'Y-m-d\TH:i:s\Z', round( filemtime( $file ), -2 ) );
+				$url .= '?' . gmdate( 'Y-m-d\TH:i:s\Z', round( filemtime( $file ), -2 ) );
 				// If we the mime-type can't be determined, no embedding will take place
 				$type = false;
 				// Try a couple of different ways to get the mime-type of a file, in order of preference
-- 
2.20.1