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

Content deleted Content added
typo
swap for document.ready
 
(19 intermediate revisions by 2 users not shown)
Line 1:
$(document).ready( function()
var lastSelectedRevdel = -1;
 
mw.hook("wikipage.content").add( function()
{
mw.loader.using(["mediawiki.api"]).then(function ()
{
var apiLimit = 500;
Line 9 ⟶ 7:
if(mw.config.get("wgCanonicalSpecialPageName") == "Contributions")
{
wkContribsCheckboxInit = true;
$("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'>\
$("ul.mw-contributions-list:first").before("<div style='display:inline-block;' id='revdelCP'><span id='revdelLabel' style='cursor:pointer;'>Revision deletion\
<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>\
$("ul.mw-contributions-list").before(" <divspan id='revdelCPBody' style='display:inline-blocknone;' id='revdelCP'>Revision deletion: <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> \
<span style='white-space:nowrap;'><input type='checkbox' id='revdelName' name='revdelOptions' value='userName'> delete user name</span> \
Line 17 ⟶ 19:
<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).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+"'>";
$(el).children(".revdelIds").data("index", ind);
}
});
$("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)
Line 32 ⟶ 41:
reasons = reasons.replace(/\* ([^<]+)([^\*]+)/g, '<optgroup label="$1">$2</optgroup>');
$('#wpRevDeleteReasonList').append(reasons);
}).done(function()
{
$.get("/w/index.php?title=MediaWiki:Revdelete-reason-dropdown-suppress&action=raw", function(data)
{
reasons = data.replace(/\*\* ([^\*]+)/g, '<option value="$1">$1</option>');
reasons = reasons.replace(/\* ([^<]+)([^\*]+)/g, '<optgroup label="$1">$2</optgroup>');
$('#wpRevDeleteReasonList').append(reasons);
});
});
//attach handlers
$("#revdelLabel").click(
function()
{
if($("#revdelCP").data("revdelToolbarShowing"))
{
$("#revdelCP").data("revdelToolbarShowing", false);
$("#revdelLabelImg").css("transform","rotate(270deg)");
$("#revdelCPBody").fadeOut();
}
else
{
$("#revdelCP").data("revdelToolbarShowing", true);
$("#revdelLabelImg").css("transform","none");
$("#revdelCPBody").fadeIn();
}
}
);
$("#revdelSelectAll").click(
function()
Line 41 ⟶ 75:
{
$(this).prop("checked", true);
});
$("#revdelCP").data("lastSelectedIndex", -1);
}
);
Line 50 ⟶ 85:
{
$(this).prop("checked", false);
});
$("#revdelCP").data("lastSelectedIndex", -1);
}
);
 
$("#revdelSelectInv").click(
function()
{
$('input.revdelIds').each(function()
{
$(this).prop("checked", !($(this).prop("checked")));
});
$("#revdelCP").data("lastSelectedIndex", -1);
}
);
$("input.revdelIds").off("click").click(
function(ev)
{
var lastSelectedRevdel = $("#revdelCP").data("lastSelectedIndex");
var newIndex = $(this).data("index")
if(ev.shiftKey && lastSelectedRevdel >= 0)
Line 66 ⟶ 114:
for(var i = start; i < stop; i++)
{
if(i != lastSelectedRevdel)
$(checkboxArray[i]).prop("checked", true);
{
$(checkboxArray[i]).prop("checked", true!($(checkboxArray[i]).prop("checked")));
}
}
}
Line 73 ⟶ 124:
for(var i = start; i > stop; i--)
{
if(i != lastSelectedRevdel)
$(checkboxArray[i]).prop("checked", true);
{
$(checkboxArray[i]).prop("checked", true!($(checkboxArray[i]).prop("checked")));
}
}
}
}
lastSelectedRevdel =$("#revdelCP").data("lastSelectedIndex", newIndex);
}
);
Line 92 ⟶ 146:
if(ind > apiLimit - 1)
{
alertmw.notify("You can't do more than " + apiLimit + " revdels at once! Canceling...");
return false;
}
Line 107 ⟶ 161:
if(numTitles == 0)
{
alertmw.notify("You didn't select any revisions to delete!");
return false;
}
Line 177 ⟶ 231:
if(deleteString == "" && revealString == "")
{
alertmw.notify("You didn't select any properties of the revisions to change!");
return false;
}
Line 188 ⟶ 242:
if($("#wpReason").val() == "")
{
alertmw.notify("You didn't select or write in an edit summary for the logs!");
return false;
}
Line 223 ⟶ 277:
if(numCompleted == numTitles)
{
alertmw.notify("modified " + revCount + " revision(s) successfully!");
return false;
}
Line 244 ⟶ 298:
if(ind > apiLimit - 1)
{
alertmw.notify("You can't do more than " + apiLimit + " revdels at once! Canceling...");
return false;
}
Line 259 ⟶ 313:
if(numTitles == 0)
{
alertmw.notify("You didn't select any revisions to delete!");
return false;
}
Line 282 ⟶ 336:
if(oversighting == 1)
{
alertmw.notify("we can't oversight and un-oversight edits at the same time!");
return false;
}
Line 297 ⟶ 351:
if(oversighting == 0)
{
alertmw.notify("we can't oversight and un-oversight edits at the same time!");
return false;
}
Line 312 ⟶ 366:
if(oversighting == 1)
{
alertmw.notify("we can't oversight and un-oversight edits at the same time!");
return false;
}
Line 331 ⟶ 385:
if(oversighting == 0)
{
alertmw.notify("we can't oversight and un-oversight edits at the same time!");
return false;
}
Line 346 ⟶ 400:
if(oversighting == 1)
{
alertmw.notify("we can't oversight and un-oversight edits at the same time!");
return false;
}
Line 359 ⟶ 413:
if(deleteString == "")
{
alertmw.notify("You didn't select any properties of the revisions to change!");
return false;
}
Line 370 ⟶ 424:
if($("#wpReason").val() == "")
{
alertmw.notify("You didn't select or write in an edit summary for the logs!");
return false;
}
Line 402 ⟶ 456:
else
{
alertmw.notify("Something went wrong, so we're going to abort without doing anything.");
}
api.postWithToken('csrf', ajaxData).done(function()
Line 409 ⟶ 463:
if(numCompleted == numTitles)
{
alertmw.notify("modified " + revCount + " revision(s) successfully!");
return false;
}