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

Content deleted Content added
try that
swap for document.ready
 
(29 intermediate revisions by 4 users not shown)
Line 1:
$(document).ready( function()
{
mw.loader.using(["mediawiki.api"]).then(function ()
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
$.post("/w/index.php?title=MediaWiki:Revdelete-reason-dropdown&action=raw",function(data)
{
wkContribsCheckboxInit = true;
reasons = data.replace(/\*\* ([^\*]+)/g, '<option value="$1">$1</option>');
$("ul.mw-contributions-list:first").before("<div style='display:inline-block;' id='revdelCP'><span id='revdelLabel' style='cursor:pointer;'>Revision deletion\
reasons = reasons.replace(/\* ([^<]+)([^\*]+)/g, '<optgroup label="$1">$2</optgroup>');
<img id='revdelLabelImg' src='/w/load.php?modules=oojs-ui.styles.icons-movement&image=expand&format=rasterized&lang=en' style='width:12px; transform:rotate(270deg);'/></span>\
$('#wpRevDeleteReasonList').append(reasons);
<span id='revdelCPBody' style='display:none;'><input type='button' id='revdelSelectAll' value='Select all'><input type='button' id='revdelSelectNone' value='Select none'>\
});
<input type='button' id='revdelSelectInv' value='Invert selection'>\
<span style='white-space:nowrap;'><input type='checkbox' id='revdelContent' name='revdelOptions' value='content'> delete content</span> \
//attach handlers
<span style='white-space:nowrap;'><input type='checkbox' id='revdelName' name='revdelOptions' value='userName'> delete user name</span> \
$("#revdelSelectAll").click(
<span style='white-space:nowrap;'><input type='checkbox' id='revdelComment' name='revdelOptions' value='editSummary'> delete edit summary</span> \
function()
<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> \
$('input.revdelIds').each(function()
<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'></span></div>");
$("ul.mw-contributions-list .mw-revdelundel-link").each(function(ind,el){
if($(this).children("a").length > 0)
{
var revId = /ids=(\d+)/.exec($(this).propchildren("checkeda", true).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+"'>";
}
$(el).children(".revdelIds").data("index", ind);
);
}
$("#revdelSelectNone").click(
function(});
$("ul.mw-contributions-list").after("</form>");
$("#revdelCP").data("revdelToolbarShowing", false);
$("#revdelCP").data("lastSelectedIndex", -1);
 
//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);
$(this).prop("checked", false);
}).done(function()
}
);
$("#revdelSubmit").click(
function()
{
$.get("/w/index.php?title=MediaWiki:Revdelete-reason-dropdown-suppress&action=raw", function(data)
//figure out which revisions and pages we're working on.
var revCount = 0;
var numTitles = 0;
var pageTitles = {};
$("input.revdelIds:checked").each(function(ind)
{
reasons = data.replace(/\*\* ([^\*]+)/g, '<option value="$1">$1</option>');
revCount = ind + 1;
reasons = reasons.replace(/\* ([^<]+)([^\*]+)/g, '<optgroup label="$1">$2</optgroup>');
if(ind > 49)
$('#wpRevDeleteReasonList').append(reasons);
});
});
//attach handlers
$("#revdelLabel").click(
function()
{
if($("#revdelCP").data("revdelToolbarShowing"))
{
$("#revdelCP").data("revdelToolbarShowing", false);
alert("You can't do more than 50 revdels at once! Canceling...");
$("#revdelLabelImg").css("transform","rotate(270deg)");
return false;
$("#revdelCPBody").fadeOut();
}
if(typeof pageTitles[$(this).attr("name")] == "undefined")
{
pageTitles[$(this).attr("name")] = $(this).val();
numTitles++;
}
else
{
$("#revdelCP").data("revdelToolbarShowing", true);
pageTitles[$(this).attr("name")] = pageTitles[$(this).attr("name")] + "|" + $(this).val();
$("#revdelLabelImg").css("transform","none");
$("#revdelCPBody").fadeIn();
}
});
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";
$("#revdelSelectAll").click(
function()
//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"))
{
$('input.revdelIds').each(function()
confirmString = confirmString + "-Content visibility won't change.\n";
{
$(this).prop("checked", true);
});
$("#revdelCP").data("lastSelectedIndex", -1);
}
);
else if($("#revdelContent").prop("checked"))
$("#revdelSelectNone").click(
function()
{
$('input.revdelIds').each(function()
deleteString = "content";
{
confirmString = confirmString + "-Content will be deleted.\n";
$(this).prop("checked", false);
});
$("#revdelCP").data("lastSelectedIndex", -1);
}
else);
 
$("#revdelSelectInv").click(
function()
{
$('input.revdelIds').each(function()
revealString = "content";
{
confirmString = confirmString + "-Content will be revealed.\n";
$(this).prop("checked", !($(this).prop("checked")));
});
$("#revdelCP").data("lastSelectedIndex", -1);
}
);
if($("#revdelComment").prop("checked") == $("#undelComment").prop("checked"))
$("input.revdelIds").off("click").click(
function(ev)
{
var lastSelectedRevdel = $("#revdelCP").data("lastSelectedIndex");
confirmString = confirmString + "-Edit summary visibility won't change.\n";
var newIndex = $(this).data("index")
}
if(ev.shiftKey && lastSelectedRevdel >= 0)
else if($("#revdelComment").prop("checked"))
{
if(deleteString != "")
{
var checkboxArray = $("input.revdelIds");
deleteString = deleteString + "|";
var start = lastSelectedRevdel;
var stop = newIndex;
if(start < stop)
{
for(var i = start; i < stop; i++)
{
if(i != lastSelectedRevdel)
{
$(checkboxArray[i]).prop("checked", !($(checkboxArray[i]).prop("checked")));
}
}
}
else
{
for(var i = start; i > stop; i--)
{
if(i != lastSelectedRevdel)
{
$(checkboxArray[i]).prop("checked", !($(checkboxArray[i]).prop("checked")));
}
}
}
}
$("#revdelCP").data("lastSelectedIndex", newIndex);
deleteString = deleteString + "comment";
confirmString = confirmString + "-Edit summary will be deleted.\n";
}
else);
$("#revdelSubmit").click(
function()
{
//figure out which revisions and pages we're working on.
if(revealString != "")
var revCount = 0;
var numTitles = 0;
var pageTitles = {};
$("input.revdelIds:checked").each(function(ind)
{
revealStringrevCount = revealStringind + "|"1;
if(ind > apiLimit - 1)
{
mw.notify("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)
{
mw.notify("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";
revealString = revealString + "comment";
confirmString = confirmString + "-Edit summary will be revealed.\n";
//figure out what we're doing to each revision. This is pretty clunky, but whatever.
}
var deleteString = "";
if($("#revdelName").prop("checked") == $("#undelName").prop("checked"))
var revealString = "";
{
var typeString = "revdel";
confirmString = confirmString + "-User name visibility won't change.\n";
}
else if($("#revdelNamerevdelContent").prop("checked") == $("#undelContent").prop("checked"))
{
if(deleteString != "")
{
confirmString = confirmString + "-Content visibility won't change.\n";
deleteString = deleteString + "|";
}
else if($("#revdelContent").prop("checked"))
deleteString = deleteString + "user";
confirmString = confirmString + "-User name will be deleted.\n";
}
else
{
if(revealString != "")
{
revealStringdeleteString = revealString + "|content";
confirmString = confirmString + "-Content will be deleted.\n";
}
else
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() == "")
{
revealString = "content";
alert("You didn't select or write in an edit summary for the logs!");
confirmString = confirmString + "-Content will be revealed.\n";
return false;
}
summaryif($("#revdelComment").prop("checked") == $("#wpReasonundelComment").valprop("checked"));
}
else
{
summary = $("#wpRevDeleteReasonList").val();
if($("#wpReason").val() != "")
{
confirmString = confirmString + "-Edit summary visibility won't change.\n";
summary = summary + ": " + $("#wpReason").val();
}
else if($("#revdelComment").prop("checked"))
}
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,token: mw.user.tokens.get( 'editToken' )};
if(deleteString != "")
{
ajaxData.hidedeleteString = deleteString + "|";
}
deleteString = deleteString + "comment";
confirmString = confirmString + "-Edit summary will be deleted.\n";
}
else
{
if(revealString != "")
{
ajaxData.showrevealString = revealString + "|";
}
revealString = revealString + "comment";
$.post('/w/api.php/', ajaxData,function()
confirmString = confirmString + "-Edit summary will be revealed.\n";
{
numCompleted++;
if(numCompleted == numTitles)
{
alert("modified " + revCount + " revision(s) successfully!");
return false;
}
});
}
if($("#revdelName").prop("checked") == $("#undelName").prop("checked"))
}
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 > 49)
{
confirmString = confirmString + "-User name visibility won't change.\n";
alert("You can't do more than 50 revdels at once! Canceling...");
return false;
}
else if(typeof pageTitles[$(this"#revdelName").attrprop("namechecked")] == "undefined")
{
if(deleteString != "")
pageTitles[$(this).attr("name")] = $(this).val();
numTitles++;{
deleteString = deleteString + "|";
}
deleteString = deleteString + "user";
confirmString = confirmString + "-User name will be deleted.\n";
}
else
{
if(revealString != "")
pageTitles[$(this).attr("name")] = pageTitles[$(this).attr("name")] + "|" + $(this).val();
{
revealString = revealString + "|";
}
revealString = revealString + "user";
confirmString = confirmString + "-User name will be revealed.\n";
}
if(deleteString == "" && revealString == "")
});
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 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)
{
alertmw.notify("weYou candidn't oversightselect andany un-oversightproperties edits atof the samerevisions to timechange!");
return false;
}
deleteString = "content";
var summary = "";
confirmString = confirmString + "-Content will be returned to normal (admin-only) revision deletion.\n";
oversighting = 0;
//construct the revdel summary
}
if($("#revdelCommentwpRevDeleteReasonList").propval("checked") == $("#undelCommentother").prop("checked"))
{
confirmString = confirmString + "-Edit summary visibility won't change.\n";
}
else if($("#revdelComment").prop("checked"))
{
if(oversighting == 0)
{
if($("#wpReason").val() == "")
alert("we can't oversight and un-oversight edits at the same time!");
return false;{
mw.notify("You didn't select or write in an edit summary for the logs!");
return false;
}
summary = $("#wpReason").val();
}
else
if(deleteString != "")
{
summary = $("#wpRevDeleteReasonList").val();
deleteString = deleteString + "|";
if($("#wpReason").val() != "")
{
summary = summary + ": " + $("#wpReason").val();
}
}
confirmString = confirmString + "\nYour revdel summary is: "+ summary +"\n\nAre you sure you want to do this?";
deleteString = deleteString + "comment";
confirmString = confirmString + "-Edit summary will be oversighted.\n";
if(confirm(confirmString))
oversighting = 1;
{
var numCompleted = 0;
for (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)
{
mw.notify("modified " + revCount + " revision(s) successfully!");
return false;
}
});
}
}
return false;
}
else)
$("#oversightSubmit").click(
function()
{
//figure out which revisions and pages we're working on.
if(oversighting == 1)
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)
{
mw.notify("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)
{
mw.notify("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 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)
{
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)
{
mw.notify("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 + "user";
confirmString = confirmString + "-User name will be oversighted.\n";
oversighting = 1;
}
else
{
if(oversighting == 1)
{
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)
{
mw.notify("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 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 == 1)
alert("You didn't select or write in an edit summary for the logs!");
return false;{
mw.notify("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;
}
summaryif($("#revdelName").prop("checked") == $("#wpReasonundelName").valprop("checked"));
}
else
{
summary = $("#wpRevDeleteReasonList").val();
if($("#wpReason").val() != "")
{
confirmString = confirmString + "-User name visibility won't change.\n";
summary = summary + ": " + $("#wpReason").val();
}
else if($("#revdelName").prop("checked"))
}
{
confirmString = confirmString + "\nYour oversight summary is: "+ summary +"\n\nAre you sure you want to do this?";
if(oversighting == 0)
{
if(confirm(confirmString))
mw.notify("we can't oversight and un-oversight edits at the same time!");
{
var return numCompleted = 0false;
}
for (title in pageTitles)
if(deleteString != "")
{
deleteString = deleteString + "|";
}
deleteString = deleteString + "user";
confirmString = confirmString + "-User name will be oversighted.\n";
oversighting = 1;
}
else
{
var ajaxData;
ajaxData = {action:"revisiondelete",type:"revision",ids:pageTitles[title],reason:summary,token: mw.user.tokens.get( 'editToken' ),hide:deleteString};
if(oversighting == 1)
{
mw.notify("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 == "")
{
mw.notify("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() == "")
{
alertmw.notify("SomethingYou wentdidn't wrong,select soor we'rewrite goingin toan abortedit withoutsummary doingfor anything.the logs!");
return false;
}
summary = $("#wpReason").val();
$.post('/w/api.php/', ajaxData,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
{
mw.notify("Something went wrong, so we're going to abort without doing anything.");
}
api.postWithToken('csrf', ajaxData).done(function()
{
numCompleted++;
if(numCompleted == numTitles)
{
mw.notify("modified " + revCount + " revision(s) successfully!");
return false;
}
});
}
}
return false;
}
)
return false;
}
});
}
});