باز کردن منو اصلی

تاریخ‌نما β

تغییرات

مدیاویکی:Gadget-Cat-a-lot.js

۳۴٬۹۵۹ بایت اضافه‌شده، ‏۲ سپتامبر ۲۰۱۸، ساعت ۱۰:۱۱
بدون خلاصه ویرایش
// <source lang="javascript">**//// * Cat-Aa-Lotlot// * Changes category of multiple files ** @rev 00:13, 10 February 2018 (or pagesUTC)//// * @author Originally by Magnus Manske(2007)// * @author RegExes by Ilmari Karonen(2010)// * @author Completely rewritten by DieBuche(2010-2012)* @author Rillke (2012-2014)* @author Perhelion (2017)//// Modified to work on regular pages instead of files, + Hebrew translation* Requires [[MediaWiki:Gadget-SettingsManager.js]] and [[MediaWiki: קיפודנחשGadget-SettingsUI.js]] (properly registered) for per-user-settings//*// * READ THIS PAGE IF YOU WANT TO TRANSLATE OR USE THIS ON ANOTHER SITE:// * http://commons.wikimedia.org/wiki/MediaWiki_talkMediaWiki:Gadget-Cat-a-lot.js/translating* <nowiki>*/ /* global jQuery, mediaWiki *//* eslint one-var:0, vars-on-top:0, no-underscore-dangle:0, valid-jsdoc:0,curly:0, camelcase:0, no-useless-escape:0, no-alert:0 */ //extends: wikimedia/* jshint unused:true, forin:false, smarttabs:true, loopfunc:true, browser:true */ ( function ( $, mw ) {'use strict'; var formattedNS = mw.config.get( 'wgFormattedNamespaces' ), ns = mw.config.get( 'wgNamespaceNumber' ), nsIDs = mw.config.get( 'wgNamespaceIds' ), userGrp = mw.config.get( 'wgUserGroups' ), project = mw.config.get( 'wgDBname' ); var catALot msgs = {// Preferences// new: added 2012-09-19. Please translate.// Use user language for i18n 'cat-a-lot-watchlistpref': 'Watchlist preference concerning files edited with Cat-a-lot', 'cat-a-lot-watch_pref': 'According to your general preferences', 'cat-a-lot-watch_nochange': 'Do not change watchstatus', 'cat-a-lot-watch_watch': 'Watch pages edited with Cat-a-lot', 'cat-a-lot-watch_unwatch': 'Remove pages while editing with Cat-a-lot from your watchlist', 'cat-a-lot-minorpref': 'Mark edits as minor (if you generally mark your edits as minor, this won’t change anything)', 'cat-a-lot-editpagespref': 'Allow categorising pages (including categories) that are not files', 'cat-a-lot-docleanuppref': 'Remove {{Check categories}} and other minor cleanup', 'cat-a-lot-uncatpref': 'Remove {{Uncategorized}}', 'cat-a-lot-subcatcountpref': 'Sub-categories to show at most', 'cat-a-lot-config-settings': 'Preferences', 'cat-a-lot-buttonpref': 'Use buttons instead of text-links', 'cat-a-lot-comment-label': 'Custom edit comment', 'cat-a-lot-edit-question': 'Why is this change necessary?',  // Progress // 'cat-a-lot-loading': 'Loading …', 'cat-a-lot-editing': 'Editing page', 'cat-a-lot-of': 'of ', 'cat-a-lot-skipped-already': 'The following {{PLURAL:$1|1= page was|$1 pages were}} skipped, because the page was already in the category:', 'cat-a-lot-skipped-not-found': 'The following {{PLURAL:$1|1=page was|$1 pages were}} skipped, because the old category could not be found:', 'cat-a-lot-skipped-server': 'The following {{PLURAL:$1|1=page|$1 pages}} couldn’t be changed, since there were problems connecting to the server:', apiUrl'cat-a-lot-all-done': 'All pages are processed.', 'cat-a-lot-done': 'Done!', // mw.configmsg("Feedback-close") 'cat-a-lot-added-cat': 'Added category $1', 'cat-a-lot-copied-cat': 'Copied to category $1', 'cat-a-lot-moved-cat': 'Moved to category $1', 'cat-a-lot-removed-cat': 'Removed from category $1', // 'cat-a-lot-return-to-page': 'Return to page', // 'cat-a-lot-cat-not-found': 'Category not found.',  // as in 17 files selected 'cat-a-lot-files-selected': '{{PLURAL:$1|1=One file|$1 files}} selected.get', 'cat-a-lot-pe_file': '$1 {{PLURAL:$1|page|pages}} of $2 affected', 'cat-a-lot-parent-cat': 'Has parent-category: ', 'cat-a-lot-sub-cat': 'Has sub-category: ',  // Actions 'cat-a-lot-copy': 'Copy', 'cat-a-lot-move': 'Move', 'cat-a-lot-add': 'Add', // 'cat-a-lot-remove-from-cat': 'Remove from this category', 'cat-a-lot-overcat': 'Check over-categorization', 'cat-a-lot-enter-name': 'Enter category name', 'cat-a-lot-select': 'Select', 'cat-a-lot-all': 'all', 'cat-a-lot-none': 'none', // 'cat-a-lot-none-selected': 'No files selected!', 'Ooui-selectfile-placeholder'  // Summaries (project language): 'cat-a-lot-pref-save-summary': 'Updating user preferences', 'cat-a-lot-summary-add': 'Adding [[Category:$1]]', 'cat-a-lot-summary-copy'wgScriptPath: 'Copying from [[Category:$1]] to [[Category:$2]]', 'cat-a-lot-summary-move': 'Moving from [[Category:$1]] to [[Category:$2]]', 'cat-a-lot-summary-remove': 'Removing from [[Category:$1]]', 'cat-a-lot-prefix-summary': '', 'cat-a-lot-using-summary': ' using [[c:Help:Cat-a-lot|Cat-a-lot]]'};mw.messages.set( msgs ); function msg( /* params */ ) { var args = Array.prototype.slice.call( arguments, 0 ) ; args[ 0 ] = 'cat-a-lot-' + "args[ 0 ]; return ( args.length === 1 ) ? mw.message( args[ 0 ] ).plain() : mw.message.apply( mw.message, args ).parse();} // There is only one Cat-a-lot on one pagevar $body, $container, $dataContainer, $searchInputContainer, $searchInput, $resultList, $markCounter, $selections, $selectFiles, $selectPages, $selectNone, $selectInvert, $settingsWrapper, $settingsLink, $head, $link, $overcat, commonsURL = 'https://commons.wikimedia.org/w/apiindex.php"', is_rtl = $( 'body' ).hasClass( 'rtl' ), reCat, // localized category search regexp non, r; // result file count for overcat var CAL = mw.libs.catALot = { apiUrl: mw.util.wikiScript( 'api' ), origin: '',
searchmode: false,
version: 2'4.1877',
setHeight: 450,
changeTag: 'Cat-a-lot',
 
settings: {
/* Any category in this category is deemed a disambiguation category; i.e., a category that should not contain
any items, but that contains links to other categories where stuff should be categorized. If you don't have
that concept on your wiki, set it to null. Use blanks, not underscores. */
disambig_category: 'Disambiguation', // Commons and EnWP
/* Any category in this category is deemed a (soft) redirect to some other category defined by a link
* to another non-blacklisted category. If your wiki doesn't have soft category redirects, set this to null.
* If a soft-redirected category contains more than one link to another non-blacklisted category, it's considered
* a disambiguation category instead. */
redir_category: 'Category redirects'
 
},
 
init: function () {
// Prevent historical double marker (maybe remove in future) if ( /Cat-?a-?lot/i.test( msgs[ 'cat-a-lot-pref-save-summary' ] ) ) { mw.messages.set( { 'cat-a-lot-prefix-summary': '', 'cat-a-lot-using-summary': '' } ); } else { mw.messages.set( { 'cat-a-lot-pref-save-summary': msgs[ 'cat-a-lot-prefix-summary' ] + msgs[ 'cat-a-lot-pref-save-summary' ] + msgs[ 'cat-a-lot-using-summary' ] } ); }  // TODO: better extern project support for possible change-tag? (needs currently change after init) if ( project === 'commonswiki' ) { mw.messages.set( { 'cat-a-lot-using-summary': '' } ); } else { // Reset this.changeTag = ''; this.settings.redir_category = ''; }  this._initSettings(); $body = $("document.body"); .append$container = $('<div >' ) .attr( 'id="', 'cat_a_lot">' + ) .appendTo( $body ); $dataContainer = $( '<div >' ) .attr( 'id', 'cat_a_lot_data' ) .appendTo( $container ); $searchInputContainer ="cat_a_lot_data">$( '<div>' + ) .appendTo( $dataContainer ); $searchInput = $( '<input type="text" >', { id=": 'cat_a_lot_searchcatname" ', placeholder=": msg( 'enter-name' + this.i18n.enterName + ), type: '"/>text' + } ) .appendTo( $searchInputContainer ); $resultList = $( '</div><div ' ) .attr( 'id="', 'cat_a_lot_category_list"style' ) .appendTo( $dataContainer ); $markCounter ="white-space:nowrap;">$( '</div>' + ) .attr( '<div id', 'cat_a_lot_mark_counter' ) .appendTo( $dataContainer ); $selections ="cat_a_lot_mark_counter"> $( '</div>' ) .attr( 'id', 'cat_a_lot_selections' ) .text( msg( 'select' ) + ':' ) .appendTo( $dataContainer ); $settingsWrapper = $( '<div >' ) .attr( 'id', 'cat_a_lot_settings' ) .appendTo( $dataContainer ); $settingsLink ="cat_a_lot_selections"$( '<a>', { id: 'cat_a_lot_config_settings', title: 'Version ' + this.i18nversion, text: msg( 'config-settings' ) } ) .selectappendTo( $settingsWrapper ); + $head = $( ' <a div>' ) .attr( 'id', 'cat_a_lot_head' ) .appendTo( $container ); $link ="cat_a_lot_select_all"$( '<a>' + this) .attr( 'id', 'cat_a_lot_toggle' ) .text( 'Cat-a-lot' ) .i18nappendTo( $head ); $settingsWrapper.all + append( $( '</a> ', { href: commonsURL + '?title=Special:MyLanguage/ Help:Gadget-Cat-a-lot', target: '_blank', style: ' float:right', title: ( $( '#n-help a' ).attr( 'title' ) || '' ) + '<a id="cat_a_lot_select_none">(v. ' + this.i18nversion + ')' } ).none + text( '?' ) ); $container.one( 'mouseover'<, function () { //a>Try load on demand earliest as possible mw.loader.load( [ 'jquery.ui.resizable', 'jquery.ui.draggable'] ); } );  + if ( this.origin && !non ) { $overcat = $( '</diva></div><div ' ) .attr( 'id', 'cat_a_lot_overcat' ) .html( msg( 'overcat' ) ) .on( 'click', function ( e ) { CAL.getOverCat( e ); } ) .insertBefore( $selections ); }  if ( ( mw.util.getParamValue( 'withJS' ) ="cat_a_lot_head">== 'MediaWiki:Gadget-Cat-a-lot.js' && !mw.util.getParamValue( 'withCSS' ) ) || mw.loader.getState( 'ext.gadget.Cat-a-lot' ) === 'registered' ) { mw.loader.load( mw.config.get( 'wgServer' ) + '<a id/w/index.php?title="cat_a_lot_toggle">MediaWiki:Gadget-Cat-a-lot<.css&action=raw&ctype=text/css', 'text/a><css' ); /div></div>importStylesheet( 'MediaWiki:Gadget-Cat-a-lot.css'); }
if reCat = new RegExp(!this'^\\s*' + CAL.searchmode) $localizedRegex(14, '#cat_a_lot_selectionsCategory').append(+ '<br><a id="cat_a_lot_remove"><b>:' + this.i18n.removeFromCat + , '</b></a>');  $searchInput.on('#cat_a_lot_removekeypress').click(, function (e ) { catALotif ( e.remove(which === 13 );{ }); CAL.updateCats( $.trim( $('#cat_a_lot_select_all'this ).click(function val() { catALot.toggleAllreplace(true/[\u200E\u200F\u202A-\u202E]/g, '' ) ); }); $ mw.cookie.set('#cat_a_lot_select_nonecatAlot'), CAL.click(function (currentCategory ) {; catALot.toggleAll(false);} }); $ .on('#cat_a_lot_toggleinput keyup').click(, function () { $( var oldVal = this).toggleClassvalue, newVal = oldVal.replace(reCat, 'cat_a_lot_enabled'); catALot.run if (newVal !== oldVal ){ this.value = newVal;} } if ( !newVal ); ${ mw.cookie.set('#cat_a_lot_searchcatnamecatAlot', null ); } .keypress(} );  function initAutocomplete(e) { if (eCAL.which == 13autoCompleteIsEnabled ){ return; }  catALot CAL.updateCatsautoCompleteIsEnabled = true;  if (!$searchInput.val(this)&& mw.cookie && mw.cookie.get( 'catAlot' ) ) { $searchInput.val(mw.cookie.get( 'catAlot' ));} }) $searchInput.autocomplete({ source: function(request, response) { catALotCAL.doAPICall({ action:'opensearch', search: request.term, redirects: 'resolve', namespace: 14 }, function(data){ if(data[1]){ response($(data[1]) .map(function(index,item){ return item.replace(/.*:/reCat, ''); }));
}
  } ); }, open: function () { $( '.ui-autocomplete' ) .position( { my: is_rtl ? 'left bottom' : 'right bottom', at: is_rtl ? 'left top' : 'right top', of: $searchInput } );
},
openappendTo: '#cat_a_lot' } ); } $( '<a>' ) // .attr( 'id', 'cat_a_lot_select_all' ) .text( msg( 'all' ) ) .on( 'click', function () { CAL.toggleAll( true ); } ) .appendTo( $selections.append( ' ' ) ); if ( this.settings.editpages ) { $selectFiles = $( '<a>' ) .on( 'click', function () { CAL.toggleAll( 'files' ); } ); $selectPages = $( '<a>' ) .on( 'click', function () { CAL.toggleAll( 'pages' ); } ); $selections.append( $( '<span>' ).hide().append( [ ' / ', $selectFiles, ' / ', $selectPages ] ) ); } $selectNone = $( '<a>' ) // .attr( 'id', 'cat_a_lot_select_none' ) .text( msg( 'none' ) ) .on( 'click', function () { CAL.toggleAll( false ); } ); $selectInvert = $( '<a>' ) .on( 'click', function () { CAL.toggleAll( null ); } ); $selections.append( [ ' • ', $selectNone, ' • ', $selectInvert, $( '<div>' ).append( [ $( '<label>' ) .attr( { 'for': 'cat_a_lot_comment', style: 'line-height:1.5em;vertical-align:bottom' } ) .text( msg( 'comment-label' ) ), $( '<input>' ) .attr( { id: 'cat_a_lot_comment', type:'checkbox' } ) ] ) ] );  $link .on( 'click', function() { $( this ).toggleClass( 'cat_a_lot_enabled' ); // Load autocomplete on demand mw.loader.using( 'jquery.ui.autocomplete', initAutocomplete );  if ( !CAL.executed ){ $.when( mw.loader.using("[ 'jquery.ui.resizable', 'jquery.ui.draggable', 'jquery.ui.button', 'mediawiki.api.messages', 'mediawiki.jqueryMsg' ] ), $.ready ) .then( function () { return new mw.Api().loadMessagesIfMissing( [ 'Cancel', 'Categorytree-not-found', // 'Checkuser-all', // 'Code-field-select', // 'Export-addcat', 'Filerevert-submit', 'Mobile-frontend-return-to-page', 'Ooui-selectfile-placeholder', // 'Visualeditor-clipboard-copy', 'Wikieditor-loading', 'Prefs-files', 'Categories', 'Checkbox-invert', 'Centralnotice-autocomplete"remove', // 'Ooui-item-remove' 'Apifeatureusage-warnings' ] ); } ).positionthen( function () { myCAL.run(); } ); } else { CAL.run(); } } ); $settingsLink .on( 'click', CAL.manageSettings ); this.localCatName = formattedNS[ 14 ] + ':'; mw.loader.using( 'mediawiki.cookie', function () { // Let catAlot stay open var val = mw.cookie.get( 'catAlotO' ); if ( val && Number( val ) === ns ) { $link.click(); } } ); },  getOverCat: function ( e ) { var files = []; r = 0; // result counter if ( e ) { e.preventDefault(); this.files = this.getMarkedLabels(); // .toArray() not working for ( var f = 0; f < this.files.length; f++ ) { files.push( this.files[ f ] ); }  } if ( !files.length || !( files instanceof Array ) ) { return alert( mw.msg( 'Ooui-selectfile-placeholder' ) ); } this.files = files; mw.loader.using( [ 'jquery.spinner' ], function () { $markCounter.injectSpinner( 'overcat' ); CAL.getFileCats(); } ); },  getFileCats: function () { var aLen = this.files.length; var bLen = this.selectedLabels.length; var file = this.files[ aLen - 1 ][ 0 ]; $overcat.text( '…' + aLen + '\/' + bLen ); if ( file ) { this.doAPICall( { prop: "left bottom"'categories', titles: file }, this.checkFileCats ); }  },  checkFileCats: function ( data ) { var cc = 0; // current cat counter; var file = CAL.files.pop(); if ( data.query && data.query.pages ) { $.each( data.query.pages, function ( id, page ) { if ( page.categories ) { var target = file[ 1 ].removeClass( 'cat_a_lot_selected' ); $.each( page.categories, function ( c, cat ) { var title = cat.title.replace( reCat, '' ), at: "left top"color = 'orange', mark = function ( kind ) { // kind ofcategory // TODO: store data to use this for special remove function if ( kind === 'sub' ) { color = 'green'; } var border = '3px dotted '; if ( $.inArray( title, CAL[ kind + 'Cats' ] ) !== -1 ) { cc++; target = target.parents( '.gallerybox' ); target = target[ 0 ] ? target : file[ 1 ]; target.css({ border: border + color } ).prop( 'title', msg( kind + '-cat'#cat_a_lot_searchcatname) + title ); color = 'red'; return false; } }; mark( 'sub'); return mark( 'parent' ); }); if ( cc ) { r++; }
}
}); importStylesheet} else { mw.log('MediaWiki:GadgetApi-Cat-a-lotfail', file, data ); } if ( CAL.files[ 0 ] ) { return setTimeout( function () { CAL.css'getFileCats(); }, 100 );} // Api has bad performance here, so we can get only each file separately this$overcat.text( msg( 'pe_file', r, CAL.localCatName = mwselectedLabels.configlength ) ); $.getremoveSpinner('wgFormattedNamespacesovercat')[14];
},
  findAllLabels: function (searchmode ) { // It's possible to allow any kind of pages as well but what happens if you click on "select all" and don't expect it switch ( searchmode ) { case 'search': this.labels = this.labels.add( $( 'table.searchResultImage' ).find( 'tr>td:eq(1)' ) ); if ( this.settings.editpages ) { this.labels = this.labels.add( 'div.mw-search-result-heading' ); }  break; case 'category': this.findAllLabels( 'gallery' ); this.labels = this.labels.add( $('#mw-pagescategory-media').find('li[class!="gallerybox"]') ); var subCats if ( this.settings.editpages ) { this.pageLabels = $('#mw-pages, #mw-subcategories').find('.CategoryTreeItemli'); for // this.files = this.labels; this.labels = this.labels.add(var sub this.pageLabels ); } break; case 'contribs': this.labels = 0this.labels.add( $( 'ul.mw-contributions-list li' ) ); sub < subCats // FIXME: Filter if !this.lengthsettings.editpages break; sub++ case 'prefix': this.labels = this.labels.add( $( 'ul.mw-prefixindex-list li' ) ) {; break; case 'listfiles': var a // this.labels = this.labels.add( $(subCats[sub]'table.listfiles>tbody>tr' ).find('atd:eq(1)') ); if this.labels = this.labels.add( $(a'.lengthTablePager_col_img_name' ) {); a[0][break; case 'titlegallery'] : // this.labels = catALotthis.labels.localCatName + ":" + a[0]add( '.innerHTMLgallerybox' );// TODO incombatible with GalleryDetails this.labels= this.labels.add( '.gallerytext' ); break; } },  getTitleFromLink: function ( $a ) { try { return decodeURIComponent( $a.pushattr(subCats'href' ) ) .match( /wiki\/(.+?)(?:#.+)?$/ )[sub1 ].replace( /_/g, ' ' ); } catch ( ex ) { }return '';
}
$('li a, .CategoryTreeLabel', mw.util.$content).attr({href: '#noSuchAnchor'});
},
/**
* @brief Get title from selected pages
* @return [array] touple of page title and $object
*/
getMarkedLabels: function () {
var marked = []; this.selectedLabels = this.labels.filter('.cat_a_lot_selected:visible'); return this.selectedLabels.eachmap(function () { var file label = $(this), file = label.find('a[title][class$="title"]'); markedfile = file.pushlength ? file : label.find('a[title]' ); var title = file.attr('title'), $||CAL.getTitleFromLink( file ) ||CAL.getTitleFromLink( label.find( 'a' ) ) ||CAL.getTitleFromLink( label.parent().find(this'a' ) ); // TODO needs optimization if ( title.indexOf( formattedNS[ 2 ]+ ':' )) { return [ [ title, label ] ];} }); return marked;
},
updateSelectionCounter: function () {
this.selectedLabels = this.labels.filter('.cat_a_lot_selected:visible'); var first = $markCounter.is('#cat_a_lot_mark_counter:hidden'); $markCounter .html( msg( 'files-selected', this.selectedLabels.length ) ) .show(); if ( first && !$dataContainer.is( ':hidden' ) ) { // Workaround to fix position glitch first = $markCounter.innerHeight(); $container .offset( { top: $container.htmloffset(this).top - first } ) .selectedLabelsheight( $container.length height() + thisfirst ); $( window ).on( 'beforeunload', function () { if ( CAL.labels.i18nfilter( '.filesSelected cat_a_lot_selected:visible' )[ 0 ] ) { return 'You have pages selected!'; } // There is a default message in the browser } ); }
},
makeClickable: function () {
this.findAllLabelslabels = $(); this.labels.click(function pageLabels = $() {; // only for distinct all selections $ this.findAllLabels(this.searchmode ); this.toggleClasslabels.catALotShiftClick( function ('cat_a_lot_selected');{ catALotCAL.updateSelectionCounter(); }) .addClass( 'cat_a_lot_label' );
},
toggleAll: function (select) { if ( typeof select === 'string' && this.pageLabels[ 0 ] ) { this.pageLabels.toggleClass( 'cat_a_lot_selected', true ); if ( select === 'files' ) // pages get deselected { this.labels.toggleClass( 'cat_a_lot_selected' ); } } else { // invert / none / all this.labels.toggleClass('cat_a_lot_selected', select); }
this.updateSelectionCounter();
},
getSubCats: function (cmcontinue) {
var data = {
action: 'query',
list: 'categorymembers',
cmnamespacecmtype: 14'subcat', cmlimit: 50this.settings.subcatcount, cmtitle: this.localCatName + 'Category:' + this.currentCategory
};
if (cmcontinue)
data.cmcontinue = cmcontinue;
else
this.subCats = [];
this.doAPICall(data, function (result) { var cats = result.query.categorymembers; CAL.subCats = []; for ( var i = 0; i < cats.length; i++ ) { CAL.subCats.push( cats[ i ].title.replace( /^[^:]+:/, '' ) ); }
var cats CAL.catCounter++; if ( CAL.catCounter == result.query= 2 ) { CAL.categorymembersshowCategoryList();}
for (var i = 0; i < cats.length; i++) { catALot.subCats.push(cats[i].title.replace(/^[^:]+:/, "")); } if (result['query-continue']) catALot.getSubCats(result['query-continue'].categorymembers.cmcontinue); else { catALot.catCounter++; if (catALot.catCounter == 2) catALot.showCategoryList(); } });
},
 
getParentCats: function () {
var data = {
action: 'query',
prop: 'categories',
cllimit: 500, titles: this.localCatName + 'Category:' + this.currentCategory
};
this.doAPICall(data, function (result) { catALotCAL.parentCats = new Array()[]; var cats, pages = result.query.pages, table = $( '<table>' );  if (pages[-1] && pages[-1].missing === '') { catALot.catlist$resultList.html('<span id="cat_a_lot_no_found">' + catALotmw.i18nmsg( 'Categorytree-not-found', this.catNotFound currentCategory ) + '</span>');
document.body.style.cursor = 'auto';
  catALotCAL.catlist.appendcreateCatLinks('<ul></ul>', [ CAL.currentCategory ], table ); catALot$resultList.createCatLinksappend("→", [catALot.currentCategory]table );
return;
}
// there should be only one, but we don't know its ID
for (var id in pages) { var cats = pages[id].categories|| [];} } for (var i = 0; i < cats.length; i++) { catALotCAL.parentCats.push(cats[i].title.replace(/^[^:]+:/, ""'' ) ); }  CAL.catCounter++; if ( CAL.catCounter === 2 ) { CAL.showCategoryList(); }  } ); },  localizedRegex: function ( namespaceNumber, fallback ) { // Copied from HotCat, thanks Lupo. var wikiTextBlank = '[\\t _\\xA0\\u1680\\u180E\\u2000-\\u200A\\u2028\\u2029\\u202F\\u205F\\u3000]+'; var wikiTextBlankRE = new RegExp( wikiTextBlank, 'g' ); var createRegexStr = function ( name ){ if ( !name || !name.length ){ return ''; }  var regexName = ''; for ( var i = 0; i < name.length; i++ ) { var ii = name[ i ]; var ll = ii.toLowerCase(); var ul = ii.toUpperCase(); regexName += ( ll === ul ) ? ii : '[' + ll + ul + ']';
}
return regexName.replace( /([\\\^\$\.\?\*\+\(\)])/g, '\\$1' )
.replace( wikiTextBlankRE, wikiTextBlank );
};
 
fallback = fallback.toLowerCase();
var canonical = formattedNS[ namespaceNumber ].toLowerCase();
var RegexString = createRegexStr( canonical );
if ( fallback && canonical !== fallback ) { RegexString += '|' + createRegexStr( fallback ); }
 
for ( var catName in nsIDs ) { if ( typeof catName === 'string' && catName.toLowerCase() !== canonical && catName.toLowerCase() !== fallback && nsIDs[ catName ] === namespaceNumber ) { RegexString += '|' + createRegexStr( catName ); } }
catALot.catCounter return ( '(?:' +RegexString +; if (catALot.catCounter == 2') catALot.showCategoryList(); }' );
},
  regexBuilderregexCatBuilder: function (category) { var catname = ( this.localCatName == 'Category' ) ? this.localCatName: this.localCatName + localizedRegex( 14, '|Category'; catname = '(' + catname + ')';
// Build a regexp string for matching the given category:
// trim leading/trailing whitespace and underscores
category = category.replace(/^[\s_]+/, "").replace(/|[\s_]+$/g, ""'' );
// escape regexp metacharacters (= any ASCII punctuation except _)
category = categorymw.RegExp.replaceescape(/([!-\/:-@\[-^`{-~])/g, '\\$1'category );
// any sequence of spaces and underscores should match any other
category = category.replace(/[\s_]+/g, '[\\s_]+');
// Make the first character case-insensitive:
var first = category.substr(0, 1); if (first.toUpperCase() !== first.toLowerCase()) { category = '[' + first.toUpperCase() + first.toLowerCase() + ']' + category.substr(1);}
// Compile it into a RegExp that matches MediaWiki category syntax (yeah, it looks ugly):
// XXX: the first capturing parens are assumed to match the sortkey, if present, including the | but excluding the ]]
return new RegExp('\\[\\[[\\s_]*' + catname + '[\\s_]*:[\\s_]*' + category + '[\\s_]*(\\|[^\\]]*(?:\\][^\\]]+)*)?\\]\\]\\s*', 'igg'); },  getContent: function ( page, targetcat, mode ) { if ( !this.cancelled ) { this.doAPICall( { curtimestamp: 1, // meta: 'tokens', prop: 'revisions', rvprop: 'content|timestamp', titles: page[ 0 ] }, function ( result ) { CAL.editCategories( result, page, targetcat, mode ); } ); } 
},
getContentgetTargetCat: function (filepages, targetcat, mode) { if ( !this.cancelled ) { this.doAPICall( { meta: 'tokens', prop: 'categories|categoryinfo', titles: 'Category:' + targetcat }, function ( result ) { if ( !result || !result.query ) { return; } CAL.edittoken = result.query.tokens.csrftoken; result = CAL._getPageQuery( result ); CAL.checkTargetCat( result ); for ( var i = 0; i < pages.length; i++ ) { CAL.getContent( pages[ i ], targetcat, mode ); }  } ); }  },  checkTargetCat: function ( page ) { var is_dab = false; // disambiguation var is_redir = typeof page.redirect === 'string'; // Hard redirect? if ( typeof page.missing === 'string' ) { return alert( mw.msg( 'Apifeatureusage-warnings', mw.msg( 'Categorytree-not-found', page.title ) ) ); } var cats = page.categories; this.is_hidden = page.categoryinfo && typeof page.categoryinfo.hidden === 'string';  if ( !is_redir && cats && ( CAL.disambig_category || CAL.redir_category ) ) { for ( var c = 0; c < cats.length; c++ ) { var cat = cats[ c ].title; if ( cat ) { // Strip namespace prefix cat = cat.substring( cat.indexOf( ':' ) + 1 ).replace( /_/g, ' ' ); if ( cat === CAL.disambig_category ) { is_dab = true; break; } else if ( cat === CAL.redir_category ) { is_redir = true; break; } } } }
var data = if ( !is_redir && !is_dab ) {return; } action: alert( mw.msg( 'queryApifeatureusage-warnings', prop: page.title + 'info|revisionsis a ',+ CAL.disambig_category ) ); rvprop: 'content|timestamp' }, intoken: 'edit', titles: file[0] };
this // Remove {{Uncategorized}} (also with comment). No need to replace it with anything.doAPICall(data, removeUncat: function (resulttext ) { catALot return ( this.settings.uncat ? text.editCategoriesreplace( /\{\{\s*[Uu]ncategorized\s*[^}]*\}\}\s*(result, file<!--.*?-->\s*)?/, targetcat, mode'' ); }: text );
},
editCategoriesdoCleanup: function (resulttext ) { return ( this.settings.docleanup ? text.replace( /\{\{\s*[Cc]heck categories\s*(\|?.*?)\}\}/, file'' ) : text ); }, targetcat, mode) {
editCategories: function ( result, file, targetcat, mode ) { if (!result == null|| !result.query ) { //Happens on unstable wifi connections.. this.connectionError.push(file[0]);
this.updateCounter();
return;
}
var pages otext, timestamp, page = CAL._getPageQuery( result.query.pages) // there should be only one, but we don't know its ID for if (var id in pagespage.ns === 2 ) { // The edittoken only changes between logins this.edittoken = pages[id].edittokenreturn;} var otext id = pages[id]page.revisions[0]['*'];, var starttimestamp catNS = pages[id]this.starttimestamplocalCatName; var timestamp = pages[id].revisions[0]['timestamp']; }// canonical cat-name
var sourcecat this.starttimestamp = mwresult.config.get(curtimestamp; otext = id[ 'wgTitle*')]; timestamp = id.timestamp;
var sourcecat = this.origin;
// Check if that file is already in that category
if (mode != "= 'remove" ' && this.regexBuilderregexCatBuilder(targetcat).test(otext)) { //If the new cat is already there, just remove the old one. if (mode === 'move') { mode='remove'; targetcat = sourcecat;
} else {
this.alreadyThere.push(file[0]);
this.updateCounter();
return;
}
// Text modification (following 3 functions are partialy taken from HotCat) var wikiTextBlankOrBidi = '[\\t _\\xA0\\u1680\\u180E\\u2000-\\u200B\\u200E\\u200F\\u2028-\\u202F\\u205F\\u3000]*'; // Whitespace regexp for handling whitespace between link components. Including the horizontal tab, but not \n\r\f\v: // a link must be on one single line. // MediaWiki also removes Unicode bidi override characters in page titles (and namespace names) completely. // This is *not* handled, as it would require us to allow any of [\u200E\u200F\u202A-\u202E] between any two // characters inside a category link. It _could_ be done though... We _do_ handle strange spaces, including the // zero-width space \u200B, and bidi overrides between the components of a category link (adjacent to the colon, // or adjacent to and inside of "[[" and "]]"). var text findCatsRE = otextnew RegExp( '\\[\\[' + wikiTextBlankOrBidi + this.localizedRegex( 14, 'Category' ) + wikiTextBlankOrBidi + ':[^\\]]+\\]\\]', 'g' );  function replaceByBlanks( match ) { return match.replace( /(\s|\S)/g, ' ' );// /./ doesn't match linebreaks. /(\s|\S)/ does. }  function find_insertionpoint( wikitext ) { var copiedtext = wikitext .replace( /<!--(\s|\S)*?-->/g, replaceByBlanks ) .replace( /<nowiki>(\s|\S)*?<\/nowiki>/g, replaceByBlanks ); // Search in copiedtext to avoid that we insert inside an HTML commentor a nowiki "element". var index = -1; findCatsRE.lastIndex = 0; while ( findCatsRE.exec( copiedtext ) !== null ) { index = findCatsRE.lastIndex; }  return index; }  /*** @brief Adds the new Category by searching the right insert point,* if there is text after the category section* @param [string] wikitext* @param [string] toAdd* @return Return wikitext*/ function addCategory( wikitext, toAdd ) { if ( toAdd && toAdd[ 0 ] ) { // TODO: support sort key var cat_point = find_insertionpoint( wikitext ); // Position of last category var newcatstring = '[[' + catNS + toAdd + ']]'; if ( cat_point > -1 ) { var suffix = wikitext.substring( cat_point ); wikitext = wikitext.substring( 0, cat_point ) + ( cat_point ? '\n' : '' ) + newcatstring; if ( suffix[ 0 ] && suffix.substr( 0, 1 ) !== '\n' ) { wikitext += '\n'; } wikitext += suffix; } else { if ( wikitext[ 0 ] && wikitext.substr( wikitext.length - 1, 1 ) !== '\n' ) { wikitext += '\n';}
wikitext += ( wikitext[ 0 ] ? '\n' : '' ) + newcatstring;
}
}
return wikitext;
}
// End HotCat functions
 
var text = otext,
arr = is_rtl ? '\u2190' : '\u2192', // left and right arrows. Don't use ← and → in the code.
sumCmt, // summary comment
sumCmtShort;
// Fix text
switch (mode) { case 'add': text += "\n[[" + this.localCatName + ":" + targetcat.replaceaddCategory("رده:"text,""targetcat ) + "]]\n"; text sumCmt =textmsg( 'summary-add' ).replace("رده:رده:"/\$1/g,"رده:"targetcat ); comment sumCmtShort = this.i18n.summaryAdd '+[[' + catNS + targetcat.replace("رده:","") + "']]"'; break; case 'copy': text = text.replace(this.regexBuilderregexCatBuilder(sourcecat), "'[[" + this.localCatName ' + ":" catNS + sourcecat + "'$21]]\n[[" + this.localCatName ' + ":" catNS + targetcat.replace("رده:","") + "'$21]]"\n' ); text sumCmt =textmsg( 'summary-copy' ).replace( /\$1/g, sourcecat ).replace("رده:رده:"/\$2/g,"رده:"targetcat ); comment sumCmtShort = this.i18n.summaryCopy '+[[' + catNS + sourcecat + "']] " ' + arr + '[[' + this.i18n.to catNS + targetcat.replace+ ']]'; // If category is added through template: if ( otext === text ) { text = addCategory("رده:"text,""targetcat ) + "]]";}  break; case 'move': text = text.replace(this.regexBuilderregexCatBuilder(sourcecat), "'[[" + this.localCatName ' + ":" catNS + targetcat.replace("رده:","") + "'$21]]"\n' ); text sumCmt =textmsg( 'summary-move' ).replace( /\$1/g, sourcecat ).replace("رده:رده:"/\$2/g,"رده:"targetcat ); comment sumCmtShort = this.i18n.summaryMove '±[[' + catNS + sourcecat + "']] " ' + arr + '[[' + this.i18n.to catNS + targetcat.replace("رده:","") + "']]"'; break; case 'remove': text = text.replace(this.regexBuilderregexCatBuilder(sourcecattargetcat ), ""'' ); text sumCmt =textmsg( 'summary-remove' ).replace("رده:رده:"/\$1/g,"رده:"targetcat ); comment sumCmtShort = this.i18n.summaryRemove '-[[' + catNS + sourcecat targetcat + "']]"'; break;
}
if (text === otext) { this.notFound.push(file[0]);
this.updateCounter();
return;
}
otext = text;
 
// Remove {{uncat}} after we checked whether we changed the text successfully.
// Otherwise we might fail to do the changes, but still replace {{uncat}}
if ( mode !== 'remove' && ( !non || userGrp.indexOf( 'autoconfirmed' ) > -1 ) ) {
if ( !this.is_hidden ) {
text = this.removeUncat( text );
if ( text.length !== otext.length ) { sumCmt += '; ' + msg( 'uncatpref' ); }
}
text = this.doCleanup( text );
}
 
sumCmt += this.summary ? ' ' + this.summary : '';
 
var preM = msg( 'prefix-summary' );
var usgM = msg( 'using-summary' );
// Try shorten summary
if ( preM || usgM ) {
sumCmt = ( sumCmt.length > 250 - preM.length - usgM.length ) ?
sumCmt + ' (CatAlot)' : preM + sumCmt + usgM;
}
 
if ( sumCmt.length > 254 ) // Try short summary
{ sumCmt = sumCmtShort; }
var data = {
action: 'edit',
assert: 'user', summary: commentsumCmt, title: file[0], tokentext: text, bot: this.edittokentrue, starttimestamp: this.starttimestamp,
basetimestamp: timestamp,
textwatchlist: textthis.settings.watchlist, minor: this.settings.minor, tags: this.changeTag, token: this.edittoken
};
var isBot=$this.inArraydoAPICall('bot'data, mwfunction ( r ) { delete CAL.configXHR[ file[ 0 ] ]; return CAL.getupdateUndoCounter('wgUserGroups'r ))>-1; if(isBot} ); data this.bot = 'markAsDone( file[ 1'], mode, targetcat ); },
markAsDone: function ( label, mode, targetcat ) { this.doAPICallmode = (data, function (retm ) { catALot.updateCounterswitch (m ){ case 'add': return 'added-cat'; case 'copy': return 'copied-cat'; case 'move': return 'moved-cat'; case 'remove': return 'removed-cat'; } }( mode ) ); thislabel.addClass( 'cat_a_lot_markAsDone' ).markAsDoneappend( '<br>' + msg(file[1], mode, targetcat) );
},
markAsDone: function (label, mode, targetcat) {
updateUndoCounter: function ( r ) { labelthis.addClassupdateCounter('cat_a_lot_markAsDone'); switch if (mode) { case 'add': label!r.append('<br>' + thisedit || r.i18nedit.addedCat + result !== ' Success' + targetcat){ return; break;} case 'copy': labelr = r.append('<br>' + this.i18n.copiedCat + ' ' + targetcat)edit; break; case 'move': label.append('<br>' + this.i18nundoList.movedCat + ' ' + targetcat);push( { break; case 'remove'title:r.title, labelid: r.append('<br>' + this.i18n.movedCat );newrevid, break;timestamp: r.newtimestamp });
},
 
updateCounter: function () {
 
this.counterCurrent++;
if (this.counterCurrent > this.counterNeeded) { this.displayResult(); } else { this.domCounter.text(this.counterCurrent);}
},
displayResult: function () {
 
document.body.style.cursor = 'auto';
$.removeSpinner('.cat_a_lot_feedbackfb-dialog'); this.progressDialog.parent() .addClass('cat_a_lot_done'); $ .find('.ui-dialog-contentbuttonpane button span').heighteq( 0 ) .text( mw.msg('autoMobile-frontend-return-to-page') ); var rep = this.domCounter.parent(); rep .height( 'auto' ) .html('<h3>' + this.i18n.msg( 'done ' ) + '</h3>' ) .append( msg( 'all-done' ) + '<br>'); if ( this.alreadyThere.length ) { rep.append( '<h5>' + msg( 'skipped-already', this.i18nalreadyThere.allDone length ) + '</h5>' ) .append( this.alreadyThere.join( '<br />') ); }
var close = $('<a>').appendif ( this.i18nnotFound.returnToPage ); close.click(function (length ) { catALot.progressDialog.remove(); catALot.toggleAll(false); }); rep.append(close); if '<h5>' + msg('skipped-not-found', this.alreadyTherenotFound.length) { rep.append( this.i18n.skippedAlready + '</h5>' ); rep .append(this.alreadyTherenotFound.join('<br>'));
}
  if (this.notFoundconnectionError.length) { rep.append( '<h5>' + msg( 'skipped-server', this.i18nconnectionError.skippedNotFound length ) + '</h5>' ); rep .append(this.notFoundconnectionError.join('<br>'));
}
if (this.connectionError.length) {
rep.append( this.i18n.skippedServer );
rep.append(this.connectionError.join('<br>'));
}
 
},
 
moveHere: function (targetcat) {
this.doSomething(targetcat, 'move');
},
 
copyHere: function (targetcat) {
this.doSomething(targetcat, 'copy');
},
addHere: function (targetcat) {
this.doSomething(targetcat, 'add');
},
remove/*** @brief set parameters for API call,* convert targetcat to string, get selected pages/files* @param [dom object] targetcat with data* @param [string] mode action* @return Return API call getTargetCat with pages*/ doSomething: function (targetcat, mode ) { var pages = this.doSomethinggetMarkedLabels(); if ( !pages.length ) { return alert( mw.msg( 'Ooui-selectfile-placeholder' ) ); } targetcat = $( targetcat ).closest('tr', ).data( 'removecat'); },
doSomething: function (targetcat, mode) {
var files = this.getMarkedLabels();
if (files.length == 0) {
alert( this.i18n.noneSelected );
return;
}
this.notFound = [];
this.alreadyThere = [];
this.connectionError = [];
this.counterCurrent = 1;
this.counterNeeded = filespages.length; this.showProgress()undoList = []; this.XHR = {}; for (var i this.cancelled = 0; i < files this.lengthsummary = '';  if ( $( '#cat_a_lot_comment' ).prop( 'checked' ) ) { this.summary = window.prompt( msg( 'edit-question' ), '' ); i++} // TODO custom pre-value if ( this.summary !== null ) { thismw.loader.getContentusing(files[i'jquery.ui.dialog', 'jquery.spinner', 'mediawiki.RegExp' ], function () { CAL.showProgress(); CAL.getTargetCat( pages, targetcat, mode); } );
}
 
},
doAPICall: function (params, callback) { params = $.extend( { action: 'query', format: 'json' }, params );  var i = 0, apiUrl = this.apiUrl, doCall, handleError = function ( jqXHR, textStatus, errorThrown ) { mw.log( 'Error: ', jqXHR, textStatus, errorThrown ); if ( i < 4 ) { window.setTimeout( doCall, 300 ); i++; } else if ( params.title ) { this.connectionError.push( params.title ); this.updateCounter(); return; } }; doCall = function () { var xhr = $.ajax( { url: apiUrl, cache: false, dataType: 'json', data: params, type: 'POST', success: callback, error: handleError } );
if ( params.format action === 'jsonedit'; $&& !CAL.ajax(cancelled ) { url: thisCAL.apiUrl, cache: false, dataType: 'json', data: XHR[ params,.title ] = xhr; } type: 'POST', success: callback }; }doCall();
},
createCatLinks: function (symbol, list, table ) {
list.sort();
var domlist button = ( this.catlistsettings.button && mw.loader.findgetState('uljquery.ui.button')=== 'ready' ) ? 1 : 0; for (var i c = 0; i c < list.length; ic++) { var li $tr = $( '<tr>' ), $link = $( '<a>', { href: mw.util.getUrl( CAL.localCatName + list[ c ] ), text: list[ c ] } ), $buttons = []; $tr.data( 'cat', list[ c ] ); $link.on( 'click', function ( e ) { if ( !e.ctrlKey ) { e.preventDefault(); CAL.updateCats( $( this ).closest( 'tr' ).data( 'cat' ) ); } } );  $tr.append( $('<litd>' ).text( symbol ) ) .append( $( '</litd>').append( $link ) );  $buttons.push( $( '<a>' ) .text( mw.msg( 'Centralnotice-remove' ) ) .on( 'click', function () { CAL.doSomething( this, 'remove' ); } ) .addClass( 'cat_a_lot_move' ) ); if ( button ) { $buttons.slice( -1 )[ 0 ].button( { icons: { primary: 'ui-icon-minusthick' }, showLabel: false, text: false } ); }
var link if ( this.origin ) { // Can't move to source category if ( list[ c ] != = this.origin ) { $buttons.push( $('<a></a>'); link .text(list[i]msg( 'move' ) ); li .dataon('catclick', list[i]function () { CAL.doSomething( this, 'move' ); link } ) .clickaddClass(function 'cat_a_lot_move' ) ); if (button ) { catALot.updateCats( $(this)buttons.parentslice(-1 )[ 0 ].databutton({ icons: { primary: 'catui-icon-arrowthick-1-e')}, showLabel: false, text: false } ); });
if $buttons.push(this.searchmode) { var add = $('<a class="cat_a_lot_action"><b>' + this) .i18n.add + text( msg( '</b></a>copy');) add .on( 'click(', function () { catALot CAL.doSomething( this, 'copy' ); } ) .addHereaddClass($'cat_a_lot_action' ) ); if (thisbutton ){ $buttons.parentslice(-1 )[ 0 ].databutton({ icons: { primary: 'catui-icon-plusthick')}, showLabel: false, text: false } ); }  });
} else {
var move = $buttons.push( $('<a class="cat_a_lot_move"><b>' + this) .i18n.move + text( msg( '</b></a>add');) move .on( 'click(', function () { CAL.doSomething( this, 'add' ); } ) catALot.moveHereaddClass($'cat_a_lot_action' ) ); if (thisbutton ){ $buttons.parentslice(-1 )[ 0 ].databutton({ icons: { primary: 'catui-icon-plusthick')}, showLabel: false, text: false } ); });
var copy = $('<a class="cat_a_lot_action"><b>' + this.i18n.copy + '</b></a>');
copy.click(function () {
catALot.copyHere($(this).parent().data('cat'));
});
}
// TODO CSS may extern
var css = button ? { fontSize: '.6em', margin: '0', width: '2.5em' } : {};
for ( var b = 0; b < $buttons.length; b++ ) { $tr.append( $( '<td>' ).append( $buttons[ b ].css( css ) ) ); }
// Can't move to source category if (list[i] != mw.config.get('wgTitle') && this.searchmode) li.append(' ').append(add); else if (list[i] != mw.config.get('wgTitle') && !this.searchmode) li.append(' ').append(move).append(' ').append(copy); li.append(symbol).append(' ').append(link);  domlisttable.append(li$tr );
}
},
this.getParentCats();
this.getSubCats();
},
 
_getPageQuery: function ( data ) {
// There should be only one, but we don't know its ID
if ( data && data.query && data.query.pages ) {
data = data.query.pages;
for ( var p in data ) { return data[ p ]; }
}
},
 
/**
* @brief takes this.currentCategory if redir_category is configured
** Cat pages with more than one cat link are still not supported for sure
* @return soft redirected cat
*/
solveSoftRedirect: function () {
this.doAPICall( {
prop: 'links', // TODO: For more accuracy the revisions could be checked
titles: 'Category:' + this.currentCategory,
// 'rvprop': 'content',
// 'pllimit': 'max',
plnamespace: 14
}, function ( page ) {
page = CAL._getPageQuery( page );
if ( page ) {
var lks = page.links;
if ( lks && lks.length === 1 && lks[ 0 ].title ) {
CAL.currentCategory = lks[ 0 ].title.replace( reCat, '' );
$searchInput.val( CAL.currentCategory );
return CAL.getCategoryList();
} else {
// TODO? better translatable warning message: "Please solve the category soft redirect manually!"
$resultList.html( '<span id="cat_a_lot_no_found">' + mw.msg( 'Apifeatureusage-warnings', mw.msg( 'Categorytree-not-found', CAL.currentCategory ) ) + '</span>' );
}
}
} );
},
showCategoryList: function () {
var thiscat if ( this.settings.redir_category && this.settings.redir_category == = this.parentCats[0 ] ) { return this.currentCategory]solveSoftRedirect();}
this.catlist.empty(); this.catlist.appendvar table = $('<ul></ultable>');
this.createCatLinks("'"', this.parentCats, table ); this.createCatLinks( '→', [ this.currentCategory ], table ); // Show on soft-redirect if ( $searchInput.val() === this.currentCategory && this.origin !== this.currentCategory ) { this.createCatLinks("'"', thiscat[ this.origin ], table );} this.createCatLinks("'"', this.subCats, table );  $resultList.empty(); $resultList.append( table );
document.body.style.cursor = 'auto';
  //Reset width var cat = $('#cat_a_lot'); catcontainer.width(''); cat$container.height(''); cat$container.width( catMath.min( table.width() * 1.05 1 + 15, $( window ); var list = $.width('#cat_a_lot_category_list') - 10 ) );  list$resultList.css({ maxHeight: Math.min( this.setHeight+'px', $( window ).height() - $container.position().top - $settingsLink.outerHeight() - $selections.outerHeight() - 15 ), height: '' } ); table.width( '100%' ); $container.height( Math.min( $container.height(), $head.offset().top - $container.offset().top + 10 ) ); $container.offset( { left: $( window ).width() - $container.outerWidth() });// Fix overlap
},
updateCats: function (newcat) {
document.body.style.cursor = 'wait';
 
this.currentCategory = newcat;
this.catlist = $('#cat_a_lot_category_list'); this.catlistresultList.html('<div class="cat_a_lot_loading">' + this.i18nmw.msg( 'Wikieditor-loading ' ) + '</div>');
this.getCategoryList();
},
 
doUndo: function () {
this.cancelled = 0;
this.doAbort();
if ( !this.undoList.length ) { return; }
 
$( '.cat_a_lot_feedback' ).removeClass( 'cat_a_lot_done' );
this.counterNeeded = this.undoList.length;
this.counterCurrent = 1;
 
document.body.style.cursor = 'wait';
 
var query = {
action: 'edit',
user: mw.config.get( 'wgUserName' ),
bot: true,
minor: this.settings.minor,
starttimestamp: this.starttimestamp,
watchlist: this.settings.watchlist,
tags: this.changeTag,
token: this.edittoken
};
for ( var i = 0; i < this.undoList.length; i++ ) {
var uID = this.undoList[ i ];
query.title = uID.title;
query.undo = uID.id;
query.basetimestamp = uID.timestamp;
this.doAPICall( query, function ( r ) {
// TODO: Add "details" to progressbar?
// $resultList.append( [mw.msg('Filerevert-submit') + " done " + r.edit.title, '<br>' ] );
if ( r && r.edit ) { mw.log( 'Revert done', r.edit.title ); }
CAL.updateCounter();
} );
}
},
 
doAbort: function () {
for ( var t in this.XHR ) { this.XHR[ t ].abort(); }
 
if ( this.cancelled ) { // still not for undo
this.progressDialog.remove();
this.toggleAll( false );
$head.last().show();
}
this.cancelled = 1;
},
 
showProgress: function () {
document.body.style.cursor = 'wait';
this.progressDialog = $( '<div>' )
.html( ' ' + msg( 'editing' ) + ' <span id="cat_a_lot_current">' + CAL.counterCurrent + '</span> ' + msg( 'of' ) + CAL.counterNeeded )
.prepend( $.createSpinner( { id: 'fb-dialog', size: 'large' } ) )
.dialog( {
width: 450,
height: 180,
minHeight: 90,
modal: true,
resizable: false,
draggable: false,
// closeOnEscape: true,
dialogClass: 'cat_a_lot_feedback',
buttons: [ {
text: mw.msg( 'Cancel' ), // Stops all actions
click: function () {
$( this ).dialog( 'close' );
}
} ],
close: function () {
CAL.cancelled = 1;
CAL.doAbort();
$( this ).remove();
},
open: function ( event, ui ) { // Workaround modify
ui = $( this ).parent();
ui.find( '.ui-dialog-titlebar' ).hide();
ui.find( '.ui-dialog-buttonpane.ui-widget-content' )
.removeClass( 'ui-widget-content' );
/* .find( 'span' ).css( { fontSize: '90%' } )*/
}
} );
if ( $head.children().length < 3 ) {
$( '<span>' )
.css( {
'float': 'right',
fontSize: '75%'
} )
.append( [ '[ ',
$( '<a>', { title: 'Revert all last done edits' } ) // TODO i18n
.on( 'click', function () {
if ( window.confirm( mw.msg( 'Apifeatureusage-warnings', this.title + '⁉' ) ) ) {
CAL.doUndo();
$( this ).parent().remove();
}
return false;
} )
.addClass( 'new' )
.text( mw.msg( 'Filerevert-submit' ) ),
' ]'
] ).insertAfter( $link );
}
this.progressDialog domCounter = $('<div></div>#cat_a_lot_current'); },  minimize: function ( e ) { CAL.htmltop = Math.max( this0, $container.i18nposition().top ); CAL.editing + ' <span idheight ="cat_a_lot_current">' + this$container.counterCurrent + '</span> ' + thisheight(); $dataContainer.i18n.of + this.counterNeededhide(); $container.dialoganimate({ widthheight: 450, $head.height: 90(), minHeighttop: 90, modal: true, resizable: false, draggable: false, closeOnEscape: false, dialogClass: "cat_a_lot_feedback"$( window ).height() - $head.height() * 1.4 }, function ();{ $('e.ui-dialog-titlebar'target ).hideone('click', CAL.maximize ); this.domCounter = $('#cat_a_lot_current'} ); },
maximize: function ( e ) {
$dataContainer.show();
$container.animate( {
top: CAL.top,
height: CAL.height
}, function () {
$( e.target ).one( 'click', CAL.minimize );
} );
},
run: function () {
if ($('.cat_a_lot_enabled').length[ 0 ] ) {
this.makeClickable();
if ( !this.executed ) { // only once $selectInvert.text( mw.msg( 'Checkbox-invert' ) ); if ( this.settings.editpages && this.pageLabels[ 0 ] ) { $selectFiles.text( mw.msg( 'Prefs-files' ) ); $selectPages.text( mw.msg( 'Categories' ) ).parent().show(); } $link.after( $( '<a>' ) .text( '–' ) .css( { fontWeight: 'bold', marginLeft: '.7em' } ) .one("#cat_a_lot_data"'click', this.minimize ) ); } $dataContainer.show(); $container.one('#cat_a_lotmouseover', function (){ $( this ) .resizable({ handles: 'n', alsoResize: '#cat_a_lot_category_list', resize: function(event, ui) { $resultList .css(this{ maxHeight: '', width: '' } ); }, start: function ( e, ui ){ // Otherwise box get static if sametime resize with draggable ui.helper.css({left top:""ui.helper.offset().top - $( window ).scrollTop(), top position:""'fixed' }); catALot }, stop: function () { CAL.setHeight = $(this)resultList.height(); } } ) $.draggable( { cursor: 'move', start: function ( e, ui ) { ui.helper.on('#cat_a_lot_category_listclick.prevent', function ( e ){ e.preventDefault(); } ); ui.helper.css({maxHeight: 'height', widthui.helper.height() ); }, stop: function ( e, ui ) { setTimeout( function () { ui.helper.off( 'click.prevent'); }, 300 ); } }); $ .one('#cat_a_lot_category_listmousedown', function (){ $container.height( $container.height() ); // Workaround to calculate } ); $resultList .css({maxHeight: '450px'450 }); if (this.searchmode) this.updateCats("Pictures and images"} ); else this.updateCats(mwthis.config.get(origin || 'wgTitleImages'));
$link.html( $( '<span>' ) .text( '×' ) .css( { font: 'bold 2em monospace', lineHeight: '.75em' } ) ); $link.next().show(); if ( this.cancelled ) { $head.last().show(); } mw.cookie.set( 'catAlotO', ns ); // Let stay open on new window } else {// Reset $("#cat_a_lot_data")dataContainer.hide(); $container .draggable("#cat_a_lot"'destroy' ) .resizable( "'destroy" ' ) .removeAttr( 'style' ); //Unbind click handlers this.labels.off('click.catALot' ); this.setHeight = 450; $link.text( 'Cat-a-lot' ) .nextAll().hide(); this.executed = 1; mw.cookie.set( 'catAlotO', null );
}
},
i18n: (mw.config.get('wgUserLanguage') == "fa") ? {
loading: 'بارگیری...',
editing: 'ویرایش صفحه',
of: ' ',
skippedAlready: '<h5>صفحهٔ انتخاب شده رها شد، چون صفحه در همان رده قرار دارد.:</h5>',
skippedNotFound: '<h5>صفحهٔ انتخاب شده رها شد چون رده قدیمی پیدا نشد!:</h5>',
skippedServer: '<h5>صفحه‌های انتخاب شده را نمی‌توان تغییر داد چون ارتباط با سرور فعلا برقرار نیست:</h5>',
allDone: 'درخواست برای تمام صفحه‌ها انجام شدند.',
done: 'انجام شد!',
addedCat: 'افزودن رده',
copiedCat: 'کپی به ردهٔ',
movedCat: 'انتقال به ردهٔ',
removedCat: 'حذف از ردهٔ',
returnToPage: 'بازگشت به صفحه',
catNotFound: 'رده یافت نشد.',
manageSettings: function () {
mw.loader.using( [ 'ext.gadget.SettingsManager', 'ext.gadget.SettingsUI', 'jquery.ui.progressbar' ], CAL._manageSettings );
},
 
_manageSettings: function () {
mw.libs.SettingsUI( CAL.defaults, 'Cat-a-lot' )
.show()
.done( function ( s, verbose, loc, settingsOut, $dlg ) {
var mustRestart = false,
_restart = function () {
if ( !mustRestart ) { return; }
$container.remove();
CAL.labels.off( 'click.catALot' );
CAL.init();
},
_saveToJS = function () {
var opt = mw.libs.settingsManager.option( {
optionName: 'catALotPrefs',
value: CAL.settings,
encloseSignature: 'catALot',
encloseBlock: '////////// Cat-a-lot user preferences //////////\n',
triggerSaveAt: /Cat.?A.?Lot/i,
editSummary: msg( 'pref-save-summary' )
} ),
oldHeight = $dlg.height(),
$prog = $( '<div>' );
$dlg.css( 'height', oldHeight ) .html( '' ); $prog.css( { height: Math.round( oldHeight /8 ), 'margin-top': Math.round( ( 7 * oldHeight ) /as in 17 files selected16 ) filesSelected: ' صفحه انتخاب شده } ) .',appendTo( $dlg );
//Actions $dlg.parent() copy: .find( 'کپی.ui-dialog-buttonpane button', move: 'انتقال', add: 'افزودن', removeFromCat: 'حذف از رده', enterName: 'نام رده مورد نظر را بنویسید',) select: .button( 'انتخابoption', all: 'همه', none: 'هیچکدامdisabled',true );
noneSelected opt.save() .done( function ( text, progress ) { $prog.progressbar( { value: progress } ); $prog.fadeOut( function () { $dlg.dialog( 'صفحه‌ای انتخاب نشده‌استclose' ); _restart(); } ); } ) .progress( function ( text, progress ) { $prog.progressbar( { value: progress } ); // TODO: Add "details" to progressbar } ) .fail( function ( text ) { $prog.addClass( 'ui-state-error' ); $dlg.prepend( $( '<p>' ) .text( text ) ); } ); }; $.each( settingsOut, function ( n, v ) { if ( v.forcerestart && CAL.settings[ v.name ] !== v.value ) { mustRestart = true; } CAL.settings[ v.name ] = CAL.catALotPrefs[ v.name ] = v.value; } ); switch ( loc ) { case 'page': $dlg.dialog( 'close' ); _restart(); break; case 'account-publicly': _saveToJS(); break; } } ); },
_initSettings: function () { //Summaries:if ( this.settings.watchlist ) { return; } this.catALotPrefs = window.catALotPrefs || {}; summaryAdd: 'for ( var i = 0; i < this.defaults.length; i++ ) { var v = this.defaults[i ]; v.value = this.settings[وپ:رده انبوه|رده‌انبوهv.name ]= ( this.catALotPrefs[ v.name ]: افزودن || v[[رده:'default'] ); v.label = msg( v.label_i18n ); if ( v.select_i18n ) { v.select = {}; $.each( v.select_i18n,function ( i18nk, val ) { summaryCopy: '[ v.select[وپ:رده انبوه|رده‌انبوه]msg( i18nk ) ]= val; } ); } } }, /* eslint-disable camelcase */ defaults: کپی از [[رده{ name:'watchlist', to'default': 'به [[رده:preferences', summaryMovelabel_i18n: '[[وپwatchlistpref', select_i18n:رده انبوه|رده‌انبوه]]{ watch_pref: انتقال از [[رده'preferences', watch_nochange:'nochange', summaryRemove watch_watch: '[[وپ:رده انبوه|رده‌انبوه]]: حذف از [[ردهwatch', watch_unwatch:'unwatch' } }, { name: {'minor', //Progress'default': false, loadinglabel_i18n: 'Loading...minorpref' },{ editingname: 'Editing pageeditpages', of'default': project !== 'of commonswiki',// on Commons false skippedAlreadylabel_i18n: '<h5>The following pages were skippededitpagespref', because the page was already in the category forcerestart:</h5>'true },{ skippedNotFoundname: '<h5>The following pages were skippeddocleanup', because the old category could not be found 'default':</h5>'false, skippedServerlabel_i18n: '<h5>The following pages couldn\docleanuppref't be changed }, since there were problems connecting to the server{ name:</h5>'subcatcount', allDone: 'All pages are processed.default': 50, min: 5, donemax: 500, label_i18n: 'Done!subcatcountpref', addedCatforcerestart: true }, { name: 'Added categoryuncat', copiedCat'default': project === 'Copied to categorycommonswiki',// on Commons true movedCatlabel_i18n: 'Moved to categoryuncatpref' },{ removedCatname: 'Removed from categorybutton', returnToPage: 'Return to pagedefault': true, catNotFoundlabel_i18n: 'Category not found.buttonpref', } ]/* eslint-enable camelcase */};
// The gadget is not immediately needed, so let the page load normally
window.setTimeout( function () {
non = mw.config.get( 'wgUserName' );
if ( non ) {
if ( mw.config.get( 'wgRelevantUserName' ) === non ) { non = 0; } else {
$.each( [ 'sysop', 'filemover', 'editor', 'rollbacker', 'patroller', 'autopatrolled', 'image-reviewer', 'reviewer', 'extendedconfirmed' ], function ( i, v ) {
non = $.inArray( v, userGrp ) === -1;
return non;
} );
}
} else { non = 1; }
switch ( ns ) { case 14: CAL.searchmode = 'category'; CAL.origin = mw.config.get( 'wgTitle' ); break; case -1: CAL.searchmode = { //as in 17 files selectedlist of accepted special page names mapped to search mode names Contributions: 'contribs', Listfiles: non ? null : 'listfiles', Prefixindex: non ? null : 'prefix', Search: 'search', Uncategorizedimages: 'gallery' }[ mw.config.get( 'wgCanonicalSpecialPageName' ) ]; break; filesSelectedcase 2: case 0: CAL.searchmode = 'gallery'; var parents = $( ' files selected#mw-normal-catlinks ul' ).find( 'a[title]' ),n; parents.each( function ( i ) { if ( new RegExp( mw.config.get( 'wgTitle' ), 'i' ).test( $( this ).text() ) ) { n = i; return false; } } ); CAL.origin = parents.eq( n || 0 ).text(); }
if ( CAL.searchmode ) { //Actionsvar loadingLocalizations = 1; copyvar loadLocalization = function ( lang, cb ) { loadingLocalizations++; switch ( lang ) { case 'zh-hk': case 'Copyzh-mo',: move: case 'Movezh-tw',: add: lang = 'Addzh-hant',; break; removeFromCat: case 'Remove from this categoryzh',: enterName: case 'Enter category namezh-cn',: select: case 'Selectzh-my',: all: case 'allzh-sg',: none: lang = 'nonezh-hans',; break; }
noneSelected $.ajax( { url: commonsURL, dataType: 'script', data: { title: 'MediaWiki:Gadget-Cat-a-lot.js/' + lang, action: 'raw', ctype: 'No files selectedtext/javascript', // Allow caching for 28 days maxage: 2419200, smaxage: 2419200 }, cache: true, success: cb, error: cb } ); }; var maybeLaunch = function () { loadingLocalizations--; function init() { $( function () { CAL.init(); } ); } if ( !loadingLocalizations ) { mw.loader.using( [ 'user'], init,init ); } };
//Summaries: summaryAdd: var userlang = mw.config.get( 'Cat-a-lot: Adding [[Category:wgUserLanguage'), summaryCopy: contlang = mw.config.get( 'Cat-a-lot: Copying from [[Category:wgContentLanguage',); to: if ( userlang !== 'to [[Category:en') { loadLocalization( userlang,maybeLaunch ); } summaryMove: if ( $.inArray( contlang, [ 'en'Cat, userlang ] ) === -a-lot: Moving from [[Category:'1 ) { loadLocalization( contlang,maybeLaunch ); } summaryRemove: 'Cat-a-lot: Removing from [[Category:'maybeLaunch();
}
}, 400 );
/**
* Derivative work of
* (replace "checkboxes" with cat-a-lot labels in your mind)
**
* jQuery checkboxShiftClick
*
* This will enable checkboxes to be checked or unchecked in a row by clicking one, holding shift and clicking another one
*
* @author Krinkle <krinklemail@gmail.com>
* @license GPL v2
*/
$.fn.catALotShiftClick = function ( cb ) {
var prevCheckbox = null,
$box = this;
// When our boxes are clicked..
$box.on( 'click.catALot', function ( e ) {
// Prevent following the link and text selection
if ( !e.ctrlKey ) { e.preventDefault(); }
// Highlight last selected
$( '#cat_a_lot_last_selected' )
.removeAttr( 'id' );
var $thisControl = $( e.target ),
method;
if ( !$thisControl.hasClass( 'cat_a_lot_label' ) ) { $thisControl = $thisControl.parents( '.cat_a_lot_label' ); }
if ((mw.config $thisControl.getattr('wgNamespaceNumberid') == -1 && mw.config.get(, 'wgCanonicalSpecialPageNamecat_a_lot_last_selected') == "Search") || mw .config.gettoggleClass('wgNamespaceNumbercat_a_lot_selected') ; // And one has been clicked before… if ( prevCheckbox !== 14null && e.shiftKey ) { if ( mw.config method = $thisControl.gethasClass('wgNamespaceNumbercat_a_lot_selected') == ? 'addClass' : 'removeClass'; // Check or uncheck this one and all in-1 ) catALotbetween checkboxes $box.searchmode = true;slice( mediaWiki Math.min( $box.loaderindex( prevCheckbox ), $box.usingindex(['jquery$thisControl ) ), Math.uimax( $box.dialog'index( prevCheckbox ), 'jquery$box.ui.autocomplete'index( $thisControl ) ) + 1 )[ method ], function ('cat_a_lot_selected' ) {; } // Either way, update the prevCheckbox variable to the one clicked now prevCheckbox = $thisControl; if (function $.isFunction(cb ) ) { catALot.initcb();} }); })return $box;};
}( jQuery, mediaWiki ) );// </sourcenowiki>
۳۱۷
ویرایش