'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"',
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',
);
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/>' );
var submitFunction = function() {
_addProgressIndicator( dialog );
_doEdit(
- page,
+ mw.config.get( 'wgPageName' ),
fn,
reasonBox.val(),
function() {
);
};
- var buttons = { };
+ var buttons = {};
buttons[mw.msg( 'ajax-confirm-save' )] = submitFunction;
var dialogOptions = {
'AutoOpen' : true,
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 = {
* @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() + ']';
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 |
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, '' );
var summary = mw.msg( 'ajax-add-category-summary', category );
_confirmEdit(
- mw.config.get( 'wgPageName' ),
function( oldText ) { return oldText + appendText },
summary,
function() {
var summary = mw.msg( 'ajax-edit-category-summary', category, categoryNew );
_confirmEdit(
- mw.config.get( 'wgPageName' ),
function( oldText ) {
var matches = oldText.match( categoryRegex );
// Unhide hidden category holders.
$('#mw-hidden-catlinks').show();
-
// Create [Add Category] link
var addLink = _createButton('icon-add',
mw.msg( 'ajax-add-category' ),
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