r78510 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78509‎ | r78510 | r78511 >
Date:19:31, 16 December 2010
Author:tparscal
Status:ok (Comments)
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/resourceloader/ResourceLoader.php (modified) (history)
  • /trunk/phase3/includes/resourceloader/ResourceLoaderFileModule.php (modified) (history)
  • /trunk/phase3/includes/resourceloader/ResourceLoaderUserOptionsModule.php (modified) (history)
  • /trunk/phase3/includes/resourceloader/ResourceLoaderWikiModule.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/resourceloader/ResourceLoader.php
@@ -111,7 +111,6 @@
112112 * Available filters are:
113113 * - minify-js \see JSMin::minify
114114 * - minify-css \see CSSMin::minify
115 - * - flip-css \see CSSJanus::transform
116115 *
117116 * If $data is empty, only contains whitespace or the filter was unknown,
118117 * $data is returned unmodified.
@@ -126,7 +125,7 @@
127126 // For empty/whitespace-only data or for unknown filters, don't perform
128127 // any caching or processing
129128 if ( trim( $data ) === ''
130 - || !in_array( $filter, array( 'minify-js', 'minify-css', 'flip-css' ) ) )
 129+ || !in_array( $filter, array( 'minify-js', 'minify-css' ) ) )
131130 {
132131 wfProfileOut( __METHOD__ );
133132 return $data;
@@ -151,9 +150,6 @@
152151 case 'minify-css':
153152 $result = CSSMin::minify( $data );
154153 break;
155 - case 'flip-css':
156 - $result = CSSJanus::transform( $data, true, false );
157 - break;
158154 }
159155 } catch ( Exception $exception ) {
160156 throw new MWException( 'ResourceLoader filter error. ' .
@@ -436,12 +432,6 @@
437433 $styles = array();
438434 if ( $context->shouldIncludeStyles() ) {
439435 $styles = $module->getStyles( $context );
440 - // Flip CSS on a per-module basis
441 - if ( $styles && $module->getFlip( $context ) ) {
442 - foreach ( $styles as $media => $style ) {
443 - $styles[$media] = $this->filter( 'flip-css', $style );
444 - }
445 - }
446436 }
447437
448438 // Messages
Index: trunk/phase3/includes/resourceloader/ResourceLoaderUserOptionsModule.php
@@ -100,7 +100,11 @@
101101 if ( $options['editfont'] !== 'default' ) {
102102 $rules[] = "textarea { font-family: {$options['editfont']}; }\n";
103103 }
104 - return array( 'all' => implode( "\n", $rules ) );
 104+ $style = implode( "\n", $rules );
 105+ if ( $this->getFlip( $context ) ) {
 106+ $style = CSSJanus::transform( $style, true, false );
 107+ }
 108+ return array( 'all' => $style );
105109 }
106110 return array();
107111 }
Index: trunk/phase3/includes/resourceloader/ResourceLoaderFileModule.php
@@ -247,9 +247,11 @@
248248 */
249249 public function getStyles( ResourceLoaderContext $context ) {
250250 // Merge general styles and skin specific styles, retaining media type collation
251 - $styles = $this->readStyleFiles( $this->styles );
 251+ $styles = $this->readStyleFiles( $this->styles, $this->getFlip( $context ) );
252252 $skinStyles = $this->readStyleFiles(
253 - self::tryForKey( $this->skinStyles, $context->getSkin(), 'default' ) );
 253+ self::tryForKey( $this->skinStyles, $context->getSkin(), 'default' ),
 254+ $this->getFlip( $context )
 255+ );
254256
255257 foreach ( $skinStyles as $media => $style ) {
256258 if ( isset( $styles[$media] ) ) {
@@ -456,14 +458,19 @@
457459 * @return Array: List of concatenated and remapped CSS data from $styles,
458460 * keyed by media type
459461 */
460 - protected function readStyleFiles( array $styles ) {
 462+ protected function readStyleFiles( array $styles, $flip ) {
461463 if ( empty( $styles ) ) {
462464 return array();
463465 }
464466 $styles = self::collateFilePathListByOption( $styles, 'media', 'all' );
465467 foreach ( $styles as $media => $files ) {
466468 $styles[$media] = implode(
467 - "\n", array_map( array( $this, 'readStyleFile' ), array_unique( $files ) )
 469+ "\n",
 470+ array_map(
 471+ array( $this, 'readStyleFile' ),
 472+ array_unique( $files ),
 473+ array( $flip )
 474+ )
468475 );
469476 }
470477 return $styles;
@@ -477,12 +484,15 @@
478485 * @param $path String: File path of script file to read
479486 * @return String: CSS data in script file
480487 */
481 - protected function readStyleFile( $path ) {
 488+ protected function readStyleFile( $path, $flip ) {
482489 $localPath = $this->getLocalPath( $path );
483490 $style = file_get_contents( $localPath );
484491 if ( $style === false ) {
485492 throw new MWException( __METHOD__.": style file not found: \"$localPath\"" );
486493 }
 494+ if ( $flip ) {
 495+ $style = CSSJanus::transform( $style, true, false );
 496+ }
487497 $dir = $this->getLocalPath( dirname( $path ) );
488498 $remoteDir = $this->getRemotePath( dirname( $path ) );
489499 // Get and register local file references
Index: trunk/phase3/includes/resourceloader/ResourceLoaderWikiModule.php
@@ -86,6 +86,9 @@
8787 if ( !$style ) {
8888 continue;
8989 }
 90+ if ( $this->getFlip( $context ) ) {
 91+ $style = CSSJanus::transform( $style, true, false );
 92+ }
9093 if ( !isset( $styles[$media] ) ) {
9194 $styles[$media] = '';
9295 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r78511Fixed right-to-left issues. This also depends on the patch to ResourceLoader ...tparscal19:32, 16 December 2010
r79129MFT r78011 r78014 r78015 r78016 r78099 r78117 r78161 r78170 r78172 r78199 r78......platonides19:58, 28 December 2010

Comments

#Comment by Catrope (talk | contribs)   13:59, 23 December 2010

This revision is OK for doing what it claims to do (marking as such), but it removes the caching of CSSJanus output.

Status & tagging log