r62341 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62340‎ | r62341 | r62342 >
Date:23:16, 11 February 2010
Author:tparscal
Status:ok (Comments)
Tags:
Comment:
Finished the per-module isSupported system.
Modified paths:
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -72,7 +72,7 @@
7373 array( 'src' => 'js/plugins/jquery.namespaceSelect.js', 'version' => 1 ),
7474 array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 7 ),
7575 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 27 ),
76 - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 122 ),
 76+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 123 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 29 ),
7878 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 48 ),
7979 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 12 ),
@@ -82,10 +82,10 @@
8383 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 2 ),
8484 ),
8585 'combined' => array(
86 - array( 'src' => 'js/plugins.combined.js', 'version' => 242 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 243 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 242 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 243 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -78,17 +78,32 @@
7979 * "open-web" way to go.
8080 */
8181 'isSupported': function( module ) {
82 - var map = module && typeof $.wikiEditor.modules[module].browsers !== 'undefined' ?
83 - $.wikiEditor.modules[module].browsers :
84 - $.wikiEditor.browsers;
85 - // Check for and make use of a cached return value
86 - if ( typeof $.wikiEditor.supported != 'undefined' ) {
87 - return $.wikiEditor.supported;
 82+ // Check for and make use of cached value and early opportunities to bail
 83+ if ( module ) {
 84+ // If the module doesn't exist, it's clearly not supported
 85+ if ( !( module in $.wikiEditor.modules ) ) {
 86+ return false;
 87+ } else if ( typeof $.wikiEditor.modules[module].supported !== 'undefined' ) {
 88+ // Cache hit
 89+ return $.wikiEditor.modules[module].supported;
 90+ }
 91+ } else if ( typeof $.wikiEditor.modules[module] !== 'undefined' ) {
 92+ if ( typeof $.wikiEditor.supported !== 'undefined' ) {
 93+ // Cache hit
 94+ return $.wikiEditor.supported;
 95+ }
8896 }
 97+ // Provide quick way to cache support
 98+ function cacheSupport( value ) {
 99+ return module ? $.wikiEditor.modules[module].supported = value : $.wikiEditor.supported = value;
 100+ }
 101+ // Fallback to the wikiEditor browser map if no special map is provided in the module
 102+ var map = module && 'browsers' in $.wikiEditor.modules[module] ?
 103+ $.wikiEditor.modules[module].browsers : $.wikiEditor.browsers;
89104 // Check if we have any compatiblity information on-hand for the current browser
90105 if ( !( $.browser.name in map[$( 'body' ).is( '.rtl' ) ? 'rtl' : 'ltr'] ) ) {
91106 // Assume good faith :)
92 - return $.wikiEditor.supported = true;
 107+ return cacheSupport( true );
93108 }
94109 // Check over each browser condition to determine if we are running in a compatible client
95110 var browser = map[$( 'body' ).is( '.rtl' ) ? 'rtl' : 'ltr'][$.browser.name];
@@ -97,16 +112,16 @@
98113 var val = browser[condition][1];
99114 if ( typeof val == 'string' ) {
100115 if ( !( eval( '$.browser.version' + op + '"' + val + '"' ) ) ) {
101 - return $.wikiEditor.supported = false;
 116+ return cacheSupport( false );
102117 }
103118 } else if ( typeof val == 'number' ) {
104119 if ( !( eval( '$.browser.versionNumber' + op + val ) ) ) {
105 - return $.wikiEditor.supported = false;
 120+ return cacheSupport( false );
106121 }
107122 }
108123 }
109124 // Return and also cache the return value - this will be checked somewhat often
110 - return $.wikiEditor.supported = true;
 125+ return cacheSupport( true );
111126 },
112127 /**
113128 * Provides a way to extract messages from objects. Wraps the mw.usability.getMsg() function, which
@@ -239,8 +254,8 @@
240255 modules = data;
241256 }
242257 for ( var module in modules ) {
243 - // Check for the existance of an available module with a matching name and a create function
244 - if ( typeof module == 'string' && module in $.wikiEditor.modules ) {
 258+ // Check for the existance of an available / supported module with a matching name and a create function
 259+ if ( typeof module == 'string' && $.wikiEditor.isSupported( module ) ) {
245260 // Extend the context's core API with this module's own API calls
246261 if ( 'api' in $.wikiEditor.modules[module] ) {
247262 for ( var call in $.wikiEditor.modules[module].api ) {
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -6511,17 +6511,32 @@
65126512 * "open-web" way to go.
65136513 */
65146514 'isSupported': function( module ) {
6515 - var map = module && typeof $.wikiEditor.modules[module].browsers !== 'undefined' ?
6516 - $.wikiEditor.modules[module].browsers :
6517 - $.wikiEditor.browsers;
6518 - // Check for and make use of a cached return value
6519 - if ( typeof $.wikiEditor.supported != 'undefined' ) {
6520 - return $.wikiEditor.supported;
 6515+ // Check for and make use of cached value and early opportunities to bail
 6516+ if ( module ) {
 6517+ // If the module doesn't exist, it's clearly not supported
 6518+ if ( !( module in $.wikiEditor.modules ) ) {
 6519+ return false;
 6520+ } else if ( typeof $.wikiEditor.modules[module].supported !== 'undefined' ) {
 6521+ // Cache hit
 6522+ return $.wikiEditor.modules[module].supported;
 6523+ }
 6524+ } else if ( typeof $.wikiEditor.modules[module] !== 'undefined' ) {
 6525+ if ( typeof $.wikiEditor.supported !== 'undefined' ) {
 6526+ // Cache hit
 6527+ return $.wikiEditor.supported;
 6528+ }
65216529 }
 6530+ // Provide quick way to cache support
 6531+ function cacheSupport( value ) {
 6532+ return module ? $.wikiEditor.modules[module].supported = value : $.wikiEditor.supported = value;
 6533+ }
 6534+ // Fallback to the wikiEditor browser map if no special map is provided in the module
 6535+ var map = module && 'browsers' in $.wikiEditor.modules[module] ?
 6536+ $.wikiEditor.modules[module].browsers : $.wikiEditor.browsers;
65226537 // Check if we have any compatiblity information on-hand for the current browser
65236538 if ( !( $.browser.name in map[$( 'body' ).is( '.rtl' ) ? 'rtl' : 'ltr'] ) ) {
65246539 // Assume good faith :)
6525 - return $.wikiEditor.supported = true;
 6540+ return cacheSupport( true );
65266541 }
65276542 // Check over each browser condition to determine if we are running in a compatible client
65286543 var browser = map[$( 'body' ).is( '.rtl' ) ? 'rtl' : 'ltr'][$.browser.name];
@@ -6530,16 +6545,16 @@
65316546 var val = browser[condition][1];
65326547 if ( typeof val == 'string' ) {
65336548 if ( !( eval( '$.browser.version' + op + '"' + val + '"' ) ) ) {
6534 - return $.wikiEditor.supported = false;
 6549+ return cacheSupport( false );
65356550 }
65366551 } else if ( typeof val == 'number' ) {
65376552 if ( !( eval( '$.browser.versionNumber' + op + val ) ) ) {
6538 - return $.wikiEditor.supported = false;
 6553+ return cacheSupport( false );
65396554 }
65406555 }
65416556 }
65426557 // Return and also cache the return value - this will be checked somewhat often
6543 - return $.wikiEditor.supported = true;
 6558+ return cacheSupport( true );
65446559 },
65456560 /**
65466561 * Provides a way to extract messages from objects. Wraps the mw.usability.getMsg() function, which
@@ -6672,8 +6687,8 @@
66736688 modules = data;
66746689 }
66756690 for ( var module in modules ) {
6676 - // Check for the existance of an available module with a matching name and a create function
6677 - if ( typeof module == 'string' && module in $.wikiEditor.modules ) {
 6691+ // Check for the existance of an available / supported module with a matching name and a create function
 6692+ if ( typeof module == 'string' && $.wikiEditor.isSupported( module ) ) {
66786693 // Extend the context's core API with this module's own API calls
66796694 if ( 'api' in $.wikiEditor.modules[module] ) {
66806695 for ( var call in $.wikiEditor.modules[module].api ) {
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -436,14 +436,15 @@
437437 options.endContainer=options.startContainer;break;case'scrollToCaretPosition':options=$.extend({'force':false},options);break;}
438438 var context=$(this).data('wikiEditor-context');var hasIframe=context!==undefined&&context.$iframe!==undefined;var needSave=false;if(hasIframe&&context.savedSelection!==null){context.fn.restoreSelection();needSave=true;}
439439 retval=(hasIframe?context.fn:fn)[command].call(this,options);if(hasIframe&&needSave){context.fn.saveSelection();}
440 -return retval;};})(jQuery);(function($){$.wikiEditor={'modules':{},'instances':[],'browsers':{'ltr':{'msie':[['>=',7]],'firefox':[['>=',2],['!=','2.0'],['!=','2.0.0.1'],['!=','2.0.0.2'],['!=','2.0.0.3'],['!=','2.0.0.4']],'opera':[['>=',9.6]],'safari':[['>=',4]]},'rtl':{'msie':[['>=',8]],'firefox':[['>=',2],['!=','2.0'],['!=','2.0.0.1'],['!=','2.0.0.2'],['!=','2.0.0.3'],['!=','2.0.0.4']],'opera':[['>=',9.6]],'safari':[['>=',4]]}},'imgPath':wgScriptPath+'/extensions/UsabilityInitiative/images/wikiEditor/','isSupported':function(module){var map=module&&typeof $.wikiEditor.modules[module].browsers!=='undefined'?$.wikiEditor.modules[module].browsers:$.wikiEditor.browsers;if(typeof $.wikiEditor.supported!='undefined'){return $.wikiEditor.supported;}
441 -if(!($.browser.name in map[$('body').is('.rtl')?'rtl':'ltr'])){return $.wikiEditor.supported=true;}
442 -var browser=map[$('body').is('.rtl')?'rtl':'ltr'][$.browser.name];for(var condition in browser){var op=browser[condition][0];var val=browser[condition][1];if(typeof val=='string'){if(!(eval('$.browser.version'+op+'"'+val+'"'))){return $.wikiEditor.supported=false;}}else if(typeof val=='number'){if(!(eval('$.browser.versionNumber'+op+val))){return $.wikiEditor.supported=false;}}}
443 -return $.wikiEditor.supported=true;},'autoMsg':function(object,property){if(typeof property=='object'){for(var i in property){if(property[i]in object||property[i]+'Msg'in object){property=property[i];break;}}}
 440+return retval;};})(jQuery);(function($){$.wikiEditor={'modules':{},'instances':[],'browsers':{'ltr':{'msie':[['>=',7]],'firefox':[['>=',2],['!=','2.0'],['!=','2.0.0.1'],['!=','2.0.0.2'],['!=','2.0.0.3'],['!=','2.0.0.4']],'opera':[['>=',9.6]],'safari':[['>=',4]]},'rtl':{'msie':[['>=',8]],'firefox':[['>=',2],['!=','2.0'],['!=','2.0.0.1'],['!=','2.0.0.2'],['!=','2.0.0.3'],['!=','2.0.0.4']],'opera':[['>=',9.6]],'safari':[['>=',4]]}},'imgPath':wgScriptPath+'/extensions/UsabilityInitiative/images/wikiEditor/','isSupported':function(module){if(module){if(!(module in $.wikiEditor.modules)){return false;}else if(typeof $.wikiEditor.modules[module].supported!=='undefined'){return $.wikiEditor.modules[module].supported;}}else if(typeof $.wikiEditor.modules[module]!=='undefined'){if(typeof $.wikiEditor.supported!=='undefined'){return $.wikiEditor.supported;}}
 441+function cacheSupport(value){return module?$.wikiEditor.modules[module].supported=value:$.wikiEditor.supported=value;}
 442+var map=module&&'browsers'in $.wikiEditor.modules[module]?$.wikiEditor.modules[module].browsers:$.wikiEditor.browsers;if(!($.browser.name in map[$('body').is('.rtl')?'rtl':'ltr'])){return cacheSupport(true);}
 443+var browser=map[$('body').is('.rtl')?'rtl':'ltr'][$.browser.name];for(var condition in browser){var op=browser[condition][0];var val=browser[condition][1];if(typeof val=='string'){if(!(eval('$.browser.version'+op+'"'+val+'"'))){return cacheSupport(false);}}else if(typeof val=='number'){if(!(eval('$.browser.versionNumber'+op+val))){return cacheSupport(false);}}}
 444+return cacheSupport(true);},'autoMsg':function(object,property){if(typeof property=='object'){for(var i in property){if(property[i]in object||property[i]+'Msg'in object){property=property[i];break;}}}
444445 if(property in object){return object[property];}else if(property+'Msg'in object){if(typeof object[property+'Msg']=='object'){return mw.usability.getMsg.apply(mw.usability,object[property+'Msg']);}else{return mw.usability.getMsg(object[property+'Msg']);}}else{return'';}},'autoLang':function(object,lang){return object[lang||wgUserLanguage]||object['default']||object;},'autoIcon':function(icon,path,lang){var src=$.wikiEditor.autoLang(icon,lang);path=path||$.wikiEditor.imgPath;if(src.substr(0,7)!='http://'&&src.substr(0,8)!='https://'&&src[0]!='/'){src=path+src;}
445446 return src+'?'+wgWikiEditorIconVersion;}};$.fn.wikiEditor=function(){if(!$j.wikiEditor.isSupported()){return $(this);}
446447 var context=$(this).data('wikiEditor-context');if(typeof context=='undefined'){context={'$textarea':$(this),'views':{},'modules':{},'data':{},'instance':$.wikiEditor.instances.push($(this))-1,'offsets':null,'htmlToTextMap':{},'oldHTML':null,'oldDelayedHTML':null,'savedSelection':null,'history':[],'historyPosition':-1};context.api={'addModule':function(context,data){var modules={};if(typeof data=='string'){modules[data]={};}else if(typeof data=='object'){modules=data;}
447 -for(var module in modules){if(typeof module=='string'&&module in $.wikiEditor.modules){if('api'in $.wikiEditor.modules[module]){for(var call in $.wikiEditor.modules[module].api){if(!(call in context.api)){context.api[call]=$.wikiEditor.modules[module].api[call];}}}
 448+for(var module in modules){if(typeof module=='string'&&$.wikiEditor.isSupported(module)){if('api'in $.wikiEditor.modules[module]){for(var call in $.wikiEditor.modules[module].api){if(!(call in context.api)){context.api[call]=$.wikiEditor.modules[module].api[call];}}}
448449 if('fn'in $.wikiEditor.modules[module]&&'create'in $.wikiEditor.modules[module].fn){context.modules[module]={};$.wikiEditor.modules[module].fn.create(context,modules[module]);}}}}};context.evt={'keydown':function(event){switch(event.which){case 90:if((event.ctrlKey||event.metaKey)&&context.history.length){if(event.shiftKey){context.historyPosition++;}else{context.historyPosition--;}
449450 if(context.history.length+context.historyPosition>=0&&context.historyPosition<0){context.$content.html(context.history[context.history.length+context.historyPosition].html);}else{context.historyPosition=Math.max(-context.history.length,Math.min(context.historyPosition,-1));}
450451 return false;}

Follow-up revisions

RevisionCommit summaryAuthorDate
r62371Cleaned up some messy code from r62341.tparscal17:47, 12 February 2010
r62400wmf-deployment: Merge r62341, r62371 from trunkcatrope00:00, 13 February 2010

Comments

#Comment by Catrope (talk | contribs)   14:01, 12 February 2010
+		if ( module ) {
...
+		} else if ( typeof $.wikiEditor.modules[module] !== 'undefined' ) {

This looks wrong: if module evaluates to false, what are the chances that module is gonna be a key in $.wikiEditor.modules? Also, this fragment of code is very inconsistent in that it uses typeof foo.bar !== 'undefined' on one line and 'bar' in foo on the next.


Status & tagging log