r56248 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56247‎ | r56248 | r56249 >
Date:21:40, 12 September 2009
Author:catrope
Status:ok
Tags:
Comment:
EditToolbar: (bug 20618) Stop the link dialog from inserting links to empty titles or URLs. Currently, the URL check only checks for the empty string and 'http://' , but we could replace that by a more elaborate URL-valiating regex. Also bump style versions and recombine for r56247
Modified paths:
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.i18n.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php (modified) (history)
  • /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)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -61,7 +61,7 @@
6262 array( 'src' => 'js/plugins/jquery.browser.js', 'version' => 3 ),
6363 array( 'src' => 'js/plugins/jquery.cookie.js', 'version' => 3 ),
6464 array( 'src' => 'js/plugins/jquery.namespaceSelect.js', 'version' => 1 ),
65 - array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 1 ),
 65+ array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 2 ),
6666 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 9 ),
6767 array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 4 ),
6868 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 11 ),
@@ -70,10 +70,10 @@
7171 array( 'src' => 'js/js2/jquery-ui-1.7.2.js', 'version' => '1.7.2x' ),
7272 ),
7373 'combined' => array(
74 - array( 'src' => 'js/plugins.combined.js', 'version' => 18 ),
 74+ array( 'src' => 'js/plugins.combined.js', 'version' => 19 ),
7575 ),
7676 'minified' => array(
77 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 18 ),
 77+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 19 ),
7878 ),
7979 ),
8080 );
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.hooks.php
@@ -50,6 +50,7 @@
5151 'edittoolbar-tool-link-int-target-status-invalid',
5252 'edittoolbar-tool-link-int-target-status-loading',
5353 'edittoolbar-tool-link-int-invalid',
 54+ 'edittoolbar-tool-link-ext-invalid',
5455 'edittoolbar-tool-file',
5556 'edittoolbar-tool-file-pre',
5657 'edittoolbar-tool-file-example',
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js
@@ -912,14 +912,15 @@
913913 var whitespace = [ '', '' ];
914914 switch ( $j( '#edittoolbar-link-tabs' ).tabs( 'option', 'selected' ) ) {
915915 case 0: // Internal link
 916+ var target = $j( '#edittoolbar-link-int-target' ).val();
 917+ var text = $j( '#edittoolbar-link-int-text' ).val();
916918 // FIXME: Exactly how fragile is this?
917 - if ( $j( '#edittoolbar-link-int-target-status-invalid' ).is( ':visible' ) ) {
 919+ if ( $j( '#edittoolbar-link-int-target-status-invalid' ).is( ':visible' ) ||
 920+ target == '' ) {
918921 // Refuse to add links to invalid titles
919922 alert( gM( 'edittoolbar-tool-link-int-invalid' ) );
920923 return;
921924 }
922 - var target = $j( '#edittoolbar-link-int-target' ).val();
923 - var text = $j( '#edittoolbar-link-int-text' ).val();
924925 whitespace = $j( '#edittoolbar-link-dialog-tab-int' ).data( 'whitespace' );
925926 if ( target == text )
926927 insertText = '[[' + target + ']]';
@@ -932,6 +933,12 @@
933934 var escTarget = escapeExternalTarget( target );
934935 var escText = escapeExternalText( text );
935936 whitespace = $j( '#edittoolbar-link-dialog-tab-ext' ).data( 'whitespace' );
 937+ if ( target == '' || target == 'http://' ) {
 938+ // Refuse to add links to invalid URLs
 939+ // TODO: More elaborate regex here?
 940+ alert( gM( 'edittoolbar-tool-link-ext-invalid' ) );
 941+ return;
 942+ }
936943 if ( escTarget == escText )
937944 insertText = escTarget;
938945 else if ( text == '' )
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.i18n.php
@@ -36,6 +36,7 @@
3737 'edittoolbar-tool-link-int-target-status-invalid' => 'Invalid title',
3838 'edittoolbar-tool-link-int-target-status-loading' => 'Checking page existence...',
3939 'edittoolbar-tool-link-int-invalid' => 'The title you specified is invalid.',
 40+ 'edittoolbar-tool-link-ext-invalid' => 'The URL you specified is invalid.',
4041 'edittoolbar-tool-file' => 'Embedded file',
4142 'edittoolbar-tool-file-pre' => '$1{{ns:file}}:',
4243 'edittoolbar-tool-file-example' => 'Example.jpg',
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php
@@ -19,7 +19,7 @@
2020 /* Configuration */
2121
2222 // Bump the version number every time you change any of the .css/.js files
23 -$wgEditToolbarStyleVersion = 29;
 23+$wgEditToolbarStyleVersion = 30;
2424
2525 // Set this to true to simply override the stock toolbar for everyone
2626 $wgEditToolbarGlobalEnable = false;
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -484,6 +484,10 @@
485485 $.suggestions.restore( context );
486486 } else {
487487 context.data.$textbox.val( result.data( 'text' ) );
 488+
 489+ // .val() doesn't call any event handlers, so
 490+ // let the world know what happened
 491+ context.data.$textbox.change();
488492 }
489493 }
490494 $.suggestions.special( context );
@@ -613,7 +617,7 @@
614618 if ( $result.get( 0 ) != $other.get( 0 ) ) {
615619 return;
616620 }
617 - highlight( $result, true );
 621+ $.suggestions.highlight( context, $result, true );
618622 context.data.$container.hide();
619623 if ( typeof context.config.result.select == 'function' ) {
620624 context.config.result.select.call( $result, context.data.$textbox );
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -31,13 +31,13 @@
3232 result=context.data.$container.find('.suggestions-results div:first');else{result=selected.next();if(result.size()==0)
3333 result=selected;}}
3434 selected.removeClass('suggestions-result-current');result.addClass('suggestions-result-current');}
35 -if(updateTextbox){if(result.size()==0){$.suggestions.restore(context);}else{context.data.$textbox.val(result.data('text'));}}
 35+if(updateTextbox){if(result.size()==0){$.suggestions.restore(context);}else{context.data.$textbox.val(result.data('text'));context.data.$textbox.change();}}
3636 $.suggestions.special(context);},keypress:function(context,key){switch(key){case 40:if(context.data.$container.is(':visible')){$.suggestions.highlight(context,'next',true);}else{$.suggestions.update(context,false);}
3737 context.data.$textbox.trigger('change');break;case 38:if(context.data.$container.is(':visible')){$.suggestions.highlight(context,'prev',true);}
3838 context.data.$textbox.trigger('change');break;case 27:context.data.$container.hide();$.suggestions.restore(context);$.suggestions.cancel(context);context.data.$textbox.trigger('change');break;case 13:context.data.$container.hide();break;default:$.suggestions.update(context,true);break;}}};$.fn.suggestions=function(){var returnValue=null;var args=arguments;$(this).each(function(){var context=$(this).data('suggestions-context');if(typeof context=='undefined'){context={config:{'fetch':function(){},'cancel':function(){},'special':{},'result':{},'$region':$(this),'suggestions':[],'maxRows':7,'delay':1200,'submitOnClick':false}};}
3939 if(args.length>0){if(typeof args[0]=='object'){for(key in args[0]){$.suggestions.configure(context,key,args[0][key]);}}else if(typeof args[0]=='string'){if(args.length>1){$.suggestions.configure(context,args[0],args[1]);}else if(returnValue==null){returnValue=(args[0]in context.config?undefined:context.config[args[0]]);}}}
4040 if(typeof context.data=='undefined'){context.data={'timerID':null,'prevText':null,'visibleResults':0,'mouseDownOn':$([]),'$textbox':$(this)};context.data.$container=$('<div />').css({'top':Math.round(context.data.$textbox.offset().top+context.data.$textbox.outerHeight()),'left':Math.round(context.data.$textbox.offset().left),'width':context.data.$textbox.outerWidth(),'display':'none'}).mouseover(function(e){$.suggestions.highlight(context,$(e.target).closest('.suggestions-results div'),false);}).addClass('suggestions').append($('<div />').addClass('suggestions-results').mousedown(function(e){context.data.mouseDownOn=$(e.target).closest('.suggestions-results div');}).mouseup(function(e){var $result=$(e.target).closest('.suggestions-results div');var $other=context.data.mouseDownOn;context.data.mouseDownOn=$([]);if($result.get(0)!=$other.get(0)){return;}
41 -highlight($result,true);context.data.$container.hide();if(typeof context.config.result.select=='function'){context.config.result.select.call($result,context.data.$textbox);}
 41+$.suggestions.highlight(context,$result,true);context.data.$container.hide();if(typeof context.config.result.select=='function'){context.config.result.select.call($result,context.data.$textbox);}
4242 context.data.$textbox.focus();})).append($('<div />').addClass('suggestions-special').mousedown(function(e){context.data.mouseDownOn=$(e.target).closest('.suggestions-special');}).mouseup(function(e){var $special=$(e.target).closest('.suggestions-special');var $other=context.data.mouseDownOn;context.data.mouseDownOn=$([]);if($special.get(0)!=$other.get(0)){return;}
4343 context.data.$container.hide();if(typeof context.config.special.select=='function'){context.config.special.select.call($special,context.data.$textbox);}
4444 context.data.$textbox.focus();})).appendTo($('body'));$(this).attr('autocomplete','off').keydown(function(e){context.data.keypressed=(e.keyCode==undefined)?e.which:e.keyCode;context.data.keypressedCount=0;}).keypress(function(){context.data.keypressedCount++;$.suggestions.keypress(context,context.data.keypressed);}).keyup(function(){if(context.data.keypressedCount==0){$.suggestions.keypress(context,context.data.keypressed);}}).blur(function(){if(context.data.mouseDownOn.size()>0){return;}

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r56247Suggestions plugin: (bug 20617) Clicking a suggestion doesn't workcatrope21:29, 12 September 2009

Status & tagging log