r71646 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71645‎ | r71646 | r71647 >
Date:19:02, 25 August 2010
Author:catrope
Status:deferred
Tags:
Comment:
resourceloader: Make the &only= parameter actually work
Modified paths:
  • /branches/resourceloader/phase3/includes/ResourceLoader.php (modified) (history)

Diff [purge]

Index: branches/resourceloader/phase3/includes/ResourceLoader.php
@@ -189,6 +189,24 @@
190190 $lang = Language::factory( $parameters['lang'] );
191191 $parameters['dir'] = $lang->getDir();
192192 }
 193+ $includeScripts = false;
 194+ $includeStyles = false;
 195+ $includeMessages = false;
 196+ switch ( $parameters['only'] ) {
 197+ case 'scripts':
 198+ $includeScripts = true;
 199+ break;
 200+ case 'styles':
 201+ $includeStyles = true;
 202+ break;
 203+ case 'messages':
 204+ $includeMessages = true;
 205+ break;
 206+ default:
 207+ $includeScripts = true;
 208+ $includeStyles = true;
 209+ $includeMessages = true;
 210+ }
193211
194212 // Set parameters on all modules
195213 // FIXME: This sucks
@@ -238,40 +256,54 @@
239257 $blobs = MessageBlobStore::get( $modules, $parameters['lang'] );
240258 foreach ( $modules as $name ) {
241259 $module = self::getModule( $name );
242 - // Script
243 - $script = $module->getScript();
244 - // Debug
245 - if ( $parameters['debug'] ) {
246 - $script .= $module->getDebugScript();
 260+
 261+ // Scripts
 262+ $scripts = '';
 263+ if ( $includeScripts ) {
 264+ $scripts .= $module->getScript();
 265+ if ( $parameters['debug'] ) {
 266+ $script .= $module->getDebugScript();
 267+ }
 268+ $scripts .= $module->getLanguageScript( $parameters['lang'] );
 269+ $scripts .= $module->getSkinScript( $parameters['skin'] );
247270 }
248 - // Language-specific scripts
249 - $script .= $module->getLanguageScript( $parameters['lang'] );
250 - // Style
251 - $style = $module->getStyle();
252 - // Skin-specific styles
253 - $style .= $module->getSkinStyle( $parameters['skin'] );
254271
255 - if ( $style !== '' ) {
 272+ // Styles
 273+ $styles = '';
 274+ if ( $includeStyles ) {
 275+ $styles .= $module->getStyle();
 276+ $styles .= $module->getSkinStyle( $parameters['skin'] );
 277+ }
 278+
 279+ if ( $styles !== '' ) {
256280 if ( $parameters['dir'] == 'rtl' ) {
257281 $style = self::filter( 'flip-css', $style );
258282 }
259 - $style = Xml::escapeJsString(
260 - $parameters['debug'] ?
261 - $style : self::filter( 'minify-css', $style )
262 - );
 283+ $styles = $parameters['debug'] ? $styles : self::filter( 'minify-css', $styles );
263284 }
264285 // Messages
265 - $messages = isset( $blobs[$name] ) ? $blobs[$name] : '{}';
 286+ $messages = $includeMessages && isset( $blobs[$name] ) ? $blobs[$name] : '{}';
266287 // Output
267 - echo "mediaWiki.loader.implement( '{$name}', function() {\n{$script}\n}, '{$style}', {$messages} );\n";
 288+ if ( $parameters['only'] == 'styles' ) {
 289+ echo $styles;
 290+ } else if ( $parameters['only'] == 'messages' ) {
 291+ echo "mediaWiki.msg.set( $messages );\n";
 292+ } else {
 293+ $styles = Xml::escapeJsString( $styles );
 294+ echo "mediaWiki.loader.implement( '{$name}', function() {\n{$scripts}\n}, '{$styles}', {$messages} );\n";
 295+ }
268296 }
269 - // Set headers -- when we support CSS only mode, this might change!
270 - header( 'Content-Type: text/javascript' );
 297+
271298 // Final processing
272 - if ( $parameters['debug'] ) {
273 - ob_end_flush();
 299+ if ( $parameters['only'] == 'styles' ) {
 300+ header( 'Content-Type: text/css' );
274301 } else {
275 - echo self::filter( 'minify-js', ob_get_clean() );
 302+ header( 'Content-Type: text/javascript' );
 303+ if ( $parameters['debug'] ) {
 304+ ob_end_flush();
 305+ } else {
 306+ echo self::filter( 'minify-js', ob_get_clean() );
 307+ }
276308 }
277309 }
278310 }

Status & tagging log