From: Leo Koppelkamm Date: Thu, 14 Jul 2011 15:00:33 +0000 (+0000) Subject: AjaxCategories: X-Git-Tag: 1.31.0-rc.0~28846 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=bfb5b65879d30abcffea81ee10eade8727e2ef11;p=lhc%2Fweb%2Fwiklou.git AjaxCategories: * Lay foundation for MultiEdit mode * Add releasenotes * Fix typo in function name * Change error msg per CR Ping r92062 --- diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index d1c5efdec2..371d38325d 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -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 diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index d00711e89b..fce45c74f2 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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', ); diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 6086a04071..30b00695e3 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -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', diff --git a/resources/Resources.php b/resources/Resources.php index 4f01b7c61c..7d06b5d4c9 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -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( diff --git a/resources/mediawiki.page/mediawiki.page.ajaxCategories.js b/resources/mediawiki.page/mediawiki.page.ajaxCategories.js index 1629e5732f..0cfa7e6cfe 100644 --- a/resources/mediawiki.page/mediawiki.page.ajaxCategories.js +++ b/resources/mediawiki.page/mediawiki.page.ajaxCategories.js @@ -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 = $( '
' ); @@ -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