Index: branches/resourceloader/phase3/includes/ResourceLoader.php |
— | — | @@ -189,6 +189,24 @@ |
190 | 190 | $lang = Language::factory( $parameters['lang'] ); |
191 | 191 | $parameters['dir'] = $lang->getDir(); |
192 | 192 | } |
| 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 | + } |
193 | 211 | |
194 | 212 | // Set parameters on all modules |
195 | 213 | // FIXME: This sucks |
— | — | @@ -238,40 +256,54 @@ |
239 | 257 | $blobs = MessageBlobStore::get( $modules, $parameters['lang'] ); |
240 | 258 | foreach ( $modules as $name ) { |
241 | 259 | $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'] ); |
247 | 270 | } |
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'] ); |
254 | 271 | |
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 !== '' ) { |
256 | 280 | if ( $parameters['dir'] == 'rtl' ) { |
257 | 281 | $style = self::filter( 'flip-css', $style ); |
258 | 282 | } |
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 ); |
263 | 284 | } |
264 | 285 | // Messages |
265 | | - $messages = isset( $blobs[$name] ) ? $blobs[$name] : '{}'; |
| 286 | + $messages = $includeMessages && isset( $blobs[$name] ) ? $blobs[$name] : '{}'; |
266 | 287 | // 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 | + } |
268 | 296 | } |
269 | | - // Set headers -- when we support CSS only mode, this might change! |
270 | | - header( 'Content-Type: text/javascript' ); |
| 297 | + |
271 | 298 | // Final processing |
272 | | - if ( $parameters['debug'] ) { |
273 | | - ob_end_flush(); |
| 299 | + if ( $parameters['only'] == 'styles' ) { |
| 300 | + header( 'Content-Type: text/css' ); |
274 | 301 | } 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 | + } |
276 | 308 | } |
277 | 309 | } |
278 | 310 | } |