From: Ori Livneh Date: Fri, 25 Sep 2015 16:43:35 +0000 (-0700) Subject: ResourceLoaderEditToolbarModule::cssSerializeString() → CSSMin::serializeStringValue() X-Git-Tag: 1.31.0-rc.0~9821^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/operations/?a=commitdiff_plain;h=889883b731d9c5676fa698453301367109bd9caa;p=lhc%2Fweb%2Fwiklou.git ResourceLoaderEditToolbarModule::cssSerializeString() → CSSMin::serializeStringValue() ResourceLoaderEditToolbarModule is clearly the wrong place for something so generic, so this method needs a new home. We can either introduce a new class or find a suitable existing home. I think CSSMin is suitable. It has public methods that do things that are closely related, like `encodeStringAsDataURI` and `buildUrlValue`. Change-Id: Icc6dfb8f47199e6188dd71948f4645baee085e51 --- diff --git a/includes/libs/CSSMin.php b/includes/libs/CSSMin.php index 5a8c4c7bc1..c93206ced9 100644 --- a/includes/libs/CSSMin.php +++ b/includes/libs/CSSMin.php @@ -180,6 +180,25 @@ class CSSMin { return false; } + /** + * Serialize a string (escape and quote) for use as a CSS string value. + * http://www.w3.org/TR/2013/WD-cssom-20131205/#serialize-a-string + * + * @param string $value + * @return string + * @throws Exception + */ + public static function serializeStringValue( $value ) { + if ( strstr( $value, "\0" ) ) { + throw new Exception( "Invalid character in CSS string" ); + } + $value = strtr( $value, array( '\\' => '\\\\', '"' => '\\"' ) ); + $value = preg_replace_callback( '/[\x01-\x1f\x7f-\x9f]/', function ( $match ) { + return '\\' . base_convert( ord( $match[0] ), 10, 16 ) . ' '; + }, $value ); + return '"' . $value . '"'; + } + /** * @param $file string * @return bool|string diff --git a/includes/resourceloader/ResourceLoaderEditToolbarModule.php b/includes/resourceloader/ResourceLoaderEditToolbarModule.php index da729fdc67..ef51e0cbd3 100644 --- a/includes/resourceloader/ResourceLoaderEditToolbarModule.php +++ b/includes/resourceloader/ResourceLoaderEditToolbarModule.php @@ -26,24 +26,6 @@ * @since 1.24 */ class ResourceLoaderEditToolbarModule extends ResourceLoaderFileModule { - /** - * Serialize a string (escape and quote) for use as a CSS string value. - * http://www.w3.org/TR/2013/WD-cssom-20131205/#serialize-a-string - * - * @param string $value - * @return string - * @throws Exception - */ - private static function cssSerializeString( $value ) { - if ( strstr( $value, "\0" ) ) { - throw new Exception( "Invalid character in CSS string" ); - } - $value = strtr( $value, array( '\\' => '\\\\', '"' => '\\"' ) ); - $value = preg_replace_callback( '/[\x01-\x1f\x7f-\x9f]/', function ( $match ) { - return '\\' . base_convert( ord( $match[0] ), 10, 16 ) . ' '; - }, $value ); - return '"' . $value . '"'; - } /** * Get language-specific LESS variables for this module. @@ -58,7 +40,7 @@ class ResourceLoaderEditToolbarModule extends ResourceLoaderFileModule { // less.php tries to be helpful and parse our variables as LESS source code foreach ( $vars as $key => &$value ) { - $value = self::cssSerializeString( $value ); + $value = CSSMin::serializeStringValue( $value ); } return $vars;