r72730 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72729‎ | r72730 | r72731 >
Date:18:24, 10 September 2010
Author:tparscal
Status:ok
Tags:
Comment:
Made OutputPage only ask for a style from ResourceLoader once with media=all, and ResourceLoader respond with styles wrapped in @media [type] { ... } blocks.
Modified paths:
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/ResourceLoader.php (modified) (history)
  • /trunk/phase3/includes/ResourceLoaderContext.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ResourceLoaderContext.php
@@ -33,7 +33,6 @@
3434 protected $skin;
3535 protected $debug;
3636 protected $only;
37 - protected $media;
3837 protected $hash;
3938
4039 /* Methods */
@@ -50,7 +49,6 @@
5150 $this->skin = $request->getVal( 'skin' );
5251 $this->debug = $request->getVal( 'debug' ) === 'true' || $request->getBool( 'debug' );
5352 $this->only = $request->getVal( 'only' );
54 - $this->media = $request->getVal( 'media', 'all' );
5553
5654 // Fallback on system defaults
5755 if ( !$this->language ) {
@@ -97,10 +95,6 @@
9896 public function getOnly() {
9997 return $this->only;
10098 }
101 -
102 - public function getMedia() {
103 - return $this->media;
104 - }
10599
106100 public function shouldIncludeScripts() {
107101 return is_null( $this->only ) || $this->only === 'scripts';
@@ -117,6 +111,6 @@
118112 public function getHash() {
119113 return isset( $this->hash ) ?
120114 $this->hash : $this->hash =
121 - implode( '|', array( $this->language, $this->skin, $this->debug, $this->only, $this->media ) );
 115+ implode( '|', array( $this->language, $this->skin, $this->debug, $this->only ) );
122116 }
123117 }
Index: trunk/phase3/includes/OutputPage.php
@@ -2280,7 +2280,7 @@
22812281 return $ret;
22822282 }
22832283
2284 - static function makeResourceLoaderLink( $skin, $modules, $only, $media = 'all' ) {
 2284+ static function makeResourceLoaderLink( $skin, $modules, $only ) {
22852285 global $wgUser, $wgLang, $wgRequest;
22862286 // TODO: Should this be a static function of ResourceLoader instead?
22872287 $query = array(
@@ -2292,8 +2292,7 @@
22932293 );
22942294 // Automatically select style/script elements
22952295 if ( $only === 'styles' ) {
2296 - $query['media'] = $media;
2297 - return Html::linkedStyle( wfAppendQuery( wfScript( 'load' ), $query ), $media );
 2296+ return Html::linkedStyle( wfAppendQuery( wfScript( 'load' ), $query ) );
22982297 } else {
22992298 return Html::linkedScript( wfAppendQuery( wfScript( 'load' ), $query ) );
23002299 }
@@ -2489,15 +2488,11 @@
24902489 // Support individual script requests in debug mode
24912490 if ( $wgRequest->getBool( 'debug' ) && $wgRequest->getVal( 'debug' ) !== 'false' ) {
24922491 foreach ( $this->getModuleStyles() as $name ) {
2493 - $tags[] = self::makeResourceLoaderLink( $sk, $name, 'styles', 'all' );
2494 - $tags[] = self::makeResourceLoaderLink( $sk, $name, 'styles', 'screen' );
2495 - $tags[] = self::makeResourceLoaderLink( $sk, $name, 'styles', 'print' );
 2492+ $tags[] = self::makeResourceLoaderLink( $sk, $name, 'styles' );
24962493 }
24972494 } else {
24982495 if ( count( $this->getModuleStyles() ) ) {
2499 - $tags[] = self::makeResourceLoaderLink( $sk, $this->getModuleStyles(), 'styles', 'all' );
2500 - $tags[] = self::makeResourceLoaderLink( $sk, $this->getModuleStyles(), 'styles', 'screen' );
2501 - $tags[] = self::makeResourceLoaderLink( $sk, $this->getModuleStyles(), 'styles', 'print' );
 2496+ $tags[] = self::makeResourceLoaderLink( $sk, $this->getModuleStyles(), 'styles' );
25022497 }
25032498 }
25042499
Index: trunk/phase3/includes/ResourceLoader.php
@@ -275,7 +275,7 @@
276276
277277 // Pre-fetch blobs
278278 $blobs = $context->shouldIncludeMessages() ?
279 - MessageBlobStore::get( $modules, $context->getLanguage() ) : array();
 279+ MessageBlobStore::get( $modules, $context->getLanguage() ) : array();
280280
281281 // Generate output
282282 foreach ( $modules as $name ) {
@@ -290,8 +290,7 @@
291291 $styles = array();
292292
293293 if (
294 - $context->shouldIncludeStyles() &&
295 - ( count( $styles = self::$modules[$name]->getStyles( $context ) ) )
 294+ $context->shouldIncludeStyles() && ( count( $styles = self::$modules[$name]->getStyles( $context ) ) )
296295 ) {
297296 foreach ( $styles as $media => $style ) {
298297 if ( self::$modules[$name]->getFlip( $context ) ) {
@@ -308,8 +307,8 @@
309308
310309 // Output
311310 if ( $context->getOnly() === 'styles' ) {
312 - if ( isset( $styles[$context->getMedia()] ) ) {
313 - echo $styles[$context->getMedia()];
 311+ foreach ( $styles as $media => $style ) {
 312+ echo "@media $media {\n$style\n}\n";
314313 }
315314 } else if ( $context->getOnly() === 'scripts' ) {
316315 echo $scripts;

Status & tagging log