From 63ea295de56cf7756cf4811d01c090c5d8c869ef Mon Sep 17 00:00:00 2001 From: Trevor Parscal Date: Thu, 16 Dec 2010 19:31:48 +0000 Subject: [PATCH] Moved CSS flipping to occur inside a module - this resolves a bug which occurs when flipping happens AFTER CSSMin::remap embeds a data URI of an un-flipped image. --- includes/resourceloader/ResourceLoader.php | 12 +---------- .../ResourceLoaderFileModule.php | 20 ++++++++++++++----- .../ResourceLoaderUserOptionsModule.php | 6 +++++- .../ResourceLoaderWikiModule.php | 3 +++ 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index f9d29fc7c6..d6d5d5234c 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -111,7 +111,6 @@ class ResourceLoader { * Available filters are: * - minify-js \see JSMin::minify * - minify-css \see CSSMin::minify - * - flip-css \see CSSJanus::transform * * If $data is empty, only contains whitespace or the filter was unknown, * $data is returned unmodified. @@ -126,7 +125,7 @@ class ResourceLoader { // For empty/whitespace-only data or for unknown filters, don't perform // any caching or processing if ( trim( $data ) === '' - || !in_array( $filter, array( 'minify-js', 'minify-css', 'flip-css' ) ) ) + || !in_array( $filter, array( 'minify-js', 'minify-css' ) ) ) { wfProfileOut( __METHOD__ ); return $data; @@ -151,9 +150,6 @@ class ResourceLoader { case 'minify-css': $result = CSSMin::minify( $data ); break; - case 'flip-css': - $result = CSSJanus::transform( $data, true, false ); - break; } } catch ( Exception $exception ) { throw new MWException( 'ResourceLoader filter error. ' . @@ -436,12 +432,6 @@ class ResourceLoader { $styles = array(); if ( $context->shouldIncludeStyles() ) { $styles = $module->getStyles( $context ); - // Flip CSS on a per-module basis - if ( $styles && $module->getFlip( $context ) ) { - foreach ( $styles as $media => $style ) { - $styles[$media] = $this->filter( 'flip-css', $style ); - } - } } // Messages diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php index b4fb38d721..e1b3159708 100644 --- a/includes/resourceloader/ResourceLoaderFileModule.php +++ b/includes/resourceloader/ResourceLoaderFileModule.php @@ -247,9 +247,11 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { */ public function getStyles( ResourceLoaderContext $context ) { // Merge general styles and skin specific styles, retaining media type collation - $styles = $this->readStyleFiles( $this->styles ); + $styles = $this->readStyleFiles( $this->styles, $this->getFlip( $context ) ); $skinStyles = $this->readStyleFiles( - self::tryForKey( $this->skinStyles, $context->getSkin(), 'default' ) ); + self::tryForKey( $this->skinStyles, $context->getSkin(), 'default' ), + $this->getFlip( $context ) + ); foreach ( $skinStyles as $media => $style ) { if ( isset( $styles[$media] ) ) { @@ -456,14 +458,19 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { * @return Array: List of concatenated and remapped CSS data from $styles, * keyed by media type */ - protected function readStyleFiles( array $styles ) { + protected function readStyleFiles( array $styles, $flip ) { if ( empty( $styles ) ) { return array(); } $styles = self::collateFilePathListByOption( $styles, 'media', 'all' ); foreach ( $styles as $media => $files ) { $styles[$media] = implode( - "\n", array_map( array( $this, 'readStyleFile' ), array_unique( $files ) ) + "\n", + array_map( + array( $this, 'readStyleFile' ), + array_unique( $files ), + array( $flip ) + ) ); } return $styles; @@ -477,12 +484,15 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { * @param $path String: File path of script file to read * @return String: CSS data in script file */ - protected function readStyleFile( $path ) { + protected function readStyleFile( $path, $flip ) { $localPath = $this->getLocalPath( $path ); $style = file_get_contents( $localPath ); if ( $style === false ) { throw new MWException( __METHOD__.": style file not found: \"$localPath\"" ); } + if ( $flip ) { + $style = CSSJanus::transform( $style, true, false ); + } $dir = $this->getLocalPath( dirname( $path ) ); $remoteDir = $this->getRemotePath( dirname( $path ) ); // Get and register local file references diff --git a/includes/resourceloader/ResourceLoaderUserOptionsModule.php b/includes/resourceloader/ResourceLoaderUserOptionsModule.php index 17352e348e..ae654b8f0e 100644 --- a/includes/resourceloader/ResourceLoaderUserOptionsModule.php +++ b/includes/resourceloader/ResourceLoaderUserOptionsModule.php @@ -100,7 +100,11 @@ class ResourceLoaderUserOptionsModule extends ResourceLoaderModule { if ( $options['editfont'] !== 'default' ) { $rules[] = "textarea { font-family: {$options['editfont']}; }\n"; } - return array( 'all' => implode( "\n", $rules ) ); + $style = implode( "\n", $rules ); + if ( $this->getFlip( $context ) ) { + $style = CSSJanus::transform( $style, true, false ); + } + return array( 'all' => $style ); } return array(); } diff --git a/includes/resourceloader/ResourceLoaderWikiModule.php b/includes/resourceloader/ResourceLoaderWikiModule.php index 4008bcd922..ad91d2b96f 100644 --- a/includes/resourceloader/ResourceLoaderWikiModule.php +++ b/includes/resourceloader/ResourceLoaderWikiModule.php @@ -86,6 +86,9 @@ abstract class ResourceLoaderWikiModule extends ResourceLoaderModule { if ( !$style ) { continue; } + if ( $this->getFlip( $context ) ) { + $style = CSSJanus::transform( $style, true, false ); + } if ( !isset( $styles[$media] ) ) { $styles[$media] = ''; } -- 2.20.1