r61620 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61619‎ | r61620 | r61621 >
Date:01:29, 28 January 2010
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: Rewrite context.fn.htmlToText() to handle <p>s at the beginning of the document properly
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' => 79 ),
 76+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 80 ),
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' => 192 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 193 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 192 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 193 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -365,16 +365,20 @@
366366 var $pre = $( '<pre>' +
367367 html
368368 .replace( /\r?\n/g, "" ) // IE7 inserts newlines before block elements
369 - .replace( /\<br[^\>]*\>/gi, "\n" )
370369 .replace( /&nbsp;/g, " " ) // We inserted these to prevent IE from collapsing spaces
371 - .replace( /\<p[^\>]*\>/gi, "\n" ) // IE uses </p><p> for user-inserted line breaks
372 - .replace( /\<\/p[^\>]*\>/gi, "" )
373 - //.replace( /\<div[^\>]*\>/gi, "\n" ) // Webkit uses </div><div> for user-inserted line breaks
374 - //.replace( /\<\/div[^\>]*\>/gi, "" )
375370 + '</pre>' );
376371 // Get rid of the noincludes when getting text
377372 $pre.find( '.wikiEditor-noinclude' ).each( function() { $( this ).remove(); } );
 373+ // Convert tabs, <p>s and <br>s back
378374 $pre.find( '.wikiEditor-tab' ).each( function() { $( this ).text( "\t" ) } );
 375+ $pre.find( 'br' ).each( function() { $( this ).replaceWith( "\n" ); } );
 376+ // Converting <p>s is wrong if there's nothing before them, so check that
 377+ // .find( '* + p' ) isn't good enough because textnodes aren't considered
 378+ $pre.find( 'p' ).each( function() {
 379+ if ( this.previousSibling || this.parentNode != $pre.get( 0 ) ) {
 380+ $( this ).text( "\n" + $( this ).text() );
 381+ }
 382+ } );
379383 return $pre.text();
380384 },
381385
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -6789,16 +6789,20 @@
67906790 var $pre = $( '<pre>' +
67916791 html
67926792 .replace( /\r?\n/g, "" ) // IE7 inserts newlines before block elements
6793 - .replace( /\<br[^\>]*\>/gi, "\n" )
67946793 .replace( /&nbsp;/g, " " ) // We inserted these to prevent IE from collapsing spaces
6795 - .replace( /\<p[^\>]*\>/gi, "\n" ) // IE uses </p><p> for user-inserted line breaks
6796 - .replace( /\<\/p[^\>]*\>/gi, "" )
6797 - //.replace( /\<div[^\>]*\>/gi, "\n" ) // Webkit uses </div><div> for user-inserted line breaks
6798 - //.replace( /\<\/div[^\>]*\>/gi, "" )
67996794 + '</pre>' );
68006795 // Get rid of the noincludes when getting text
68016796 $pre.find( '.wikiEditor-noinclude' ).each( function() { $( this ).remove(); } );
 6797+ // Convert tabs, <p>s and <br>s back
68026798 $pre.find( '.wikiEditor-tab' ).each( function() { $( this ).text( "\t" ) } );
 6799+ $pre.find( 'br' ).each( function() { $( this ).replaceWith( "\n" ); } );
 6800+ // Converting <p>s is wrong if there's nothing before them, so check that
 6801+ // .find( '* + p' ) isn't good enough because textnodes aren't considered
 6802+ $pre.find( 'p' ).each( function() {
 6803+ if ( this.previousSibling || this.parentNode != $pre.get( 0 ) ) {
 6804+ $( this ).text( "\n" + $( this ).text() );
 6805+ }
 6806+ } );
68036807 return $pre.text();
68046808 },
68056809
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -449,8 +449,8 @@
450450 event.preventDefault();return false;}).text($.wikiEditor.autoMsg(options,'title'))).appendTo(context.$tabs);}
451451 if(!context.$tabs.children().size()){addTab({'name':'wikitext','titleMsg':'wikieditor-wikitext-tab'});}
452452 addTab(options);return $('<div></div>').addClass('wikiEditor-ui-view wikiEditor-ui-view-'+options.name).hide().appendTo(context.$ui);},'htmlToText':function(html){var $pre=$('<pre>'+
453 -html.replace(/\r?\n/g,"").replace(/\<br[^\>]*\>/gi,"\n").replace(/&nbsp;/g," ").replace(/\<p[^\>]*\>/gi,"\n").replace(/\<\/p[^\>]*\>/gi,"")
454 -+'</pre>');$pre.find('.wikiEditor-noinclude').each(function(){$(this).remove();});$pre.find('.wikiEditor-tab').each(function(){$(this).text("\t")});return $pre.text();},'getContents':function(){return context.fn.htmlToText(context.$content.html());},'getSelection':function(){var retval;if(context.$iframe[0].contentWindow.getSelection){retval=context.$iframe[0].contentWindow.getSelection();}else if(context.$iframe[0].contentWindow.document.selection){retval=context.$iframe[0].contentWindow.document.selection.createRange();}
 453+html.replace(/\r?\n/g,"").replace(/&nbsp;/g," ")
 454++'</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(){if(this.previousSibling||this.parentNode!=$pre.get(0)){$(this).text("\n"+$(this).text());}});return $pre.text();},'getContents':function(){return context.fn.htmlToText(context.$content.html());},'getSelection':function(){var retval;if(context.$iframe[0].contentWindow.getSelection){retval=context.$iframe[0].contentWindow.getSelection();}else if(context.$iframe[0].contentWindow.document.selection){retval=context.$iframe[0].contentWindow.document.selection.createRange();}
455455 if(typeof retval.text!='undefined'){retval=context.fn.htmlToText(retval.htmlText);}else if(retval.toString){retval=retval.toString();}
456456 return retval;},'encapsulateSelection':function(options){var selText=$(this).textSelection('getSelection');var selTextArr;var selectAfter=false;var pre=options.pre,post=options.post;if(!selText){selText=options.peri;selectAfter=true;}else if(options.replace){selText=options.peri;}else if(selText.charAt(selText.length-1)==' '){selText=selText.substring(0,selText.length-1);post+=' ';}
457457 if(options.splitlines){selTextArr=selText.split(/\n/);}

Status & tagging log