AjaxCategories:
authorLeo Koppelkamm <diebuche@users.mediawiki.org>
Thu, 14 Jul 2011 15:00:33 +0000 (15:00 +0000)
committerLeo Koppelkamm <diebuche@users.mediawiki.org>
Thu, 14 Jul 2011 15:00:33 +0000 (15:00 +0000)
* Lay foundation for MultiEdit mode
* Add releasenotes
* Fix typo in function name
* Change error msg per CR
Ping r92062

RELEASE-NOTES-1.19
languages/messages/MessagesEn.php
maintenance/language/messages.inc
resources/Resources.php
resources/mediawiki.page/mediawiki.page.ajaxCategories.js

index d1c5efd..371d383 100644 (file)
@@ -74,6 +74,9 @@ production.
   the message keys.
 * (bug 29868) Add support for passing parameters to mw.msg in jquery.localize.
 * (bug 29558) $wgMiserMode now disables update.php by default
+* AjaxCategories: Easily add, edit or delete categories on article pages.
+  Suggests possible categories when typing, all saves are done via AJAX.
+  Supports editing of multiple categories and then saving them in one batch.
 
 === Bug fixes in 1.19 ===
 * (bug 28868) Show total pages in the subtitle of an image on the
index d00711e..fce45c7 100644 (file)
@@ -4596,6 +4596,7 @@ This site is experiencing technical difficulties.',
 'ajax-confirm-prompt'          => 'You can provide an edit summary below.
 Click "Save" to save your edit.',
 'ajax-confirm-save'            => 'Save',
+'ajax-confirm-save-all'        => 'Save all changes',
 'ajax-add-category-summary'    => 'Add category "$1"',
 'ajax-edit-category-summary'   => 'Change category "$1" to "$2"',
 'ajax-remove-category-summary' => 'Remove category "$1"',
@@ -4606,5 +4607,5 @@ Click "Save" to save your edit.',
 This usually occurs when the category has been added to the page in a template.',
 'ajax-edit-category-error'     => 'It was not possible to edit this category.
 This usually occurs when the category has been added to the page in a template.',
-'ajax-category-already-present' => 'This page already has the category you specified.',
+'ajax-category-already-present' => 'This page already belongs to the category $1',
 );
index 6086a04..30b0069 100644 (file)
@@ -3467,6 +3467,7 @@ $wgMessageStructure = array(
                'ajax-confirm-title',
                'ajax-confirm-prompt',
                'ajax-confirm-save',
+               'ajax-confirm-save-all',
                'ajax-add-category-summary',
                'ajax-edit-category-summary',
                'ajax-remove-category-summary',
index 4f01b7c..7d06b5d 100644 (file)
@@ -501,6 +501,7 @@ return array(
                        'ajax-confirm-prompt',
                        'ajax-confirm-title',
                        'ajax-confirm-save',
+                       'ajax-confirm-save-all',
                        'ajax-add-category-summary',
                        'ajax-remove-category-summary',
                        'ajax-edit-category-summary',
@@ -509,6 +510,7 @@ return array(
                        'ajax-error-dismiss',
                        'ajax-remove-category-error',
                        'ajax-edit-category-error',
+                       'ajax-category-already-present',
                ),
        ),
        'mediawiki.libs.jpegmeta' => array(
index 1629e57..0cfa7e6 100644 (file)
@@ -157,8 +157,37 @@ var ajaxCategories = function ( options ) {
                return _getCats().filter( function() { return $.ucFirst(this) == $.ucFirst(cat); } ).length !== 0;
        };
        
-       _confirmEdit = function ( page, fn, actionSummary, doneFn ) {
+       /**
+        * This get's called by all action buttons
+        * Displays a dialog to confirm the action
+        * Afterwords do the actual edit
+        *
+        * @param function fn text-modifying function 
+        * @param string actionSummary Changes done
+        * @param function fn doneFn callback after everything is done
+        * @return boolean True for exists
+        */
+       _confirmEdit = function ( fn, actionSummary, doneFn, all ) {
+               // Check whether to use multiEdit mode
+               if ( mw.config.get('AJAXCategoriesMulti') && !all ) {
+                       // Stash away
+                       _stash.summaries.push( actionSummary );
+                       _stash.fns.push( fn );
+                       _stash.doneFns.push( doneFn );
+
+                       // Make sure we have a save button
+                       if ( !_saveAllButton ) {
+                               //TODO Make more clickable
+                               _saveAllButton = _createButton( 'icon-tick', 
+                                                                                               mw.msg( 'ajax-confirm-save-all' ), 
+                                                                                               '', 
+                                                                                               mw.msg( 'ajax-confirm-save-all' ) 
+                                                                                               );
+                               _saveAllButton.click( _handleStashedCategories );
+                       }
 
+                       return;
+               }
                // Produce a confirmation dialog
                var dialog = $( '<div/>' );
 
@@ -190,7 +219,7 @@ var ajaxCategories = function ( options ) {
                var submitFunction = function() {
                        _addProgressIndicator( dialog );
                        _doEdit(
-                               page,
+                               mw.config.get( 'wgPageName' ),
                                fn,
                                reasonBox.val(),
                                function() {
@@ -201,7 +230,7 @@ var ajaxCategories = function ( options ) {
                        );
                };
 
-               var buttons = { };
+               var buttons = {};
                buttons[mw.msg( 'ajax-confirm-save' )] = submitFunction;
                var dialogOptions = {
                        'AutoOpen' : true,
@@ -213,6 +242,33 @@ var ajaxCategories = function ( options ) {
                dialog.dialog( dialogOptions );
        };
 
+       /**
+        * When multiEdit mode is enabled,
+        * this is called when the user clicks "save all"
+        * Combines the summaries and edit functions
+        */
+       _handleStashedCategories = function() {
+               // Save fns
+               fns = _stash.fns;
+               
+               //TODO do I need a space?
+               var summary = _stash.summaries.join(' ');
+               var combinedFn = function( oldtext ) {
+                       // Run the text through all action functions
+                       newtext = oldtext;
+                       for ( var i = 0; i < fns.length; i++ ) {
+                               newtext = fns[i]( newtext );
+                       };
+                       return newtext;
+               }
+               var doneFn = function() {
+                       //Remove saveAllButton
+                       _saveAllButton.remove();
+                       _saveAllButton = undefined;
+               };
+
+       };
+
        _doEdit = function ( page, fn, summary, doneFn ) {
                // Get an edit token for the page.
                var getTokenVars = {
@@ -282,7 +338,7 @@ var ajaxCategories = function ( options ) {
         * @param string Regex string.
         * @return string Processed regex string
         */
-       _makeCaseInsensitiv = function ( string ) {
+       _makeCaseInsensitive = function ( string ) {
                var newString = '';
                for (var i=0; i < string.length; i++) {
                        newString += '[' + string[i].toUpperCase() + string[i].toLowerCase() + ']';
@@ -296,7 +352,7 @@ var ajaxCategories = function ( options ) {
                        if ( id == 14 ) {
                                // The parser accepts stuff like cATegORy, 
                                // we need to do the same
-                               categoryNSFragment += '|' + _makeCaseInsensitiv ( $.escapeRE(name) );
+                               categoryNSFragment += '|' + _makeCaseInsensitive ( $.escapeRE(name) );
                        }
                } );
                categoryNSFragment = categoryNSFragment.substr( 1 ); // Remove leading |
@@ -347,7 +403,6 @@ var ajaxCategories = function ( options ) {
                var summary = mw.msg( 'ajax-remove-category-summary', category );
 
                _confirmEdit(
-                       mw.config.get('wgPageName'),
                        function( oldText ) {
                                //TODO Cleanup whitespace safely?
                                var newText = oldText.replace( categoryRegex, '' );
@@ -382,7 +437,6 @@ var ajaxCategories = function ( options ) {
                var summary = mw.msg( 'ajax-add-category-summary', category );
 
                _confirmEdit(
-                       mw.config.get( 'wgPageName' ),
                        function( oldText ) { return oldText + appendText },
                        summary,
                        function() {
@@ -413,7 +467,6 @@ var ajaxCategories = function ( options ) {
                var summary = mw.msg( 'ajax-edit-category-summary', category, categoryNew );
 
                _confirmEdit(
-                       mw.config.get( 'wgPageName' ),
                        function( oldText ) {
                                var matches = oldText.match( categoryRegex );
                                
@@ -537,7 +590,6 @@ var ajaxCategories = function ( options ) {
                // Unhide hidden category holders.
                $('#mw-hidden-catlinks').show();
 
-
                // Create [Add Category] link
                var addLink = _createButton('icon-add', 
                                                                        mw.msg( 'ajax-add-category' ), 
@@ -558,18 +610,11 @@ var ajaxCategories = function ( options ) {
 
                clElement.append( promptContainer );
        };
-
-       _tasks = {
-               list : [],
-               executed : [],
-               add : function( obj ) {
-                       this.list.push( obj );
-               },
-               next : function() {
-                       var task = this.list.shift();
-                       //run task
-                       this.executed.push( task );
-               }
+       
+       _stash = {
+               summaries : [],
+               fns : [],
+               doneFns : [],
        };
 };
 // Now make a new version