User:Writ Keeper/Scripts/massRevdel.js: Difference between revisions

Content deleted Content added
up limit to 500, since admins have apihighlmiit
fx
Line 1:
$.when( mw.loader.usinghook( 'mediawiki.api' ), $"wikipage.ready content").thenadd( function()
{
mw.loader.using("mediawiki.api").then(function ()
var apiLimit = 500;
var api = new mw.Api();
if(mw.config.get("wgCanonicalSpecialPageName") == "Contributions")
{
var apiLimit = 500;
$("ul.mw-contributions-list").before("<div style='display:inline-block;' id='revdelCP'>Revision deletion: <input type='button' id='revdelSelectAll' value='Select all'><input type='button' id='revdelSelectNone' value='Select none'>\
var api = new mw.Api();
<span style='white-space:nowrap;'><input type='checkbox' id='revdelContent' name='revdelOptions' value='content'> delete content</span> \
if(mw.config.get("wgCanonicalSpecialPageName") == "Contributions")
<span style='white-space:nowrap;'><input type='checkbox' id='revdelName' name='revdelOptions' value='userName'> delete user name</span> \
<span style='white-space:nowrap;'><input type='checkbox' id='revdelComment' name='revdelOptions' value='editSummary'> delete edit summary</span> \
<span style='white-space:nowrap;'><input type='checkbox' id='undelContent' name='revdelOptions' value='content'> undelete content</span> \
<span style='white-space:nowrap;'><input type='checkbox' id='undelName' name='revdelOptions' value='userName'> undelete user name</span> \
<span style='white-space:nowrap;'><input type='checkbox' id='undelComment' name='revdelOptions' value='editSummary'> undelete edit summary</span> \
<br/><select id='wpRevDeleteReasonList'><option value='other'>Other reason</option></select><input name='wpReason' size='60' id='wpReason' maxlength='100'>\
<input type='button' class='revdelSubmit' id='revdelSubmit' value='Revdel selected entries'> <input type='button' class='revdelSubmit' id='oversightSubmit' value='Oversight selected entries'></div>");
$("ul.mw-contributions-list .mw-revdelundel-link").each(function(ind,el){
var revId = /ids=(\d+)/.exec($(this).children("a").attr("href"))[1];
var pageTitle = /target=([^&]+)/.exec($(this).children("a").attr("href"))[1];
el.innerHTML = "<input type='checkbox' name='"+decodeURIComponent(pageTitle)+"' class='revdelIds' value='"+revId+"'>";
});
$("ul.mw-contributions-list").after("</form>");
//load canned summaries
$.get("/w/index.php?title=MediaWiki:Revdelete-reason-dropdown&action=raw",function(data)
{
$("ul.mw-contributions-list").before("<div style='display:inline-block;' id='revdelCP'>Revision deletion: <input type='button' id='revdelSelectAll' value='Select all'><input type='button' id='revdelSelectNone' value='Select none'>\
reasons = data.replace(/\*\* ([^\*]+)/g, '<option value="$1">$1</option>');
<span style='white-space:nowrap;'><input type='checkbox' id='revdelContent' name='revdelOptions' value='content'> delete content</span> \
reasons = reasons.replace(/\* ([^<]+)([^\*]+)/g, '<optgroup label="$1">$2</optgroup>');
<span style='white-space:nowrap;'><input type='checkbox' id='revdelName' name='revdelOptions' value='userName'> delete user name</span> \
$('#wpRevDeleteReasonList').append(reasons);
<span style='white-space:nowrap;'><input type='checkbox' id='revdelComment' name='revdelOptions' value='editSummary'> delete edit summary</span> \
});
<span style='white-space:nowrap;'><input type='checkbox' id='undelContent' name='revdelOptions' value='content'> undelete content</span> \
<span style='white-space:nowrap;'><input type='checkbox' id='undelName' name='revdelOptions' value='userName'> undelete user name</span> \
//attach handlers
<span style='white-space:nowrap;'><input type='checkbox' id='undelComment' name='revdelOptions' value='editSummary'> undelete edit summary</span> \
$("#revdelSelectAll").click(
<br/><select id='wpRevDeleteReasonList'><option value='other'>Other reason</option></select><input name='wpReason' size='60' id='wpReason' maxlength='100'>\
function()
<input type='button' class='revdelSubmit' id='revdelSubmit' value='Revdel selected entries'> <input type='button' class='revdelSubmit' id='oversightSubmit' value='Oversight selected entries'></div>");
$("ul.mw-contributions-list .mw-revdelundel-link").each(function(ind,el){
var revId = /ids=(\d+)/.exec($(this).children("a").attr("href"))[1];
var pageTitle = /target=([^&]+)/.exec($(this).children("a").attr("href"))[1];
el.innerHTML = "<input type='checkbox' name='"+decodeURIComponent(pageTitle)+"' class='revdelIds' value='"+revId+"'>";
});
$("ul.mw-contributions-list").after("</form>");
//load canned summaries
$.get("/w/index.php?title=MediaWiki:Revdelete-reason-dropdown&action=raw",function(data)
{
reasons = data.replace(/\*\* ([^\*]+)/g, '<option value="$1">$1</option>');
$('input.revdelIds').each(function()
reasons = reasons.replace(/\* ([^<]+)([^\*]+)/g, '<optgroup label="$1">$2</optgroup>');
$('#wpRevDeleteReasonList').append(reasons);
});
//attach handlers
$("#revdelSelectAll").click(
function()
{
$('input.revdelIds').each(function()
$(this).prop("checked", true);
}) {
$(this).prop("checked", true);
}
});
}
$("#revdelSelectNone").click(
function();
$("#revdelSelectNone").click(
{
$('input.revdelIds').each(function()
{
$('input.revdelIds').each(function()
$(this).prop("checked", false);
}) {
$(this).prop("checked", false);
}
});
}
$("#revdelSubmit").click(
function();
$("#revdelSubmit").click(
{
function()
//figure out which revisions and pages we're working on.
var revCount = 0;
var numTitles = 0;
var pageTitles = {};
$("input.revdelIds:checked").each(function(ind)
{
//figure out which revisions and pages we're working on.
revCount = ind + 1;
if(indvar >revCount apiLimit= - 1)0;
var numTitles = 0;
var pageTitles = {};
$("input.revdelIds:checked").each(function(ind)
{
revCount = ind + 1;
alert("You can't do more than " + apiLimit + " revdels at once! Canceling...");
if(ind > apiLimit - 1)
{
alert("You can't do more than " + apiLimit + " revdels at once! Canceling...");
return false;
}
if(typeof pageTitles[$(this).attr("name")] == "undefined")
{
pageTitles[$(this).attr("name")] = $(this).val();
numTitles++;
}
else
{
pageTitles[$(this).attr("name")] = pageTitles[$(this).attr("name")] + "|" + $(this).val();
}
});
if(numTitles == 0)
{
alert("You didn't select any revisions to delete!");
return false;
}
var confirmString = "You are attempting to modify " + revCount + " revisions.\n\nThe following revision attributes will be changed:\n";
if(typeof pageTitles[$(this).attr("name")] == "undefined")
//figure out what we're doing to each revision. This is pretty clunky, but whatever.
var deleteString = "";
var revealString = "";
var typeString = "revdel";
if($("#revdelContent").prop("checked") == $("#undelContent").prop("checked"))
{
confirmString = confirmString + "-Content visibility won't change.\n";
pageTitles[$(this).attr("name")] = $(this).val();
numTitles++;
}
else if($("#revdelContent").prop("checked"))
else
{
deleteString = "content";
pageTitles[$(this).attr("name")] = pageTitles[$(this).attr("name")] + "|" + $(this).val();
confirmString = confirmString + "-Content will be deleted.\n";
}
}); else
if(numTitles == 0)
{
alert("You didn't select any revisions to delete!");
return false;
}
var confirmString = "You are attempting to modify " + revCount + " revisions.\n\nThe following revision attributes will be changed:\n";
//figure out what we're doing to each revision. This is pretty clunky, but whatever.
var deleteString = "";
var revealString = "";
var typeString = "revdel";
if($("#revdelContent").prop("checked") == $("#undelContent").prop("checked"))
{
confirmString = confirmString + "-Content visibility won't change.\n";
}
else if($("#revdelContent").prop("checked"))
{
deleteString = "content";
confirmString = confirmString + "-Content will be deleted.\n";
}
else
{
revealString = "content";
confirmString = confirmString + "-Content will be revealed.\n";
}
if($("#revdelComment").prop("checked") == $("#undelComment").prop("checked"))
{
confirmString = confirmString + "-Edit summary visibility won't change.\n";
}
else if($("#revdelComment").prop("checked"))
{
if(deleteString != "")
{
deleteStringrevealString = deleteString + "|content";
confirmString = confirmString + "-Content will be revealed.\n";
}
if($("#revdelComment").prop("checked") == $("#undelComment").prop("checked"))
deleteString = deleteString + "comment";
confirmString = confirmString + "-Edit summary will be deleted.\n";
}
else
{
if(revealString != "")
{
confirmString = confirmString + "-Edit summary visibility won't change.\n";
revealString = revealString + "|";
}
else if($("#revdelComment").prop("checked"))
revealString = revealString + "comment";
confirmString = confirmString + "-Edit summary will be revealed.\n";
}
if($("#revdelName").prop("checked") == $("#undelName").prop("checked"))
{
confirmString = confirmString + "-User name visibility won't change.\n";
}
else if($("#revdelName").prop("checked"))
{
if(deleteString != "")
{
if(deleteString != deleteString + "|";)
{
deleteString = deleteString + "|";
}
deleteString = deleteString + "comment";
confirmString = confirmString + "-Edit summary will be deleted.\n";
}
else
deleteString = deleteString + "user";
confirmString = confirmString + "-User name will be deleted.\n";
}
else
{
if(revealString != "")
{
if(revealString != revealString + "|";)
{
revealString = revealString + "|";
}
revealString = revealString + "comment";
confirmString = confirmString + "-Edit summary will be revealed.\n";
}
if($("#revdelName").prop("checked") == $("#undelName").prop("checked"))
revealString = revealString + "user";
confirmString = confirmString + "-User name will be revealed.\n";
}
if(deleteString == "" && revealString == "")
{
alert("You didn't select any properties of the revisions to change!");
return false;
}
var summary = "";
//construct the revdel summary
if($("#wpRevDeleteReasonList").val() == "other")
{
if($("#wpReason").val() == "")
{
confirmString = confirmString + "-User name visibility won't change.\n";
alert("You didn't select or write in an edit summary for the logs!");
return false;
}
summary =else if($("#wpReasonrevdelName").valprop("checked"));
}
else
{
summary = $("#wpRevDeleteReasonList").val();
if($("#wpReason").val() != "")
{
summary = summary + ": " + $("#wpReason").val();
}
}
confirmString = confirmString + "\nYour revdel summary is: "+ summary +"\n\nAre you sure you want to do this?";
if(confirm(confirmString))
{
var numCompleted = 0;
for (title in pageTitles)
{
var ajaxData;
ajaxData = {action:"revisiondelete",type:"revision",ids:pageTitles[title],reason:summary};
if(deleteString != "")
{
ajaxData.hidedeleteString = deleteString + "|";
}
deleteString = deleteString + "user";
confirmString = confirmString + "-User name will be deleted.\n";
}
else
{
if(revealString != "")
{
ajaxData.showrevealString = revealString + "|";
}
revealString = revealString + "user";
api.postWithToken('csrf', ajaxData).done(function()
confirmString = confirmString + "-User name will be revealed.\n";
{
numCompleted++;
if(numCompleted == numTitles)
{
alert("modified " + revCount + " revision(s) successfully!");
return false;
}
});
}
if(deleteString == "" && revealString == "")
}
return false;
}
)
$("#oversightSubmit").click(
function()
{
//figure out which revisions and pages we're working on.
var revCount = 0;
var numTitles = 0;
var pageTitles = {};
$("input.revdelIds:checked").each(function(ind)
{
revCount = ind + 1;
if(ind > apiLimit - 1)
{
alert("You candidn't doselect moreany thanproperties "of +the apiLimitrevisions +to " revdels at oncechange! Canceling...");
return false;
}
if(typeof pageTitles[$(this).attr("name")] == "undefined")
var summary = "";
//construct the revdel summary
if($("#wpRevDeleteReasonList").val() == "other")
{
pageTitles[if($(this"#wpReason").attrval("name")] == $(this).val("");
numTitles++;{
alert("You didn't select or write in an edit summary for the logs!");
return false;
}
summary = $("#wpReason").val();
}
else
{
summary = $("#wpRevDeleteReasonList").val();
pageTitles[$(this).attr("name")] = pageTitles[$(this).attr("name")] + "|" + $(this).val();
if($("#wpReason").val() != "")
{
summary = summary + ": " + $("#wpReason").val();
}
}
confirmString = confirmString + "\nYour revdel summary is: "+ summary +"\n\nAre you sure you want to do this?";
});
if(numTitles == 0)
if(confirm(confirmString))
{
alert("You didn't select any revisions to delete!");
return false;
}
var confirmString = "You are attempting to modify " + revCount + " revisions.\n\nThe following revision attributes will be changed:\n";
//figure out what we're doing to each revision. This is pretty clunky, but whatever.
var deleteString = "";
var oversighting = -1;
if($("#revdelContent").prop("checked") == $("#undelContent").prop("checked"))
{
confirmString = confirmString + "-Content visibility won't change.\n";
}
else if($("#revdelContent").prop("checked"))
{
deleteString = "content";
confirmString = confirmString + "-Content will be oversighted.\n";
oversighting = 1;
}
else
{
if(oversighting == 1)
{
var numCompleted = 0;
alert("we can't oversight and un-oversight edits at the same time!");
returnfor false;(title in pageTitles)
{
var ajaxData;
ajaxData = {action:"revisiondelete",type:"revision",ids:pageTitles[title],reason:summary};
if(deleteString != "")
{
ajaxData.hide=deleteString;
}
if(revealString != "")
{
ajaxData.show=revealString;
}
api.postWithToken('csrf', ajaxData).done(function()
{
numCompleted++;
if(numCompleted == numTitles)
{
alert("modified " + revCount + " revision(s) successfully!");
return false;
}
});
}
}
deleteStringreturn = "content"false;
confirmString = confirmString + "-Content will be returned to normal (admin-only) revision deletion.\n";
oversighting = 0;
}
if($("#revdelComment").prop("checked") == $("#undelComment").prop("checked"))
{
confirmString = confirmString + "-Edit summary visibility won't change.\n";
}
)
else if($("#revdelComment").prop("checked"))
$("#oversightSubmit").click(
function()
{
//figure out which revisions and pages we're working on.
if(oversighting == 0)
var revCount = 0;
var numTitles = 0;
var pageTitles = {};
$("input.revdelIds:checked").each(function(ind)
{
revCount = ind + 1;
alert("we can't oversight and un-oversight edits at the same time!");
if(ind > apiLimit - 1)
{
alert("You can't do more than " + apiLimit + " revdels at once! Canceling...");
return false;
}
if(typeof pageTitles[$(this).attr("name")] == "undefined")
{
pageTitles[$(this).attr("name")] = $(this).val();
numTitles++;
}
else
{
pageTitles[$(this).attr("name")] = pageTitles[$(this).attr("name")] + "|" + $(this).val();
}
});
if(numTitles == 0)
{
alert("You didn't select any revisions to delete!");
return false;
}
var confirmString = "You are attempting to modify " + revCount + " revisions.\n\nThe following revision attributes will be changed:\n";
if(deleteString != "")
//figure out what we're doing to each revision. This is pretty clunky, but whatever.
var deleteString = "";
var oversighting = -1;
if($("#revdelContent").prop("checked") == $("#undelContent").prop("checked"))
{
confirmString = confirmString + "-Content visibility won't change.\n";
deleteString = deleteString + "|";
}
else if($("#revdelContent").prop("checked"))
deleteString = deleteString + "comment";
confirmString = confirmString + "-Edit summary will be oversighted.\n";
oversighting = 1;
}
else
{
if(oversighting == 1)
{
deleteString = "content";
alert("we can't oversight and un-oversight edits at the same time!");
confirmString = confirmString + "-Content will be oversighted.\n";
return false;
oversighting = 1;
}
else
if(deleteString != "")
{
deleteStringif(oversighting == deleteString + "|";1)
{
alert("we can't oversight and un-oversight edits at the same time!");
return false;
}
deleteString = "content";
confirmString = confirmString + "-Content will be returned to normal (admin-only) revision deletion.\n";
oversighting = 0;
}
if($("#revdelComment").prop("checked") == $("#undelComment").prop("checked"))
deleteString = deleteString + "comment";
confirmString = confirmString + "-Edit summary will be returned to normal (admin-only) revision deletion.\n";
oversighting = 0;
}
if($("#revdelName").prop("checked") == $("#undelName").prop("checked"))
{
confirmString = confirmString + "-User name visibility won't change.\n";
}
else if($("#revdelName").prop("checked"))
{
if(oversighting == 0)
{
confirmString = confirmString + "-Edit summary visibility won't change.\n";
alert("we can't oversight and un-oversight edits at the same time!");
return false;
}
else if(deleteString != $("#revdelComment").prop("checked"))
{
deleteStringif(oversighting == deleteString + "|";0)
{
alert("we can't oversight and un-oversight edits at the same time!");
return false;
}
if(deleteString != "")
{
deleteString = deleteString + "|";
}
deleteString = deleteString + "comment";
confirmString = confirmString + "-Edit summary will be oversighted.\n";
oversighting = 1;
}
else
deleteString = deleteString + "user";
confirmString = confirmString + "-User name will be oversighted.\n";
oversighting = 1;
}
else
{
if(oversighting == 1)
{
if(oversighting == 1)
{
alert("we can't oversight and un-oversight edits at the same time!");
return false;
}
if(deleteString != "")
{
deleteString = deleteString + "|";
}
deleteString = deleteString + "comment";
confirmString = confirmString + "-Edit summary will be returned to normal (admin-only) revision deletion.\n";
oversighting = 0;
}
if($("#revdelName").prop("checked") == $("#undelName").prop("checked"))
if(deleteString != "")
{
confirmString = confirmString + "-User name visibility won't change.\n";
deleteString = deleteString + "|";
}
else if($("#revdelName").prop("checked"))
deleteString = deleteString + "user";
confirmString = confirmString + "-User name will be returned to normal (admin-only) revision deletion.\n";
oversighting = 0;
}
if(deleteString == "")
{
alert("You didn't select any properties of the revisions to change!");
return false;
}
var summary = "";
//construct the revdel summary
if($("#wpRevDeleteReasonList").val() == "other")
{
if($("#wpReason").val() == "")
{
if(oversighting == 0)
alert("You didn't select or write in an edit summary for the logs!");
return false;{
alert("we can't oversight and un-oversight edits at the same time!");
return false;
}
if(deleteString != "")
{
deleteString = deleteString + "|";
}
deleteString = deleteString + "user";
confirmString = confirmString + "-User name will be oversighted.\n";
oversighting = 1;
}
else
summary = $("#wpReason").val();
}
else
{
summary = $("#wpRevDeleteReasonList").val();
if($("#wpReason").val() != "")
{
summary = summary + ": " + $("#wpReason").val();
}
}
confirmString = confirmString + "\nYour oversight summary is: "+ summary +"\n\nAre you sure you want to do this?";
if(confirm(confirmString))
{
var numCompleted = 0;
for (title in pageTitles)
{
var ajaxData;
ajaxData = {action:"revisiondelete",type:"revision",ids:pageTitles[title],reason:summary,hide:deleteString};
if(oversighting == 1)
{
alert("we can't oversight and un-oversight edits at the same time!");
ajaxData.suppress = "yes";
return false;
}
else if(oversightingdeleteString =!= 0"")
{
ajaxData.suppressdeleteString = deleteString + "no|";
}
deleteString = deleteString + "user";
else
confirmString = confirmString + "-User name will be returned to normal (admin-only) revision deletion.\n";
oversighting = 0;
}
if(deleteString == "")
{
alert("You didn't select any properties of the revisions to change!");
return false;
}
var summary = "";
//construct the revdel summary
if($("#wpRevDeleteReasonList").val() == "other")
{
if($("#wpReason").val() == "")
{
alert("SomethingYou wentdidn't wrong,select soor we'rewrite in goingan toedit abortsummary withoutfor doingthe anything.logs!");
return false;
}
summary = $("#wpReason").val();
api.postWithToken('csrf', ajaxData).done(function()
}
else
{
summary = $("#wpRevDeleteReasonList").val();
if($("#wpReason").val() != "")
{
summary = summary + ": " + $("#wpReason").val();
}
}
confirmString = confirmString + "\nYour oversight summary is: "+ summary +"\n\nAre you sure you want to do this?";
if(confirm(confirmString))
{
var numCompleted = 0;
for (title in pageTitles)
{
numCompleted++var ajaxData;
ajaxData = {action:"revisiondelete",type:"revision",ids:pageTitles[title],reason:summary,hide:deleteString};
if(numCompleted == numTitles)
if(oversighting == 1)
{
ajaxData.suppress = "yes";
alert("modified " + revCount + " revision(s) successfully!");
return false;
}
} else if(oversighting == 0);
{
ajaxData.suppress = "no";
}
else
{
alert("Something went wrong, so we're going to abort without doing anything.");
}
api.postWithToken('csrf', ajaxData).done(function()
{
numCompleted++;
if(numCompleted == numTitles)
{
alert("modified " + revCount + " revision(s) successfully!");
return false;
}
});
}
}
return false;
}
)
return false;
}
});
}
});