User:Technical 13/MRollback.js

/* 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");		}	};	/* GUI Module */	MRollback.GUI.initiate = function  {		if (MRollback.active !== true) {			MRollback.active = true;			var popupHTML = '  Mass Rollback      Summary:   How many:    '; $('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); });