Index: trunk/phase3/includes/resourceloader/ResourceLoaderFileModule.php |
— | — | @@ -96,9 +96,12 @@ |
97 | 97 | /** |
98 | 98 | * Constructs a new module from an options array. |
99 | 99 | * |
100 | | - * @param {array} $options Options array. If not given or empty, an empty module will be constructed |
101 | | - * @param {string} $localBasePath base path to prepend to all local paths in $options. Defaults to $IP |
102 | | - * @param {string} $remoteBasePath base path to prepend to all remote paths in $options. Defaults to $wgScriptPath |
| 100 | + * @param {array} $options Options array. If not given or empty, an empty |
| 101 | + * module will be constructed |
| 102 | + * @param {string} $localBasePath base path to prepend to all local paths |
| 103 | + * in $options. Defaults to $IP |
| 104 | + * @param {string} $remoteBasePath base path to prepend to all remote paths |
| 105 | + * in $options. Defaults to $wgScriptPath |
103 | 106 | * |
104 | 107 | * @format $options |
105 | 108 | * array( |
— | — | @@ -130,7 +133,9 @@ |
131 | 134 | * 'group' => [group name string], |
132 | 135 | * ) |
133 | 136 | */ |
134 | | - public function __construct( $options = array(), $localBasePath = null, $remoteBasePath = null ) { |
| 137 | + public function __construct( $options = array(), $localBasePath = null, |
| 138 | + $remoteBasePath = null ) |
| 139 | + { |
135 | 140 | global $IP, $wgScriptPath; |
136 | 141 | $this->localBasePath = $localBasePath === null ? $IP : $localBasePath; |
137 | 142 | $this->remoteBasePath = $remoteBasePath === null ? $wgScriptPath : $remoteBasePath; |
— | — | @@ -149,13 +154,15 @@ |
150 | 155 | case 'skinStyles': |
151 | 156 | if ( !is_array( $option ) ) { |
152 | 157 | throw new MWException( |
153 | | - "Invalid collated file path list error. '$option' given, array expected." |
| 158 | + "Invalid collated file path list error. " . |
| 159 | + "'$option' given, array expected." |
154 | 160 | ); |
155 | 161 | } |
156 | 162 | foreach ( $option as $key => $value ) { |
157 | 163 | if ( !is_string( $key ) ) { |
158 | 164 | throw new MWException( |
159 | | - "Invalid collated file path list key error. '$key' given, string expected." |
| 165 | + "Invalid collated file path list key error. " . |
| 166 | + "'$key' given, string expected." |
160 | 167 | ); |
161 | 168 | } |
162 | 169 | $this->{$member}[$key] = (array) $value; |
— | — | @@ -227,7 +234,8 @@ |
228 | 235 | public function getStyles( ResourceLoaderContext $context ) { |
229 | 236 | // Merge general styles and skin specific styles, retaining media type collation |
230 | 237 | $styles = $this->readStyleFiles( $this->styles ); |
231 | | - $skinStyles = $this->readStyleFiles( self::tryForKey( $this->skinStyles, $context->getSkin(), 'default' ) ); |
| 238 | + $skinStyles = $this->readStyleFiles( |
| 239 | + self::tryForKey( $this->skinStyles, $context->getSkin(), 'default' ) ); |
232 | 240 | |
233 | 241 | foreach ( $skinStyles as $media => $style ) { |
234 | 242 | if ( isset( $styles[$media] ) ) { |
— | — | @@ -282,11 +290,14 @@ |
283 | 291 | /** |
284 | 292 | * Get the last modified timestamp of this module. |
285 | 293 | * |
286 | | - * Last modified timestamps are calculated from the highest last modified timestamp of this module's constituent |
287 | | - * files as well as the files it depends on. This function is context-sensitive, only performing calculations on |
288 | | - * files relevant to the given language, skin and debug mode. |
| 294 | + * Last modified timestamps are calculated from the highest last modified |
| 295 | + * timestamp of this module's constituent files as well as the files it |
| 296 | + * depends on. This function is context-sensitive, only performing |
| 297 | + * calculations on files relevant to the given language, skin and debug |
| 298 | + * mode. |
289 | 299 | * |
290 | | - * @param {ResourceLoaderContext} $context Context in which to calculate the modified time |
| 300 | + * @param {ResourceLoaderContext} $context Context in which to calculate |
| 301 | + * the modified time |
291 | 302 | * @return {integer} UNIX timestamp |
292 | 303 | * @see {ResourceLoaderModule::getFileDependencies} |
293 | 304 | */ |
— | — | @@ -304,7 +315,9 @@ |
305 | 316 | $files = array_merge( $files, $styleFiles ); |
306 | 317 | } |
307 | 318 | $skinFiles = self::tryForKey( |
308 | | - self::collateFilePathListByOption( $this->skinStyles, 'media', 'all' ), $context->getSkin(), 'default' |
| 319 | + self::collateFilePathListByOption( $this->skinStyles, 'media', 'all' ), |
| 320 | + $context->getSkin(), |
| 321 | + 'default' |
309 | 322 | ); |
310 | 323 | foreach ( $skinFiles as $styleFiles ) { |
311 | 324 | $files = array_merge( $files, $styleFiles ); |
— | — | @@ -323,7 +336,8 @@ |
324 | 337 | // File deps need to be treated separately because they're already prefixed |
325 | 338 | $files = array_merge( $files, $this->getFileDependencies( $context->getSkin() ) ); |
326 | 339 | |
327 | | - // If a module is nothing but a list of dependencies, we need to avoid giving max() an empty array |
| 340 | + // If a module is nothing but a list of dependencies, we need to avoid |
| 341 | + // giving max() an empty array |
328 | 342 | if ( count( $files ) === 0 ) { |
329 | 343 | return $this->modifiedTime[$context->getHash()] = 1; |
330 | 344 | } |
— | — | @@ -331,7 +345,9 @@ |
332 | 346 | wfProfileIn( __METHOD__.'-filemtime' ); |
333 | 347 | $filesMtime = max( array_map( 'filemtime', $files ) ); |
334 | 348 | wfProfileOut( __METHOD__.'-filemtime' ); |
335 | | - $this->modifiedTime[$context->getHash()] = max( $filesMtime, $this->getMsgBlobMtime( $context->getLanguage() ) ); |
| 349 | + $this->modifiedTime[$context->getHash()] = max( |
| 350 | + $filesMtime, |
| 351 | + $this->getMsgBlobMtime( $context->getLanguage() ) ); |
336 | 352 | wfProfileOut( __METHOD__ ); |
337 | 353 | return $this->modifiedTime[$context->getHash()]; |
338 | 354 | } |
— | — | @@ -349,7 +365,8 @@ |
350 | 366 | /** |
351 | 367 | * Collates file paths by option (where provided). |
352 | 368 | * |
353 | | - * @param {array} $list List of file paths in any combination of index/path or path/options pairs |
| 369 | + * @param {array} $list List of file paths in any combination of index/path |
| 370 | + * or path/options pairs |
354 | 371 | * @return {array} List of file paths, collated by $option |
355 | 372 | */ |
356 | 373 | protected static function collateFilePathListByOption( array $list, $option, $default ) { |
— | — | @@ -379,12 +396,16 @@ |
380 | 397 | * @param {array} $list List of lists to select from |
381 | 398 | * @param {string} $key Key to look for in $map |
382 | 399 | * @param {string} $fallback Key to look for in $list if $key doesn't exist |
383 | | - * @return {array} List of elements from $map which matched $key or $fallback, or an empty list in case of no match |
| 400 | + * @return {array} List of elements from $map which matched $key or $fallback, |
| 401 | + * or an empty list in case of no match |
384 | 402 | */ |
385 | 403 | protected static function tryForKey( array $list, $key, $fallback = null ) { |
386 | 404 | if ( isset( $list[$key] ) && is_array( $list[$key] ) ) { |
387 | 405 | return $list[$key]; |
388 | | - } else if ( is_string( $fallback ) && isset( $list[$fallback] ) && is_array( $list[$fallback] ) ) { |
| 406 | + } else if ( is_string( $fallback ) |
| 407 | + && isset( $list[$fallback] ) |
| 408 | + && is_array( $list[$fallback] ) ) |
| 409 | + { |
389 | 410 | return $list[$fallback]; |
390 | 411 | } |
391 | 412 | return array(); |
— | — | @@ -400,14 +421,24 @@ |
401 | 422 | if ( empty( $scripts ) ) { |
402 | 423 | return ''; |
403 | 424 | } |
404 | | - return implode( "\n", array_map( 'file_get_contents', array_map( array( $this, 'getLocalPath' ), array_unique( $scripts ) ) ) ); |
| 425 | + $js = ''; |
| 426 | + foreach ( array_unique( $scripts ) as $fileName ) { |
| 427 | + $localPath = $this->getLocalPath( $fileName ); |
| 428 | + $contents = file_get_contents( $localPath ); |
| 429 | + if ( $contents === false ) { |
| 430 | + throw new MWException( __METHOD__.": script file not found: \"$localPath\"" ); |
| 431 | + } |
| 432 | + $js .= $contents . "\n"; |
| 433 | + } |
| 434 | + return $js; |
405 | 435 | } |
406 | 436 | |
407 | 437 | /** |
408 | 438 | * Gets the contents of a list of CSS files. |
409 | 439 | * |
410 | 440 | * @param {array} $styles List of file paths to styles to read, remap and concetenate |
411 | | - * @return {array} List of concatenated and remapped CSS data from $styles, keyed by media type |
| 441 | + * @return {array} List of concatenated and remapped CSS data from $styles, |
| 442 | + * keyed by media type |
412 | 443 | */ |
413 | 444 | protected function readStyleFiles( array $styles ) { |
414 | 445 | if ( empty( $styles ) ) { |
— | — | @@ -431,11 +462,17 @@ |
432 | 463 | * @return {string} CSS data in script file |
433 | 464 | */ |
434 | 465 | protected function readStyleFile( $path ) { |
435 | | - $style = file_get_contents( $this->getLocalPath( $path ) ); |
| 466 | + $localPath = $this->getLocalPath( $path ); |
| 467 | + $style = file_get_contents( $localPath ); |
| 468 | + if ( $style === false ) { |
| 469 | + throw new MWException( __METHOD__.": style file not found: \"$localPath\"" ); |
| 470 | + } |
436 | 471 | $dir = $this->getLocalPath( dirname( $path ) ); |
437 | 472 | $remoteDir = $this->getRemotePath( dirname( $path ) ); |
438 | 473 | // Get and register local file references |
439 | | - $this->localFileRefs = array_merge( $this->localFileRefs, CSSMin::getLocalFileReferences( $style, $dir ) ); |
| 474 | + $this->localFileRefs = array_merge( |
| 475 | + $this->localFileRefs, |
| 476 | + CSSMin::getLocalFileReferences( $style, $dir ) ); |
440 | 477 | return CSSMin::remap( |
441 | 478 | $style, $dir, $remoteDir, true |
442 | 479 | ); |
Index: trunk/phase3/includes/resourceloader/ResourceLoaderWikiModule.php |
— | — | @@ -25,8 +25,9 @@ |
26 | 26 | /** |
27 | 27 | * Abstraction for resource loader modules which pull from wiki pages |
28 | 28 | * |
29 | | - * This can only be used for wiki pages in the MediaWiki and User namespaces, because of it's dependence on the |
30 | | - * functionality of Title::isValidCssJsSubpage. |
| 29 | + * This can only be used for wiki pages in the MediaWiki and User namespaces, |
| 30 | + * because of it's dependence on the functionality of |
| 31 | + * Title::isValidCssJsSubpage. |
31 | 32 | */ |
32 | 33 | abstract class ResourceLoaderWikiModule extends ResourceLoaderModule { |
33 | 34 | |
Index: trunk/phase3/resources/Resources.php |
— | — | @@ -25,7 +25,9 @@ |
26 | 26 | |
27 | 27 | /* jQuery */ |
28 | 28 | |
29 | | - 'jquery' => new ResourceLoaderFileModule( array( 'scripts' => 'resources/jquery/jquery.js', 'debugRaw' => false ) ), |
| 29 | + 'jquery' => new ResourceLoaderFileModule( |
| 30 | + array( 'scripts' => 'resources/jquery/jquery.js', 'debugRaw' => false ) |
| 31 | + ), |
30 | 32 | |
31 | 33 | /* jQuery Plugins */ |
32 | 34 | |
— | — | @@ -109,7 +111,9 @@ |
110 | 112 | ) ), |
111 | 113 | 'jquery.ui.droppable' => new ResourceLoaderFileModule( array( |
112 | 114 | 'scripts' => 'resources/jquery.ui/jquery.ui.droppable.js', |
113 | | - 'dependencies' => array( 'jquery.ui.core', 'jquery.ui.mouse', 'jquery.ui.widget', 'jquery.ui.draggable' ), |
| 115 | + 'dependencies' => array( |
| 116 | + 'jquery.ui.core', 'jquery.ui.mouse', 'jquery.ui.widget', 'jquery.ui.draggable' |
| 117 | + ), |
114 | 118 | ) ), |
115 | 119 | 'jquery.ui.resizable' => new ResourceLoaderFileModule( array( |
116 | 120 | 'scripts' => 'resources/jquery.ui/jquery.ui.resizable.js', |
— | — | @@ -393,7 +397,10 @@ |
394 | 398 | |
395 | 399 | 'mediawiki.legacy.ajax' => new ResourceLoaderFileModule( array( |
396 | 400 | 'scripts' => 'skins/common/ajax.js', |
397 | | - 'messages' => array( 'watch', 'unwatch', 'watching', 'unwatching', 'tooltip-ca-watch', 'tooltip-ca-unwatch' ), |
| 401 | + 'messages' => array( |
| 402 | + 'watch', 'unwatch', 'watching', 'unwatching', 'tooltip-ca-watch', |
| 403 | + 'tooltip-ca-unwatch' |
| 404 | + ), |
398 | 405 | 'dependencies' => 'mediawiki.legacy.wikibits', |
399 | 406 | ) ), |
400 | 407 | 'mediawiki.legacy.ajaxwatch' => new ResourceLoaderFileModule( array( |
Index: trunk/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -60,9 +60,11 @@ |
61 | 61 | /* Prototypes */ |
62 | 62 | |
63 | 63 | /** |
64 | | - * An object which allows single and multiple get/set/exists functionality on a list of key / value pairs. |
| 64 | + * An object which allows single and multiple get/set/exists functionality |
| 65 | + * on a list of key / value pairs. |
65 | 66 | * |
66 | | - * @param {boolean} global Whether to get/set/exists values on the window object or a private object |
| 67 | + * @param {boolean} global Whether to get/set/exists values on the window |
| 68 | + * object or a private object |
67 | 69 | */ |
68 | 70 | function Map( global ) { |
69 | 71 | this.values = ( global === true ) ? window : {}; |
— | — | @@ -216,7 +218,8 @@ |
217 | 219 | /* Public Members */ |
218 | 220 | |
219 | 221 | /* |
220 | | - * Dummy function which in debug mode can be replaced with a function that does something clever |
| 222 | + * Dummy function which in debug mode can be replaced with a function that |
| 223 | + * does something clever |
221 | 224 | */ |
222 | 225 | this.log = function() { }; |
223 | 226 | |
— | — | @@ -278,9 +281,11 @@ |
279 | 282 | /** |
280 | 283 | * Mapping of registered modules |
281 | 284 | * |
282 | | - * The jquery module is pre-registered, because it must have already been provided for this object to have |
283 | | - * been built, and in debug mode jquery would have been provided through a unique loader request, making it |
284 | | - * impossible to hold back registration of jquery until after mediawiki. |
| 285 | + * The jquery module is pre-registered, because it must have already |
| 286 | + * been provided for this object to have been built, and in debug mode |
| 287 | + * jquery would have been provided through a unique loader request, |
| 288 | + * making it impossible to hold back registration of jquery until after |
| 289 | + * mediawiki. |
285 | 290 | * |
286 | 291 | * Format: |
287 | 292 | * { |
— | — | @@ -347,7 +352,7 @@ |
348 | 353 | if ( typeof registry[module] === 'undefined' ) { |
349 | 354 | throw new Error( 'Unknown dependency: ' + module ); |
350 | 355 | } |
351 | | - // Resolves dynamic loader function and replaces it with it's own results |
| 356 | + // Resolves dynamic loader function and replaces it with its own results |
352 | 357 | if ( typeof registry[module].dependencies === 'function' ) { |
353 | 358 | registry[module].dependencies = registry[module].dependencies(); |
354 | 359 | // Ensures the module's dependencies are always in an array |
— | — | @@ -360,7 +365,8 @@ |
361 | 366 | if ( $.inArray( registry[module].dependencies[n], resolved ) === -1 ) { |
362 | 367 | if ( $.inArray( registry[module].dependencies[n], unresolved ) !== -1 ) { |
363 | 368 | throw new Error( |
364 | | - 'Circular reference detected: ' + module + ' -> ' + registry[module].dependencies[n] |
| 369 | + 'Circular reference detected: ' + module + |
| 370 | + ' -> ' + registry[module].dependencies[n] |
365 | 371 | ); |
366 | 372 | } |
367 | 373 | recurse( registry[module].dependencies[n], resolved, unresolved ); |
— | — | @@ -371,7 +377,7 @@ |
372 | 378 | } |
373 | 379 | |
374 | 380 | /** |
375 | | - * Gets a list of modules names that a module dependencies in their proper dependency order |
| 381 | + * Gets a list of module names that a module depends on in their proper dependency order |
376 | 382 | * |
377 | 383 | * @param mixed string module name or array of string module names |
378 | 384 | * @return list of dependencies |
— | — | @@ -401,11 +407,13 @@ |
402 | 408 | }; |
403 | 409 | |
404 | 410 | /** |
405 | | - * Narrows a list of module names down to those matching a specific state. Possible states are 'undefined', |
406 | | - * 'registered', 'loading', 'loaded', or 'ready' |
| 411 | + * Narrows a list of module names down to those matching a specific |
| 412 | + * state. Possible states are 'undefined', 'registered', 'loading', |
| 413 | + * 'loaded', or 'ready' |
407 | 414 | * |
408 | 415 | * @param mixed string or array of strings of module states to filter by |
409 | | - * @param array list of module names to filter (optional, all modules will be used by default) |
| 416 | + * @param array list of module names to filter (optional, all modules |
| 417 | + * will be used by default) |
410 | 418 | * @return array list of filtered module names |
411 | 419 | */ |
412 | 420 | function filter( states, modules ) { |
— | — | @@ -424,17 +432,26 @@ |
425 | 433 | // Build a list of modules which are in one of the specified states |
426 | 434 | for ( var s = 0; s < states.length; s++ ) { |
427 | 435 | for ( var m = 0; m < modules.length; m++ ) { |
428 | | - if ( |
429 | | - ( states[s] == 'undefined' && typeof registry[modules[m]] === 'undefined' ) || |
430 | | - ( typeof registry[modules[m]] === 'object' && registry[modules[m]].state === states[s] ) |
431 | | - ) { |
432 | | - list[list.length] = modules[m]; |
| 436 | + if ( typeof registry[modules[m]] === 'undefined' ) { |
| 437 | + // Module does not exist |
| 438 | + if ( states[s] == 'undefined' ) { |
| 439 | + // OK, undefined |
| 440 | + list[list.length] = modules[m]; |
| 441 | + } |
| 442 | + } else { |
| 443 | + // Module exists, check state |
| 444 | + if ( registry[modules[m]].state === states[s] ) { |
| 445 | + // OK, correct state |
| 446 | + list[list.length] = modules[m]; |
| 447 | + } |
433 | 448 | } |
434 | 449 | } |
435 | 450 | } |
436 | 451 | return list; |
437 | 452 | } |
438 | 453 | |
| 454 | + this.filter_ = filter; |
| 455 | + |
439 | 456 | /** |
440 | 457 | * Executes a loaded module, making it ready to use |
441 | 458 | * |
— | — | @@ -452,11 +469,16 @@ |
453 | 470 | } |
454 | 471 | // Add style sheet to document |
455 | 472 | if ( typeof registry[module].style === 'string' && registry[module].style.length ) { |
456 | | - $( 'head' ).append( '<style type="text/css">' + registry[module].style + '</style>' ); |
457 | | - } else if ( typeof registry[module].style === 'object' && !( registry[module].style instanceof Array ) ) { |
| 473 | + $( 'head' ) |
| 474 | + .append( '<style type="text/css">' + registry[module].style + '</style>' ); |
| 475 | + } else if ( typeof registry[module].style === 'object' |
| 476 | + && !( registry[module].style instanceof Array ) ) |
| 477 | + { |
458 | 478 | for ( var media in registry[module].style ) { |
459 | 479 | $( 'head' ).append( |
460 | | - '<style type="text/css" media="' + media + '">' + registry[module].style[media] + '</style>' |
| 480 | + '<style type="text/css" media="' + media + '">' + |
| 481 | + registry[module].style[media] + |
| 482 | + '</style>' |
461 | 483 | ); |
462 | 484 | } |
463 | 485 | } |
— | — | @@ -470,7 +492,10 @@ |
471 | 493 | registry[module].state = 'ready'; |
472 | 494 | // Run jobs who's dependencies have just been met |
473 | 495 | for ( var j = 0; j < jobs.length; j++ ) { |
474 | | - if ( compare( filter( 'ready', jobs[j].dependencies ), jobs[j].dependencies ) ) { |
| 496 | + if ( compare( |
| 497 | + filter( 'ready', jobs[j].dependencies ), |
| 498 | + jobs[j].dependencies ) ) |
| 499 | + { |
475 | 500 | if ( typeof jobs[j].ready === 'function' ) { |
476 | 501 | jobs[j].ready(); |
477 | 502 | } |
— | — | @@ -481,7 +506,10 @@ |
482 | 507 | // Execute modules who's dependencies have just been met |
483 | 508 | for ( r in registry ) { |
484 | 509 | if ( registry[r].state == 'loaded' ) { |
485 | | - if ( compare( filter( ['ready'], registry[r].dependencies ), registry[r].dependencies ) ) { |
| 510 | + if ( compare( |
| 511 | + filter( ['ready'], registry[r].dependencies ), |
| 512 | + registry[r].dependencies ) ) |
| 513 | + { |
486 | 514 | execute( r ); |
487 | 515 | } |
488 | 516 | } |
— | — | @@ -504,7 +532,8 @@ |
505 | 533 | } |
506 | 534 | |
507 | 535 | /** |
508 | | - * Adds a dependencies to the queue with optional callbacks to be run when the dependencies are ready or fail |
| 536 | + * Adds a dependencies to the queue with optional callbacks to be run |
| 537 | + * when the dependencies are ready or fail |
509 | 538 | * |
510 | 539 | * @param mixed string moulde name or array of string module names |
511 | 540 | * @param function ready callback to execute when all dependencies are ready |
— | — | @@ -516,14 +545,17 @@ |
517 | 546 | dependencies = [dependencies]; |
518 | 547 | if ( dependencies[0] in registry ) { |
519 | 548 | for ( var n = 0; n < registry[dependencies[0]].dependencies.length; n++ ) { |
520 | | - dependencies[dependencies.length] = registry[dependencies[0]].dependencies[n]; |
| 549 | + dependencies[dependencies.length] = |
| 550 | + registry[dependencies[0]].dependencies[n]; |
521 | 551 | } |
522 | 552 | } |
523 | 553 | } |
524 | 554 | // Add ready and error callbacks if they were given |
525 | 555 | if ( arguments.length > 1 ) { |
526 | 556 | jobs[jobs.length] = { |
527 | | - 'dependencies': filter( ['undefined', 'registered', 'loading', 'loaded'], dependencies ), |
| 557 | + 'dependencies': filter( |
| 558 | + ['undefined', 'registered', 'loading', 'loaded'], |
| 559 | + dependencies ), |
528 | 560 | 'ready': ready, |
529 | 561 | 'error': error |
530 | 562 | }; |
— | — | @@ -577,7 +609,8 @@ |
578 | 610 | queue = []; |
579 | 611 | // After document ready, handle the batch |
580 | 612 | if ( !suspended && batch.length ) { |
581 | | - // Always order modules alphabetically to help reduce cache misses for otherwise identical content |
| 613 | + // Always order modules alphabetically to help reduce cache |
| 614 | + // misses for otherwise identical content |
582 | 615 | batch.sort(); |
583 | 616 | // Build a list of request parameters |
584 | 617 | var base = { |
— | — | @@ -608,9 +641,11 @@ |
609 | 642 | { 'modules': groups[group].join( '|' ), 'version': formatVersionNumber( version ) }, base |
610 | 643 | ); |
611 | 644 | } |
612 | | - // Clear the batch - this MUST happen before we append the script element to the body or it's |
613 | | - // possible that the script will be locally cached, instantly load, and work the batch again, |
614 | | - // all before we've cleared it causing each request to include modules which are already loaded |
| 645 | + // Clear the batch - this MUST happen before we append the |
| 646 | + // script element to the body or it's possible that the script |
| 647 | + // will be locally cached, instantly load, and work the batch |
| 648 | + // again, all before we've cleared it causing each request to |
| 649 | + // include modules which are already loaded |
615 | 650 | batch = []; |
616 | 651 | // Asynchronously append a script tag to the end of the body |
617 | 652 | function request() { |
— | — | @@ -633,8 +668,8 @@ |
634 | 669 | }; |
635 | 670 | |
636 | 671 | /** |
637 | | - * Registers a module, letting the system know about it and it's dependencies. loader.js files contain calls |
638 | | - * to this function. |
| 672 | + * Registers a module, letting the system know about it and its |
| 673 | + * dependencies. loader.js files contain calls to this function. |
639 | 674 | */ |
640 | 675 | this.register = function( module, version, dependencies, group ) { |
641 | 676 | // Allow multiple registration |
— | — | @@ -666,14 +701,16 @@ |
667 | 702 | // Allow dependencies to be given as a single module name |
668 | 703 | registry[module].dependencies = [dependencies]; |
669 | 704 | } else if ( typeof dependencies === 'object' || typeof dependencies === 'function' ) { |
670 | | - // Allow dependencies to be given as an array of module names or a function which returns an array |
| 705 | + // Allow dependencies to be given as an array of module names |
| 706 | + // or a function which returns an array |
671 | 707 | registry[module].dependencies = dependencies; |
672 | 708 | } |
673 | 709 | }; |
674 | 710 | |
675 | 711 | /** |
676 | | - * Implements a module, giving the system a course of action to take upon loading. Results of a request for |
677 | | - * one or more modules contain calls to this function. |
| 712 | + * Implements a module, giving the system a course of action to take |
| 713 | + * upon loading. Results of a request for one or more modules contain |
| 714 | + * calls to this function. |
678 | 715 | */ |
679 | 716 | this.implement = function( module, script, style, localization ) { |
680 | 717 | // Automaically register module |
— | — | @@ -684,27 +721,39 @@ |
685 | 722 | if ( typeof script !== 'function' ) { |
686 | 723 | throw new Error( 'script must be a function, not a ' + typeof script ); |
687 | 724 | } |
688 | | - if ( typeof style !== 'undefined' && typeof style !== 'string' && typeof style !== 'object' ) { |
| 725 | + if ( typeof style !== 'undefined' |
| 726 | + && typeof style !== 'string' |
| 727 | + && typeof style !== 'object' ) |
| 728 | + { |
689 | 729 | throw new Error( 'style must be a string or object, not a ' + typeof style ); |
690 | 730 | } |
691 | | - if ( typeof localization !== 'undefined' && typeof localization !== 'object' ) { |
| 731 | + if ( typeof localization !== 'undefined' |
| 732 | + && typeof localization !== 'object' ) |
| 733 | + { |
692 | 734 | throw new Error( 'localization must be an object, not a ' + typeof localization ); |
693 | 735 | } |
694 | | - if ( typeof registry[module] !== 'undefined' && typeof registry[module].script !== 'undefined' ) { |
| 736 | + if ( typeof registry[module] !== 'undefined' |
| 737 | + && typeof registry[module].script !== 'undefined' ) |
| 738 | + { |
695 | 739 | throw new Error( 'module already implemeneted: ' + module ); |
696 | 740 | } |
697 | 741 | // Mark module as loaded |
698 | 742 | registry[module].state = 'loaded'; |
699 | 743 | // Attach components |
700 | 744 | registry[module].script = script; |
701 | | - if ( typeof style === 'string' || typeof style === 'object' && !( style instanceof Array ) ) { |
| 745 | + if ( typeof style === 'string' |
| 746 | + || typeof style === 'object' && !( style instanceof Array ) ) |
| 747 | + { |
702 | 748 | registry[module].style = style; |
703 | 749 | } |
704 | 750 | if ( typeof localization === 'object' ) { |
705 | 751 | registry[module].messages = localization; |
706 | 752 | } |
707 | 753 | // Execute or queue callback |
708 | | - if ( compare( filter( ['ready'], registry[module].dependencies ), registry[module].dependencies ) ) { |
| 754 | + if ( compare( |
| 755 | + filter( ['ready'], registry[module].dependencies ), |
| 756 | + registry[module].dependencies ) ) |
| 757 | + { |
709 | 758 | execute( module ); |
710 | 759 | } else { |
711 | 760 | request( module ); |
— | — | @@ -714,7 +763,8 @@ |
715 | 764 | /** |
716 | 765 | * Executes a function as soon as one or more required modules are ready |
717 | 766 | * |
718 | | - * @param mixed string or array of strings of modules names the callback dependencies to be ready before |
| 767 | + * @param mixed string or array of strings of modules names the callback |
| 768 | + * dependencies to be ready before |
719 | 769 | * executing |
720 | 770 | * @param function callback to execute when all dependencies are ready (optional) |
721 | 771 | * @param function callback to execute when if dependencies have a errors (optional) |
— | — | @@ -722,7 +772,8 @@ |
723 | 773 | this.using = function( dependencies, ready, error ) { |
724 | 774 | // Validate input |
725 | 775 | if ( typeof dependencies !== 'object' && typeof dependencies !== 'string' ) { |
726 | | - throw new Error( 'dependencies must be a string or an array, not a ' + typeof dependencies ) |
| 776 | + throw new Error( 'dependencies must be a string or an array, not a ' + |
| 777 | + typeof dependencies ) |
727 | 778 | } |
728 | 779 | // Allow calling with a single dependency as a string |
729 | 780 | if ( typeof dependencies === 'string' ) { |
— | — | @@ -751,21 +802,29 @@ |
752 | 803 | /** |
753 | 804 | * Loads an external script or one or more modules for future use |
754 | 805 | * |
755 | | - * @param {mixed} modules either the name of a module, array of modules, or a URL of an external script or style |
756 | | - * @param {string} type mime-type to use if calling with a URL of an external script or style; acceptable values |
757 | | - * are "text/css" and "text/javascript"; if no type is provided, text/javascript is assumed |
| 806 | + * @param {mixed} modules either the name of a module, array of modules, |
| 807 | + * or a URL of an external script or style |
| 808 | + * @param {string} type mime-type to use if calling with a URL of an |
| 809 | + * external script or style; acceptable values are "text/css" and |
| 810 | + * "text/javascript"; if no type is provided, text/javascript is |
| 811 | + * assumed |
758 | 812 | */ |
759 | 813 | this.load = function( modules, type ) { |
760 | 814 | // Validate input |
761 | 815 | if ( typeof modules !== 'object' && typeof modules !== 'string' ) { |
762 | | - throw new Error( 'dependencies must be a string or an array, not a ' + typeof dependencies ) |
| 816 | + throw new Error( 'dependencies must be a string or an array, not a ' + |
| 817 | + typeof dependencies ) |
763 | 818 | } |
764 | 819 | // Allow calling with an external script or single dependency as a string |
765 | 820 | if ( typeof modules === 'string' ) { |
766 | 821 | // Support adding arbitrary external scripts |
767 | | - if ( modules.substr( 0, 7 ) == 'http://' || modules.substr( 0, 8 ) == 'https://' ) { |
| 822 | + if ( modules.substr( 0, 7 ) == 'http://' |
| 823 | + || modules.substr( 0, 8 ) == 'https://' ) |
| 824 | + { |
768 | 825 | if ( type === 'text/css' ) { |
769 | | - $( 'head' ).append( $( '<link rel="stylesheet" type="text/css" />' ).attr( 'href', modules ) ); |
| 826 | + $( 'head' ) |
| 827 | + .append( $( '<link rel="stylesheet" type="text/css" />' ) |
| 828 | + .attr( 'href', modules ) ); |
770 | 829 | return true; |
771 | 830 | } else if ( type === 'text/javascript' || typeof type === 'undefined' ) { |
772 | 831 | var script = '<script type="text/javascript" src="' + modules + '"></script>'; |
— | — | @@ -858,4 +917,4 @@ |
859 | 918 | |
860 | 919 | // Alias $j to jQuery for backwards compatibility |
861 | 920 | window.$j = jQuery; |
862 | | -window.mw = mediaWiki; |
\ No newline at end of file |
| 921 | +window.mw = mediaWiki; |
Index: trunk/phase3/resources/mediawiki.language/mediawiki.language.js |
— | — | @@ -1,8 +1,9 @@ |
2 | 2 | /** |
3 | 3 | * Base language object |
4 | 4 | * |
5 | | - * Localized Language support attempts to mirror some of the functionality of Language.php in MediaWiki. This object |
6 | | - * contains methods for loading and transforming message text. |
| 5 | + * Localized Language support attempts to mirror some of the functionality of |
| 6 | + * Language.php in MediaWiki. This object contains methods for loading and |
| 7 | + * transforming message text. |
7 | 8 | */ |
8 | 9 | |
9 | 10 | mediaWiki.language = { |
Index: trunk/phase3/resources/mediawiki.advanced/mediawiki.advanced.rightclickedit.js |
— | — | @@ -4,8 +4,13 @@ |
5 | 5 | $( function() { |
6 | 6 | |
7 | 7 | // Select all h1-h6 elements that contain editsection links |
8 | | - $('h1:has(.editsection a), h2:has(.editsection a), h3:has(.editsection a), h4:has(.editsection a), h5:has(.editsection a), h6:has(.editsection a)').live( 'contextmenu', function( e ) { |
9 | | - |
| 8 | + $('h1:has(.editsection a), ' + |
| 9 | + 'h2:has(.editsection a), ' + |
| 10 | + 'h3:has(.editsection a), ' + |
| 11 | + 'h4:has(.editsection a), ' + |
| 12 | + 'h5:has(.editsection a), ' + |
| 13 | + 'h6:has(.editsection a)' |
| 14 | + ).live( 'contextmenu', function( e ) { |
10 | 15 | // Get href of the [edit] link |
11 | 16 | var href = $(this).find( '.editsection a' ).attr( 'href' ); |
12 | 17 | |
— | — | @@ -19,4 +24,4 @@ |
20 | 25 | |
21 | 26 | }); |
22 | 27 | |
23 | | -}); |
\ No newline at end of file |
| 28 | +}); |
Index: trunk/phase3/resources/startup.js |
— | — | @@ -1,11 +1,13 @@ |
2 | 2 | /** |
3 | | - * This script provides a function which is run to evaluate whether or not to continue loading the jquery and mediawiki |
4 | | - * modules. This code should work on even the most ancient of browsers, so be very careful when editing. |
| 3 | + * This script provides a function which is run to evaluate whether or not to |
| 4 | + * continue loading the jquery and mediawiki modules. This code should work on |
| 5 | + * even the most ancient of browsers, so be very careful when editing. |
5 | 6 | */ |
6 | 7 | /** |
7 | 8 | * Returns false when run in a black-listed browser |
8 | 9 | * |
9 | | - * This function will be deleted after it's used, so do not expand it to be generally useful beyond startup |
| 10 | + * This function will be deleted after it's used, so do not expand it to be |
| 11 | + * generally useful beyond startup |
10 | 12 | * |
11 | 13 | * jQuery has minimum requirements of: |
12 | 14 | * * Firefox 2.0+ |
— | — | @@ -16,7 +18,9 @@ |
17 | 19 | */ |
18 | 20 | var isCompatible = function() { |
19 | 21 | // IE < 6 |
20 | | - if ( navigator.appVersion.indexOf( 'MSIE' ) !== -1 && parseFloat( navigator.appVersion.split( 'MSIE' )[1] ) < 6 ) { |
| 22 | + if ( navigator.appVersion.indexOf( 'MSIE' ) !== -1 |
| 23 | + && parseFloat( navigator.appVersion.split( 'MSIE' )[1] ) < 6 ) |
| 24 | + { |
21 | 25 | return false; |
22 | 26 | } |
23 | 27 | // TODO: Firefox < 2 |