r61676 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61675‎ | r61676 | r61677 >
Date:19:27, 29 January 2010
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: Fix edge case where a document starting with <p>== Foo ==</p> would cause the header anchor to alternate between being added and removed
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' => 85 ),
 76+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 86 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 26 ),
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' => 198 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 199 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 198 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 199 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -376,13 +376,24 @@
377377 // .find( '* + p' ) isn't good enough because textnodes aren't considered
378378 $pre.find( 'p' ).each( function() {
379379 if ( this.previousSibling || this.parentNode != $pre.get( 0 ) ) {
380 - var text = "\n" + $( this ).text();
 380+ var text = $( this ).text();
381381 // If this <p> is preceded by some text, add a \n at the beginning, and if
382382 // it's followed by a textnode, add a \n at the end
383383 // We need the traverser because there can be other weird stuff in between
384 - // TODO: We need a reverse traverser, write this
385 - var t = new context.fn.rawTraverser( this.lastChild, -10, this ).next();
 384+
 385+ // Check for preceding text
 386+ // FIXME: Add an option to disable depth checking, -10 is a hack
 387+ var t = new context.fn.rawTraverser( this.firstChild, -10, this ).prev();
386388 while ( t && t.node.nodeName != '#text' && t.node.nodeName != 'BR' && t.node.nodeName != 'P' ) {
 389+ t = t.prev();
 390+ }
 391+ if ( t ) {
 392+ text = "\n" + text;
 393+ }
 394+
 395+ // Check for following text
 396+ t = new context.fn.rawTraverser( this.lastChild, -10, this ).next();
 397+ while ( t && t.node.nodeName != '#text' && t.node.nodeName != 'BR' && t.node.nodeName != 'P' ) {
387398 t = t.next();
388399 }
389400 if ( t && !t.inP && t.node.nodeName != 'P' ) {
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -6800,13 +6800,24 @@
68016801 // .find( '* + p' ) isn't good enough because textnodes aren't considered
68026802 $pre.find( 'p' ).each( function() {
68036803 if ( this.previousSibling || this.parentNode != $pre.get( 0 ) ) {
6804 - var text = "\n" + $( this ).text();
 6804+ var text = $( this ).text();
68056805 // If this <p> is preceded by some text, add a \n at the beginning, and if
68066806 // it's followed by a textnode, add a \n at the end
68076807 // We need the traverser because there can be other weird stuff in between
6808 - // TODO: We need a reverse traverser, write this
6809 - var t = new context.fn.rawTraverser( this.lastChild, -10, this ).next();
 6808+
 6809+ // Check for preceding text
 6810+ // FIXME: Add an option to disable depth checking, -10 is a hack
 6811+ var t = new context.fn.rawTraverser( this.firstChild, -10, this ).prev();
68106812 while ( t && t.node.nodeName != '#text' && t.node.nodeName != 'BR' && t.node.nodeName != 'P' ) {
 6813+ t = t.prev();
 6814+ }
 6815+ if ( t ) {
 6816+ text = "\n" + text;
 6817+ }
 6818+
 6819+ // Check for following text
 6820+ t = new context.fn.rawTraverser( this.lastChild, -10, this ).next();
 6821+ while ( t && t.node.nodeName != '#text' && t.node.nodeName != 'BR' && t.node.nodeName != 'P' ) {
68116822 t = t.next();
68126823 }
68136824 if ( t && !t.inP && t.node.nodeName != 'P' ) {
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -450,7 +450,9 @@
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>'+
453453 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)){var text="\n"+$(this).text();var t=new context.fn.rawTraverser(this.lastChild,-10,this).next();while(t&&t.node.nodeName!='#text'&&t.node.nodeName!='BR'&&t.node.nodeName!='P'){t=t.next();}
 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)){var text=$(this).text();var t=new context.fn.rawTraverser(this.firstChild,-10,this).prev();while(t&&t.node.nodeName!='#text'&&t.node.nodeName!='BR'&&t.node.nodeName!='P'){t=t.prev();}
 455+if(t){text="\n"+text;}
 456+t=new context.fn.rawTraverser(this.lastChild,-10,this).next();while(t&&t.node.nodeName!='#text'&&t.node.nodeName!='BR'&&t.node.nodeName!='P'){t=t.next();}
455457 if(t&&!t.inP&&t.node.nodeName!='P'){text+="\n";}
456458 $(this).text(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();}
457459 if(typeof retval.text!='undefined'){retval=context.fn.htmlToText(retval.htmlText);}else if(retval.toString){retval=retval.toString();}

Status & tagging log