From: Roan Kattouw Date: Tue, 19 Jul 2011 21:19:50 +0000 (+0000) Subject: Fixes for URL expanding in CSSMin: adjust the offset correctly (this could've theoret... X-Git-Tag: 1.31.0-rc.0~28735 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=commitdiff_plain;h=cb8418647f53b101d9f1d35277c55796915b17f9;p=lhc%2Fweb%2Fwiklou.git 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) --- 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