Index: branches/resourceloader/phase3/includes/ResourceLoader.php |
— | — | @@ -32,8 +32,8 @@ |
33 | 33 | * 'loader' => 'resources/foo/loader.js', |
34 | 34 | * // If you need any localized messages brought into the JavaScript environment, list the keys here |
35 | 35 | * 'messages' => array( 'foo-hello', 'foo-goodbye' ), |
36 | | - * // Base-only scripts are special scripts loaded in the base-package |
37 | | - * 'base' => false, |
| 36 | + * // Raw scripts are are loaded without using the loader and can not bundle loaders, styles and messages |
| 37 | + * 'raw' => false, |
38 | 38 | * // Debug-only scripts are special scripts that are only loaded when requested and while in debug mode |
39 | 39 | * 'debug' => false, |
40 | 40 | * ) ); |
— | — | @@ -154,7 +154,7 @@ |
155 | 155 | * 'style' => [string: path to file, optional], |
156 | 156 | * 'loader' => [string: path to file, optional], |
157 | 157 | * 'messages' => [array: message keys, optional], |
158 | | - * 'base' => [boolean: include in base package only, optional], |
| 158 | + * 'raw' => [boolean: include directly without any loading support, optional], |
159 | 159 | * 'debug' => [boolean: include in debug mode only, optional], |
160 | 160 | * ) |
161 | 161 | * |
— | — | @@ -183,7 +183,7 @@ |
184 | 184 | 'style' => null, |
185 | 185 | 'messages' => null, |
186 | 186 | 'loader' => null, |
187 | | - 'base' => false, |
| 187 | + 'raw' => false, |
188 | 188 | 'debug' => false, |
189 | 189 | ), $options ); |
190 | 190 | // Validate script option |
— | — | @@ -217,7 +217,6 @@ |
218 | 218 | * 'lang' => [string: language code, optional, code of default language by default], |
219 | 219 | * 'skin' => [string: name of skin, optional, name of default skin by default], |
220 | 220 | * 'dir' => [string: 'ltr' or 'rtl', optional, direction of lang by default], |
221 | | - * 'base' => [boolean: true to include base-only scripts, optional, false by default], |
222 | 221 | * 'debug' => [boolean: true to include debug-only scripts, optional, false by default], |
223 | 222 | * ) |
224 | 223 | */ |
— | — | @@ -228,89 +227,81 @@ |
229 | 228 | 'user' => $request->getBool( 'user', $wgUser->isLoggedIn() ), |
230 | 229 | 'lang' => $request->getVal( 'lang', $wgLang->getCode() ), |
231 | 230 | 'skin' => $request->getVal( 'skin', $wgDefaultSkin ), |
232 | | - 'base' => $request->getBool( 'base' ), |
233 | 231 | 'debug' => $request->getBool( 'debug' ), |
234 | 232 | ) ); |
235 | | - $modules = explode( '|', $request->getVal( 'modules' ) ); |
236 | 233 | // Get the direction from the requested language |
237 | 234 | if ( !isset( $parameters['dir'] ) ) { |
238 | 235 | $lang = $wgLang->factory( $parameters['lang'] ); |
239 | 236 | $parameters['dir'] = $lang->getDir(); |
240 | 237 | } |
241 | | - // Optionally include all base-only scripts |
242 | | - $base = array(); |
243 | | - if ( $parameters['base'] ) { |
244 | | - foreach ( static::$modules as $name => $options ) { |
245 | | - if ( $options['base'] ) { |
246 | | - // Only include debug scripts in debug mode |
247 | | - if ( $options['debug'] ) { |
248 | | - if ( $parameters['debug'] ) { |
249 | | - $base[] = $name; |
250 | | - } |
251 | | - } else { |
252 | | - $base[] = $name; |
| 238 | + // Get modules - filtering out any we don't know about |
| 239 | + $modules = array(); |
| 240 | + foreach ( explode( '|', $request->getVal( 'modules' ) ) as $module ) { |
| 241 | + if ( isset( static::$modules[$module] ) ) { |
| 242 | + if ( static::$modules[$module]['debug'] ) { |
| 243 | + if ( $parameters['debug'] ) { |
| 244 | + $modules[] = $module; |
253 | 245 | } |
| 246 | + } else { |
| 247 | + $modules[] = $module; |
254 | 248 | } |
255 | 249 | } |
256 | 250 | } |
257 | | - // Include requested modules which have been registered - ignoring any which have not been |
258 | | - $other = array(); |
259 | | - foreach ( static::$modules as $name => $options ) { |
260 | | - if ( in_array( $name, $modules ) && !in_array( $name, $base )) { |
261 | | - $other[] = $name; |
262 | | - } |
263 | | - } |
264 | 251 | // Use output buffering |
265 | 252 | ob_start(); |
266 | | - // Optionally include base modules |
267 | | - if ( $parameters['base'] ) { |
268 | | - // Base modules |
269 | | - foreach ( $base as $module ) { |
| 253 | + // Output raw modules first |
| 254 | + foreach ( $modules as $module ) { |
| 255 | + if ( static::$modules[$module]['raw'] ) { |
270 | 256 | readfile( static::$modules[$module]['script'] ); |
271 | 257 | } |
272 | | - // All module loaders - keep track of which loaders have been included to prevent multiple modules with a |
273 | | - // single loader causing the loader to be included more than once |
| 258 | + } |
| 259 | + // Special meta-information for the 'mw' module |
| 260 | + if ( in_array( 'mw', $modules ) ) { |
| 261 | + // Collect all loaders |
274 | 262 | $loaders = array(); |
275 | 263 | foreach ( self::$modules as $name => $options ) { |
276 | | - if ( $options['loader'] !== null && !in_array( $options['loader'], $loaders ) ) { |
277 | | - readfile( $options['loader'] ); |
| 264 | + if ( $options['loader'] !== null ) { |
278 | 265 | $loaders[] = $options['loader']; |
279 | 266 | } |
280 | 267 | } |
281 | | - } |
282 | | - |
283 | | - /* |
284 | | - * Skin::makeGlobalVariablesScript needs to be modified so that we still output the globals for now, but also |
285 | | - * put them into the initial payload like this: |
286 | | - * |
287 | | - * // Sets the inital configuration |
288 | | - * mw.config.set( { 'name': 'value', ... } ); |
289 | | - * |
290 | | - * Also, the naming of these variables is horrible and sad, hopefully this can be worked on |
291 | | - */ |
292 | | - |
293 | | - // Other modules |
294 | | - $blobs = static::messages( $parameters['lang'], $other ); |
295 | | - foreach ( $other as $module ) { |
296 | | - // Script |
297 | | - $script = file_get_contents( static::$modules[$module]['script'] ); |
298 | | - if ( !$parameters['debug'] ) { |
299 | | - $script = static::filter( 'strip-debug', $script ); |
| 268 | + // Include each loader once |
| 269 | + foreach ( array_unique( $loaders ) as $loader ) { |
| 270 | + readfile( $loader ); |
300 | 271 | } |
301 | | - // Style |
302 | | - $style = static::$modules[$module]['style'] ? file_get_contents( static::$modules[$module]['style'] ) : ''; |
303 | | - if ( $style !== '' ) { |
304 | | - if ( $parameters['dir'] == 'rtl' ) { |
305 | | - $style = static::filter( 'flip-css', $style ); |
| 272 | + /* |
| 273 | + * Skin::makeGlobalVariablesScript needs to be modified so that we still output the globals for now, but also |
| 274 | + * put them into the initial payload like this: |
| 275 | + * |
| 276 | + * // Sets the inital configuration |
| 277 | + * mw.config.set( { 'name': 'value', ... } ); |
| 278 | + * |
| 279 | + * Also, the naming of these variables is horrible and sad, hopefully this can be worked on |
| 280 | + */ |
| 281 | + } |
| 282 | + // Output non-raw modules |
| 283 | + $blobs = static::messages( $parameters['lang'], $modules ); |
| 284 | + foreach ( $modules as $module ) { |
| 285 | + if ( !static::$modules[$module]['raw'] ) { |
| 286 | + // Script |
| 287 | + $script = file_get_contents( static::$modules[$module]['script'] ); |
| 288 | + if ( !$parameters['debug'] ) { |
| 289 | + $script = static::filter( 'strip-debug', $script ); |
306 | 290 | } |
307 | | - $style = Xml::escapeJsString( |
308 | | - static::filter( 'minify-css', $style, static::$modules[$module]['style'] ) |
309 | | - ); |
| 291 | + // Style |
| 292 | + $style = static::$modules[$module]['style'] ? file_get_contents( static::$modules[$module]['style'] ) : ''; |
| 293 | + if ( $style !== '' ) { |
| 294 | + if ( $parameters['dir'] == 'rtl' ) { |
| 295 | + $style = static::filter( 'flip-css', $style ); |
| 296 | + } |
| 297 | + $style = Xml::escapeJsString( |
| 298 | + static::filter( 'minify-css', $style, static::$modules[$module]['style'] ) |
| 299 | + ); |
| 300 | + } |
| 301 | + // Messages |
| 302 | + $messages = isset( $blobs[$module] ) ? $blobs[$module] : '{}'; |
| 303 | + // Output |
| 304 | + echo "mw.loader.implement(\n'{$module}', function() { {$script} }, '{$style}', {$messages}\n);\n"; |
310 | 305 | } |
311 | | - // Messages |
312 | | - $messages = isset( $blobs[$module] ) ? $blobs[$module] : '{}'; |
313 | | - // Output |
314 | | - echo "mw.loader.implement(\n'{$module}', function() { {$script} }, '{$style}', {$messages}\n);\n"; |
315 | 306 | } |
316 | 307 | // Set headers -- when we support CSS only mode, this might change! |
317 | 308 | header( 'Content-Type: text/javascript' ); |
Index: branches/resourceloader/phase3/resources/test/index.html |
— | — | @@ -8,7 +8,8 @@ |
9 | 9 | color: white; |
10 | 10 | } |
11 | 11 | </style> |
12 | | - <script type="text/javascript" src="../../load.php?modules=test&base=1&debug=0"></script> |
| 12 | + <script type="text/javascript" src="../../load.php?modules=jquery|mw|mw.debug&debug=1"></script> |
| 13 | + <script type="text/javascript" src="../../load.php?modules=mw.util|test&debug=1"></script> |
13 | 14 | <script> |
14 | 15 | mw.config.set( 'wgScriptPath', '../..' ); |
15 | 16 | </script> |
Index: branches/resourceloader/phase3/resources/Resources.php |
— | — | @@ -3,19 +3,19 @@ |
4 | 4 | ResourceLoader::register( array( |
5 | 5 | 'jquery' => array( |
6 | 6 | 'script' => 'resources/base/jquery-1.4.2.js', |
7 | | - 'base' => true, |
| 7 | + 'raw' => true, |
8 | 8 | ), |
9 | 9 | 'mw' => array( |
10 | 10 | 'script' => 'resources/base/mw.js', |
11 | | - 'base' => true, |
| 11 | + 'raw' => true, |
12 | 12 | ), |
13 | 13 | 'mw.util' => array( |
14 | 14 | 'script' => 'resources/base/mw/mw.util.js', |
15 | | - 'base' => true, |
| 15 | + 'raw' => true, |
16 | 16 | ), |
17 | 17 | 'mw.debug' => array( |
18 | 18 | 'script' => 'resources/base/mw/mw.debug.js', |
19 | | - 'base' => true, |
| 19 | + 'raw' => true, |
20 | 20 | 'debug' => true |
21 | 21 | ), |
22 | 22 | 'test' => array( |