r65763 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65762‎ | r65763 | r65764 >
Date:21:14, 1 May 2010
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: Various fixes
* Fix Makefile broken by r65660 and run it to combine+minify the AMW code into WikiEditor.combined.js and .min.js
* Fix some whitespace in AddMediaWizard.js while I'm in there
* Fix excessive $newElement.html() calls added in r65646, these are expensive. Instead, build the HTML first, then add it with .html()
* Fix some style and a missing semicolon for r65646 and previous revs
Modified paths:
  • /trunk/extensions/UsabilityInitiative/Makefile (modified) (history)
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/WikiEditor/Modules/AddMediaWizard/AddMediaWizard.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.combined.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.combined.min.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.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.delayedBind.js', 'version' => 1 ),
7474 array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 11 ),
7575 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 30 ),
76 - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 183 ),
 76+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 184 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 52 ),
7878 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 59 ),
7979 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 24 ),
@@ -82,10 +82,10 @@
8383 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 5 ),
8484 ),
8585 'combined' => array(
86 - array( 'src' => 'js/plugins.combined.js', 'version' => 387 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 388 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 387 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 388 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.hooks.php
@@ -21,10 +21,10 @@
2222 array( 'src' => 'Modules/AddMediaWizard/AddMediaWizard.js', 'version' => 6 ),
2323 ),
2424 'combined' => array(
25 - array( 'src' => 'WikiEditor.combined.js', 'version' => 87 ),
 25+ array( 'src' => 'WikiEditor.combined.js', 'version' => 88 ),
2626 ),
2727 'minified' => array(
28 - array( 'src' => 'WikiEditor.combined.min.js', 'version' => 87 ),
 28+ array( 'src' => 'WikiEditor.combined.min.js', 'version' => 88 ),
2929 ),
3030 );
3131 static $messages = array(
Index: trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.combined.js
@@ -2078,3 +2078,13 @@
20792079 $j( 'textarea#wpTextbox1' ).wikiEditor( 'addModule', 'templateEditor' );
20802080 }
20812081 });
 2082+/* JavaScript for AddMediaWizard gadget */
 2083+if ( wgWikiEditorEnabledModules.addMediaWizard ) {
 2084+ if( typeof mwAddMediaConfig == 'undefined' ) {
 2085+ mwAddMediaConfig = {};
 2086+ }
 2087+ mwAddMediaConfig['enabled_providers'] = [ 'wiki_commons', 'upload' ];
 2088+
 2089+ // Transclude mwEmbed support
 2090+ importScriptURI( 'http://prototype.wikimedia.org/s-2/js/mwEmbed/remotes/mediaWiki.js?&uselang=' + wgUserLanguage );
 2091+}
Index: trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.combined.min.js
@@ -191,4 +191,5 @@
192192 $textarea.textSelection('scrollToCaretPosition');$textarea.textSelection('setSelection',{'start':start,'end':mode=='replace'?newEnd:end});$j(this).data('offset',mode=='replace'?newEnd:end);var textbox=typeof context.$iframe!='undefined'?context.$iframe[0].contentWindow:$textarea;textbox.focus();}});},dialog:{width:500,dialogClass:'wikiEditor-toolbar-dialog',buttons:{'wikieditor-toolbar-tool-replace-button-findnext':function(e){$j(this).closest('.ui-dialog').data('dialogaction',e.target);$j(this).data('replaceCallback').call(this,'find');},'wikieditor-toolbar-tool-replace-button-replacenext':function(e){$j(this).closest('.ui-dialog').data('dialogaction',e.target);$j(this).data('replaceCallback').call(this,'replace');},'wikieditor-toolbar-tool-replace-button-replaceall':function(e){$j(this).closest('.ui-dialog').data('dialogaction',e.target);$j(this).data('replaceCallback').call(this,'replaceAll');},'wikieditor-toolbar-tool-replace-close':function(){$j(this).dialog('close');}},open:function(){$j(this).data('offset',0);$j('#wikieditor-toolbar-replace-search').focus();$j('#wikieditor-toolbar-replace-nomatch, #wikieditor-toolbar-replace-success, #wikieditor-toolbar-replace-emptysearch, #wikieditor-toolbar-replace-invalidregex').hide();if(!($j(this).data('onetimeonlystuff'))){$j(this).data('onetimeonlystuff',true);$j(this).closest('.ui-dialog').keypress(function(e){if((e.keyCode||e.which)==13){var button=$j(this).data('dialogaction')||$j(this).find('button:first');button.click();e.preventDefault();}});$j(this).closest('.ui-dialog').find('button').focus(function(){$j(this).closest('.ui-dialog').data('dialogaction',this);});}
193193 var dialog=$j(this).closest('.ui-dialog');var that=this;var context=$j(this).data('context');var textbox=typeof context.$iframe!='undefined'?context.$iframe[0].contentWindow.document:context.$textarea;$j(textbox).bind('keypress.srdialog',function(e){if((e.keyCode||e.which)==13){var button=dialog.data('dialogaction')||dialog.find('button:first');button.click();e.preventDefault();}else if((e.keyCode||e.which)==27){$j(that).dialog('close');}});},close:function(){var context=$j(this).data('context');var textbox=typeof context.$iframe!='undefined'?context.$iframe[0].contentWindow.document:context.$textarea;$j(textbox).unbind('keypress.srdialog');$j(this).closest('.ui-dialog').data('dialogaction',false);}}}}});}});$j(document).ready(function(){if(!wgWikiEditorEnabledModules.templateEditor){return true;}
194194 if(wgNamespaceNumber==10){return true;}
195 -if($j.fn.wikiEditor){$j('textarea#wpTextbox1').wikiEditor('addModule','templateEditor');}});
\ No newline at end of file
 195+if($j.fn.wikiEditor){$j('textarea#wpTextbox1').wikiEditor('addModule','templateEditor');}});if(wgWikiEditorEnabledModules.addMediaWizard){if(typeof mwAddMediaConfig=='undefined'){mwAddMediaConfig={};}
 196+mwAddMediaConfig['enabled_providers']=['wiki_commons','upload'];importScriptURI('http://prototype.wikimedia.org/s-2/js/mwEmbed/remotes/mediaWiki.js?&uselang='+wgUserLanguage);}
\ No newline at end of file
Index: trunk/extensions/UsabilityInitiative/WikiEditor/Modules/AddMediaWizard/AddMediaWizard.js
@@ -1,11 +1,10 @@
2 -
32 /* JavaScript for AddMediaWizard gadget */
4 -if ( wgWikiEditorEnabledModules.addMediaWizard ) {
5 - if( typeof mwAddMediaConfig == 'undefined'){
 3+if ( wgWikiEditorEnabledModules.addMediaWizard ) {
 4+ if( typeof mwAddMediaConfig == 'undefined' ) {
65 mwAddMediaConfig = {};
76 }
87 mwAddMediaConfig['enabled_providers'] = [ 'wiki_commons', 'upload' ];
98
109 // Transclude mwEmbed support
11 - importScriptURI('http://prototype.wikimedia.org/s-2/js/mwEmbed/remotes/mediaWiki.js?&uselang=' + wgUserLanguage );
 10+ importScriptURI( 'http://prototype.wikimedia.org/s-2/js/mwEmbed/remotes/mediaWiki.js?&uselang=' + wgUserLanguage );
1211 }
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -446,12 +446,12 @@
447447
448448 // If the pasted content is plain text then wrap it in a <p> and adjust the <br> accordingly
449449 var pasteContent = context.fn.getOffset( cursorPos[0] ).node;
450 - var removeNextBR = false
451 - while ( pasteContent != null && ! $( pasteContent ).hasClass( 'wikiEditor' ) ) {
 450+ var removeNextBR = false;
 451+ while ( pasteContent != null && !$( pasteContent ).hasClass( 'wikiEditor' ) ) {
452452 var currentNode = pasteContent;
453453 pasteContent = pasteContent.nextSibling;
454454 if ( currentNode.nodeName == '#text' && currentNode.nodeValue == currentNode.wholeText ) {
455 - var pWrapper = $( '<p></p>' ).addClass( 'wikiEditor' );
 455+ var pWrapper = $( '<p />' ).addClass( 'wikiEditor' );
456456 $( currentNode ).wrap( pWrapper );
457457 $( currentNode ).addClass( 'wikiEditor' );
458458 removeNextBR = true;
@@ -472,25 +472,25 @@
473473 var $newElement;
474474 if ( $currentElement.is( 'p' ) || $currentElement.is( 'div' ) || $currentElement.is( 'pre' ) ) {
475475 //Convert all <div>, <p> and <pre> that was pasted into a <p> element
476 - $newElement = $( '<p></p>' );
 476+ $newElement = $( '<p />' );
477477 } else {
478478 // everything else becomes a <span>
479 - $newElement = $( '<span></span>' ).addClass( 'wikiEditor' );
 479+ $newElement = $( '<span />' ).addClass( 'wikiEditor' );
480480 }
481481
482482 // If the pasted content was html, just convert it into text and <br>
483 - var text = $.trim( $currentElement.text() );
484 - var pieces = text.split('\n');
 483+ var pieces = $.trim( $currentElement.text() ).split( '\n' );
 484+ var newElementHTML = '';
485485 for ( var i = 0; i < pieces.length; i++ ) {
486 - if ( pieces[i] ) {
487 - $newElement.html( $newElement.html() + $.trim( pieces[i] ) );
 486+ if ( pieces[i] ) {
 487+ newElementHTML += $.trim( pieces[i] );
488488 } else {
489 - var $brElement = $( '<span></span>' ).html( '<br class = "wikiEditor" />' );
490 - $newElement.html( $newElement.html() + $brElement.html() );
 489+ newElementHTML += '<span><br class="wikiEditor" /></span>';
491490 }
492 - }
493 - $newElement.insertAfter( $currentElement );
494 - $newElement.addClass( 'wikiEditor' );
 491+ }
 492+ $newElement.html( newElementHTML )
 493+ .addClass( 'wikiEditor' )
 494+ .insertAfter( $currentElement );
495495 $currentElement.remove();
496496
497497 $selection = context.$content.find( ':not(.wikiEditor)' );
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -7031,12 +7031,12 @@
70327032
70337033 // If the pasted content is plain text then wrap it in a <p> and adjust the <br> accordingly
70347034 var pasteContent = context.fn.getOffset( cursorPos[0] ).node;
7035 - var removeNextBR = false
7036 - while ( pasteContent != null && ! $( pasteContent ).hasClass( 'wikiEditor' ) ) {
 7035+ var removeNextBR = false;
 7036+ while ( pasteContent != null && !$( pasteContent ).hasClass( 'wikiEditor' ) ) {
70377037 var currentNode = pasteContent;
70387038 pasteContent = pasteContent.nextSibling;
70397039 if ( currentNode.nodeName == '#text' && currentNode.nodeValue == currentNode.wholeText ) {
7040 - var pWrapper = $( '<p></p>' ).addClass( 'wikiEditor' );
 7040+ var pWrapper = $( '<p />' ).addClass( 'wikiEditor' );
70417041 $( currentNode ).wrap( pWrapper );
70427042 $( currentNode ).addClass( 'wikiEditor' );
70437043 removeNextBR = true;
@@ -7057,25 +7057,25 @@
70587058 var $newElement;
70597059 if ( $currentElement.is( 'p' ) || $currentElement.is( 'div' ) || $currentElement.is( 'pre' ) ) {
70607060 //Convert all <div>, <p> and <pre> that was pasted into a <p> element
7061 - $newElement = $( '<p></p>' );
 7061+ $newElement = $( '<p />' );
70627062 } else {
70637063 // everything else becomes a <span>
7064 - $newElement = $( '<span></span>' ).addClass( 'wikiEditor' );
 7064+ $newElement = $( '<span />' ).addClass( 'wikiEditor' );
70657065 }
70667066
70677067 // If the pasted content was html, just convert it into text and <br>
7068 - var text = $.trim( $currentElement.text() );
7069 - var pieces = text.split('\n');
 7068+ var pieces = $.trim( $currentElement.text() ).split( '\n' );
 7069+ var newElementHTML = '';
70707070 for ( var i = 0; i < pieces.length; i++ ) {
7071 - if ( pieces[i] ) {
7072 - $newElement.html( $newElement.html() + $.trim( pieces[i] ) );
 7071+ if ( pieces[i] ) {
 7072+ newElementHTML += $.trim( pieces[i] );
70737073 } else {
7074 - var $brElement = $( '<span></span>' ).html( '<br class = "wikiEditor" />' );
7075 - $newElement.html( $newElement.html() + $brElement.html() );
 7074+ newElementHTML += '<span><br class="wikiEditor" /></span>';
70767075 }
7077 - }
7078 - $newElement.insertAfter( $currentElement );
7079 - $newElement.addClass( 'wikiEditor' );
 7076+ }
 7077+ $newElement.html( newElementHTML )
 7078+ .addClass( 'wikiEditor' )
 7079+ .insertAfter( $currentElement );
70807080 $currentElement.remove();
70817081
70827082 $selection = context.$content.find( ':not(.wikiEditor)' );
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -467,12 +467,11 @@
468468 if(context.$content.children().length==0){context.$content.append('<p></p>');}
469469 return true;},'delayedChange':function(event){event.data.scope='division';var newHTML=context.$content.html();if(context.oldDelayedHTML!=newHTML){context.oldDelayedHTML=newHTML;event.data.scope='realchange';var cursorPos=context.fn.getCaretPosition();var t=context.fn.getOffset(cursorPos[0]);if(t&&t.node.nodeName=='#text'&&t.node.parentNode.nodeName.toLowerCase()=='body'){$(t.node).wrap("<p></p>");context.fn.purgeOffsets();context.fn.setSelection({start:cursorPos[0],end:cursorPos[1]});}}
470470 context.fn.updateHistory(event.data.scope=='realchange');return true;},'cut':function(event){setTimeout(function(){context.$content.find('br').each(function(){if($(this).parent().is('body')){$(this).wrap($('<p></p>'));}});},100);return true;},'paste':function(event){var cursorPos=context.fn.getCaretPosition();var oldLength=context.fn.getContents().length-(cursorPos[1]-cursorPos[0]);context.$content.find(':not(.wikiEditor)').addClass('wikiEditor');if($.layout.name!=='webkit'){context.$content.addClass('pasting');}
471 -setTimeout(function(){context.$content.find('script,style,img,input,select,textarea,hr,button,link,meta').remove();context.$content.find('*').each(function(){if($(this).children().length==0&&this.childNodes.length>0){$(this).text($(this).text());}});context.$content.find('p:not(.wikiEditor) p:not(.wikiEditor)').each(function(){var outerParent=$(this).parent();outerParent.replaceWith(outerParent.childNodes);});context.$content.find('span.Apple-style-span').each(function(){$(this).replaceWith(this.childNodes);});var pasteContent=context.fn.getOffset(cursorPos[0]).node;var removeNextBR=false
472 -while(pasteContent!=null&&!$(pasteContent).hasClass('wikiEditor')){var currentNode=pasteContent;pasteContent=pasteContent.nextSibling;if(currentNode.nodeName=='#text'&&currentNode.nodeValue==currentNode.wholeText){var pWrapper=$('<p></p>').addClass('wikiEditor');$(currentNode).wrap(pWrapper);$(currentNode).addClass('wikiEditor');removeNextBR=true;}else if(currentNode.nodeName=='BR'&&removeNextBR){$(currentNode).remove();removeNextBR=false;}else{removeNextBR=false;}}
 471+setTimeout(function(){context.$content.find('script,style,img,input,select,textarea,hr,button,link,meta').remove();context.$content.find('*').each(function(){if($(this).children().length==0&&this.childNodes.length>0){$(this).text($(this).text());}});context.$content.find('p:not(.wikiEditor) p:not(.wikiEditor)').each(function(){var outerParent=$(this).parent();outerParent.replaceWith(outerParent.childNodes);});context.$content.find('span.Apple-style-span').each(function(){$(this).replaceWith(this.childNodes);});var pasteContent=context.fn.getOffset(cursorPos[0]).node;var removeNextBR=false;while(pasteContent!=null&&!$(pasteContent).hasClass('wikiEditor')){var currentNode=pasteContent;pasteContent=pasteContent.nextSibling;if(currentNode.nodeName=='#text'&&currentNode.nodeValue==currentNode.wholeText){var pWrapper=$('<p />').addClass('wikiEditor');$(currentNode).wrap(pWrapper);$(currentNode).addClass('wikiEditor');removeNextBR=true;}else if(currentNode.nodeName=='BR'&&removeNextBR){$(currentNode).remove();removeNextBR=false;}else{removeNextBR=false;}}
473472 var $selection=context.$content.find(':not(.wikiEditor)');while($selection.length&&$selection.length>0){var $currentElement=$selection.eq(0);while(!$currentElement.parent().is('body')&&!$currentElement.parent().is('.wikiEditor')){$currentElement=$currentElement.parent();}
474 -var $newElement;if($currentElement.is('p')||$currentElement.is('div')||$currentElement.is('pre')){$newElement=$('<p></p>');}else{$newElement=$('<span></span>').addClass('wikiEditor');}
475 -var text=$.trim($currentElement.text());var pieces=text.split('\n');for(var i=0;i<pieces.length;i++){if(pieces[i]){$newElement.html($newElement.html()+$.trim(pieces[i]));}else{var $brElement=$('<span></span>').html('<br class = "wikiEditor" />');$newElement.html($newElement.html()+$brElement.html());}}
476 -$newElement.insertAfter($currentElement);$newElement.addClass('wikiEditor');$currentElement.remove();$selection=context.$content.find(':not(.wikiEditor)');}
 473+var $newElement;if($currentElement.is('p')||$currentElement.is('div')||$currentElement.is('pre')){$newElement=$('<p />');}else{$newElement=$('<span />').addClass('wikiEditor');}
 474+var pieces=$.trim($currentElement.text()).split('\n');var newElementHTML='';for(var i=0;i<pieces.length;i++){if(pieces[i]){newElementHTML+=$.trim(pieces[i]);}else{newElementHTML+='<span><br class="wikiEditor" /></span>';}}
 475+$newElement.html(newElementHTML).addClass('wikiEditor').insertAfter($currentElement);$currentElement.remove();$selection=context.$content.find(':not(.wikiEditor)');}
477476 context.$content.find('.wikiEditor').removeClass('wikiEditor');if($.layout.name!=='webkit'){context.$content.removeClass('pasting');}
478477 context.fn.purgeOffsets();var newLength=context.fn.getContents().length;var restoreTo=cursorPos[0]+newLength-oldLength;context.fn.setSelection({start:restoreTo,end:restoreTo});},0);return true;},'ready':function(event){context.history.push({'html':context.$content.html(),'sel':context.fn.getCaretPosition()});return true;}};context.fn={'trigger':function(name,event){if(typeof event=='undefined'){event={'type':'custom'};}
479478 if(typeof event.data=='undefined'){event.data={};}
Index: trunk/extensions/UsabilityInitiative/Makefile
@@ -33,7 +33,7 @@
3434 js/plugins/jquery.wikiEditor.highlight.js\
3535 js/plugins/jquery.wikiEditor.preview.js\
3636 js/plugins/jquery.wikiEditor.publish.js\
37 - js/plugins/jquery.wikiEditor.templateEditor.js\
 37+ js/plugins/jquery.wikiEditor.templateEditor.js\
3838 js/plugins/jquery.wikiEditor.toc.js\
3939 js/plugins/jquery.wikiEditor.toolbar.js
4040
@@ -43,7 +43,7 @@
4444 WikiEditor/Modules/Publish/Publish.js\
4545 WikiEditor/Modules/Toc/Toc.js\
4646 WikiEditor/Modules/Toolbar/Toolbar.js\
47 - WikiEditor/Modules/TemplateEditor/TemplateEditor.js
 47+ WikiEditor/Modules/TemplateEditor/TemplateEditor.js\
4848 WikiEditor/Modules/AddMediaWizard/AddMediaWizard.js
4949
5050 VECTOR_MODULES := \

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r65646Except for the cursor position in same cases and MSWord lists. Paste mostly w...pdhanda23:16, 28 April 2010
r65660Integrated Michael Dale's patch to add a preference to the Labs section of us...tparscal17:34, 29 April 2010

Status & tagging log