Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.hooks.php |
— | — | @@ -101,7 +101,11 @@ |
102 | 102 | 'edittoolbar-tool-replace-title', |
103 | 103 | 'edittoolbar-tool-replace-search', |
104 | 104 | 'edittoolbar-tool-replace-replace', |
| 105 | + 'edittoolbar-tool-replace-case', |
| 106 | + 'edittoolbar-tool-replace-regex', |
| 107 | + 'edittoolbar-tool-replace-all', |
105 | 108 | 'edittoolbar-tool-replace-button', |
| 109 | + 'edittoolbar-tool-replace-nomatch', |
106 | 110 | /* Special Characters Section */ |
107 | 111 | 'edittoolbar-section-characters', |
108 | 112 | 'edittoolbar-characters-page-latin', |
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js |
— | — | @@ -8,6 +8,13 @@ |
9 | 9 | ); |
10 | 10 | }); |
11 | 11 | |
| 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 | + |
12 | 19 | /** |
13 | 20 | * This enormous structure is what makes the toolbar what it is. Customization |
14 | 21 | * of this structure prior to the document being ready and thus executing the |
— | — | @@ -331,20 +338,35 @@ |
332 | 339 | type: 'dialog', |
333 | 340 | titleMsg: 'edittoolbar-tool-replace-title', |
334 | 341 | 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' ) + |
337 | 344 | '</label><input type="text" id="edittoolbar-replace-search" style="display:block;" /><label for="edittoolbar-replace-replace">' + |
338 | 345 | 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>'; |
340 | 352 | }, |
341 | 353 | dialog: { |
342 | 354 | buttons: { |
343 | 355 | 'edittoolbar-tool-replace-button': function() { |
344 | 356 | var searchStr = $j( '#edittoolbar-replace-search' ).val(); |
345 | 357 | 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 ); |
347 | 366 | 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 ) ); |
349 | 371 | // TODO: Hook for wikEd |
350 | 372 | } |
351 | 373 | } |
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.i18n.php |
— | — | @@ -75,9 +75,13 @@ |
76 | 76 | | row 2, cell 3", |
77 | 77 | 'edittoolbar-tool-replace' => 'Replace', |
78 | 78 | '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:', |
80 | 80 | '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', |
81 | 84 | 'edittoolbar-tool-replace-button' => 'Replace', |
| 85 | + 'edittoolbar-tool-replace-nomatch' => "Your search didn't match anything.", |
82 | 86 | /* Special characters Section */ |
83 | 87 | 'edittoolbar-section-characters' => 'Special characters', |
84 | 88 | 'edittoolbar-characters-page-latin' => 'Latin', |
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | /* Configuration */ |
21 | 21 | |
22 | 22 | // Bump the version number every time you change any of the .css/.js files |
23 | | -$wgEditToolbarStyleVersion = 17; |
| 23 | +$wgEditToolbarStyleVersion = 18; |
24 | 24 | |
25 | 25 | // Set this to true to simply override the stock toolbar for everyone |
26 | 26 | $wgEditToolbarGlobalEnable = false; |