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 '); Api.get({   action: 'query',    list: 'usercontribs',    ucuser: user,    uclimit: 500             }) .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: <input type="text" id="nuke-namespace"/> Maximum number of pages: <input type="text" id="nuke-no-pages" value="500"/> <a class="wikia-button" id="nuke-rc">Go</a>'); $('#nuke-rc').click(function {	 if ($('#nuke-username').val) {	    location.replace(location + '&nukeuser=' + $('#nuke-username').val)	  }	  else {	  }	}); /*Api.get({   action: 'query',    list: 'usercontribs',    ucuser: user,    uclimit: 5000              }) .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('<input type="checkbox" class="nuke-title-check"/>' + ' <a href="' + articlePath + usercontribs[i].title + '" target="_blank">' + usercontribs[i].title + '</a></li>');        }      }	  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;    }); }*/ $('.nuke-submit').click(function {    $('.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); }); }); }