r92159 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92158‎ | r92159 | r92160 >
Date:15:00, 14 July 2011
Author:diebuche
Status:deferred (Comments)
Tags:
Comment:
AjaxCategories:
* Lay foundation for MultiEdit mode
* Add releasenotes
* Fix typo in function name
* Change error msg per CR
Ping r92062
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)
  • /trunk/phase3/resources/Resources.php (modified) (history)
  • /trunk/phase3/resources/mediawiki.page/mediawiki.page.ajaxCategories.js (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -74,6 +74,9 @@
7575 the message keys.
7676 * (bug 29868) Add support for passing parameters to mw.msg in jquery.localize.
7777 * (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.
7881
7982 === Bug fixes in 1.19 ===
8083 * (bug 28868) Show total pages in the subtitle of an image on the
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -4596,6 +4596,7 @@
45974597 'ajax-confirm-prompt' => 'You can provide an edit summary below.
45984598 Click "Save" to save your edit.',
45994599 'ajax-confirm-save' => 'Save',
 4600+'ajax-confirm-save-all' => 'Save all changes',
46004601 'ajax-add-category-summary' => 'Add category "$1"',
46014602 'ajax-edit-category-summary' => 'Change category "$1" to "$2"',
46024603 'ajax-remove-category-summary' => 'Remove category "$1"',
@@ -4606,5 +4607,5 @@
46074608 This usually occurs when the category has been added to the page in a template.',
46084609 'ajax-edit-category-error' => 'It was not possible to edit this category.
46094610 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',
46114612 );
Index: trunk/phase3/resources/mediawiki.page/mediawiki.page.ajaxCategories.js
@@ -157,8 +157,37 @@
158158 return _getCats().filter( function() { return $.ucFirst(this) == $.ucFirst(cat); } ).length !== 0;
159159 };
160160
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 );
162178
 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+ }
163192 // Produce a confirmation dialog
164193 var dialog = $( '<div/>' );
165194
@@ -190,7 +219,7 @@
191220 var submitFunction = function() {
192221 _addProgressIndicator( dialog );
193222 _doEdit(
194 - page,
 223+ mw.config.get( 'wgPageName' ),
195224 fn,
196225 reasonBox.val(),
197226 function() {
@@ -201,7 +230,7 @@
202231 );
203232 };
204233
205 - var buttons = { };
 234+ var buttons = {};
206235 buttons[mw.msg( 'ajax-confirm-save' )] = submitFunction;
207236 var dialogOptions = {
208237 'AutoOpen' : true,
@@ -213,6 +242,33 @@
214243 dialog.dialog( dialogOptions );
215244 };
216245
 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+
217273 _doEdit = function ( page, fn, summary, doneFn ) {
218274 // Get an edit token for the page.
219275 var getTokenVars = {
@@ -282,7 +338,7 @@
283339 * @param string Regex string.
284340 * @return string Processed regex string
285341 */
286 - _makeCaseInsensitiv = function ( string ) {
 342+ _makeCaseInsensitive = function ( string ) {
287343 var newString = '';
288344 for (var i=0; i < string.length; i++) {
289345 newString += '[' + string[i].toUpperCase() + string[i].toLowerCase() + ']';
@@ -296,7 +352,7 @@
297353 if ( id == 14 ) {
298354 // The parser accepts stuff like cATegORy,
299355 // we need to do the same
300 - categoryNSFragment += '|' + _makeCaseInsensitiv ( $.escapeRE(name) );
 356+ categoryNSFragment += '|' + _makeCaseInsensitive ( $.escapeRE(name) );
301357 }
302358 } );
303359 categoryNSFragment = categoryNSFragment.substr( 1 ); // Remove leading |
@@ -347,7 +403,6 @@
348404 var summary = mw.msg( 'ajax-remove-category-summary', category );
349405
350406 _confirmEdit(
351 - mw.config.get('wgPageName'),
352407 function( oldText ) {
353408 //TODO Cleanup whitespace safely?
354409 var newText = oldText.replace( categoryRegex, '' );
@@ -382,7 +437,6 @@
383438 var summary = mw.msg( 'ajax-add-category-summary', category );
384439
385440 _confirmEdit(
386 - mw.config.get( 'wgPageName' ),
387441 function( oldText ) { return oldText + appendText },
388442 summary,
389443 function() {
@@ -413,7 +467,6 @@
414468 var summary = mw.msg( 'ajax-edit-category-summary', category, categoryNew );
415469
416470 _confirmEdit(
417 - mw.config.get( 'wgPageName' ),
418471 function( oldText ) {
419472 var matches = oldText.match( categoryRegex );
420473
@@ -537,7 +590,6 @@
538591 // Unhide hidden category holders.
539592 $('#mw-hidden-catlinks').show();
540593
541 -
542594 // Create [Add Category] link
543595 var addLink = _createButton('icon-add',
544596 mw.msg( 'ajax-add-category' ),
@@ -558,18 +610,11 @@
559611
560612 clElement.append( promptContainer );
561613 };
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 : [],
574619 };
575620 };
576621 // Now make a new version
Index: trunk/phase3/resources/Resources.php
@@ -501,6 +501,7 @@
502502 'ajax-confirm-prompt',
503503 'ajax-confirm-title',
504504 'ajax-confirm-save',
 505+ 'ajax-confirm-save-all',
505506 'ajax-add-category-summary',
506507 'ajax-remove-category-summary',
507508 'ajax-edit-category-summary',
@@ -509,6 +510,7 @@
510511 'ajax-error-dismiss',
511512 'ajax-remove-category-error',
512513 'ajax-edit-category-error',
 514+ 'ajax-category-already-present',
513515 ),
514516 ),
515517 'mediawiki.libs.jpegmeta' => array(
Index: trunk/phase3/maintenance/language/messages.inc
@@ -3467,6 +3467,7 @@
34683468 'ajax-confirm-title',
34693469 'ajax-confirm-prompt',
34703470 'ajax-confirm-save',
 3471+ 'ajax-confirm-save-all',
34713472 'ajax-add-category-summary',
34723473 'ajax-edit-category-summary',
34733474 'ajax-remove-category-summary',

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r92112Rewrite ajaxCategories for ResourceLoader. Add some missing functionality (ed...diebuche22:36, 13 July 2011

Comments

#Comment by Krinkle (talk | contribs)   20:54, 3 October 2011

AjaxCategories moved out of core. Marking deferred for now.

Status & tagging log