m (Wikia moved page AjaxBatchDelete/code.2.js to MediaWiki:AjaxBatchDelete/code.2.js without leaving a redirect) |
No edit summary Tag: sourceedit |
||
(One intermediate revision by one other user not shown) | |||
Line 17: | Line 17: | ||
var ug = mw.config.get("wgUserGroups").join(' '); |
var ug = mw.config.get("wgUserGroups").join(' '); |
||
− | if (ug.indexOf('sysop') + ug.indexOf('vstf') + ug.indexOf('staff') + ug.indexOf('helper') > - |
+ | if (ug.indexOf('sysop') + ug.indexOf('vstf') + ug.indexOf('staff') + ug.indexOf('helper') + ug.indexOf('content-moderator') > -5) { |
var FormHTML = '\ |
var FormHTML = '\ |
Revision as of 01:32, 8 February 2016
//<syntaxhighlight lang="javascript">
/*
* Ajax Batch Delete V2
* @description Delete listed multiple pages
* Based on and faster than the original
* http://dev.wikia.com/wiki/AjaxBatchDelete
* Does not need to go to Special:BlankPage to use
* Includes the option to protect after deleting
* Includes the option to grab a whole category's contents
* @author Ozuzanna
*/
;(function($, mw) {
if ($('#t-bd').length)
return;
var ug = mw.config.get("wgUserGroups").join(' ');
if (ug.indexOf('sysop') + ug.indexOf('vstf') + ug.indexOf('staff') + ug.indexOf('helper') + ug.indexOf('content-moderator') > -5) {
var FormHTML = '\
<form method="" name="" class="WikiaForm "> \
<fieldset> \
<p>Reason for deleting: \
<input type="text" id="delete-reason" value="" /> \
<br/> \
<label for="protect-check">Protect for admin only? <input type="checkbox" id="protect-check" /></label> \
</p> \
<p>Put the name of each page you want to delete on a <b>separate line</b>.</p> \
<textarea style="resize: none; height: 20em; width: 100%;" id="text-mass-delete"/> \
<p>Any errors encountered will appear below:</p>\
<table id="text-error-output" style="resize: none; height:10em; width: 100%; color:black; background-color: #ffbfbf; height: 150px; font-weight: bold"></table> \
</fieldset> \
</form>',
token = mw.user.tokens.get('editToken'),
delay = window.batchDeleteDelay || 1000;
//Support for Monobook
if (mw.config.get('skin') === 'monobook') {
mw.util.addPortletLink('p-tb', '#', 'Batch Delete', 't-bd');
}
else {
$('#my-tools-menu').prepend('<li class="custom"><a style="cursor:pointer" id="t-bd">Batch Delete</a></li>');
}
$('#t-bd').click(function () {
$.showCustomModal('Ajax Batch Delete', FormHTML, {
id: 'form-mass-delete',
width: 500,
buttons: [{
message: 'Cancel',
handler: function() {
$('#form-mass-delete').closeModal();
}
}, {
message: 'Add category contents',
defaultButton: true,
handler: function() {
addCategoryContents();
}
}, {
id: 'startButton',
message: 'Initiate',
defaultButton: true,
handler: function () {
init();
}
}]
});
});
function init() {
var txt = document.getElementById('text-mass-delete'),
deleteReason = document.getElementById('delete-reason').value,
pages = txt.value.split('\n'),
currentPage = pages[0];
if (!deleteReason) {
alert('Please state a reason!');
return;
}
document.getElementById('startButton').setAttribute('disabled','disabled');
if (!currentPage) {
document.getElementById('startButton').removeAttribute("disabled");
$.showCustomModal('Finished!', 'Nothing left to do, or next line is blank.', {
id: 'mass-delete-complete',
width: 200,
buttons: [{
message: 'Close',
defaultButton: true,
handler: function() {
$('#mass-delete-complete').closeModal();
}
}]
});
}
else {
process(currentPage,deleteReason);
}
pages = pages.slice(1,pages.length);
txt.value = pages.join('\n');
}
function addCategoryContents() {
var category = prompt('Please enter the category name (no category prefix):');
new mw.Api().get({
action: 'query',
list: 'categorymembers',
cmtitle: "Category:"+category,
cmlimit: 5000
})
.done(function(d) {
if (!d.error) {
var data = d.query;
for (var i in data.categorymembers) {
$('#text-mass-delete').append(data.categorymembers[i].title+'\n');
}
}
else {
$('#text-error-output').append('<tr><td>Failed to get contents of '+ category +' : '+ d.error.code +'</tr></td>');
}
})
.fail(function() {
$('#text-error-output').append('<tr><td>Failed to get contents of '+ category +'</tr></td>');
});
}
function process(page,reason) {
new mw.Api().post({
format: 'json',
action: 'delete',
watchlist: 'nochange',
title: page,
reason: reason,
token: token
})
.done(function(d) {
if (!d.error) {
console.log('Deletion of '+page+' successful!');
if (document.getElementById('protect-check').checked) {
new mw.Api().post({
format: 'json',
action: 'protect',
expiry: 'infinite',
protections: 'create=sysop',
watchlist: 'nochange',
title: page,
reason: reason,
token: token
})
.done(function(d) {
if (!d.error) {
console.log('Protection of '+page+' successful!');
}
else {
console.log('Failed to protect '+page+': '+ d.error.code);
$('#text-error-output').append('Failed to protect '+page+': '+d.error.code+'<br/>');
}
})
.fail(function() {
console.log('Failed to protect '+page+': unknownerror');
$('#text-error-output').append('Failed to protect '+page+': unknownerror<br/>');
});
}
}
else {
console.log('Failed to delete '+page+': '+ d.error.code);
$('#text-error-output').append('Failed to delete '+page+': '+d.error.code+'<br/>');
}
})
.fail(function() {
console.log('Failed to delete '+page+': unknownerror');
$('#text-error-output').append('Failed to delete '+page+': unknownerror<br/>');
});
setTimeout(init,delay);
}
}
}) (this.jQuery, this.mediaWiki);
//</syntaxhighlight>