Index: trunk/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -4,10 +4,10 @@ |
5 | 5 | |
6 | 6 | jQuery.extend({ |
7 | 7 | trimLeft : function( str ) { |
8 | | - return str == null ? '' : str.toString().replace( /^\s+/, '' ); |
| 8 | + return str === null ? '' : str.toString().replace( /^\s+/, '' ); |
9 | 9 | }, |
10 | 10 | trimRight : function( str ) { |
11 | | - return str == null ? |
| 11 | + return str === null ? |
12 | 12 | '' : str.toString().replace( /\s+$/, '' ); |
13 | 13 | }, |
14 | 14 | ucFirst : function( str ) { |
— | — | @@ -300,7 +300,7 @@ |
301 | 301 | Message.prototype.escaped = function() { |
302 | 302 | this.format = 'escaped'; |
303 | 303 | return this.toString(); |
304 | | - } |
| 304 | + }; |
305 | 305 | |
306 | 306 | /** |
307 | 307 | * Checks if message exists |
— | — | @@ -376,7 +376,7 @@ |
377 | 377 | */ |
378 | 378 | this.sessionId = function () { |
379 | 379 | var sessionId = $.cookie( 'mediaWiki.user.sessionId' ); |
380 | | - if ( typeof sessionId == 'undefined' || sessionId == null ) { |
| 380 | + if ( typeof sessionId == 'undefined' || sessionId === null ) { |
381 | 381 | sessionId = generateId(); |
382 | 382 | $.cookie( 'mediaWiki.user.sessionId', sessionId, { 'expires': null, 'path': '/' } ); |
383 | 383 | } |
— | — | @@ -402,7 +402,7 @@ |
403 | 403 | return name; |
404 | 404 | } |
405 | 405 | var id = $.cookie( 'mediaWiki.user.id' ); |
406 | | - if ( typeof id == 'undefined' || id == null ) { |
| 406 | + if ( typeof id == 'undefined' || id === null ) { |
407 | 407 | id = generateId(); |
408 | 408 | } |
409 | 409 | // Set cookie if not set, or renew it if already set |
— | — | @@ -489,16 +489,16 @@ |
490 | 490 | * mediawiki. |
491 | 491 | * |
492 | 492 | * Format: |
493 | | - * { |
494 | | - * 'moduleName': { |
495 | | - * 'dependencies': ['required module', 'required module', ...], (or) function() {} |
496 | | - * 'state': 'registered', 'loading', 'loaded', 'ready', or 'error' |
497 | | - * 'script': function() {}, |
498 | | - * 'style': 'css code string', |
499 | | - * 'messages': { 'key': 'value' }, |
500 | | - * 'version': ############## (unix timestamp) |
501 | | - * } |
502 | | - * } |
| 493 | + * { |
| 494 | + * 'moduleName': { |
| 495 | + * 'dependencies': ['required module', 'required module', ...], (or) function() {} |
| 496 | + * 'state': 'registered', 'loading', 'loaded', 'ready', or 'error' |
| 497 | + * 'script': function() {}, |
| 498 | + * 'style': 'css code string', |
| 499 | + * 'messages': { 'key': 'value' }, |
| 500 | + * 'version': ############## (unix timestamp) |
| 501 | + * } |
| 502 | + * } |
503 | 503 | */ |
504 | 504 | var registry = {}; |
505 | 505 | // List of modules which will be loaded as when ready |
— | — | @@ -556,7 +556,7 @@ |
557 | 557 | throw new Error( 'Unknown dependency: ' + module ); |
558 | 558 | } |
559 | 559 | // Resolves dynamic loader function and replaces it with its own results |
560 | | - if ( typeof registry[module].dependencies === 'function' ) { |
| 560 | + if ( $.isFunction( registry[module].dependencies ) ) { |
561 | 561 | registry[module].dependencies = registry[module].dependencies(); |
562 | 562 | // Ensures the module's dependencies are always in an array |
563 | 563 | if ( typeof registry[module].dependencies !== 'object' ) { |
— | — | @@ -625,7 +625,7 @@ |
626 | 626 | states = [states]; |
627 | 627 | } |
628 | 628 | // If called without a list of modules, build and use a list of all modules |
629 | | - var list = []; |
| 629 | + var list = [], module; |
630 | 630 | if ( typeof modules === 'undefined' ) { |
631 | 631 | modules = []; |
632 | 632 | for ( module in registry ) { |
— | — | @@ -659,6 +659,7 @@ |
660 | 660 | * @param module string module name to execute |
661 | 661 | */ |
662 | 662 | function execute( module ) { |
| 663 | + var _method = 'mw.loader::execute'; |
663 | 664 | if ( typeof registry[module] === 'undefined' ) { |
664 | 665 | throw new Error( 'Module has not been registered yet: ' + module ); |
665 | 666 | } else if ( registry[module].state === 'registered' ) { |
— | — | @@ -675,7 +676,7 @@ |
676 | 677 | new mediaWiki.html.Cdata( registry[module].style ) |
677 | 678 | ) ); |
678 | 679 | } else if ( typeof registry[module].style === 'object' |
679 | | - && !( registry[module].style instanceof Array ) ) |
| 680 | + && !( $.isArray( registry[module].style ) ) ) |
680 | 681 | { |
681 | 682 | for ( var media in registry[module].style ) { |
682 | 683 | $marker.before( mediaWiki.html.element( 'style', |
— | — | @@ -691,6 +692,7 @@ |
692 | 693 | // Execute script |
693 | 694 | try { |
694 | 695 | registry[module].script( jQuery ); |
| 696 | + mw.log( 'State ready: ' + module, _method ) |
695 | 697 | registry[module].state = 'ready'; |
696 | 698 | // Run jobs who's dependencies have just been met |
697 | 699 | for ( var j = 0; j < jobs.length; j++ ) { |
— | — | @@ -698,7 +700,7 @@ |
699 | 701 | filter( 'ready', jobs[j].dependencies ), |
700 | 702 | jobs[j].dependencies ) ) |
701 | 703 | { |
702 | | - if ( typeof jobs[j].ready === 'function' ) { |
| 704 | + if ( $.isFunction( jobs[j].ready ) ) { |
703 | 705 | jobs[j].ready(); |
704 | 706 | } |
705 | 707 | jobs.splice( j, 1 ); |
— | — | @@ -706,7 +708,7 @@ |
707 | 709 | } |
708 | 710 | } |
709 | 711 | // Execute modules who's dependencies have just been met |
710 | | - for ( r in registry ) { |
| 712 | + for ( var r in registry ) { |
711 | 713 | if ( registry[r].state == 'loaded' ) { |
712 | 714 | if ( compare( |
713 | 715 | filter( ['ready'], registry[r].dependencies ), |
— | — | @@ -717,13 +719,13 @@ |
718 | 720 | } |
719 | 721 | } |
720 | 722 | } catch ( e ) { |
721 | | - mediaWiki.log( 'Exception thrown by ' + module + ': ' + e.message ); |
| 723 | + mediaWiki.log( 'Exception thrown by ' + module + ': ' + e.message, _method ); |
722 | 724 | mediaWiki.log( e ); |
723 | 725 | registry[module].state = 'error'; |
724 | 726 | // Run error callbacks of jobs affected by this condition |
725 | 727 | for ( var j = 0; j < jobs.length; j++ ) { |
726 | 728 | if ( $.inArray( module, jobs[j].dependencies ) !== -1 ) { |
727 | | - if ( typeof jobs[j].error === 'function' ) { |
| 729 | + if ( $.isFunction( jobs[j].error ) ) { |
728 | 730 | jobs[j].error(); |
729 | 731 | } |
730 | 732 | jobs.splice( j, 1 ); |
— | — | @@ -863,7 +865,7 @@ |
864 | 866 | } |
865 | 867 | // Load asynchronously after documument ready |
866 | 868 | if ( ready ) { |
867 | | - setTimeout( function() { $( 'body' ).append( request() ); }, 0 ) |
| 869 | + setTimeout( function() { $( 'body' ).append( request() ); }, 0 ); |
868 | 870 | } else { |
869 | 871 | document.write( request() ); |
870 | 872 | } |
— | — | @@ -898,12 +900,12 @@ |
899 | 901 | 'state': 'registered', |
900 | 902 | 'group': typeof group === 'string' ? group : null, |
901 | 903 | 'dependencies': [], |
902 | | - 'version': typeof version !== 'undefined' ? parseInt( version ) : 0 |
| 904 | + 'version': typeof version !== 'undefined' ? parseInt( version, 10 ) : 0 |
903 | 905 | }; |
904 | 906 | if ( typeof dependencies === 'string' ) { |
905 | 907 | // Allow dependencies to be given as a single module name |
906 | 908 | registry[module].dependencies = [dependencies]; |
907 | | - } else if ( typeof dependencies === 'object' || typeof dependencies === 'function' ) { |
| 909 | + } else if ( typeof dependencies === 'object' || $.isFunction( dependencies ) ) { |
908 | 910 | // Allow dependencies to be given as an array of module names |
909 | 911 | // or a function which returns an array |
910 | 912 | registry[module].dependencies = dependencies; |
— | — | @@ -921,7 +923,7 @@ |
922 | 924 | mediaWiki.loader.register( module ); |
923 | 925 | } |
924 | 926 | // Validate input |
925 | | - if ( typeof script !== 'function' ) { |
| 927 | + if ( !$.isFunction( script ) ) { |
926 | 928 | throw new Error( 'script must be a function, not a ' + typeof script ); |
927 | 929 | } |
928 | 930 | if ( typeof style !== 'undefined' |
— | — | @@ -976,7 +978,7 @@ |
977 | 979 | // Validate input |
978 | 980 | if ( typeof dependencies !== 'object' && typeof dependencies !== 'string' ) { |
979 | 981 | throw new Error( 'dependencies must be a string or an array, not a ' + |
980 | | - typeof dependencies ) |
| 982 | + typeof dependencies ); |
981 | 983 | } |
982 | 984 | // Allow calling with a single dependency as a string |
983 | 985 | if ( typeof dependencies === 'string' ) { |
— | — | @@ -986,13 +988,13 @@ |
987 | 989 | dependencies = resolve( dependencies ); |
988 | 990 | // If all dependencies are met, execute ready immediately |
989 | 991 | if ( compare( filter( ['ready'], dependencies ), dependencies ) ) { |
990 | | - if ( typeof ready === 'function' ) { |
| 992 | + if ( $.isFunction( ready ) ) { |
991 | 993 | ready(); |
992 | 994 | } |
993 | 995 | } |
994 | 996 | // If any dependencies have errors execute error immediately |
995 | 997 | else if ( filter( ['error'], dependencies ).length ) { |
996 | | - if ( typeof error === 'function' ) { |
| 998 | + if ( $.isFunction( error ) ) { |
997 | 999 | error(); |
998 | 1000 | } |
999 | 1001 | } |
— | — | @@ -1016,7 +1018,7 @@ |
1017 | 1019 | // Validate input |
1018 | 1020 | if ( typeof modules !== 'object' && typeof modules !== 'string' ) { |
1019 | 1021 | throw new Error( 'modules must be a string or an array, not a ' + |
1020 | | - typeof modules ) |
| 1022 | + typeof modules ); |
1021 | 1023 | } |
1022 | 1024 | // Allow calling with an external script or single dependency as a string |
1023 | 1025 | if ( typeof modules === 'string' ) { |
— | — | @@ -1205,7 +1207,7 @@ |
1206 | 1208 | |
1207 | 1209 | /* Auto-register from pre-loaded startup scripts */ |
1208 | 1210 | |
1209 | | -if ( typeof startUp === 'function' ) { |
| 1211 | +if ( $.isFunction( startUp ) ) { |
1210 | 1212 | startUp(); |
1211 | 1213 | delete startUp; |
1212 | 1214 | } |
Index: trunk/phase3/resources/mediawiki/mediawiki.log.js |
— | — | @@ -15,9 +15,11 @@ |
16 | 16 | * @author Trevor Parscal <tparscal@wikimedia.org> |
17 | 17 | * @param {string} string Message to output to console |
18 | 18 | */ |
19 | | - mw.log = function( string ) { |
| 19 | + mw.log = function( string, prefix ) { |
20 | 20 | // Allow log messages to use a configured prefix |
21 | | - if ( mw.config.exists( 'mw.log.prefix' ) ) { |
| 21 | + if ( typeof prefix == 'string' ) { |
| 22 | + string = prefix + '> ' + string; |
| 23 | + } else if ( mw.config.exists( 'mw.log.prefix' ) ) { |
22 | 24 | string = mw.config.get( 'mw.log.prefix' ) + '> ' + string; |
23 | 25 | } |
24 | 26 | // Try to use an existing console |