/* 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 ( window, $, mw ) {
var ns = {
version: "2.34",
active: false,
};
ns.init = function () {
if (mw.config.get('wgCanonicalSpecialPageName') === "Contributions" && $.inArray(mw.config.get('wgUserGroups'), ["rollbacker", "sysop"])) {
$("#firstHeading").append('<span style="margin-left:20px; font-size:20px">[<span id="mr-link" style="color:#0645ad; cursor:pointer;">Mass Rollback</span>]</span>');
$("#mr-link").click(function () {
MRollback.open();
});
}
};
/* GUI Module */
ns.open = function () {
if (!MRollback.active) {
MRollback.active = true;
var popupHTML = '<div id="mr-ui" style="display:none; z-index: 1000;background-color: white;padding: 4px;border: 1px solid rgb(170, 170, 170);border-radius: 6px;text-align: left;font-size: 11px;color: black;display: block;position: absolute;top: 244px;left: 207px;" class="ui-draggable"><div style="font-weight: bold;border-bottom: 1px solid #aaaaaa;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.close();"><img src="http://up.wiki.x.io/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;width: 4em;margin-right:10px;">Summary:</div><input id="mr-sum" size="58" type="text"></div><div style="margin: 4px auto;"><div style="display: inline-block;width: 4em;">How many:</div><input id="mr-limit" placeholder="Number of contribs to rollback" size="60" type="text" style="background-color: rgb(255, 255, 255);"></div></div><div style="display: inline-block;padding: 4px;width: 110px;vertical-align: middle;"><input id="mr-some" class="mr-button" type="button" value="Rollback Some"><input id="mr-all" class="mr-button" type="button" value="Rollback All"></div></div></div>';
$('body').append(popupHTML);
$('.mr-button').css({'width': '100px', 'font-size': '10px', 'margin-bottom': '4px'});
$('#mr-ui').show().draggable();
$("#mr-all, #mr-some").click(function (e) {
var bool = e.toElement().id === "mr-all";
MRollback.rollback(bool);
});
}
};
ns.close = function () {
if (MRollback.active) {
MRollback.active = false;
$('#mr-ui').hide();
}
};
/* API functions */
ns.rollback = function (all) {
var mrlimit = all ? 500 : parseInt($('#mr-limit').val(), 10),
ucuser = encodeURIComponent($('#contentSub a:first').html()),
rbcontribs = 0;
if (isNaN(mrlimit) || /^\d+$/.test($('#mr-limit').val())) return;
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() + ' ([[User:Kangaroopower/scripts/Mass_Rollback|MRollback]])',
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();
};
window.MRollback = ns;
if (typeof mw.loader.moduleRegistry.Flash === "undefined") {
mw.loader.implement('Flash', [mw.util.wikiScript('index') + '?title=User:Kangaroopower/Flash.js&action=raw&ctype=text/javascript'], {}, {});
}
mw.loader.using(['Flash'], function () {
MRollback.init();
});
}( this, jQuery, mediaWiki ) );