r72686 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72685‎ | r72686 | r72687 >
Date:21:57, 9 September 2010
Author:tparscal
Status:ok
Tags:
Comment:
Using constant to reduce duplication of CSS URL matching regular expression. Adjusted some naming for readability.
Modified paths:
  • /trunk/phase3/includes/libs/CSSMin.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/libs/CSSMin.php
@@ -34,6 +34,7 @@
3535 * result in a 1/3 increase in size.
3636 */
3737 const EMBED_SIZE_LIMIT = 24576;
 38+ const URL_REGEX = 'url\([\'"]?(?<file>[^\?\)\:\'"]*)\??[^\)\'"]*[\'"]?\)';
3839
3940 /* Protected Static Members */
4041
@@ -59,9 +60,8 @@
6061 * @return array List of local file references
6162 */
6263 public static function getLocalFileReferences( $source, $path = null ) {
63 - $pattern = '/url\([\'"]?(?<file>[^\?\)\:]*)\??[^\)]*[\'"]?\)/';
6464 $files = array();
65 - if ( preg_match_all( $pattern, $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER ) ) {
 65+ if ( preg_match_all( '/' . self::URL_REGEX . '/', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER ) ) {
6666 foreach ( $matches as $match ) {
6767 $file = ( isset( $path ) ? rtrim( $path, '/' ) . '/' : '' ) . "{$match['file'][0]}";
6868
@@ -82,13 +82,13 @@
8383 * @return string Remapped CSS data
8484 */
8585 public static function remap( $source, $path, $embed = true ) {
86 - $pattern = '/((?<embed>\s*\/\*\s*\@embed\s*\*\/)(?<rule>[^\;\}]*))?url\([\'"]?(?<file>[^\?\)\:\'"]*)\??[^\)\'"]*[\'"]?\)(?<extra>[^;]*)[\;]?/';
 86+ $pattern = '/((?<embed>\s*\/\*\s*\@embed\s*\*\/)(?<pre>[^\;\}]*))?' . self::URL_REGEX . '(?<post>[^;]*)[\;]?/';
8787 $offset = 0;
8888 while ( preg_match( $pattern, $source, $match, PREG_OFFSET_CAPTURE, $offset ) ) {
8989 // Shortcuts
9090 $embed = $match['embed'][0];
91 - $rule = $match['rule'][0];
92 - $extra = $match['extra'][0];
 91+ $pre = $match['pre'][0];
 92+ $post = $match['post'][0];
9393 $file = "{$path}/{$match['file'][0]}";
9494 // Only proceed if we can access the file
9595 if ( file_exists( $file ) ) {
@@ -117,10 +117,10 @@
118118 // Build 2 CSS properties; one which uses a base64 encoded data URI in place of the @embed
119119 // comment to try and retain line-number integrity , and the other with a remapped an versioned
120120 // URL and an Internet Explorer hack making it ignored in all browsers that support data URIs
121 - $replacement = "{$rule}url(data:{$type};base64,{$data}){$extra};{$rule}url({$url}){$extra}!ie;";
 121+ $replacement = "{$pre}url(data:{$type};base64,{$data}){$post};{$pre}url({$url}){$post}!ie;";
122122 } else {
123 - // Build a CSS property with a remapped and versioned URL
124 - $replacement = "{$embed}{$rule}url({$url}){$extra};";
 123+ // Build a CSS property with a remapped and versioned URL, preserving comment for debug mode
 124+ $replacement = "{$embed}{$pre}url({$url}){$post};";
125125 }
126126
127127 // Perform replacement on the source

Status & tagging log