User:Writ Keeper/Scripts/massProtect.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Writ Keeper/Scripts/massProtect. |
function protectAllTheThings(protectLevel, editSummary)
{
mw.loader.using('mediawiki.api').done(function ()
{
if (editSummary === null)
{
return false;
}
if (editSummary === '')
{
if(protectLevel == "all")
{
editSummary = "protection no longer necessary";
}
else
{
editSummary = "Mass protecting pages due to abuse";
}
}
var api = new mw.Api();
$(".mw-prefixindex-list a").each(function (ind, el)
{
api.postWithEditToken(
{
"action": "protect",
"title": el.title,
"protections": "edit=" + protectLevel,
"expiry": "never",
"reason": editSummary
}
).done(function ()
{
$(el).after("*");
}
);
}
);
}
);
return false;
}
mw.hook('wikipage.content').add(function ()
{
if (mw.config.get("wgCanonicalSpecialPageName") == "Prefixindex")
{
mw.loader.using(['mediawiki.util', 'oojs-ui']).done(function ()
{
mw.util.addPortletLink('p-cactions', '#', "semiprotect all", "ca-semiprotecteverything", "semiprotect all pages displayed here");
$("#ca-semiprotecteverything").click(function (event)
{
event.preventDefault();
mw.loader.load('mediawiki.api');
return protectAllTheThings("autoconfirmed", prompt("Enter an edit summary, or leave blank to use the default (or hit Cancel to cancel the semiprotection entirely)"));
}
);
mw.util.addPortletLink('p-cactions', '#', "te-protect all", "ca-teprotecteverything", "te-protect all pages displayed here");
$("#ca-teprotecteverything").click(function (event)
{
event.preventDefault();
mw.loader.load('mediawiki.api');
return protectAllTheThings("templateeditor", prompt("Enter an edit summary, or leave blank to use the default (or hit Cancel to cancel the te-protection entirely)"));
}
);
mw.util.addPortletLink('p-cactions', '#', "unprotect all", "ca-unprotecteverything", "unprotect all pages displayed here");
$("#ca-unprotecteverything").click(function (event)
{
event.preventDefault();
mw.loader.load('mediawiki.api');
return protectAllTheThings("all", prompt("Enter an edit summary, or leave blank to use the default (or hit Cancel to cancel the unprotection entirely)"));
}
);
}
);
}
}
);