Index: trunk/phase3/RELEASE-NOTES-1.19 |
— | — | @@ -74,6 +74,9 @@ |
75 | 75 | the message keys. |
76 | 76 | * (bug 29868) Add support for passing parameters to mw.msg in jquery.localize. |
77 | 77 | * (bug 29558) $wgMiserMode now disables update.php by default |
| 78 | +* AjaxCategories: Easily add, edit or delete categories on article pages. |
| 79 | + Suggests possible categories when typing, all saves are done via AJAX. |
| 80 | + Supports editing of multiple categories and then saving them in one batch. |
78 | 81 | |
79 | 82 | === Bug fixes in 1.19 === |
80 | 83 | * (bug 28868) Show total pages in the subtitle of an image on the |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -4596,6 +4596,7 @@ |
4597 | 4597 | 'ajax-confirm-prompt' => 'You can provide an edit summary below. |
4598 | 4598 | Click "Save" to save your edit.', |
4599 | 4599 | 'ajax-confirm-save' => 'Save', |
| 4600 | +'ajax-confirm-save-all' => 'Save all changes', |
4600 | 4601 | 'ajax-add-category-summary' => 'Add category "$1"', |
4601 | 4602 | 'ajax-edit-category-summary' => 'Change category "$1" to "$2"', |
4602 | 4603 | 'ajax-remove-category-summary' => 'Remove category "$1"', |
— | — | @@ -4606,5 +4607,5 @@ |
4607 | 4608 | This usually occurs when the category has been added to the page in a template.', |
4608 | 4609 | 'ajax-edit-category-error' => 'It was not possible to edit this category. |
4609 | 4610 | This usually occurs when the category has been added to the page in a template.', |
4610 | | -'ajax-category-already-present' => 'This page already has the category you specified.', |
| 4611 | +'ajax-category-already-present' => 'This page already belongs to the category $1', |
4611 | 4612 | ); |
Index: trunk/phase3/resources/mediawiki.page/mediawiki.page.ajaxCategories.js |
— | — | @@ -157,8 +157,37 @@ |
158 | 158 | return _getCats().filter( function() { return $.ucFirst(this) == $.ucFirst(cat); } ).length !== 0; |
159 | 159 | }; |
160 | 160 | |
161 | | - _confirmEdit = function ( page, fn, actionSummary, doneFn ) { |
| 161 | + /** |
| 162 | + * This get's called by all action buttons |
| 163 | + * Displays a dialog to confirm the action |
| 164 | + * Afterwords do the actual edit |
| 165 | + * |
| 166 | + * @param function fn text-modifying function |
| 167 | + * @param string actionSummary Changes done |
| 168 | + * @param function fn doneFn callback after everything is done |
| 169 | + * @return boolean True for exists |
| 170 | + */ |
| 171 | + _confirmEdit = function ( fn, actionSummary, doneFn, all ) { |
| 172 | + // Check whether to use multiEdit mode |
| 173 | + if ( mw.config.get('AJAXCategoriesMulti') && !all ) { |
| 174 | + // Stash away |
| 175 | + _stash.summaries.push( actionSummary ); |
| 176 | + _stash.fns.push( fn ); |
| 177 | + _stash.doneFns.push( doneFn ); |
162 | 178 | |
| 179 | + // Make sure we have a save button |
| 180 | + if ( !_saveAllButton ) { |
| 181 | + //TODO Make more clickable |
| 182 | + _saveAllButton = _createButton( 'icon-tick', |
| 183 | + mw.msg( 'ajax-confirm-save-all' ), |
| 184 | + '', |
| 185 | + mw.msg( 'ajax-confirm-save-all' ) |
| 186 | + ); |
| 187 | + _saveAllButton.click( _handleStashedCategories ); |
| 188 | + } |
| 189 | + |
| 190 | + return; |
| 191 | + } |
163 | 192 | // Produce a confirmation dialog |
164 | 193 | var dialog = $( '<div/>' ); |
165 | 194 | |
— | — | @@ -190,7 +219,7 @@ |
191 | 220 | var submitFunction = function() { |
192 | 221 | _addProgressIndicator( dialog ); |
193 | 222 | _doEdit( |
194 | | - page, |
| 223 | + mw.config.get( 'wgPageName' ), |
195 | 224 | fn, |
196 | 225 | reasonBox.val(), |
197 | 226 | function() { |
— | — | @@ -201,7 +230,7 @@ |
202 | 231 | ); |
203 | 232 | }; |
204 | 233 | |
205 | | - var buttons = { }; |
| 234 | + var buttons = {}; |
206 | 235 | buttons[mw.msg( 'ajax-confirm-save' )] = submitFunction; |
207 | 236 | var dialogOptions = { |
208 | 237 | 'AutoOpen' : true, |
— | — | @@ -213,6 +242,33 @@ |
214 | 243 | dialog.dialog( dialogOptions ); |
215 | 244 | }; |
216 | 245 | |
| 246 | + /** |
| 247 | + * When multiEdit mode is enabled, |
| 248 | + * this is called when the user clicks "save all" |
| 249 | + * Combines the summaries and edit functions |
| 250 | + */ |
| 251 | + _handleStashedCategories = function() { |
| 252 | + // Save fns |
| 253 | + fns = _stash.fns; |
| 254 | + |
| 255 | + //TODO do I need a space? |
| 256 | + var summary = _stash.summaries.join(' '); |
| 257 | + var combinedFn = function( oldtext ) { |
| 258 | + // Run the text through all action functions |
| 259 | + newtext = oldtext; |
| 260 | + for ( var i = 0; i < fns.length; i++ ) { |
| 261 | + newtext = fns[i]( newtext ); |
| 262 | + }; |
| 263 | + return newtext; |
| 264 | + } |
| 265 | + var doneFn = function() { |
| 266 | + //Remove saveAllButton |
| 267 | + _saveAllButton.remove(); |
| 268 | + _saveAllButton = undefined; |
| 269 | + }; |
| 270 | + |
| 271 | + }; |
| 272 | + |
217 | 273 | _doEdit = function ( page, fn, summary, doneFn ) { |
218 | 274 | // Get an edit token for the page. |
219 | 275 | var getTokenVars = { |
— | — | @@ -282,7 +338,7 @@ |
283 | 339 | * @param string Regex string. |
284 | 340 | * @return string Processed regex string |
285 | 341 | */ |
286 | | - _makeCaseInsensitiv = function ( string ) { |
| 342 | + _makeCaseInsensitive = function ( string ) { |
287 | 343 | var newString = ''; |
288 | 344 | for (var i=0; i < string.length; i++) { |
289 | 345 | newString += '[' + string[i].toUpperCase() + string[i].toLowerCase() + ']'; |
— | — | @@ -296,7 +352,7 @@ |
297 | 353 | if ( id == 14 ) { |
298 | 354 | // The parser accepts stuff like cATegORy, |
299 | 355 | // we need to do the same |
300 | | - categoryNSFragment += '|' + _makeCaseInsensitiv ( $.escapeRE(name) ); |
| 356 | + categoryNSFragment += '|' + _makeCaseInsensitive ( $.escapeRE(name) ); |
301 | 357 | } |
302 | 358 | } ); |
303 | 359 | categoryNSFragment = categoryNSFragment.substr( 1 ); // Remove leading | |
— | — | @@ -347,7 +403,6 @@ |
348 | 404 | var summary = mw.msg( 'ajax-remove-category-summary', category ); |
349 | 405 | |
350 | 406 | _confirmEdit( |
351 | | - mw.config.get('wgPageName'), |
352 | 407 | function( oldText ) { |
353 | 408 | //TODO Cleanup whitespace safely? |
354 | 409 | var newText = oldText.replace( categoryRegex, '' ); |
— | — | @@ -382,7 +437,6 @@ |
383 | 438 | var summary = mw.msg( 'ajax-add-category-summary', category ); |
384 | 439 | |
385 | 440 | _confirmEdit( |
386 | | - mw.config.get( 'wgPageName' ), |
387 | 441 | function( oldText ) { return oldText + appendText }, |
388 | 442 | summary, |
389 | 443 | function() { |
— | — | @@ -413,7 +467,6 @@ |
414 | 468 | var summary = mw.msg( 'ajax-edit-category-summary', category, categoryNew ); |
415 | 469 | |
416 | 470 | _confirmEdit( |
417 | | - mw.config.get( 'wgPageName' ), |
418 | 471 | function( oldText ) { |
419 | 472 | var matches = oldText.match( categoryRegex ); |
420 | 473 | |
— | — | @@ -537,7 +590,6 @@ |
538 | 591 | // Unhide hidden category holders. |
539 | 592 | $('#mw-hidden-catlinks').show(); |
540 | 593 | |
541 | | - |
542 | 594 | // Create [Add Category] link |
543 | 595 | var addLink = _createButton('icon-add', |
544 | 596 | mw.msg( 'ajax-add-category' ), |
— | — | @@ -558,18 +610,11 @@ |
559 | 611 | |
560 | 612 | clElement.append( promptContainer ); |
561 | 613 | }; |
562 | | - |
563 | | - _tasks = { |
564 | | - list : [], |
565 | | - executed : [], |
566 | | - add : function( obj ) { |
567 | | - this.list.push( obj ); |
568 | | - }, |
569 | | - next : function() { |
570 | | - var task = this.list.shift(); |
571 | | - //run task |
572 | | - this.executed.push( task ); |
573 | | - } |
| 614 | + |
| 615 | + _stash = { |
| 616 | + summaries : [], |
| 617 | + fns : [], |
| 618 | + doneFns : [], |
574 | 619 | }; |
575 | 620 | }; |
576 | 621 | // Now make a new version |
Index: trunk/phase3/resources/Resources.php |
— | — | @@ -501,6 +501,7 @@ |
502 | 502 | 'ajax-confirm-prompt', |
503 | 503 | 'ajax-confirm-title', |
504 | 504 | 'ajax-confirm-save', |
| 505 | + 'ajax-confirm-save-all', |
505 | 506 | 'ajax-add-category-summary', |
506 | 507 | 'ajax-remove-category-summary', |
507 | 508 | 'ajax-edit-category-summary', |
— | — | @@ -509,6 +510,7 @@ |
510 | 511 | 'ajax-error-dismiss', |
511 | 512 | 'ajax-remove-category-error', |
512 | 513 | 'ajax-edit-category-error', |
| 514 | + 'ajax-category-already-present', |
513 | 515 | ), |
514 | 516 | ), |
515 | 517 | 'mediawiki.libs.jpegmeta' => array( |
Index: trunk/phase3/maintenance/language/messages.inc |
— | — | @@ -3467,6 +3467,7 @@ |
3468 | 3468 | 'ajax-confirm-title', |
3469 | 3469 | 'ajax-confirm-prompt', |
3470 | 3470 | 'ajax-confirm-save', |
| 3471 | + 'ajax-confirm-save-all', |
3471 | 3472 | 'ajax-add-category-summary', |
3472 | 3473 | 'ajax-edit-category-summary', |
3473 | 3474 | 'ajax-remove-category-summary', |