r62143 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62142‎ | r62143 | r62144 >
Date:22:51, 8 February 2010
Author:catrope
Status:ok
Tags:
Comment:
UsabilityInitiative: (bug 22435) Stuff like <p> and &nbsp; in the original wikitext gets eaten. Using a proper escaping scheme for this now
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' => 110 ),
 76+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 111 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 29 ),
7878 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 47 ),
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' => 228 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 229 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 228 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 229 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -1201,25 +1201,26 @@
12021202 // If we just do "context.$content.text( context.$textarea.val() )", Internet Explorer will strip out the
12031203 // whitespace charcters, specifically "\n" - so we must manually encode the text and append it
12041204 // TODO: Refactor this into a textToHtml() function
1205 - // Because we're gonna insert instances of <br>, &nbsp; and <span class="wikiEditor-tab"></span>,
1206 - // we have to escape existing instances first. This'll cause them to be double-escaped, which we
1207 - // fix later on
12081205 var html = context.$textarea.val()
1209 - .replace( /&nbsp;/g, '&amp;nbsp;' )
1210 - .replace( /\<br\>/g, '&lt;br&gt;' )
1211 - .replace( /\<span class="wikiEditor-tab"\>\<\/span\>/g, '&lt;span class=&quot;wikiEditor-tab&quot;&gt;&lt;/span&gt;' );
 1206+ // We're gonna use &esc; as an escape sequence
 1207+ .replace( /&esc;/g, '&esc;&esc;' )
 1208+ // Escape existing uses of <p>, </p>, &nbsp; and <span class="wikiEditor-tab"></span>
 1209+ .replace( /\<p\>/g, '&esc;&lt;p&gt;' )
 1210+ .replace (/\<\/p\>/g, '&esc;&lt;/p&gt;' )
 1211+ .replace( /\<span class="wikiEditor-tab"\>\<\/span\>/g, '&esc;&lt;span class="wikiEditor-tab"&gt;&lt;/span&gt;' )
 1212+ .replace( /&nbsp;/g, '&esc;&amp;nbsp;' );
12121213 // We must do some extra processing on IE to avoid dirty diffs, specifically IE will collapse leading spaces
 1214+ // Browser sniffing is not ideal, but executing this code on a non-broken browser doesn't cause harm
12131215 if ( $.browser.msie ) {
1214 - // Browser sniffing is not ideal, but executing this code on a non-broken browser doesn't cause harm
 1216+ html = html.replace( /\t/g, '<span class="wikiEditor-tab"></span>' );
12151217 if ( $.browser.versionNumber <= 7 ) {
12161218 // Replace all spaces matching &nbsp; - IE <= 7 needs this because of its overzealous
1217 - // whitespace collapsing;
 1219+ // whitespace collapsing
12181220 html = html.replace( / /g, "&nbsp;" );
12191221 } else {
12201222 // IE8 is happy if we just convert the first leading space to &nbsp;
12211223 html = html.replace( /(^|\n) /g, "$1&nbsp;" );
12221224 }
1223 - html = html.replace( /\t/g, '<span class="wikiEditor-tab"></span>' );
12241225 }
12251226 // Use a dummy div to escape all entities
12261227 // This'll also escape <br>, <span> and &nbsp; , so we unescape those after
@@ -1231,10 +1232,12 @@
12321233 .replace( /&lt;\/p&gt;/g, '</p>' )
12331234 // Empty p tags should just be br tags
12341235 .replace( /<p><\/p>/g, '<br>' )
1235 - .replace( /&lt;span class=&quot;wikiEditor-tab&quot;&gt;&lt;\/span&gt;/g, '<span class="wikiEditor-tab"></span>' )
1236 - .replace( /&amp;amp;nbsp;/g, '&amp;nbsp;' )
1237 - .replace( /&amp;lt;br&amp;gt;/g, '&lt;br&gt;' )
1238 - .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;' );
 1236+ // Unescape &esc; stuff
 1237+ .replace( /&amp;esc;&amp;amp;nbsp;/g, '&amp;nbsp;' )
 1238+ .replace( /&amp;esc;&amp;lt;p&amp;gt;/g, '&lt;p&gt;' )
 1239+ .replace( /&amp;esc;&amp;lt;\/p&amp;gt;/g, '&lt;/p&gt;' )
 1240+ .replace( /&amp;esc;&amp;lt;span class="wikiEditor-tab"&amp;gt;&amp;lt;\/span&amp;gt;/g, '&lt;span class="wikiEditor-tab"&gt;&lt;\/span&gt;' )
 1241+ .replace( /&amp;esc;&amp;esc;/g, '&amp;esc;' );
12391242 context.$content.html( html );
12401243 context.oldHTML = html;
12411244 // FIXME: This needs to be merged somehow with the oldHTML thing
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -7634,25 +7634,26 @@
76357635 // If we just do "context.$content.text( context.$textarea.val() )", Internet Explorer will strip out the
76367636 // whitespace charcters, specifically "\n" - so we must manually encode the text and append it
76377637 // TODO: Refactor this into a textToHtml() function
7638 - // Because we're gonna insert instances of <br>, &nbsp; and <span class="wikiEditor-tab"></span>,
7639 - // we have to escape existing instances first. This'll cause them to be double-escaped, which we
7640 - // fix later on
76417638 var html = context.$textarea.val()
7642 - .replace( /&nbsp;/g, '&amp;nbsp;' )
7643 - .replace( /\<br\>/g, '&lt;br&gt;' )
7644 - .replace( /\<span class="wikiEditor-tab"\>\<\/span\>/g, '&lt;span class=&quot;wikiEditor-tab&quot;&gt;&lt;/span&gt;' );
 7639+ // We're gonna use &esc; as an escape sequence
 7640+ .replace( /&esc;/g, '&esc;&esc;' )
 7641+ // Escape existing uses of <p>, </p>, &nbsp; and <span class="wikiEditor-tab"></span>
 7642+ .replace( /\<p\>/g, '&esc;&lt;p&gt;' )
 7643+ .replace (/\<\/p\>/g, '&esc;&lt;/p&gt;' )
 7644+ .replace( /\<span class="wikiEditor-tab"\>\<\/span\>/g, '&esc;&lt;span class="wikiEditor-tab"&gt;&lt;/span&gt;' )
 7645+ .replace( /&nbsp;/g, '&esc;&amp;nbsp;' );
76457646 // We must do some extra processing on IE to avoid dirty diffs, specifically IE will collapse leading spaces
 7647+ // Browser sniffing is not ideal, but executing this code on a non-broken browser doesn't cause harm
76467648 if ( $.browser.msie ) {
7647 - // Browser sniffing is not ideal, but executing this code on a non-broken browser doesn't cause harm
 7649+ html = html.replace( /\t/g, '<span class="wikiEditor-tab"></span>' );
76487650 if ( $.browser.versionNumber <= 7 ) {
76497651 // Replace all spaces matching &nbsp; - IE <= 7 needs this because of its overzealous
7650 - // whitespace collapsing;
 7652+ // whitespace collapsing
76517653 html = html.replace( / /g, "&nbsp;" );
76527654 } else {
76537655 // IE8 is happy if we just convert the first leading space to &nbsp;
76547656 html = html.replace( /(^|\n) /g, "$1&nbsp;" );
76557657 }
7656 - html = html.replace( /\t/g, '<span class="wikiEditor-tab"></span>' );
76577658 }
76587659 // Use a dummy div to escape all entities
76597660 // This'll also escape <br>, <span> and &nbsp; , so we unescape those after
@@ -7664,10 +7665,12 @@
76657666 .replace( /&lt;\/p&gt;/g, '</p>' )
76667667 // Empty p tags should just be br tags
76677668 .replace( /<p><\/p>/g, '<br>' )
7668 - .replace( /&lt;span class=&quot;wikiEditor-tab&quot;&gt;&lt;\/span&gt;/g, '<span class="wikiEditor-tab"></span>' )
7669 - .replace( /&amp;amp;nbsp;/g, '&amp;nbsp;' )
7670 - .replace( /&amp;lt;br&amp;gt;/g, '&lt;br&gt;' )
7671 - .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;' );
 7669+ // Unescape &esc; stuff
 7670+ .replace( /&amp;esc;&amp;amp;nbsp;/g, '&amp;nbsp;' )
 7671+ .replace( /&amp;esc;&amp;lt;p&amp;gt;/g, '&lt;p&gt;' )
 7672+ .replace( /&amp;esc;&amp;lt;\/p&amp;gt;/g, '&lt;/p&gt;' )
 7673+ .replace( /&amp;esc;&amp;lt;span class="wikiEditor-tab"&amp;gt;&amp;lt;\/span&amp;gt;/g, '&lt;span class="wikiEditor-tab"&gt;&lt;\/span&gt;' )
 7674+ .replace( /&amp;esc;&amp;esc;/g, '&amp;esc;' );
76727675 context.$content.html( html );
76737676 context.oldHTML = html;
76747677 // FIXME: This needs to be merged somehow with the oldHTML thing
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -525,9 +525,8 @@
526526 t=nextT;}},'saveSelection':function(){if(!$.browser.msie){return;}
527527 context.$iframe[0].contentWindow.focus();context.savedSelection=context.$iframe[0].contentWindow.document.selection.createRange();},'restoreSelection':function(){if(!$.browser.msie||context.savedSelection===null){return;}
528528 context.$iframe[0].contentWindow.focus();context.savedSelection.select();context.savedSelection=null;}};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,'tabindex':1,'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;}}
529 -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;");}
530 -html=html.replace(/\t/g,'<span class="wikiEditor-tab"></span>');}
531 -html=$('<div />').text('<p>'+html.replace(/\r?\n/g,'</p><p>')+'</p>').html().replace(/&amp;nbsp;/g,'&nbsp;').replace(/&lt;p&gt;/g,'<p>').replace(/&lt;\/p&gt;/g,'</p>').replace(/<p><\/p>/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);context.oldHTML=html;context.history.push({'html':html});if($('body').is('.rtl')){context.$content.addClass('rtl').attr('dir','rtl');}
 529+context.$content=$(context.$iframe[0].contentWindow.document.body);var html=context.$textarea.val().replace(/&esc;/g,'&esc;&esc;').replace(/\<p\>/g,'&esc;&lt;p&gt;').replace(/\<\/p\>/g,'&esc;&lt;/p&gt;').replace(/\<span class="wikiEditor-tab"\>\<\/span\>/g,'&esc;&lt;span class="wikiEditor-tab"&gt;&lt;/span&gt;').replace(/&nbsp;/g,'&esc;&amp;nbsp;');if($.browser.msie){html=html.replace(/\t/g,'<span class="wikiEditor-tab"></span>');if($.browser.versionNumber<=7){html=html.replace(/ /g,"&nbsp;");}else{html=html.replace(/(^|\n) /g,"$1&nbsp;");}}
 530+html=$('<div />').text('<p>'+html.replace(/\r?\n/g,'</p><p>')+'</p>').html().replace(/&amp;nbsp;/g,'&nbsp;').replace(/&lt;p&gt;/g,'<p>').replace(/&lt;\/p&gt;/g,'</p>').replace(/<p><\/p>/g,'<br>').replace(/&amp;esc;&amp;amp;nbsp;/g,'&amp;nbsp;').replace(/&amp;esc;&amp;lt;p&amp;gt;/g,'&lt;p&gt;').replace(/&amp;esc;&amp;lt;\/p&amp;gt;/g,'&lt;/p&gt;').replace(/&amp;esc;&amp;lt;span class="wikiEditor-tab"&amp;gt;&amp;lt;\/span&amp;gt;/g,'&lt;span class="wikiEditor-tab"&gt;&lt;\/span&gt;').replace(/&amp;esc;&amp;esc;/g,'&amp;esc;');context.$content.html(html);context.oldHTML=html;context.history.push({'html':html});if($('body').is('.rtl')){context.$content.addClass('rtl').attr('dir','rtl');}
532531 context.$textarea.attr('disabled',true);context.$textarea.hide();context.$iframe.show();context.fn.trigger('ready');$(context.$iframe[0].contentWindow.document).bind('keydown',function(event){return context.fn.trigger('keydown',event);}).bind('keyup mouseup paste cut encapsulateSelection',function(event){return 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'));if(context.fallbackWindowOnBeforeUnload){return context.fallbackWindowOnBeforeUnload();}};}
533532 var args=$.makeArray(arguments);if(args.length>0){var call=args.shift();if(call in context.api){context.api[call](context,typeof args[0]=='undefined'?{}:args[0]);}}
534533 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];}

Follow-up revisions

RevisionCommit summaryAuthorDate
r62146UsabilityInitiative: Fix for r62143: make stuff work in IE7catrope23:34, 8 February 2010
r62181wmf-deployment: Merge r62143, r62146 (UsabilityInitiative fixes) from trunkcatrope14:17, 9 February 2010

Status & tagging log