مدیاویکی:Gadget-Cat-a-lot.js: تفاوت میان نسخه‌ها

محتوای حذف‌شده محتوای افزوده‌شده
Mardetanha (بحث | مشارکت‌ها)
صفحهٔ جدید: // Variables var cat_a_lot_mark_color = "#3399FF" ; var cat_a_lot_api_url = "/w/api.php" ; var cat_a_lot_query_url = "/w/query.php" ; var cat_a_lot_edit_url = "/w/index.php?titl...
 
Abot (بحث | مشارکت‌ها)
بدون خلاصۀ ویرایش
خط ۱:
// <source lang="javascript">
// Variables
//
var cat_a_lot_mark_color = "#3399FF" ;
// Cat-A-Lot
var cat_a_lot_api_url = "/w/api.php" ;
// Changes category of multiple files (or pages)
var cat_a_lot_query_url = "/w/query.php" ;
//
var cat_a_lot_edit_url = "/w/index.php?title=" ;
// Originally by Magnus Manske
// RegExes by Ilmari Karonen
// Completely rewritten by DieBuche
//
// Modified to work on regular pages instead of files, + Hebrew translation: קיפודנחש
//
// READ THIS PAGE IF YOU WANT TO TRANSLATE OR USE THIS ON ANOTHER SITE:
// http://commons.wikimedia.org/wiki/MediaWiki_talk:Gadget-Cat-a-lot.js/translating
//
var catALot = {
apiUrl: wgScriptPath + "/api.php",
searchmode: false,
version: 2.18,
setHeight: 450,
init: function () {
$("body")
.append('<div id="cat_a_lot">' + '<div id="cat_a_lot_data"><div>' + '<input type="text" id="cat_a_lot_searchcatname" placeholder="' + this.i18n.enterName + '"/>'
+ '</div><div id="cat_a_lot_category_list"style="white-space:nowrap;"></div>' + '<div id="cat_a_lot_mark_counter"> </div>' + '<div id="cat_a_lot_selections">' + this.i18n.select
+ ' <a id="cat_a_lot_select_all">' + this.i18n.all + '</a> / ' + '<a id="cat_a_lot_select_none">' + this.i18n.none + '</a>'
+ '</div></div><div id="cat_a_lot_head">' + '<a id="cat_a_lot_toggle">Cat-a-lot</a></div></div>');
 
if (!this.searchmode) $('#cat_a_lot_selections').append('<br><a id="cat_a_lot_remove"><b>' + this.i18n.removeFromCat + '</b></a>');
$('#cat_a_lot_remove').click(function () {
catALot.remove();
});
$('#cat_a_lot_select_all').click(function () {
catALot.toggleAll(true);
});
$('#cat_a_lot_select_none').click(function () {
catALot.toggleAll(false);
});
$('#cat_a_lot_toggle').click(function () {
$(this).toggleClass('cat_a_lot_enabled');
catALot.run();
});
$('#cat_a_lot_searchcatname')
.keypress(function (e) {
if (e.which == 13)
catALot.updateCats($(this).val());
})
.autocomplete({
source: function(request, response) {
catALot.doAPICall({action:'opensearch', search: request.term, namespace: 14},
function(data){
if(data[1])
response($(data[1]).map(function(index,item){return item.replace(/.*:/, '');}));
}
);
},
open:function(){
$(".ui-autocomplete")
.position({
my: "left bottom",
at: "left top",
of: $('#cat_a_lot_searchcatname')
});
}
});
importStylesheet('MediaWiki:Gadget-Cat-a-lot.css');
this.localCatName = mw.config.get('wgFormattedNamespaces')[14];
},
findAllLabels: function () {
this.labels = $('#mw-pages').find('li');
var subCats = $('#mw-subcategories').find('.CategoryTreeItem');
for (var sub = 0; sub < subCats.length; sub++) {
var a = $(subCats[sub]).find('a');
if (a.length) {
a[0]['title'] = catALot.localCatName + ":" + a[0].innerHTML;
this.labels.push(subCats[sub]);
}
}
$('li a, .CategoryTreeLabel', mw.util.$content).attr({href: '#noSuchAnchor'});
},
 
String.prototype.trim = getMarkedLabels: function () {
var smarked = this [];
this.selectedLabels = this.labels.filter('.cat_a_lot_selected');
while (s.substring(0,1) == ' ') {
this.selectedLabels.each(function () {
s = s.substring(1,s.length);
var file = $(this).find('a[title]');
}
marked.push([file.attr('title'), $(this)]);
while (s.substring(s.length-1,s.length) == ' ') {
});
s = s.substring(0,s.length-1);
return marked;
}
},
return s;
}
 
String.prototype.ucFirst = updateSelectionCounter: function () {
this.selectedLabels = this.labels.filter('.cat_a_lot_selected');
return this.substr(0,1).toUpperCase() + this.substr(1,this.length);
$('#cat_a_lot_mark_counter').show().html(this.selectedLabels.length + this.i18n.filesSelected );
}
},
 
String.prototype.lcFirst = makeClickable: function () {
this.findAllLabels();
return this.substr(0,1).toLowerCase() + this.substr(1,this.length);
this.labels.click(function () {
}
$(this).toggleClass('cat_a_lot_selected');
catALot.updateSelectionCounter();
});
},
 
String.prototype.replaceAll = toggleAll: function ( s , r select) {
this.labels.toggleClass('cat_a_lot_selected', select);
return this.split(s).join(r);
this.updateSelectionCounter();
}
},
 
getSubCats: function (cmcontinue) {
if ( wgNamespaceNumber == 14 ) {
var data = {
// document.addEventListener("DOMContentLoaded", init_cat_a_lot, false);
action: 'query',
addOnloadHook ( init_cat_a_lot ) ;
list: 'categorymembers',
}
cmnamespace: 14,
cmlimit: 50,
cmtitle: this.localCatName + ':' + this.currentCategory
};
if (cmcontinue)
data.cmcontinue = cmcontinue;
else
this.subCats = [];
 
this.doAPICall(data, function (result) {
// Add this to URLs to get around cache issues
function cat_a_lot_dummy_time() {
var t = new Date () ;
return "&dummytime=" + t.getTime() ;
}
 
var cats = result.query.categorymembers;
function init_cat_a_lot () {
var c1_div = document.getElementById("column-one") ;
c1_div.innerHTML += '<div id="cat_a_lot" style="z-index:9999;display:block;background-color:white; width:108px height:145px; position:fixed; bottom:0; right:0;">' +
'<div class="cat_a_lot_data" id="cat_a_lot_data" style="display:none;border:1px solid black">' +
 
for (var i = 0; i < cats.length; i++) {
'<div style="border-bottom:1px solid black">' +
catALot.subCats.push(cats[i].title.replace(/^[^:]+:/, ""));
'<form name="cat_a_lot_searchcat" method="post" onSubmit="return false;">' +
}
'<input type="text" input="8" name="cat_a_lot_searchcatname" />' +
if (result['query-continue'])
'<input type="button" name="cat_a_lot_go" value="Go" onclick="cat_a_lot_search_cat();"/>' +
catALot.getSubCats(result['query-continue'].categorymembers.cmcontinue);
'</form>' +
else {
'</div>' +
catALot.catCounter++;
if (catALot.catCounter == 2) catALot.showCategoryList();
}
});
},
 
'<div class="cat_a_lot_category_list" id="cat_a_lot_category_list" style="border-bottom:1px solid black;max-height:500px;overflow:auto"> </div>' +
'<div class="cat_a_lot_mark_counter" id="cat_a_lot_mark_counter"> </div>' +
'<div class="cat_a_lot_selections" id="cat_a_lot_selections" style="border-top:1px solid black">Select ' +
'<a href="#" onClick="cat_a_lot_mark_all(' + "'2'" + ');">all</a> / ' +
'<a href="#" onClick="cat_a_lot_mark_all(' + "'3'" + ');">none</a>' +
'</div>' +
'<div>' +
'<a href="#" onclick ="cat_a_lot_remove()"><b>Remove from this category</b></a>' +
'</div>' +
'<form name="cat_a_lot_edit" enctype="multipart/form-data" method="post" target="_blank">' +
'<input type="hidden" name="wpTextbox1" />' +
'<input type="hidden" name="wpSummary" />' +
'<input type="hidden" name="wpDiff" value="wpDiff" />' +
'<input type="hidden" name="wpStarttime" />' +
'<input type="hidden" name="wpEdittime" />' +
'</form>' +
'</div>' +
'<div id="cat_a_lot_head" class="pBody">' +
'<form><input id="cat_a_lot_mode" type="checkbox" onchange="run_cat_a_lot();"/><label for="cat_a_lot_mode">Cat-a-lot mode</label></form>' +
'</div></div>' ;
}
 
getParentCats: function () {
function cat_a_lot_get_marked_labels () {
var retdata = new Array () ;{
action: 'query',
var divs = document.getElementsByTagName ( "div" ) ;
prop: 'categories',
for ( i = 0 ; i < divs.length ; i++ ) {
cllimit: 500,
if ( divs[i].className != "gallerytext" ) continue ;
titles: this.localCatName + ':' + this.currentCategory
if ( divs[i].style.backgroundColor == "" ) continue ;
};
var files = divs[i].getElementsByTagName ( "a" ) ;
this.doAPICall(data, function (result) {
ret.push ( files[0].title ) ;
catALot.parentCats = new Array();
}
var pages = result.query.pages;
return ret ;
if (pages[-1] && pages[-1].missing == '') {
}
catALot.catlist.html('<span id="cat_a_lot_no_found">' + catALot.i18n.catNotFound + '</span>');
document.body.style.cursor = 'auto';
 
catALot.catlist.append('<ul></ul>');
function cat_a_lot_update_selection_counter () {
catALot.createCatLinks("→", [catALot.currentCategory]);
var cat_a_lot_mark_counter = document.getElementById("cat_a_lot_mark_counter") ;
return;
var l = cat_a_lot_get_marked_labels () ;
}
cat_a_lot_mark_counter.innerHTML = l.length + " files selected." ;
// 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++) {
catALot.parentCats.push(cats[i].title.replace(/^[^:]+:/, ""));
}
 
catALot.catCounter++;
function cat_a_lot_on_click_label ( title ) {
if (catALot.catCounter == 2) catALot.showCategoryList();
cat_a_lot_alter_label ( title , "onclick" ) ;
});
}
},
regexBuilder: function (category) {
var catname = ( this.localCatName == 'Category' ) ? this.localCatName: this.localCatName + '|Category';
catname = '(' + catname + ')';
 
// Build a regexp string for matching the given category:
function cat_a_lot_invalidate_label ( title , mode ) {
// trim leading/trailing whitespace and underscores
cat_a_lot_alter_label ( title , mode ) ;
category = category.replace(/^[\s_]+/, "").replace(/[\s_]+$/, "");
}
 
// escape regexp metacharacters (= any ASCII punctuation except _)
function cat_a_lot_alter_label ( title , mode ) {
category = category.replace(/([!-\/:-@\[-^`{-~])/g, '\\$1');
var divs = document.getElementsByTagName ( "div" ) ;
for ( i = 0 ; i < divs.length ; i++ ) {
if ( divs[i].className != "gallerytext" ) continue ;
var files = divs[i].getElementsByTagName ( "a" ) ;
if ( files.length == 0 ) continue ;
if ( files[0].title != title ) continue ;
 
// any sequence of spaces and underscores should match any other
if ( mode == "move" ) {
category = category.replace(/[\s_]+/g, '[\\s_]+');
divs[i].innerHTML = "<div style='width:100%;color:white;background-color:red;text-align:center'>Moved to new category</div>" ;
divs[i].style.backgroundColor = "#FF0000" ;
} else if ( mode == "remove" ) {
divs[i].innerHTML = "<div style='width:100%;color:white;background-color:red;text-align:center'>Removed from category</div>" ;
divs[i].style.backgroundColor = "#FF0000" ;
} else if ( mode == "copy" ) {
divs[i].innerHTML += "<br/><b>Copied to new category!</b>" ;
}
 
// Make the first character case-insensitive:
// Clicked on this element
var first = category.substr(0, 1);
if ( divs[i].style.backgroundColor != "" ) {
if (first.toUpperCase() != first.toLowerCase()) category = '[' + first.toUpperCase() + first.toLowerCase() + ']' + category.substr(1);
divs[i].style.backgroundColor = "" ;
} else {
divs[i].style.backgroundColor = cat_a_lot_mark_color ;
}
cat_a_lot_update_selection_counter () ;
return ;
}
}
 
// Compile it into a RegExp that matches MediaWiki category syntax (yeah, it looks ugly):
function cat_a_lot_fix_quotes ( text , quote ) {
// XXX: the first capturing parens are assumed to match the sortkey, if present, including the | but excluding the ]]
return text.split(quote).join("\\"+quote) ;
return new RegExp('\\[\\[[\\s_]*' + catname + '[\\s_]*:[\\s_]*' + category + '[\\s_]*(\\|[^\\]]*(?:\\][^\\]]+)*)?\\]\\]', 'ig');
}
},
 
getContent: function (file, targetcat, mode) {
function cat_a_lot_mark_all ( how ) {
var divs = document.getElementsByTagName ( "div" ) ;
for ( i = 0 ; i < divs.length ; i++ ) {
if ( divs[i].className != "gallerytext" ) continue ;
var files = divs[i].getElementsByTagName ( "a" ) ;
if ( files.length == 0 ) continue ;
 
var data = {
divs[i].style.backgroundColor = "" ; // Deselect
action: 'query',
if ( how == 1 ) { // Activate
prop: 'info|revisions',
eval("divs[i].onclick = function () { cat_a_lot_on_click_label('" + cat_a_lot_fix_quotes ( files[0].title , "'" ) + "'); };") ;
rvprop: 'content|timestamp',
} else if ( how == 2 ) { // Select
intoken: 'edit',
divs[i].style.backgroundColor = cat_a_lot_mark_color ;
titles: file[0]
} else if ( how == 0 ) { // Deactivate
};
divs[i].onclick = "" ;
}
}
cat_a_lot_update_selection_counter () ;
}
 
this.doAPICall(data, function (result) {
function cat_a_lot_get_subcategories () {
catALot.editCategories(result, file, targetcat, mode);
var url = cat_a_lot_query_url + "?what=category&format=xml&cpnamespace=14&cptitle=" + cat_a_lot_current_category + cat_a_lot_dummy_time() ;
});
var xmlreq = new XMLHttpRequest() ;
},
xmlreq.open ( "GET" , url , false ) ;
xmlreq.send ( null ) ;
xml = xmlreq.responseXML ;
var cls = xml.getElementsByTagName('title') ;
var ret = new Array () ;
for ( var i = 0 ; i < cls.length ; i++ ) {
var title = cls[i].firstChild.data ;
title = title.split(":",2)[1] ;
ret.push ( title ) ;
}
return ret ;
}
 
editCategories: function (result, file, targetcat, mode) {
function cat_a_lot_get_parent_categories () {
var url = cat_a_lot_api_url + "?action=query&format=xml&prop=categories&titles=Category:" + cat_a_lot_current_category + cat_a_lot_dummy_time() ;
var xmlreq = new XMLHttpRequest() ;
xmlreq.open ( "GET" , url , false ) ;
xmlreq.send ( null ) ;
xml = xmlreq.responseXML ;
var cls = xml.getElementsByTagName('cl') ;
var ret = new Array () ;
for ( var i = 0 ; i < cls.length ; i++ ) {
var title = cls[i].attributes.getNamedItem("title").value ;
title = title.split(":",2)[1] ;
ret.push ( title ) ;
}
return ret ;
}
 
if (result == null) {
function cat_a_lot_replace_category ( text , sourcecat , targetcat , catname , ending ) {
//Happens on unstable wifi connections..
// alert ( "[[" + catname + ":" + sourcecat + ending + " : " + "[[Category:" + targetcat + ending ) ;
this.connectionError.push(file[0]);
return text.replaceAll ( "[[" + catname + ":" + sourcecat + ending , "[[Category:" + targetcat + ending ) ;
this.updateCounter();
}
return;
}
var pages = result.query.pages;
 
// there should be only one, but we don't know its ID
for (var id in pages) {
// The edittoken only changes between logins
this.edittoken = pages[id].edittoken;
var otext = pages[id].revisions[0]['*'];
var starttimestamp = pages[id].starttimestamp;
var timestamp = pages[id].revisions[0]['timestamp'];
}
 
function cat_a_lot_fix_time ( time ) {
time = time.replace ( /:/g , "" ) ;
time = time.replace ( / /g , "" ) ;
time = time.replace ( /-/g , "" ) ;
time = time.replace ( /Z/g , "" ) ;
time = time.replace ( /T/g , "" ) ;
return time ;
}
 
var sourcecat = wgTitle;
function cat_a_lot_get_article_timestamp ( title ) {
var ret ;
var url = cat_a_lot_query_url + '?format=xml&what=revisions&rvlimit=1&rvcomments&titles=' + title ;
 
// Check if that file is already in that category
var xmlreq = new XMLHttpRequest() ;
if (mode != "remove" && this.regexBuilder(targetcat).test(otext)) {
xmlreq.open ( "GET" , url , false ) ;
//If the new cat is already there, just remove the old one.
xmlreq.send ( null ) ;
if (mode == 'move') {
var xml = xmlreq.responseXML ;
mode='remove';
var rev = xml.getElementsByTagName('rv') ;
} else {
if ( rev.length == 0 ) return cat_a_lot_get_current_utc_timestamp () ;
this.alreadyThere.push(file[0]);
this.updateCounter();
return;
}
}
 
var text = otext;
ret = rev.item(0).getAttribute('timestamp') ;
var comment;
return cat_a_lot_fix_time ( ret ) ;
}
 
// Fix text
function cat_a_lot_remove_category ( text , sourcecat , cat , ending ) {
switch (mode) {
text = " " + text ;
case 'add':
var parts = text.split ( "[[" + cat + ":" + sourcecat + ending ) ;
text += "\n[[" + this.localCatName + ":" + targetcat.replace("رده:","") + "]]\n";
if ( parts.length == 1 ) return text.trim() ; // Not found
text=text.replace("رده:رده:","رده:");
text = parts.shift () ;
comment = this.i18n.summaryAdd + targetcat.replace("رده:","") + "]]";
while ( parts.length > 0 ) {
break;
var s = parts.shift () ;
case 'copy':
if ( ending == "|" ) s = s.split("]]",2).pop () ;
text = text.replace(this.regexBuilder(sourcecat), "[[" + this.localCatName + ":" + sourcecat + "$2]]\n[[" + this.localCatName + ":" + targetcat.replace("رده:","") + "$2]]");
text += s ;
text=text.replace("رده:رده:","رده:");
}
comment = this.i18n.summaryCopy + sourcecat + "]] " + this.i18n.to + targetcat.replace("رده:","") + "]]";
return text.trim() ;
break;
}
case 'move':
text = text.replace(this.regexBuilder(sourcecat), "[[" + this.localCatName + ":" + targetcat.replace("رده:","") + "$2]]");
text=text.replace("رده:رده:","رده:");
comment = this.i18n.summaryMove + sourcecat + "]] " + this.i18n.to + targetcat.replace("رده:","") + "]]";
break;
case 'remove':
text = text.replace(this.regexBuilder(sourcecat), "");
text=text.replace("رده:رده:","رده:");
comment = this.i18n.summaryRemove + sourcecat + "]]";
break;
}
 
if (text == otext) {
function cat_a_lot_edit_move ( filename , targetcat , mode ) {
this.notFound.push(file[0]);
var sourcecat = wgTitle ;
this.updateCounter();
var url = cat_a_lot_edit_url + filename + "&action=raw" + cat_a_lot_dummy_time() ;
return;
var xmlreq = new XMLHttpRequest() ;
}
xmlreq.open ( "GET" , url , false ) ;
xmlreq.send ( null ) ;
var otext = xmlreq.responseText.trim() ;
 
var data = {
// Check if that file is already in that category
action: 'edit',
if ( mode != "remove" ) {
summary: comment,
if ( otext.indexOf ( "ategory:" + targetcat.ucFirst() ) != -1 ||
title: file[0],
otext.indexOf ( "ategory:" + targetcat.lcFirst() ) != -1 ) {
token: this.edittoken,
alert ( filename + " is already in category " + targetcat + " - skipping." ) ;
starttimestamp: starttimestamp,
return ;
basetimestamp: timestamp,
}
text: text
}
};
 
var isBot=$.inArray('bot', wgUserGroups)>-1;
// Fix text
if(isBot)
var text = otext ;
data.bot = '1';
if ( mode == 'copy' ) {
text += "\n[[Category:" + targetcat + "]]\n" ;
} else if ( mode == 'move' ) {
text = cat_a_lot_replace_category ( text , sourcecat.ucFirst() , targetcat , "category" , "]]" ) ;
text = cat_a_lot_replace_category ( text , sourcecat.lcFirst() , targetcat , "category" , "]]" ) ;
text = cat_a_lot_replace_category ( text , sourcecat.ucFirst() , targetcat , "Category" , "]]" ) ;
text = cat_a_lot_replace_category ( text , sourcecat.lcFirst() , targetcat , "Category" , "]]" ) ;
text = cat_a_lot_replace_category ( text , sourcecat.ucFirst() , targetcat , "category" , "|" ) ;
text = cat_a_lot_replace_category ( text , sourcecat.lcFirst() , targetcat , "category" , "|" ) ;
text = cat_a_lot_replace_category ( text , sourcecat.ucFirst() , targetcat , "Category" , "|" ) ;
text = cat_a_lot_replace_category ( text , sourcecat.lcFirst() , targetcat , "Category" , "|" ) ;
} else if ( mode == 'remove' ) {
text = cat_a_lot_remove_category ( text , sourcecat.ucFirst() , "category" , "]]" ) ;
text = cat_a_lot_remove_category ( text , sourcecat.lcFirst() , "category" , "]]" ) ;
text = cat_a_lot_remove_category ( text , sourcecat.ucFirst() , "category" , "|" ) ;
text = cat_a_lot_remove_category ( text , sourcecat.lcFirst() , "category" , "|" ) ;
text = cat_a_lot_remove_category ( text , sourcecat.ucFirst() , "Category" , "]]" ) ;
text = cat_a_lot_remove_category ( text , sourcecat.lcFirst() , "Category" , "]]" ) ;
text = cat_a_lot_remove_category ( text , sourcecat.ucFirst() , "Category" , "|" ) ;
text = cat_a_lot_remove_category ( text , sourcecat.lcFirst() , "Category" , "|" ) ;
}
 
this.doAPICall(data, function (ret) {
if ( text == otext ) {
catALot.updateCounter();
alert ( "Could not find an occurrence of category " + sourcecat + " in description of file " + filename + " - skipping." ) ;
});
return ;
this.markAsDone(file[1], mode, targetcat);
}
},
markAsDone: function (label, mode, targetcat) {
 
label.addClass('cat_a_lot_markAsDone');
var time = new Date () ;
switch (mode) {
var last_version_timestamp = cat_a_lot_get_article_timestamp ( filename ) ;
case 'add':
var starttime = cat_a_lot_get_current_utc_timestamp () ;
label.append('<br>' + this.i18n.addedCat + ' ' + targetcat);
break;
case 'copy':
label.append('<br>' + this.i18n.copiedCat + ' ' + targetcat);
break;
case 'move':
label.append('<br>' + this.i18n.movedCat + ' ' + targetcat);
break;
case 'remove':
label.append('<br>' + this.i18n.movedCat );
break;
}
},
updateCounter: function () {
 
this.counterCurrent++;
var comment ;
if (this.counterCurrent > this.counterNeeded) this.displayResult();
if ( mode == "move" ) comment = "Moving from [[Category:" + sourcecat + "]] to [[Category:" + targetcat + "]]" ;
else this.domCounter.text(this.counterCurrent);
if ( mode == "copy" ) comment = "Copying from [[Category:" + sourcecat + "]] to [[Category:" + targetcat + "]]" ;
},
if ( mode == "remove" ) comment = "Removing from [[Category:" + sourcecat + "]]" ;
url = cat_a_lot_edit_url + filename + "&action=edit" ;
document.cat_a_lot_edit.action = url ;
document.cat_a_lot_edit.wpSummary.value = comment ;
document.cat_a_lot_edit.wpTextbox1.value = text ;
document.cat_a_lot_edit.wpStarttime.value = starttime ;
document.cat_a_lot_edit.wpEdittime.value = last_version_timestamp ;
document.cat_a_lot_edit.submit () ;
 
displayResult: function () {
cat_a_lot_invalidate_label ( filename , mode ) ;
}
 
document.body.style.cursor = 'auto';
// Generates current timestamp
$('.cat_a_lot_feedback').addClass('cat_a_lot_done');
function cat_a_lot_get_current_utc_timestamp () {
$('.ui-dialog-content').height('auto');
var today=new Date() ;
var rep = this.domCounter.parent();
rep.html('<h3>' + this.i18n.done + '</h3>');
rep.append( this.i18n.allDone + '<br />');
 
var close = $('<a>').append( this.i18n.returnToPage );
var y = "00" + today.getUTCFullYear() ;
close.click(function () {
var mo = today.getUTCMonth() + 1 ;
catALot.progressDialog.remove();
var d = "00" + today.getUTCDate() ;
catALot.toggleAll(false);
mo = "00" + mo ;
});
rep.append(close);
if (this.alreadyThere.length) {
rep.append( this.i18n.skippedAlready );
rep.append(this.alreadyThere.join('<br>'));
}
if (this.notFound.length) {
rep.append( this.i18n.skippedNotFound );
rep.append(this.notFound.join('<br>'));
}
if (this.connectionError.length) {
rep.append( this.i18n.skippedServer );
rep.append(this.connectionError.join('<br>'));
}
 
},
var h = "00" + today.getUTCHours() ;
var m = "00" + today.getUTCMinutes() ;
var s = "00" + today.getUTCSeconds() ;
 
moveHere: function (targetcat) {
var ret = "" ;
this.doSomething(targetcat, 'move');
ret += y.substr ( y.length - 4 ) ;
},
ret += mo.substr ( mo.length - 2 ) ;
ret += d.substr ( d.length - 2 ) ;
ret += h.substr ( h.length - 2 ) ;
ret += m.substr ( m.length - 2 ) ;
ret += s.substr ( s.length - 2 ) ;
return ret ;
}
 
copyHere: function (targetcat) {
this.doSomething(targetcat, 'copy');
},
 
addHere: function (targetcat) {
this.doSomething(targetcat, 'add');
},
 
remove: function cat_a_lot_move_here ( targetcat ) {
this.doSomething('', 'remove');
cat_a_lot_do_something ( targetcat , 'move' ) ;
},
 
doSomething: function cat_a_lot_copy_here ( targetcat, mode) {
var files = this.getMarkedLabels();
cat_a_lot_do_something ( targetcat , 'copy' ) ;
if (files.length == 0) {
}
alert( this.i18n.noneSelected );
return;
}
this.notFound = [];
this.alreadyThere = [];
this.connectionError = [];
this.counterCurrent = 1;
this.counterNeeded = files.length;
this.showProgress();
for (var i = 0; i < files.length; i++) {
this.getContent(files[i], targetcat, mode);
}
},
 
doAPICall: function cat_a_lot_remove (params, callback) {
cat_a_lot_do_something ( '' , 'remove' ) ;
}
 
params.format = 'json';
function cat_a_lot_do_something ( targetcat , mode ) {
$.ajax({
var files = cat_a_lot_get_marked_labels () ;
url: this.apiUrl,
if ( files.length == 0 ) {
cache: false,
alert ( "No files selected." ) ;
dataType: 'json',
return ;
data: params,
}
type: 'POST',
for ( var i = 0 ; i < files.length ; i++ ) {
success: callback
cat_a_lot_edit_move ( files[i] , targetcat , mode ) ;
});
}
},
 
createCatLinks: function cat_a_lot_get_cat_links ( symbol , list ) {
list.sort();
var ret = "" ;
var domlist = this.catlist.find('ul');
list.sort () ;
for ( var i = 0 ; i < list.length ; i++ ) {
var li = $('<li></li>');
ret += "<tr style='border:1px solid #AAAAAA'><td>" + symbol + "</td><td>" ;
ret += '<a href="#" onclick ="cat_a_lot_update_cats(\'' + list[i] + '\')">' + list[i] + '</a>' ;
ret += "</td><td>" ;
if ( list[i] != wgTitle ) { // Can't move to source category
ret += '<a href="#" onclick ="cat_a_lot_move_here(\'' + list[i] + '\')"><b>Move</b></a> ' ;
ret += '<a href="#" onclick ="cat_a_lot_copy_here(\'' + list[i] + '\')"><b>Copy</b></a>' ;
}
ret += "</td></tr>" ;
}
return ret ;
}
 
var link = $('<a></a>');
function cat_a_lot_show_category_list () {
link.text(list[i]);
var parcats = cat_a_lot_get_parent_categories () ;
li.data('cat', list[i]);
var subcats = cat_a_lot_get_subcategories () ;
link.click(function () {
var thiscat = new Array () ;
catALot.updateCats($(this).parent().data('cat'));
thiscat.push ( cat_a_lot_current_category ) ;
});
var out = "<table border='0'>" ;
out += cat_a_lot_get_cat_links ( "&uarr;" , parcats ) ;
out += cat_a_lot_get_cat_links ( "&rarr;" , thiscat ) ;
out += cat_a_lot_get_cat_links ( "&darr;" , subcats ) ;
out += "</table>" ;
 
if (this.searchmode) {
catlist = document.getElementById("cat_a_lot_category_list") ;
var add = $('<a class="cat_a_lot_action"><b>' + this.i18n.add + '</b></a>');
catlist.innerHTML = out ;
add.click(function () {
document.body.style.cursor = 'auto' ;
catALot.addHere($(this).parent().data('cat'));
}
});
} else {
var move = $('<a class="cat_a_lot_move"><b>' + this.i18n.move + '</b></a>');
move.click(function () {
catALot.moveHere($(this).parent().data('cat'));
});
 
var copy = $('<a class="cat_a_lot_action"><b>' + this.i18n.copy + '</b></a>');
function cat_a_lot_update_cats ( newcat ) {
copy.click(function () {
document.body.style.cursor = 'wait' ;
catALot.copyHere($(this).parent().data('cat'));
cat_a_lot_current_category = newcat ;
});
catlist = document.getElementById("cat_a_lot_category_list") ;
}
catlist.innerHTML = '<div style="background-color:red;color:white">Loading...</div>' ;
 
window.setTimeout("cat_a_lot_show_category_list()", 0);
// Can't move to source category
}
if (list[i] != wgTitle && this.searchmode) li.append(' ').append(add);
else if (list[i] != wgTitle && !this.searchmode) li.append(' ').append(move).append(' ').append(copy);
li.append(symbol).append(' ').append(link);
 
domlist.append(li);
}
},
 
getCategoryList: function () {
this.catCounter = 0;
this.getParentCats();
this.getSubCats();
},
 
showCategoryList: function () {
var thiscat = [this.currentCategory];
 
this.catlist.empty();
this.catlist.append('<ul></ul>');
 
this.createCatLinks("↑", this.parentCats);
this.createCatLinks("→", thiscat);
this.createCatLinks("↓", this.subCats);
 
document.body.style.cursor = 'auto';
//Reset width
var cat = $('#cat_a_lot');
cat.width('');
cat.height('');
cat.width( cat.width() * 1.05 );
var list = $('#cat_a_lot_category_list');
list.css({maxHeight: this.setHeight+'px', height: ''});
},
 
updateCats: function (newcat) {
document.body.style.cursor = 'wait';
 
this.currentCategory = newcat;
function cat_a_lot_search_cat() {
this.catlist = $('#cat_a_lot_category_list');
var newcat = document.cat_a_lot_searchcat.cat_a_lot_searchcatname.value ;
this.catlist.html('<div class="cat_a_lot_loading">' + this.i18n.loading + '</div>');
cat_a_lot_update_cats ( newcat ) ;
this.getCategoryList();
}
},
showProgress: function () {
document.body.style.cursor = 'wait';
 
this.progressDialog = $('<div></div>')
.html( this.i18n.editing + ' <span id="cat_a_lot_current">' + this.counterCurrent + '</span> ' + this.i18n.of + this.counterNeeded)
.dialog({
width: 450,
height: 90,
minHeight: 90,
modal: true,
resizable: false,
draggable: false,
closeOnEscape: false,
dialogClass: "cat_a_lot_feedback"
});
$('.ui-dialog-titlebar').hide();
this.domCounter = $('#cat_a_lot_current');
 
},
 
run: function () {
if ($('.cat_a_lot_enabled').length) {
this.makeClickable();
$("#cat_a_lot_data").show();
$('#cat_a_lot').resizable({
handles: 'n',
alsoResize: '#cat_a_lot_category_list',
resize: function(event, ui) {
$(this).css({left:"", top:""});
catALot.setHeight = $(this).height();
$('#cat_a_lot_category_list').css({maxHeight: '', width: ''});
}
});
$('#cat_a_lot_category_list').css({maxHeight: '450px'});
if (this.searchmode) this.updateCats("Pictures and images");
else this.updateCats(wgTitle);
 
} else {
$("#cat_a_lot_data").hide();
$("#cat_a_lot").resizable( "destroy" );
//Unbind click handlers
this.labels.unbind('click');
}
},
i18n: (wgUserLanguage == "fa") ? {
loading: 'بارگیری...',
editing: 'ویرایش صفحه',
of: ' ',
skippedAlready: '<h5>صفحهٔ انتخاب شده رها شد، چون صفحه در همان رده قرار دارد.:</h5>',
skippedNotFound: '<h5>صفحهٔ انتخاب شده رها شد چون رده قدیمی پیدا نشد!:</h5>',
skippedServer: '<h5>صفحه‌های انتخاب شده را نمی‌توان تغییر داد چون ارتباط با سرور فعلا برقرار نیست:</h5>',
allDone: 'درخواست برای تمام صفحه‌ها انجام شدند.',
done: 'انجام شد!',
addedCat: 'افزودن رده',
copiedCat: 'کپی به ردهٔ',
movedCat: 'انتقال به ردهٔ',
removedCat: 'حذف از ردهٔ',
returnToPage: 'بازگشت به صفحه',
catNotFound: 'رده یافت نشد.',
 
 
//as in 17 files selected
filesSelected: ' صفحه انتخاب شده.',
 
//Actions
copy: 'کپی',
move: 'انتقال',
add: 'افزودن',
removeFromCat: 'حذف از رده',
enterName: 'نام رده مورد نظر را بنویسید',
select: 'انتخاب',
all: 'همه',
none: 'هیچکدام',
 
noneSelected: 'صفحه‌ای انتخاب نشده‌است!',
 
//Summaries:
summaryAdd: '[[وپ:رده انبوه|رده‌انبوه]]: افزودن [[رده:',
summaryCopy: '[[وپ:رده انبوه|رده‌انبوه]]: کپی از [[رده:',
to: 'به [[رده:',
summaryMove: '[[وپ:رده انبوه|رده‌انبوه]]: انتقال از [[رده:',
summaryRemove: '[[وپ:رده انبوه|رده‌انبوه]]: حذف از [[رده:'
}: {
//Progress
loading: 'Loading...',
editing: 'Editing page',
of: 'of ',
skippedAlready: '<h5>The following pages were skipped, because the page was already in the category:</h5>',
skippedNotFound: '<h5>The following pages were skipped, because the old category could not be found:</h5>',
skippedServer: '<h5>The following pages couldn\'t be changed, since there were problems connecting to the server:</h5>',
allDone: 'All pages are processed.',
done: 'Done!',
addedCat: 'Added category',
copiedCat: 'Copied to category',
movedCat: 'Moved to category',
removedCat: 'Removed from category',
returnToPage: 'Return to page',
catNotFound: 'Category not found.',
 
 
function run_cat_a_lot () {
//as in 17 files selected
cat_a_lot_data = document.getElementById("cat_a_lot_data") ;
filesSelected: ' files selected.',
cat_a_lot_mode = document.getElementById("cat_a_lot_mode").checked ;
 
if ( cat_a_lot_mode == false ) {
//Actions
cat_a_lot_data.style.display = "none" ;
copy: 'Copy',
cat_a_lot_mark_all ( 0 ) ;
move: 'Move',
} else {
add: 'Add',
cat_a_lot_mark_all ( 1 ) ;
removeFromCat: 'Remove from this category',
cat_a_lot_data.style.display = "block" ;
enterName: 'Enter category name',
cat_a_lot_update_cats ( wgTitle ) ;
select: 'Select',
}
all: 'all',
none: 'none',
 
noneSelected: 'No files selected!',
 
//Summaries:
summaryAdd: 'Cat-a-lot: Adding [[Category:',
summaryCopy: 'Cat-a-lot: Copying from [[Category:',
to: 'to [[Category:',
summaryMove: 'Cat-a-lot: Moving from [[Category:',
summaryRemove: 'Cat-a-lot: Removing from [[Category:'
}
};
 
 
if ((wgNamespaceNumber == -1 && wgCanonicalSpecialPageName == "Search") || wgNamespaceNumber == 14) {
if ( wgNamespaceNumber == -1 ) catALot.searchmode = true;
mediaWiki.loader.using(['jquery.ui.dialog', 'jquery.ui.autocomplete'], function () {
$(function () {
catALot.init();
});
});
}
 
// </source>