Fixes for URL expanding in CSSMin: adjust the offset correctly (this could've theoret...
authorRoan Kattouw <catrope@users.mediawiki.org>
Tue, 19 Jul 2011 21:19:50 +0000 (21:19 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Tue, 19 Jul 2011 21:19:50 +0000 (21:19 +0000)
includes/libs/CSSMin.php

index 3050071..a2aa879 100644 (file)
@@ -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