From cb8418647f53b101d9f1d35277c55796915b17f9 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Tue, 19 Jul 2011 21:19:50 +0000 Subject: [PATCH] Fixes for URL expanding in CSSMin: adjust the offset correctly (this could've theoretically resulted in very strange bugs) and only call wfExpandUrl() if available (the file is in includes/libs so it should work outside of MediaWiki) --- includes/libs/CSSMin.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/includes/libs/CSSMin.php b/includes/libs/CSSMin.php index 3050071550..a2aa879184 100644 --- a/includes/libs/CSSMin.php +++ b/includes/libs/CSSMin.php @@ -131,11 +131,18 @@ class CSSMin { // to absolute URLs but otherwise left alone if ( $match['file'][0] !== '' && $match['file'][0][0] === '/' ) { // Replace the file path with an expanded URL - $source = substr_replace( $source, wfExpandUrl( $match['file'][0] ), - $match['file'][1], strlen( $match['file'][0] ) - ); + // ...but only if wfExpandUrl() is even available. This will not be the case if we're running outside of MW + $lengthIncrease = 0; + if ( function_exists( 'wfExpandUrl' ) ) { + $expanded = wfExpandUrl( $match['file'][0] ); + $origLength = strlen( $match['file'][0] ); + $lengthIncrease = strlen( $expanded ) - $origLength; + $source = substr_replace( $source, wfExpandUrl( $match['file'][0] ), + $match['file'][1], $origLength + ); + } // Move the offset to the end of the match, leaving it alone - $offset = $match[0][1] + strlen( $match[0][0] ); + $offset = $match[0][1] + strlen( $match[0][0] ) + $lengthIncrease; continue; } // Shortcuts -- 2.20.1