r65985 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65984‎ | r65985 | r65986 >
Date:13:22, 6 May 2010
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: Various style fixes for r65913. No functional changes, so no style version bumps.
* Fix comments referring to templateEditor or highlight module
* Add parentheses to a massively-chained statement for readability
* Fix undeclared variables (they get put in the global scope instead)
* Fix behavior for when .markAfter is defined but set to false
* Various typos
* Add FIXME comment about performance issue
Modified paths:
  • /trunk/extensions/UsabilityInitiative/WikiEditor/Modules/Templates/Templates.i18n.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/WikiEditor/Modules/Templates/Templates.js (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.highlight.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templates.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/WikiEditor/Modules/Templates/Templates.i18n.php
@@ -1,6 +1,6 @@
22 <?php
33 /**
4 - * Internationalisation for the Highlight module of the Usability Initiative wikiEditor extension
 4+ * Internationalisation for the Templates module of the Usability Initiative wikiEditor extension
55 *
66 * @file
77 * @ingroup Extensions
Index: trunk/extensions/UsabilityInitiative/WikiEditor/Modules/Templates/Templates.js
@@ -1,7 +1,7 @@
22 /* JavaScript for WikiEditor Templates module */
33
44 $j(document).ready( function() {
5 - // Check preferences for templateEditor
 5+ // Check preferences for templates
66 if ( !wgWikiEditorEnabledModules.templates ) {
77 return true;
88 }
@@ -9,7 +9,7 @@
1010 if ( wgNamespaceNumber == 10 ) {
1111 return true;
1212 }
13 - // Add the templateEditor module
 13+ // Add the templates module
1414 if ( $j.fn.wikiEditor ) {
1515 $j( 'textarea#wpTextbox1' ).wikiEditor( 'addModule', 'templates' );
1616 }
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templates.js
@@ -35,8 +35,8 @@
3636 var tokens = context.modules.highlight.tokenArray;
3737 // Use depth-tracking to extract top-level templates from tokens
3838 var depth = 0, bias, start;
39 - for ( i in tokens ) {
40 - depth += bias = tokens[i].label == 'TEMPLATE_BEGIN' ? 1 : tokens[i].label == 'TEMPLATE_END' ? -1 : 0;
 39+ for ( var i in tokens ) {
 40+ depth += ( bias = tokens[i].label == 'TEMPLATE_BEGIN' ? 1 : ( tokens[i].label == 'TEMPLATE_END' ? -1 : 0 ) );
4141 if ( bias > 0 && depth == 1 ) {
4242 // Top-level opening - use offset as start
4343 start = tokens[i].offset;
@@ -48,7 +48,7 @@
4949 );
5050 }
5151 if ( depth < 0 ) {
52 - depth = 0;
 52+ depth = 0;
5353 }
5454 }
5555 }
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.highlight.js
@@ -50,15 +50,17 @@
5151 // Scan text for new tokens
5252 var text = context.fn.getContents();
5353 // Perform a scan for each module which provides any expressions to scan for
54 - for ( module in context.modules ) {
 54+ // FIXME: This traverses the entire string once for every regex. Investigate
 55+ // whether |-concatenating regexes then traversing once is faster.
 56+ for ( var module in context.modules ) {
5557 if ( module in $.wikiEditor.modules && 'exp' in $.wikiEditor.modules[module] ) {
56 - for ( exp in $.wikiEditor.modules[module].exp ) {
 58+ for ( var exp in $.wikiEditor.modules[module].exp ) {
5759 // Prepare configuration
5860 var regex = $.wikiEditor.modules[module].exp[exp].regex;
5961 var label = $.wikiEditor.modules[module].exp[exp].label;
60 - var markAfter = ( typeof $.wikiEditor.modules[module].exp[exp].markAfter != 'undefined' );
 62+ var markAfter = $.wikiEditor.modules[module].exp[exp].markAfter || false;
6163 // Search for tokens
62 - var offset = 0, left, right;
 64+ var offset = 0, left, right, match;
6365 while ( ( match = text.substr( offset ).match( regex ) ) != null ) {
6466 right = ( left = offset + match.index ) + match[0].length;
6567 tokenArray[tokenArray.length] = {
@@ -75,7 +77,7 @@
7678 }
7779 // Sort by start
7880 tokenArray.sort( function( a, b ) { return a.tokenStart - b.tokenStart; } );
79 - // Let the world know, a scan just happend!
 81+ // Let the world know, a scan just happened!
8082 context.fn.trigger( 'scan' );
8183 },
8284 /**
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -8665,15 +8665,17 @@
86668666 // Scan text for new tokens
86678667 var text = context.fn.getContents();
86688668 // Perform a scan for each module which provides any expressions to scan for
8669 - for ( module in context.modules ) {
 8669+ // FIXME: This traverses the entire string once for every regex. Investigate
 8670+ // whether |-concatenating regexes then traversing once is faster.
 8671+ for ( var module in context.modules ) {
86708672 if ( module in $.wikiEditor.modules && 'exp' in $.wikiEditor.modules[module] ) {
8671 - for ( exp in $.wikiEditor.modules[module].exp ) {
 8673+ for ( var exp in $.wikiEditor.modules[module].exp ) {
86728674 // Prepare configuration
86738675 var regex = $.wikiEditor.modules[module].exp[exp].regex;
86748676 var label = $.wikiEditor.modules[module].exp[exp].label;
8675 - var markAfter = ( typeof $.wikiEditor.modules[module].exp[exp].markAfter != 'undefined' );
 8677+ var markAfter = $.wikiEditor.modules[module].exp[exp].markAfter || false;
86768678 // Search for tokens
8677 - var offset = 0, left, right;
 8679+ var offset = 0, left, right, match;
86788680 while ( ( match = text.substr( offset ).match( regex ) ) != null ) {
86798681 right = ( left = offset + match.index ) + match[0].length;
86808682 tokenArray[tokenArray.length] = {
@@ -8690,7 +8692,7 @@
86918693 }
86928694 // Sort by start
86938695 tokenArray.sort( function( a, b ) { return a.tokenStart - b.tokenStart; } );
8694 - // Let the world know, a scan just happend!
 8696+ // Let the world know, a scan just happened!
86958697 context.fn.trigger( 'scan' );
86968698 },
86978699 /**
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -588,7 +588,7 @@
589589 configuration.newButtons[mw.usability.getMsg(msg)]=configuration.buttons[msg];configuration.buttons=configuration.newButtons;var dialogDiv=$('<div />').attr('id',module.id).html(module.html).data('context',context).appendTo($('body')).each(module.init).dialog(configuration);$.wikiEditor.modules.dialogs.fn.setTabindexes(dialogDiv.closest('.ui-dialog').find('button').not('[tabindex]'));if(!('resizeme'in module)||module.resizeme){dialogDiv.bind('dialogopen',$.wikiEditor.modules.dialogs.fn.resize).find('.ui-tabs').bind('tabsshow',function(){$(this).closest('.ui-dialog-content').each($.wikiEditor.modules.dialogs.fn.resize);});}
590590 dialogDiv.bind('dialogclose',function(){context.fn.restoreSelection();});context.$textarea.trigger('wikiEditor-dialogs-loaded-'+mod);});},resize:function(){var wrapper=$(this).closest('.ui-dialog');var oldWidth=wrapper.width();var oldHidden=$(this).find('*').not(':visible');oldHidden.each(function(){$(this).data('oldstyle',$(this).attr('style'));});oldHidden.show();var oldWS=$(this).css('white-space');$(this).css('white-space','nowrap');if(wrapper.width()<=$(this).get(0).scrollWidth){var thisWidth=$(this).data('thisWidth')?$(this).data('thisWidth'):0;thisWidth=Math.max($(this).get(0).scrollWidth,thisWidth);$(this).width(thisWidth);$(this).data('thisWidth',thisWidth);var wrapperWidth=$(this).data('wrapperWidth')?$(this).data('wrapperWidth'):0;wrapperWidth=Math.max(wrapper.get(0).scrollWidth,wrapperWidth);wrapper.width(wrapperWidth);$(this).data('wrapperWidth',wrapperWidth);$(this).dialog({'width':wrapper.width()});wrapper.css('left',parseInt(wrapper.css('left'))-(wrapper.width()-oldWidth)/2);}
591591 $(this).css('white-space',oldWS);oldHidden.each(function(){$(this).attr('style',$(this).data('oldstyle'));});},setTabindexes:function($elements){var maxTI=0;$j('[tabindex]').each(function(){var ti=parseInt($j(this).attr('tabindex'));if(ti>maxTI)
592 -maxTI=ti;});var tabIndex=maxTI+1;$elements.each(function(){$j(this).attr('tabindex',tabIndex++);});}},modules:{},quickDialog:function(body,settings){$('<div />').text(body).appendTo($('body')).dialog($.extend({bgiframe:true,modal:true},settings)).dialog('open');}};})(jQuery);(function($){$.wikiEditor.modules.highlight={'req':['iframe'],'cfg':{'styleVersion':3},'evt':{'delayedChange':function(context,event){if(event.data.scope=='realchange'){$.wikiEditor.modules.highlight.fn.scan(context);$.wikiEditor.modules.highlight.fn.mark(context,event.data.scope);}},'ready':function(context,event){$.wikiEditor.modules.highlight.fn.scan(context);$.wikiEditor.modules.highlight.fn.mark(context,'ready');}},'fn':{'create':function(context,config){context.modules.highlight.markersStr='';},'scan':function(context,division){var tokenArray=context.modules.highlight.tokenArray=[];var text=context.fn.getContents();for(module in context.modules){if(module in $.wikiEditor.modules&&'exp'in $.wikiEditor.modules[module]){for(exp in $.wikiEditor.modules[module].exp){var regex=$.wikiEditor.modules[module].exp[exp].regex;var label=$.wikiEditor.modules[module].exp[exp].label;var markAfter=(typeof $.wikiEditor.modules[module].exp[exp].markAfter!='undefined');var offset=0,left,right;while((match=text.substr(offset).match(regex))!=null){right=(left=offset+match.index)+match[0].length;tokenArray[tokenArray.length]={'offset':markAfter?right:left,'label':label,'tokenStart':left,'match':match};offset=right;}}}}
 592+maxTI=ti;});var tabIndex=maxTI+1;$elements.each(function(){$j(this).attr('tabindex',tabIndex++);});}},modules:{},quickDialog:function(body,settings){$('<div />').text(body).appendTo($('body')).dialog($.extend({bgiframe:true,modal:true},settings)).dialog('open');}};})(jQuery);(function($){$.wikiEditor.modules.highlight={'req':['iframe'],'cfg':{'styleVersion':3},'evt':{'delayedChange':function(context,event){if(event.data.scope=='realchange'){$.wikiEditor.modules.highlight.fn.scan(context);$.wikiEditor.modules.highlight.fn.mark(context,event.data.scope);}},'ready':function(context,event){$.wikiEditor.modules.highlight.fn.scan(context);$.wikiEditor.modules.highlight.fn.mark(context,'ready');}},'fn':{'create':function(context,config){context.modules.highlight.markersStr='';},'scan':function(context,division){var tokenArray=context.modules.highlight.tokenArray=[];var text=context.fn.getContents();for(var module in context.modules){if(module in $.wikiEditor.modules&&'exp'in $.wikiEditor.modules[module]){for(var exp in $.wikiEditor.modules[module].exp){var regex=$.wikiEditor.modules[module].exp[exp].regex;var label=$.wikiEditor.modules[module].exp[exp].label;var markAfter=$.wikiEditor.modules[module].exp[exp].markAfter||false;var offset=0,left,right,match;while((match=text.substr(offset).match(regex))!=null){right=(left=offset+match.index)+match[0].length;tokenArray[tokenArray.length]={'offset':markAfter?right:left,'label':label,'tokenStart':left,'match':match};offset=right;}}}}
593593 tokenArray.sort(function(a,b){return a.tokenStart-b.tokenStart;});context.fn.trigger('scan');},'mark':function(context,division,tokens){var markers=[];if(context.modules.highlight.markers&&division!=''){for(var i=0;i<context.modules.highlight.markers.length;i++){if(context.modules.highlight.markers[i].skipDivision==division){markers.push(context.modules.highlight.markers[i]);}}}
594594 context.modules.highlight.markers=markers;context.fn.trigger('mark');markers.sort(function(a,b){return a.start-b.start||a.end-b.end;});var markersStr='';for(var i=0;i<markers.length;i++){markersStr+=markers[i].start+','+markers[i].end+','+markers[i].type+',';}
595595 if(context.modules.highlight.markersStr==markersStr){return;}

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r65913Added templates module to WikiEditor. Also, rewrote the highligh module's sca...tparscal19:10, 4 May 2010

Status & tagging log