User:Technical 13/MRollback.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:Technical 13/MRollback. |
/* global mw:true, Flash:true */
/**
* Mass Rollback Script
*
* Creates a form to mass rollback edits
*
* @author Kangaroopower
* @credits Ale_jrb (UI)
*
* From: [[User:Kangaroopower/Scripts]]
*
* To Do :
* - From what time
*
*/
$(function () {
importScript('User:Kangaroopower/Flash.js');
window.MRollback = {
version: "2.22",
active: false,
GUI: {}
};
var MRollback = window.MRollback;
MRollback.init = function () {
if ( mw.config.get('wgCanonicalSpecialPageName') === "Contributions" && $.inArray( mw.config.get('wgUserGroups'), ["reviewer", "rollbacker", "sysop"]) ) {
mw.util.addPortletLink('p-cactions', 'javascript:MRollback.GUI.initiate();', "Mrollback", "ca-mrollback", "Mass Rollback");
}
};
/* Functions for popup functionality */
var thisUser = mw.config.get('wgPageName').substring(wgPageName.indexOf("/") + 1, wgPageName.length);
function isVandal() {
if ($('#mr-sum').prop('readonly') === false) {
$('#mr-sum').prop('readonly', true);
}
$('#mr-sockinfo').css('display', 'none');
$('#mr-sum').css('background-color', '#CCC');
$('#mr-sum').text('[[User:Technical 13/MRollback|Mass rollback]] of [[Special:Contributions/' + thisUser + '|the edits]] of this [[WP:SPA|SPA]] [[WP:VANDAL|vandal only]] account.');
}
function isSock() {
if ($('#mr-sum').prop('readonly') === false) {
$('#mr-sum').prop('readonly', true);
}
$('#mr-sockinfo').css('display', 'block');
var sockMaster = $('#SM').val();
$('#mr-sum').css('background-color', '#CCC');
$('#mr-sum').text('[[User:Technical 13/MRollback|Mass rollback]] of [[Special:Contributions/' + thisUser + '|the edits]] of this [[WP:SOCK|sock puppet]] of [[WP:Sockpuppet investigations/' + sockMaster + '|' + sockMaster + ']].');
}
function isCustom() {
if ($('#mr-sum').prop('readonly') === true) {
$('#mr-sum').prop('readonly', false);
}
$('#mr-sockinfo').css('display', 'none');
$('#mr-sum').css('background-color', '#FFF');
}
/* GUI Module */
MRollback.GUI.initiate = function () {
if (MRollback.active !== true) {
MRollback.active = true;
var popupHTML = '<div id="mr-ui" style="z-index: 1000; background-color: #FFDBDB; padding: 4px; border: 1px solid #BB7070; border-radius: 6px; text-align: left; font-size: 11px; color: black; display: block; position: absolute; top: 2px; left: 10px; width; 150px;" class="ui-draggable"><form action="#" method="get"><div style="font-weight: bold; border-bottom: 1px solid #AAA; padding: 4px;"> <span id="mr-title">Mass Rollback</span><span style="float: right; text-transform: none;"><a id="mr-close" style="cursor: pointer" onclick="MRollback.GUI.close();"><img src="/media/wikipedia/commons/b/b6/Chrome_close_button.png"/></a></span></div><div><div style="display: inline-block; padding: 4px; vertical-align: middle;"><div style="margin: 4px auto;"><div style="display: inline-block; margin-right: 10px;"><input name="Select_summary" type="radio" value="Vandal" onChange="isVandal()" />Vandal only account<input name="Select_summary" type="radio" value="Sock" onChange="isSock()" />Sock puppet<input name="Select_summary" type="radio" value="Custom" checked="checked" onChange="isCustom()" />Custom summary:</div><div style="display: none;" id="mr-sockinfo"><input id="SM" type="text" size="60px" style="display: inline-block;" placeholder="Sockmaster's username" onKeyUp="isSock()" /></div><textarea id="mr-sum" cols="64" rows="4" maxlength="255" spellcheck="true" style="display: block;" autofocus></textarea></div><div style="margin: 4px auto;"><div style="display: inline-block; width: 4em;">How many:</div><input id="mr-limit" value="25" max="500" size="3" pattern="[\d]{1,3}" title="1-999" type="text" autocomplete="off" style="background-color: #FF0;" /><input id="mr-some" style="width: 100px; font-size: 12px; margin-bottom: 4px; background-color: #FFFFBD;" type="button" value="Rollback Some" onClick="alert('Rolling back `' + $('#mr-limit').val() + '` edits using the `' + $( '[name=Select_summary]:checked' ).val() + '` summary of `' + $('#mr-sum').val() + '`');" /><input id="mr-all" style="width: 100px; font-size: 12px; margin-bottom: 4px; background-color: #DDACAC;" type="button" value="Rollback All" onClick="alert('Rolling back all edits using the `' + $( '[name=Select_summary]:checked' ).val() + '` summary of `' + $('#mr-sum').val() + '`');" /><input id="mr-sum-cls" style="width: 100px; font-size: 12px; margin-bottom: 4px; background-color: #ACDDAC;" type="button" value="Clear summary" onClick="if ($('#mr-sum').prop('readonly') === false){alert('Press [OK] to clear `' + $('#mr-sum').val() + '` from the summary.');$('#mr-sum').text('');}else{alert('Unable to clear `' + $('#mr-sum').val() + '` from the summary in read-only mode.');}" /></div></div></div></form></div>';
$('body').append(popupHTML);
$('#mr-ui').show();
$('#mr-ui').draggable();
$("#mr-all").click(function () {
MRollback.rollback(true);
});
$("#mr-some").click(MRollback.rollback);
}
};
MRollback.GUI.close = function () {
if (MRollback.active !== false) {
MRollback.active = false;
$('#mr-ui').hide();
}
};
/* API functions */
MRollback.rollback = function (all) {
var mrlimit = $('#mr-limit').val(), rbcontribs = 0;
if (all === true) {
mrlimit = 500;
} else {
if (mrlimit !== '' && /^\d+$/.test(mrlimit)) mrlimit = parseInt(mrlimit, 10);
else return;
}
var ucuser = encodeURIComponent($('#contentSub a:first').html());
Flash('getUserContribs').load({number: mrlimit, user: ucuser}).wait(function (data) {
for(var i in data.query.usercontribs) {
if(data.query.usercontribs[i].top == '') {
var rbsummary = $('#mr-sum').val(),
latestcontribs = data.query.usercontribs[i].title;
console.log("Latest Contribs:" + latestcontribs);
Flash('rollback').load({targ: latestcontribs, user: ucuser, summary: rbsummary}).wait(function () {
rbcontribs++
console.log("rbcontribs:" + rbcontribs);
}).run();
}
}
}).run();
};
$(document).ready(MRollback.init);
});