r61991 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61990‎ | r61991 | r61992 >
Date:21:22, 4 February 2010
Author:tparscal
Status:resolved (Comments)
Tags:
Comment:
Roan added the right code, but in the wrong place. This fixes the empty paragraph off by one issue in firefox before the paragraphs get converted to newlines.
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' => 103 ),
 76+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 104 ),
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' => 220 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 221 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 220 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 221 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -443,16 +443,17 @@
444444 // IE does overzealous whitespace collapsing for $( '<pre />' ).html( html );
445445 // We also do <br> and easy cases for <p> conversion here, complicated cases are handled later
446446 html = html
447 - .replace( /\r?\n/g, "" ) // IE7 inserts newlines before block elements
448 - .replace( /&nbsp;/g, " " ) // We inserted these to prevent IE from collapsing spaces
449 - .replace( /\<br[^\>]*\>\<\/p\>/gi, '</p>' ) // Remove trailing <br> from <p>
450 - .replace( /\<\/p\>\s*\<p[^\>]*\>/gi, "\n" ) // Easy case for <p> conversion
451 - .replace( /\<br[^\>]*\>/gi, "\n" ) // <br> conversion
452 - .replace( /\<\/p\>(\n*)\<p[^\>]*\>/gi, "$1\n" );
453 - // TODO: Why do we do this? Trevor knows, please explain here
 447+ .replace( /\r?\n/g, "" ) // IE7 inserts newlines before block elements
 448+ .replace( /&nbsp;/g, " " ) // We inserted these to prevent IE from collapsing spaces
 449+ .replace( /\<br[^\>]*\>\<\/p\>/gi, '</p>' ) // Remove trailing <br> from <p>
 450+ // Firefox ends up with one too many empty paragraphs, so this reduced consective strings of them by 1
454451 if ( $.browser.firefox ) {
455452 html = html.replace( /\<p[^\>]*\>\<\/p\>(\<p[^\>]*\>\<\/p\>)*/gi, '$1' );
456453 }
 454+ html = html
 455+ .replace( /\<\/p\>\s*\<p[^\>]*\>/gi, "\n" ) // Easy case for <p> conversion
 456+ .replace( /\<br[^\>]*\>/gi, "\n" ) // <br> conversion
 457+ .replace( /\<\/p\>(\n*)\<p[^\>]*\>/gi, "$1\n" );
457458 // Save leading and trailing whitespace now and restore it later. IE eats it all, and even Firefox
458459 // won't leave everything alone
459460 var leading = html.match( /^\s*/ )[0];
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -6876,16 +6876,17 @@
68776877 // IE does overzealous whitespace collapsing for $( '<pre />' ).html( html );
68786878 // We also do <br> and easy cases for <p> conversion here, complicated cases are handled later
68796879 html = html
6880 - .replace( /\r?\n/g, "" ) // IE7 inserts newlines before block elements
6881 - .replace( /&nbsp;/g, " " ) // We inserted these to prevent IE from collapsing spaces
6882 - .replace( /\<br[^\>]*\>\<\/p\>/gi, '</p>' ) // Remove trailing <br> from <p>
6883 - .replace( /\<\/p\>\s*\<p[^\>]*\>/gi, "\n" ) // Easy case for <p> conversion
6884 - .replace( /\<br[^\>]*\>/gi, "\n" ) // <br> conversion
6885 - .replace( /\<\/p\>(\n*)\<p[^\>]*\>/gi, "$1\n" );
6886 - // TODO: Why do we do this? Trevor knows, please explain here
 6880+ .replace( /\r?\n/g, "" ) // IE7 inserts newlines before block elements
 6881+ .replace( /&nbsp;/g, " " ) // We inserted these to prevent IE from collapsing spaces
 6882+ .replace( /\<br[^\>]*\>\<\/p\>/gi, '</p>' ) // Remove trailing <br> from <p>
 6883+ // Firefox ends up with one too many empty paragraphs, so this reduced consective strings of them by 1
68876884 if ( $.browser.firefox ) {
68886885 html = html.replace( /\<p[^\>]*\>\<\/p\>(\<p[^\>]*\>\<\/p\>)*/gi, '$1' );
68896886 }
 6887+ html = html
 6888+ .replace( /\<\/p\>\s*\<p[^\>]*\>/gi, "\n" ) // Easy case for <p> conversion
 6889+ .replace( /\<br[^\>]*\>/gi, "\n" ) // <br> conversion
 6890+ .replace( /\<\/p\>(\n*)\<p[^\>]*\>/gi, "$1\n" );
68906891 // Save leading and trailing whitespace now and restore it later. IE eats it all, and even Firefox
68916892 // won't leave everything alone
68926893 var leading = html.match( /^\s*/ )[0];
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -460,8 +460,9 @@
461461 event.preventDefault();return false;}).text($.wikiEditor.autoMsg(options,'title'))).appendTo(context.$tabs);}
462462 if(!context.$tabs.children().size()){addTab({'name':'wikitext','titleMsg':'wikieditor-wikitext-tab'});}
463463 addTab(options);return $('<div></div>').addClass('wikiEditor-ui-view wikiEditor-ui-view-'+options.name).hide().appendTo(context.$ui);},'htmlToText':function(html){if(html in context.htmlToTextMap){return context.htmlToTextMap[html];}
464 -var origHTML=html;html=html.replace(/\r?\n/g,"").replace(/&nbsp;/g," ").replace(/\<br[^\>]*\>\<\/p\>/gi,'</p>').replace(/\<\/p\>\s*\<p[^\>]*\>/gi,"\n").replace(/\<br[^\>]*\>/gi,"\n").replace(/\<\/p\>(\n*)\<p[^\>]*\>/gi,"$1\n");if($.browser.firefox){html=html.replace(/\<p[^\>]*\>\<\/p\>(\<p[^\>]*\>\<\/p\>)*/gi,'$1');}
465 -var leading=html.match(/^\s*/)[0];var trailing=html.match(/\s*$/)[0];html=html.substr(leading.length,html.length-leading.length-trailing.length);var $pre=$('<pre>'+html+'</pre>');$pre.find('.wikiEditor-noinclude').each(function(){$(this).remove();});$pre.find('.wikiEditor-tab').each(function(){$(this).text("\t");});$pre.find('br').each(function(){$(this).replaceWith("\n");});$pre.find('p').each(function(){var text=$(this).text();var t=new context.fn.rawTraverser(this.firstChild,0,this,$pre.get(0)).prev();while(t&&t.node.nodeName!='#text'&&t.node.nodeName!='BR'&&t.node.nodeName!='P'){t=t.prev();}
 464+var origHTML=html;html=html.replace(/\r?\n/g,"").replace(/&nbsp;/g," ").replace(/\<br[^\>]*\>\<\/p\>/gi,'</p>')
 465+if($.browser.firefox){html=html.replace(/\<p[^\>]*\>\<\/p\>(\<p[^\>]*\>\<\/p\>)*/gi,'$1');}
 466+html=html.replace(/\<\/p\>\s*\<p[^\>]*\>/gi,"\n").replace(/\<br[^\>]*\>/gi,"\n").replace(/\<\/p\>(\n*)\<p[^\>]*\>/gi,"$1\n");var leading=html.match(/^\s*/)[0];var trailing=html.match(/\s*$/)[0];html=html.substr(leading.length,html.length-leading.length-trailing.length);var $pre=$('<pre>'+html+'</pre>');$pre.find('.wikiEditor-noinclude').each(function(){$(this).remove();});$pre.find('.wikiEditor-tab').each(function(){$(this).text("\t");});$pre.find('br').each(function(){$(this).replaceWith("\n");});$pre.find('p').each(function(){var text=$(this).text();var t=new context.fn.rawTraverser(this.firstChild,0,this,$pre.get(0)).prev();while(t&&t.node.nodeName!='#text'&&t.node.nodeName!='BR'&&t.node.nodeName!='P'){t=t.prev();}
466467 if(t){text="\n"+text;}
467468 t=new context.fn.rawTraverser(this.lastChild,0,this,$pre.get(0)).next();while(t&&t.node.nodeName!='#text'&&t.node.nodeName!='BR'&&t.node.nodeName!='P'){t=t.next();}
468469 if(t&&!t.inP&&t.node.nodeName=='#text'&&t.node.nodeValue.charAt(0)!='\n'&&t.node.nodeValue.charAt(0)!='\r'){text+="\n";}

Comments

#Comment by Platonides (talk | contribs)   18:32, 5 February 2010

It is now imposible to add a blank line to force a new paragraph.

This edit http://en.wikinews.org/w/index.php?title=Obama_urges_Americans_to_turn_off_%22echo_chamber%22_of_Cable_News&action=historysubmit&diff=952349&oldid=952347 had to be done with javascript disabled. Otherwise the edit was ignored.

Yes, the bug is live in wikimedia projects.

#Comment by Shuhari (talk | contribs)   00:01, 6 February 2010
#Comment by Platonides (talk | contribs)   00:24, 6 February 2010

r62041 was also expected to fix it.

#Comment by Catrope (talk | contribs)   00:48, 9 February 2010

Turns out that rev did fix it, it just wasn't deployed properly.

Status & tagging log