r61616 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61615‎ | r61616 | r61617 >
Date:23:41, 27 January 2010
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: Fix bug where the strings <br>, &nbsp; and <div class="wikiEditor-tab"></div> occurring verbatim in an article would not be left alone. Also fix a JS error
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' => 26 ),
76 - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 77 ),
 76+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 78 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 25 ),
7878 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 45 ),
7979 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 11 ),
@@ -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' => 190 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 191 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 190 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 191 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -796,7 +796,7 @@
797797 var base = context.offsets[lowerBound];
798798 return context.offsets[offset] = {
799799 'node': base.node,
800 - 'offset': base.offset + offset - o,
 800+ 'offset': base.offset + offset - lowerBound,
801801 'length': base.length,
802802 'depth': base.depth,
803803 'lastTextNode': base.lastTextNode,
@@ -923,7 +923,13 @@
924924 // If we just do "context.$content.text( context.$textarea.val() )", Internet Explorer will strip out the
925925 // whitespace charcters, specifically "\n" - so we must manually encode the text and append it
926926 // TODO: Refactor this into a textToHtml() function
927 - var html = context.$textarea.val();
 927+ // Because we're gonna insert instances of <br>, &nbsp; and <span class="wikiEditor-tab"></span>,
 928+ // we have to escape existing instances first. This'll cause them to be double-escaped, which we
 929+ // fix later on
 930+ var html = context.$textarea.val()
 931+ .replace( /&nbsp;/g, '&amp;nbsp;' )
 932+ .replace( /\<br\>/g, '&lt;br&gt;' )
 933+ .replace( /\<span class="wikiEditor-tab"\>\<\/span\>/g, '&lt;span class=&quot;wikiEditor-tab&quot;&gt;&lt;/span&gt;' );
928934 // We must do some extra processing on IE to avoid dirty diffs, specifically IE will collapse leading spaces
929935 if ( $.browser.msie ) {
930936 // Browser sniffing is not ideal, but executing this code on a non-broken browser doesn't cause harm
@@ -939,10 +945,14 @@
940946 }
941947 // Use a dummy div to escape all entities
942948 // This'll also escape <br>, <span> and &nbsp; , so we unescape those after
 949+ // We also need to unescape the doubly-escaped things mentioned above
943950 html = $( '<div />' ).text( html.replace( /\r?\n/g, '<br>' ) ).html()
944951 .replace( /&amp;nbsp;/g, '&nbsp;' )
945952 .replace( /&lt;br&gt;/g, '<br>' )
946 - .replace( /&lt;span class=&quot;wikiEditor-tab&quot;&gt;&lt;\/span&gt;/g, '<span class="wikiEditor-tab"></span>' );
 953+ .replace( /&lt;span class=&quot;wikiEditor-tab&quot;&gt;&lt;\/span&gt;/g, '<span class="wikiEditor-tab"></span>' )
 954+ .replace( /&amp;amp;nbsp;/g, '&amp;nbsp;' )
 955+ .replace( /&amp;lt;br&amp;gt;/g, '&lt;br&gt;' )
 956+ .replace( /&amp;lt;span class=&amp;quot;wikiEditor-tab&amp;quot;&amp;gt;&amp;lt;\/span&amp;gt;/g, '&lt;span class=&quot;wikiEditor-tab&quot;&gt;&lt;/span&gt;' );
947957 context.$content.html( html );
948958
949959 // Reflect direction of parent frame into child
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -7220,7 +7220,7 @@
72217221 var base = context.offsets[lowerBound];
72227222 return context.offsets[offset] = {
72237223 'node': base.node,
7224 - 'offset': base.offset + offset - o,
 7224+ 'offset': base.offset + offset - lowerBound,
72257225 'length': base.length,
72267226 'depth': base.depth,
72277227 'lastTextNode': base.lastTextNode,
@@ -7347,7 +7347,13 @@
73487348 // If we just do "context.$content.text( context.$textarea.val() )", Internet Explorer will strip out the
73497349 // whitespace charcters, specifically "\n" - so we must manually encode the text and append it
73507350 // TODO: Refactor this into a textToHtml() function
7351 - var html = context.$textarea.val();
 7351+ // Because we're gonna insert instances of <br>, &nbsp; and <span class="wikiEditor-tab"></span>,
 7352+ // we have to escape existing instances first. This'll cause them to be double-escaped, which we
 7353+ // fix later on
 7354+ var html = context.$textarea.val()
 7355+ .replace( /&nbsp;/g, '&amp;nbsp;' )
 7356+ .replace( /\<br\>/g, '&lt;br&gt;' )
 7357+ .replace( /\<span class="wikiEditor-tab"\>\<\/span\>/g, '&lt;span class=&quot;wikiEditor-tab&quot;&gt;&lt;/span&gt;' );
73527358 // We must do some extra processing on IE to avoid dirty diffs, specifically IE will collapse leading spaces
73537359 if ( $.browser.msie ) {
73547360 // Browser sniffing is not ideal, but executing this code on a non-broken browser doesn't cause harm
@@ -7363,10 +7369,14 @@
73647370 }
73657371 // Use a dummy div to escape all entities
73667372 // This'll also escape <br>, <span> and &nbsp; , so we unescape those after
 7373+ // We also need to unescape the doubly-escaped things mentioned above
73677374 html = $( '<div />' ).text( html.replace( /\r?\n/g, '<br>' ) ).html()
73687375 .replace( /&amp;nbsp;/g, '&nbsp;' )
73697376 .replace( /&lt;br&gt;/g, '<br>' )
7370 - .replace( /&lt;span class=&quot;wikiEditor-tab&quot;&gt;&lt;\/span&gt;/g, '<span class="wikiEditor-tab"></span>' );
 7377+ .replace( /&lt;span class=&quot;wikiEditor-tab&quot;&gt;&lt;\/span&gt;/g, '<span class="wikiEditor-tab"></span>' )
 7378+ .replace( /&amp;amp;nbsp;/g, '&amp;nbsp;' )
 7379+ .replace( /&amp;lt;br&amp;gt;/g, '&lt;br&gt;' )
 7380+ .replace( /&amp;lt;span class=&amp;quot;wikiEditor-tab&amp;quot;&amp;gt;&amp;lt;\/span&amp;gt;/g, '&lt;span class=&quot;wikiEditor-tab&quot;&gt;&lt;/span&gt;' );
73717381 context.$content.html( html );
73727382
73737383 // Reflect direction of parent frame into child
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -490,13 +490,13 @@
491491 var lowerBound=-1;for(var o in context.offsets){if(o>offset){break;}
492492 lowerBound=o;}
493493 if(!(lowerBound in context.offsets)){return null;}
494 -var base=context.offsets[lowerBound];return context.offsets[offset]={'node':base.node,'offset':base.offset+offset-o,'length':base.length,'depth':base.depth,'lastTextNode':base.lastTextNode,'lastTextNodeDepth':base.lastTextNodeDepth};},'purgeOffsets':function(){context.offsets=null;},'refreshOffsets':function(){context.offsets=[];var t=context.fn.traverser(context.$content);var pos=0,lastTextNode=null,lastTextNodeDepth=null;while(t){if(t.node.nodeName!='#text'&&t.node.nodeName!='BR'){t=t.next();continue;}
 494+var base=context.offsets[lowerBound];return context.offsets[offset]={'node':base.node,'offset':base.offset+offset-lowerBound,'length':base.length,'depth':base.depth,'lastTextNode':base.lastTextNode,'lastTextNodeDepth':base.lastTextNodeDepth};},'purgeOffsets':function(){context.offsets=null;},'refreshOffsets':function(){context.offsets=[];var t=context.fn.traverser(context.$content);var pos=0,lastTextNode=null,lastTextNodeDepth=null;while(t){if(t.node.nodeName!='#text'&&t.node.nodeName!='BR'){t=t.next();continue;}
495495 var nextPos=t.node.nodeName=='#text'?pos+t.node.nodeValue.length:pos+1;var nextT=t.next();var leavingP=t.inP&&nextT&&!nextT.inP;context.offsets[pos]={'node':t.node,'offset':0,'length':nextPos-pos+(leavingP?1:0),'depth':t.depth,'lastTextNode':lastTextNode,'lastTextNodeDepth':lastTextNodeDepth};if(leavingP){context.offsets[nextPos]={'node':t.node,'offset':nextPos-pos,'length':nextPos-pos+1,'depth':t.depth,'lastTextNode':lastTextNode,'lastTextNodeDepth':lastTextNodeDepth};}
496496 pos=nextPos+(leavingP?1:0);if(t.node.nodeName=='#text'){lastTextNode=t.node;lastTextNodeDepth=t.depth;}
497497 t=nextT;}}};context.$textarea.wrap($('<div></div>').addClass('wikiEditor-ui')).wrap($('<div></div>').addClass('wikiEditor-ui-view wikiEditor-ui-view-wikitext')).wrap($('<div></div>').addClass('wikiEditor-ui-left')).wrap($('<div></div>').addClass('wikiEditor-ui-bottom')).wrap($('<div></div>').addClass('wikiEditor-ui-text'));context.$ui=context.$textarea.parent().parent().parent().parent().parent();context.$wikitext=context.$textarea.parent().parent().parent().parent();context.$wikitext.before($('<div></div>').addClass('wikiEditor-ui-controls').append($('<div></div>').addClass('wikiEditor-ui-tabs').hide()).append($('<div></div>').addClass('wikiEditor-ui-buttons'))).before($('<div style="clear:both;"></div>'));context.$controls=context.$ui.find('.wikiEditor-ui-buttons').hide();context.$buttons=context.$ui.find('.wikiEditor-ui-buttons');context.$tabs=context.$ui.find('.wikiEditor-ui-tabs');context.$ui.after($('<div style="clear:both;"></div>'));context.$wikitext.append($('<div></div>').addClass('wikiEditor-ui-right'));context.$wikitext.find('.wikiEditor-ui-left').prepend($('<div></div>').addClass('wikiEditor-ui-top'));context.view='wikitext';$(window).resize(function(event){context.fn.trigger('resize',event)});context.$iframe=$('<iframe></iframe>').attr({'frameBorder':0,'border':0,'src':wgScriptPath+'/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.html?'+'instance='+context.instance+'&ts='+(new Date()).getTime(),'id':'wikiEditor-iframe-'+context.instance}).css({'backgroundColor':'white','width':'100%','height':context.$textarea.height(),'display':'none','overflow-y':'scroll','overflow-x':'hidden'}).insertAfter(context.$textarea).load(function(){if(!this.isSecondRun){context.$iframe[0].contentWindow.document.designMode='on';if($.browser.msie){this.isSecondRun=true;return;}}
498 -context.$content=$(context.$iframe[0].contentWindow.document.body);var html=context.$textarea.val();if($.browser.msie){if($.browser.versionNumber<=7){html=html.replace(/ /g,"&nbsp;");}else{html=html.replace(/(^|\n) /g,"$1&nbsp;");}
 498+context.$content=$(context.$iframe[0].contentWindow.document.body);var html=context.$textarea.val().replace(/&nbsp;/g,'&amp;nbsp;').replace(/\<br\>/g,'&lt;br&gt;').replace(/\<span class="wikiEditor-tab"\>\<\/span\>/g,'&lt;span class=&quot;wikiEditor-tab&quot;&gt;&lt;/span&gt;');if($.browser.msie){if($.browser.versionNumber<=7){html=html.replace(/ /g,"&nbsp;");}else{html=html.replace(/(^|\n) /g,"$1&nbsp;");}
499499 html=html.replace(/\t/g,'<span class="wikiEditor-tab"></span>');}
500 -html=$('<div />').text(html.replace(/\r?\n/g,'<br>')).html().replace(/&amp;nbsp;/g,'&nbsp;').replace(/&lt;br&gt;/g,'<br>').replace(/&lt;span class=&quot;wikiEditor-tab&quot;&gt;&lt;\/span&gt;/g,'<span class="wikiEditor-tab"></span>');context.$content.html(html);if($('body').is('.rtl')){context.$content.addClass('rtl').attr('dir','rtl');}
 500+html=$('<div />').text(html.replace(/\r?\n/g,'<br>')).html().replace(/&amp;nbsp;/g,'&nbsp;').replace(/&lt;br&gt;/g,'<br>').replace(/&lt;span class=&quot;wikiEditor-tab&quot;&gt;&lt;\/span&gt;/g,'<span class="wikiEditor-tab"></span>').replace(/&amp;amp;nbsp;/g,'&amp;nbsp;').replace(/&amp;lt;br&amp;gt;/g,'&lt;br&gt;').replace(/&amp;lt;span class=&amp;quot;wikiEditor-tab&amp;quot;&amp;gt;&amp;lt;\/span&amp;gt;/g,'&lt;span class=&quot;wikiEditor-tab&quot;&gt;&lt;/span&gt;');context.$content.html(html);if($('body').is('.rtl')){context.$content.addClass('rtl').attr('dir','rtl');}
501501 context.$textarea.attr('disabled',true);context.$textarea.hide();context.$iframe.show();context.fn.trigger('ready');$(context.$iframe[0].contentWindow.document).bind('keyup mouseup paste cut encapsulateSelection',function(event){context.fn.trigger('change',event);}).delayedBind(250,'keyup mouseup paste cut encapsulateSelection',function(event){context.fn.trigger('delayedChange',event);});});context.$textarea.closest('form').submit(function(){context.$textarea.attr('disabled',false);context.$textarea.val(context.$textarea.textSelection('getContents'));});context.fallbackWindowOnBeforeUnload=window.onbeforeunload;window.onbeforeunload=function(){context.$textarea.val(context.$textarea.textSelection('getContents'));return context.fallbackWindowOnBeforeUnload?context.fallbackWindowOnBeforeUnload():null;}}
502502 arguments=$.makeArray(arguments);if(arguments.length>0){var call=arguments.shift();if(call in context.api){context.api[call](context,typeof arguments[0]=='undefined'?{}:arguments[0]);}}
503503 return $(this).data('wikiEditor-context',context);};})(jQuery);RegExp.escape=function(s){return s.replace(/([.*+?^${}()|\/\\[\]])/g,'\\$1');};(function($){$.wikiEditor.modules.dialogs={api:{addDialog:function(context,data){$.wikiEditor.modules.dialogs.fn.create(context,data)},openDialog:function(context,module){if(module in $.wikiEditor.modules.dialogs.modules){$('#'+$.wikiEditor.modules.dialogs.modules[module].id).dialog('open');}},closeDialog:function(context,data){if(module in $.wikiEditor.modules.dialogs.modules){$('#'+$.wikiEditor.modules.dialogs.modules[module].id).dialog('close');}}},fn:{create:function(context,config){for(module in config){$.wikiEditor.modules.dialogs.modules[module]=config[module];}

Status & tagging log