r60121 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60120‎ | r60121 | r60122 >
Date:12:25, 16 December 2009
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: Make template wrapping work again, broken by recent commits. Still some issues to work out
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.highlight.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -72,19 +72,19 @@
7373 array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 6 ),
7474 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 21 ),
7575 array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 36 ),
76 - array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 5 ),
 76+ array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 6 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 40 ),
7878 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 10 ),
7979 array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 52 ),
8080 array( 'src' => 'js/plugins/jquery.wikiEditor.preview.js', 'version' => 8 ),
81 - array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 7 ),
 81+ array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 8 ),
8282 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 1 ),
8383 ),
8484 'combined' => array(
85 - array( 'src' => 'js/plugins.combined.js', 'version' => 117 ),
 85+ array( 'src' => 'js/plugins.combined.js', 'version' => 118 ),
8686 ),
8787 'minified' => array(
88 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 117 ),
 88+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 118 ),
8989 ),
9090 ),
9191 );
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -2163,10 +2163,12 @@
21642164 },
21652165 ready: function( context, event ) {
21662166 // Add our CSS to the iframe
 2167+ // Style version for wikiEditor.highlight.css is here
 2168+ // FIXME: That's not ideal
21672169 context.$content.parent().find( 'head' ).append( $j( '<link />' ).attr( {
21682170 'rel': 'stylesheet',
21692171 'type': 'text/css',
2170 - 'href': wgScriptPath + '/extensions/UsabilityInitiative/css/wikiEditor.highlight.css',
 2172+ 'href': wgScriptPath + '/extensions/UsabilityInitiative/css/wikiEditor.highlight.css?0',
21712173 } ) );
21722174 // Highlight stuff for the first time
21732175 $.wikiEditor.modules.highlight.fn.scan( context, "" );
@@ -2653,39 +2655,47 @@
26542656 */
26552657 evt: {
26562658 mark: function( context, event ) {
2657 - // Get refrences to the markers and tokens from the current context
 2659+ // Get references to the markers and tokens from the current context
26582660 var markers = context.modules.highlight.markers;
26592661 var tokenArray = context.modules.highlight.tokenArray;
2660 - // Collect matching level 0 template call boundaries from the tokenArrray
 2662+ // Collect matching level 0 template call boundaries from the tokenArray
26612663 var level = 0;
2662 - var boundaries = [];
2663 - var boundary = 0;
2664 - for ( token in tokenArray ) {
2665 - if ( tokenArray[token].label == 'TEMPLATE_BEGIN' ) {
2666 - if ( level++ == 0 ) {
2667 - boundary = boundaries.push( { 'begin': tokenArray[token].offset } ) - 1;
2668 - }
2669 - } else if ( tokenArray[token].label == 'TEMPLATE_END' ) {
2670 - if ( --level == 0 ) {
2671 - boundaries[boundary].end = tokenArray[token].offset;
2672 - }
 2664+
 2665+ var tokenIndex = 0;
 2666+ while( tokenIndex < tokenArray.length ){
 2667+ while( tokenIndex < tokenArray.length && tokenArray[tokenIndex].label != 'TEMPLATE_BEGIN'){
 2668+ tokenIndex++;
26732669 }
2674 - }
2675 - // Add encapsulations to markers at the offsets of matching sets of level 0 template call boundaries
2676 - for ( boundary in boundaries ) {
2677 - if ( 'begin' in boundaries[boundary] && 'end' in boundaries[boundary] ) {
2678 - // Ensure arrays exist at the begining and ending offsets for boundary
2679 - if ( !( boundaries[boundary].begin in markers ) ) {
2680 - markers[boundaries[boundary].begin] = [];
 2670+ //open template
 2671+ if(tokenIndex < tokenArray.length){
 2672+ var beginIndex = tokenIndex;
 2673+ var endIndex = -1; //no match found
 2674+ var openTemplates = 1;
 2675+ var templatesMatched = false;
 2676+ while(tokenIndex < tokenArray.length && (endIndex == -1) ){
 2677+ tokenIndex++;
 2678+ if(tokenArray[tokenIndex].label == 'TEMPLATE_BEGIN'){
 2679+ openTemplates++;
 2680+ } else if(tokenArray[tokenIndex].label == 'TEMPLATE_END') {
 2681+ openTemplates--;
 2682+ if(openTemplates == 0){
 2683+ endIndex = tokenIndex;
 2684+ } //we can stop looping
 2685+ }
 2686+ }//while finding template ending
 2687+ if(endIndex != -1){
 2688+ markers.push( {
 2689+ start: tokenArray[beginIndex].offset,
 2690+ end: tokenArray[endIndex].offset,
 2691+ wrapElement: function() {
 2692+ return $( '<div />' ).addClass( 'wikiEditor-highlight-template' );
 2693+ }
 2694+ } );
 2695+ } else { //else this was an unmatched opening
 2696+ tokenArray[beginIndex].label = 'TEMPLATE_FALSE_BEGIN';
 2697+ tokenIndex = beginIndex;
26812698 }
2682 - if ( !( boundaries[boundary].end in markers ) ) {
2683 - markers[boundaries[boundary].end] = [];
2684 - }
2685 - // Append boundary markers
2686 - markers[boundaries[boundary].begin].push( "<div class='wiki-template'>" );
2687 - markers[boundaries[boundary].end].push( "</div>" );
2688 -
2689 - }
 2699+ }//if opentemplates
26902700 }
26912701 }
26922702 },
@@ -2707,6 +2717,7 @@
27082718 */
27092719 create: function( context, config ) {
27102720 // Initialize module within the context
 2721+ context.modules.templateEditor = {};
27112722 },
27122723 stylize: function( context ) {
27132724 var $templates = context.$content.find( '.wiki-template' );
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -119,7 +119,7 @@
120120 configuration.newButtons[gM(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);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);});}
121121 var maxTI=0;$j('[tabindex]').each(function(){var ti=parseInt($j(this).attr('tabindex'));if(ti>maxTI)
122122 maxTI=ti;});var tabIndex=maxTI+1;$j('.ui-dialog input, .ui-dialog button').not('[tabindex]').each(function(){$j(this).attr('tabindex',tabIndex++);});}}});},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);}
123 -$(this).css('white-space',oldWS);oldHidden.each(function(){$(this).attr('style',$(this).data('oldstyle'));});}},modules:{},quickDialog:function(body,settings){$('<div />').text(body).appendTo($('body')).dialog($.extend({bgiframe:true,modal:true},settings)).dialog('open');}};})(jQuery);(function($){$.wikiEditor.modules.highlight={evt:{change:function(context,event){if(event.data.scope=='keydown'){$.wikiEditor.modules.highlight.fn.scan(context,"");$.wikiEditor.modules.highlight.fn.mark(context,"","");}},ready:function(context,event){context.$content.parent().find('head').append($j('<link />').attr({'rel':'stylesheet','type':'text/css','href':wgScriptPath+'/extensions/UsabilityInitiative/css/wikiEditor.highlight.css',}));$.wikiEditor.modules.highlight.fn.scan(context,"");$.wikiEditor.modules.highlight.fn.mark(context,"","");}},fn:{create:function(context,config){},divide:function(context){},isolate:function(context){return[];},strip:function(context,division){return $('<div />').html(division.html().replace(/\<br[^\>]*\>/g,"\n")).text();},scan:function(context,division){function Token(offset,label){this.offset=offset;this.label=label;}
 123+$(this).css('white-space',oldWS);oldHidden.each(function(){$(this).attr('style',$(this).data('oldstyle'));});}},modules:{},quickDialog:function(body,settings){$('<div />').text(body).appendTo($('body')).dialog($.extend({bgiframe:true,modal:true},settings)).dialog('open');}};})(jQuery);(function($){$.wikiEditor.modules.highlight={evt:{change:function(context,event){if(event.data.scope=='keydown'){$.wikiEditor.modules.highlight.fn.scan(context,"");$.wikiEditor.modules.highlight.fn.mark(context,"","");}},ready:function(context,event){context.$content.parent().find('head').append($j('<link />').attr({'rel':'stylesheet','type':'text/css','href':wgScriptPath+'/extensions/UsabilityInitiative/css/wikiEditor.highlight.css?0',}));$.wikiEditor.modules.highlight.fn.scan(context,"");$.wikiEditor.modules.highlight.fn.mark(context,"","");}},fn:{create:function(context,config){},divide:function(context){},isolate:function(context){return[];},strip:function(context,division){return $('<div />').html(division.html().replace(/\<br[^\>]*\>/g,"\n")).text();},scan:function(context,division){function Token(offset,label){this.offset=offset;this.label=label;}
124124 var tokenArray=context.modules.highlight.tokenArray=[];var text=context.fn.getContents();for(module in $.wikiEditor.modules){if('exp'in $.wikiEditor.modules[module]){for(var i=0;i<$.wikiEditor.modules[module].exp.length;i++){var regex=$.wikiEditor.modules[module].exp[i].regex;var label=$.wikiEditor.modules[module].exp[i].label;var markAfter=false;if(typeof $.wikiEditor.modules[module].exp[i].markAfter!='undefined'){markAfter=true;}
125125 match=text.match(regex);var oldOffset=0;while(match!=null){var markOffset=0;if(markAfter){markOffset+=match[0].length;}
126126 tokenArray.push(new Token(match.index+oldOffset+markOffset,label));oldOffset+=match.index+match[0].length;newSubstring=text.substring(oldOffset);match=newSubstring.match(regex);}}}}
@@ -169,10 +169,9 @@
170170 $('#wikiEditor-'+context.instance+'-dialog-minor').hide();else if($('#wpMinoredit').is(':checked'))
171171 $('#wikiEditor-'+context.instance+'-dialog-minor').attr('checked','checked');if($('#wpWatchthis').size()==0)
172172 $('#wikiEditor-'+context.instance+'-dialog-watch').hide();else if($('#wpWatchthis').is(':checked'))
173 -$('#wikiEditor-'+context.instance+'-dialog-watch').attr('checked','checked');$(this).find('form').submit(function(e){$(this).closest('.ui-dialog').find('button:first').click();e.preventDefault();});},dialog:{buttons:{'wikieditor-publish-dialog-publish':function(){var minorChecked=$('#wikiEditor-'+context.instance+'-dialog-minor').is(':checked')?'checked':'';var watchChecked=$('#wikiEditor-'+context.instance+'-dialog-watch').is(':checked')?'checked':'';$('#wpMinoredit').attr('checked',minorChecked);$('#wpWatchthis').attr('checked',watchChecked);$('#wpSummary').val($j('#wikiEditor-'+context.instance+'-dialog-summary').val());$('#editform').submit();},'wikieditor-publish-dialog-goback':function(){$(this).dialog('close');}},open:function(){$('#wikiEditor-'+context.instance+'-dialog-summary').focus();},width:500},resizeme:false}});context.fn.addButton({'captionMsg':'wikieditor-publish-button-publish','action':function(){$('#'+dialogID).dialog('open');return false;}});context.fn.addButton({'captionMsg':'wikieditor-publish-button-cancel','action':function(){}});}}};})(jQuery);(function($){$.wikiEditor.modules.templateEditor={evt:{mark:function(context,event){var markers=context.modules.highlight.markers;var tokenArray=context.modules.highlight.tokenArray;var level=0;var boundaries=[];var boundary=0;for(token in tokenArray){if(tokenArray[token].label=='TEMPLATE_BEGIN'){if(level++==0){boundary=boundaries.push({'begin':tokenArray[token].offset})-1;}}else if(tokenArray[token].label=='TEMPLATE_END'){if(--level==0){boundaries[boundary].end=tokenArray[token].offset;}}}
174 -for(boundary in boundaries){if('begin'in boundaries[boundary]&&'end'in boundaries[boundary]){if(!(boundaries[boundary].begin in markers)){markers[boundaries[boundary].begin]=[];}
175 -if(!(boundaries[boundary].end in markers)){markers[boundaries[boundary].end]=[];}
176 -markers[boundaries[boundary].begin].push("<div class='wiki-template'>");markers[boundaries[boundary].end].push("</div>");}}}},exp:[{'regex':/{{/,'label':"TEMPLATE_BEGIN"},{'regex':/}}/,'label':"TEMPLATE_END",'markAfter':true}],fn:{create:function(context,config){},stylize:function(context){var $templates=context.$content.find('.wiki-template');$templates.each(function(){if(typeof $(this).data('model')!='undefined'){return;}
 173+$('#wikiEditor-'+context.instance+'-dialog-watch').attr('checked','checked');$(this).find('form').submit(function(e){$(this).closest('.ui-dialog').find('button:first').click();e.preventDefault();});},dialog:{buttons:{'wikieditor-publish-dialog-publish':function(){var minorChecked=$('#wikiEditor-'+context.instance+'-dialog-minor').is(':checked')?'checked':'';var watchChecked=$('#wikiEditor-'+context.instance+'-dialog-watch').is(':checked')?'checked':'';$('#wpMinoredit').attr('checked',minorChecked);$('#wpWatchthis').attr('checked',watchChecked);$('#wpSummary').val($j('#wikiEditor-'+context.instance+'-dialog-summary').val());$('#editform').submit();},'wikieditor-publish-dialog-goback':function(){$(this).dialog('close');}},open:function(){$('#wikiEditor-'+context.instance+'-dialog-summary').focus();},width:500},resizeme:false}});context.fn.addButton({'captionMsg':'wikieditor-publish-button-publish','action':function(){$('#'+dialogID).dialog('open');return false;}});context.fn.addButton({'captionMsg':'wikieditor-publish-button-cancel','action':function(){}});}}};})(jQuery);(function($){$.wikiEditor.modules.templateEditor={evt:{mark:function(context,event){var markers=context.modules.highlight.markers;var tokenArray=context.modules.highlight.tokenArray;var level=0;var tokenIndex=0;while(tokenIndex<tokenArray.length){while(tokenIndex<tokenArray.length&&tokenArray[tokenIndex].label!='TEMPLATE_BEGIN'){tokenIndex++;}
 174+if(tokenIndex<tokenArray.length){var beginIndex=tokenIndex;var endIndex=-1;var openTemplates=1;var templatesMatched=false;while(tokenIndex<tokenArray.length&&(endIndex==-1)){tokenIndex++;if(tokenArray[tokenIndex].label=='TEMPLATE_BEGIN'){openTemplates++;}else if(tokenArray[tokenIndex].label=='TEMPLATE_END'){openTemplates--;if(openTemplates==0){endIndex=tokenIndex;}}}
 175+if(endIndex!=-1){markers.push({start:tokenArray[beginIndex].offset,end:tokenArray[endIndex].offset,wrapElement:function(){return $('<div />').addClass('wikiEditor-highlight-template');}});}else{tokenArray[beginIndex].label='TEMPLATE_FALSE_BEGIN';tokenIndex=beginIndex;}}}}},exp:[{'regex':/{{/,'label':"TEMPLATE_BEGIN"},{'regex':/}}/,'label':"TEMPLATE_END",'markAfter':true}],fn:{create:function(context,config){context.modules.templateEditor={};},stylize:function(context){var $templates=context.$content.find('.wiki-template');$templates.each(function(){if(typeof $(this).data('model')!='undefined'){return;}
177176 $(this).addClass('wikieditor-nodisplay');$(this).data('model',new model($(this).text()));var model=$(this).data('model');function expandTemplate($displayDiv){$displayDiv.removeClass('wiki-collapsed-template');$displayDiv.addClass('wiki-expanded-template');$displayDiv.data('mode')="expanded";$displayDiv.text(model.getText());};function collapseTemplate($displayDiv){$displayDiv.addClass('wiki-collapsed-template');$displayDiv.removeClass('wiki-expanded-template');$displayDiv.data('mode')="collapsed";$displayDiv.text(model.getName());};var $visibleDiv=$("<div></div>").addClass('wikieditor-noinclude');$(this).data('display',$visibleDiv);$visibleDiv.data('wikitext-node',$(this));$(this).after($visibleDiv);$visibleDiv.click(function(){if($(this).data('mode')=='collapsed'){expandTemplate($(this));}else{collapseTemplate($(this));}});collapseTemplate($visibleDiv);});},model:function(wikitext){function Param(name,value,number,nameIndex,equalsIndex,valueIndex){this.name=name;this.value=value;this.number=number;this.nameIndex=nameIndex;this.equalsIndex=equalsIndex;this.valueIndex=valueIndex;}
178177 function Range(begin,end){this.begin=begin;this.end=end;}
179178 function getSetValue(name,value,original){var valueRange;var rangeIndex;var retVal;if(isNaN(name)){if(typeof paramsByName[name]=='undefined'){return"";}
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.highlight.js
@@ -35,10 +35,12 @@
3636 },
3737 ready: function( context, event ) {
3838 // Add our CSS to the iframe
 39+ // Style version for wikiEditor.highlight.css is here
 40+ // FIXME: That's not ideal
3941 context.$content.parent().find( 'head' ).append( $j( '<link />' ).attr( {
4042 'rel': 'stylesheet',
4143 'type': 'text/css',
42 - 'href': wgScriptPath + '/extensions/UsabilityInitiative/css/wikiEditor.highlight.css',
 44+ 'href': wgScriptPath + '/extensions/UsabilityInitiative/css/wikiEditor.highlight.css?0',
4345 } ) );
4446 // Highlight stuff for the first time
4547 $.wikiEditor.modules.highlight.fn.scan( context, "" );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js
@@ -6,17 +6,15 @@
77 */
88 evt: {
99 mark: function( context, event ) {
10 - // Get refrences to the markers and tokens from the current context
 10+ // Get references to the markers and tokens from the current context
1111 var markers = context.modules.highlight.markers;
1212 var tokenArray = context.modules.highlight.tokenArray;
13 - // Collect matching level 0 template call boundaries from the tokenArrray
 13+ // Collect matching level 0 template call boundaries from the tokenArray
1414 var level = 0;
15 - var boundaries = [];
16 - var boundary = 0;
1715
1816 var tokenIndex = 0;
1917 while( tokenIndex < tokenArray.length ){
20 - while( tokenIndex < tokenArray.length && tokenArrray[tokenIndex].label != 'TEMPLATE_BEGIN'){
 18+ while( tokenIndex < tokenArray.length && tokenArray[tokenIndex].label != 'TEMPLATE_BEGIN'){
2119 tokenIndex++;
2220 }
2321 //open template
@@ -37,28 +35,19 @@
3836 }
3937 }//while finding template ending
4038 if(endIndex != -1){
41 - boundaries.push([beginIndex,endIndex]); //push the boundaries
 39+ markers.push( {
 40+ start: tokenArray[beginIndex].offset,
 41+ end: tokenArray[endIndex].offset,
 42+ wrapElement: function() {
 43+ return $( '<div />' ).addClass( 'wikiEditor-highlight-template' );
 44+ }
 45+ } );
4246 } else { //else this was an unmatched opening
4347 tokenArray[beginIndex].label = 'TEMPLATE_FALSE_BEGIN';
4448 tokenIndex = beginIndex;
4549 }
4650 }//if opentemplates
4751 }
48 -
49 - // Add encapsulations to markers at the offsets of matching sets of level 0 template call boundaries
50 - for ( boundary in boundaries ) {
51 - if ( !( boundaries[boundary][0] in markers ) ) {
52 - markers[boundaries[boundary][0]] = [];
53 - }
54 - if ( !( boundaries[boundary][1] in markers ) ) {
55 - markers[boundaries[boundary][1]] = [];
56 - }
57 - // Append boundary markers
58 - markers[boundaries[boundary][0]].push( "<div class='wiki-template'>" );
59 - markers[boundaries[boundary][1]].push( "</div>" );
60 -
61 - }
62 - }
6352 }
6453 },
6554 /**
@@ -79,6 +68,7 @@
8069 */
8170 create: function( context, config ) {
8271 // Initialize module within the context
 72+ context.modules.templateEditor = {};
8373 },
8474 stylize: function( context ) {
8575 var $templates = context.$content.find( '.wiki-template' );

Status & tagging log