User:Ozuzanna/nuke.js

/* if (mw.config.get('wgCanonicalSpecialPageName') === "Contributions" && mw.config.get('wgUserGroups').indexOf('sysop') != -1) $('#contentSub a:nth-child(8)').after(' | Nuke');
 * WORK IN PROGRESS - THIS SCRIPT IS INCOMPLETE (missing RC)
 * ~50% complete
 * Nuke
 * @description reverse engineered version of the Nuke extension, rewritten in JavaScript
 * https://www.mediawiki.org/wiki/Extension:Nuke
 * Is faster than the original Nuke when deleting
 * @author Ozuzanna

if (mw.config.get('wgCanonicalSpecialPageName') == "Blankpage" && $.getUrlVar('blankspecial') == "nuke") { var articlePath = mw.config.get('wgArticlePath').slice(0,-2), mainpage = mw.config.get('wgMainpage'), Api = new mw.Api; $('.AdminDashboardGeneralHeader h1').text('Nuke'); document.title = "Nuke - " + mw.config.get('wgSiteName'); if ($.getUrlVar('nukeuser')) { var user = $.getUrlVar('nukeuser'); $('#mw-content-text p').html('The following pages were created by ' + user + '; put in a comment and hit the button to delete them. Reason for deletion:  Delete Delete'); $('#nuke-status').html('Getting pages... please wait '); var UCJSON = { action: 'query', list: 'usercontribs', ucuser: user, uclimit: 5000 };	if ($.getUrlVar('nukenamespace')) UCJSON.ucnamespace = $.getUrlVar('nukenamespace');

Api.get(UCJSON) .done(function(d) {     if (!d.error) {        var usercontribs = d.query.usercontribs;        for (var i in usercontribs) {          if (usercontribs[i].hasOwnProperty('new'))            $('#nuke-query-results').append('' + ' ' + usercontribs[i].title + '');        }      }      else {        $('#nuke-query-results').html(' Failed to get query results: ' + d.error.code + ' ');      }      $('#nuke-status').empty;	}) .fail(function {     $('#nuke-query-results').html(' Failed to get query results ');      $('#nuke-status').empty;    }); } else { $('#mw-content-text p').html('This tool allows for mass deletions of pages recently added by a given user or IP address. Input the username or IP address to get a list of pages to delete, or leave blank for all users. Username, IP address or blank:  Pattern for the page name: <input type="text" id="nuke-match"/> Limit to namespace: <select id="nuke-namespace"> All Main  Talk  User  User talk  File  File talk  Template  Template talk  Help  Help talk  Category  Category talk  Maximum number of pages: <input type="text" id="nuke-max" value="500"/> <a class="wikia-button" id="nuke-rc">Go</a> <a class="wikia-button nuke-submit">Delete</a>  <a class="wikia-button nuke-submit">Delete</a>'); $('#nuke-rc').click(function {     if ($('#nuke-username').val) {	    var locationStr = articlePath + 'Special:Blankpage?blankspecial=nuke&nukeuser=' + $('#nuke-username').val;		if ($('#nuke-namespace').val != "all")		  locationStr += '&nukenamespace=' + $('#nuke-namespace').val;        location.replace(locationStr);        return;	  }      var rclimit = 500;	  if ($.isNumeric($('#nuke-max').val) && $('#nuke-max').val > 0)	    rclimit = $('#nuke-max').val;	  var RCJSON = {	    action: 'query',        list: 'recentchanges',        rctype: 'new',		rcnamespace: $('#nuke-namespace').val,        rclimit: rclimit	  };	  if ($('#nuke-namespace').val == 'all' || $('#nuke-namespace').val == 6)	    RCJSON.rctype = "new|log";	  if ($('#nuke-namespace').val == "all")	    delete RCJSON.rcnamespace;	  $('#nuke-status').html('Getting pages... please wait <img src="http://slot1.images.wikia.nocookie.net/__cb62004/common/skins/common/progress-wheel.gif"/>');     Api.get(RCJSON)      .done(function(d) { if (!d.error) { var recentchanges = d.query.recentchanges; for (var i in recentchanges) { if (recentchanges[i].hasOwnProperty('new') || recentchanges[i].type == "log" && recentchanges[i].ns == 6) //&& (!$('#nuke-match').val || recentchanges[i].title.indexOf($('#nuke-match').val) != -1))             $('#nuke-query-results').append('<input type="checkbox" class="nuke-title-check" checked="checked"/>' + ' <a href="' + articlePath + recentchanges[i].title + '" target="_blank">' + recentchanges[i].title + '</a></li>');          }		  $('#nuke-status').empty;        }	    else {	      $('#nuke-status').html(' Failed to get query results: ' + d.error.code + ' ');	    }	  }) .fail(function {	   $('#nuke-status').html(' Failed to get query results ');      }); });   $('.nuke-submit').click(function { if (!$('.nuke-query-result').length) return; $('.nuke-submit').attr('disabled','disabled'); $('#nuke-status').html('Deleting... please wait <img src="http://slot1.images.wikia.nocookie.net/__cb62004/common/skins/common/progress-wheel.gif"/>'); $('.nuke-query-result a').each(function(i) {       var currLi = $(this),        title = currLi.text;        setTimeout(function { if (currLi.parent.find('input').attr('Checked')) { Api.post({           action: 'delete',            title: title,            reason: $('#nuke-delete-reason').val,            bot: true,            token: mw.user.tokens.get("editToken")            }) .done(function(d) {              if (!d.error) {                console.log('Deletion of ' + title + ' successful!');              } else {                console.log('Failed to delete ' + title + ': '+ d.error.code);              }            }) .fail(function {             console.log('Failed to delete ' + title + '!');            }); }         if (i === $('.nuke-query-result a').length - 1) location.replace(articlePath + mainpage); }, i*100);   	  }); }); } }