r54827 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54826‎ | r54827 | r54828 >
Date:23:18, 11 August 2009
Author:catrope
Status:deferred
Tags:
Comment:
EditToolbar: Extend search&replace dialog with case sensitive/insensitive checkbox and regex checkbox
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)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.hooks.php
@@ -101,7 +101,11 @@
102102 'edittoolbar-tool-replace-title',
103103 'edittoolbar-tool-replace-search',
104104 'edittoolbar-tool-replace-replace',
 105+ 'edittoolbar-tool-replace-case',
 106+ 'edittoolbar-tool-replace-regex',
 107+ 'edittoolbar-tool-replace-all',
105108 'edittoolbar-tool-replace-button',
 109+ 'edittoolbar-tool-replace-nomatch',
106110 /* Special Characters Section */
107111 'edittoolbar-section-characters',
108112 'edittoolbar-characters-page-latin',
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js
@@ -8,6 +8,13 @@
99 );
1010 });
1111
 12+/*
 13+ * Extend the RegExp object with an escaping function
 14+ * From http://simonwillison.net/2006/Jan/20/escape/
 15+ */
 16+
 17+RegExp.escape = function(s) { return s.replace(/([.*+?^${}()|\/\\[\]])/g, '\\$1'); }
 18+
1219 /**
1320 * This enormous structure is what makes the toolbar what it is. Customization
1421 * of this structure prior to the document being ready and thus executing the
@@ -331,20 +338,35 @@
332339 type: 'dialog',
333340 titleMsg: 'edittoolbar-tool-replace-title',
334341 id: 'edittoolbar-replace-dialog',
335 - html: function() { return '<form><fieldset><label for="edittoolbar-replace-search">'
336 - + gM( 'edittoolbar-tool-replace-search' ) +
 342+ html: function() { return '<form><fieldset><label for="edittoolbar-replace-search">'+
 343+ gM( 'edittoolbar-tool-replace-search' ) +
337344 '</label><input type="text" id="edittoolbar-replace-search" style="display:block;" /><label for="edittoolbar-replace-replace">' +
338345 gM( 'edittoolbar-tool-replace-replace' ) +
339 - '</label><input type="text" id="edittoolbar-replace-replace" style="display:block;" /></fieldset></form>';
 346+ '</label><input type="text" id="edittoolbar-replace-replace" style="display:block;" /><input type="checkbox" id="edittoolbar-replace-case" /><label for="edittoolbar-replace-case">' +
 347+ gM( 'edittoolbar-tool-replace-case' ) +
 348+ '</label><br /><input type="checkbox" id="edittoolbar-replace-regex" /><label for="edittoolbar-replace-regex">' +
 349+ gM( 'edittoolbar-tool-replace-regex' ) + '</label><br /><input type="checkbox" id="edittoolbar-replace-all" /><label for="edittoolbar-replace-all">' +
 350+ gM( 'edittoolbar-tool-replace-all' ) +
 351+ '</label></fieldset></form>';
340352 },
341353 dialog: {
342354 buttons: {
343355 'edittoolbar-tool-replace-button': function() {
344356 var searchStr = $j( '#edittoolbar-replace-search' ).val();
345357 var replaceStr = $j( '#edittoolbar-replace-replace' ).val();
346 - var regex = new RegExp( searchStr, 'g' );
 358+ var flags = '';
 359+ if ( !$j( '#edittoolbar-replace-case' ).is( ':checked' ) )
 360+ flags += 'i';
 361+ if ( $j( '#edittoolbar-replace-all' ).is( ':checked' ) )
 362+ flags += 'g';
 363+ if ( !$j( '#edittoolbar-replace-regex' ).is( ':checked' ) )
 364+ searchStr = RegExp.escape( searchStr );
 365+ var regex = new RegExp( searchStr, flags );
347366 var $textarea = $j(this).data( 'context' ).$textarea;
348 - $textarea.val( $textarea.val().replace( regex, replaceStr ) );
 367+ if ( !$textarea.val().match( regex ) )
 368+ alert( gM( 'edittoolbar-tool-replace-nomatch' ) );
 369+ else
 370+ $textarea.val( $textarea.val().replace( regex, replaceStr ) );
349371 // TODO: Hook for wikEd
350372 }
351373 }
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.i18n.php
@@ -75,9 +75,13 @@
7676 | row 2, cell 3",
7777 'edittoolbar-tool-replace' => 'Replace',
7878 'edittoolbar-tool-replace-title' => 'Search and replace',
79 - 'edittoolbar-tool-replace-search' => 'Search for (may be a regex):',
 79+ 'edittoolbar-tool-replace-search' => 'Search for:',
8080 'edittoolbar-tool-replace-replace' => 'Replace with:',
 81+ 'edittoolbar-tool-replace-case' => 'Match case',
 82+ 'edittoolbar-tool-replace-regex' => 'Treat search string as a regular expression',
 83+ 'edittoolbar-tool-replace-all' => 'Replace all occurences',
8184 'edittoolbar-tool-replace-button' => 'Replace',
 85+ 'edittoolbar-tool-replace-nomatch' => "Your search didn't match anything.",
8286 /* Special characters Section */
8387 'edittoolbar-section-characters' => 'Special characters',
8488 'edittoolbar-characters-page-latin' => 'Latin',
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 = 17;
 23+$wgEditToolbarStyleVersion = 18;
2424
2525 // Set this to true to simply override the stock toolbar for everyone
2626 $wgEditToolbarGlobalEnable = false;

Status & tagging log