MediaWiki:WHAM/code.2.js

/*
 * A modified version of WHAM with a more up-to-date modal, as well as less coding
 * Includes ability to delete forum/message wall threads, which the original doesn't support
 * Original "WHAM" - http://dev.wikia.com/wiki/WHAM/code.js
 * @author Ozuzanna

var username = mw.config.get("wgPageName").split("/")[1], token = mw.user.tokens.get('editToken');
 * (function($, mw) {

if (mw.config.get("wgCanonicalSpecialPageName") === "Contributions") { $(".chat-ban-log").after(' | Super Tool');

$('#contribs-wham').click(function {     $.showCustomModal('WHAM!', '', { id: 'form-main', width: 350, buttons: [{ message: 'Delete all pages', defaultButton: true, handler: function { doDelete; }	       }, {		           message: 'Rollback all edits', defaultButton: true, handler: function { doRollback; }       },{		           message: 'Quick block', defaultButton: true, handler: function { doBlock; }       },{		           message: 'All of the options', defaultButton: true, handler: function { doAll; }       }, {          message: 'Cancel', handler: function { $('#form-main').closeModal; }       }]      });    });

function apiDelete(page) { new mw.Api.post({     format: 'json',      action: 'delete',      title: page,      token: token,      reason: 'Cleanup'      }) .done(function(d) {        if (!d.error) {          console.log('Deletion of '+page+' successful!');        } else {          console.log('Failed to delete '+page+': '+ d.error.code);        }      }) .fail(function {       console.log('Failed to delete '+page+'!');      }); }

function doRollback { $('.mw-rollback-link a').each(function {       var href = $(this).attr('href');	$.get(href);        $(this).text('gone!').css('color','grey').removeAttr('href');      }); }   function doDelete { $('li .newpage ~ a').each(function {       var title = $(this).attr('title');        if (title.slice(0,12) == 'Message Wall')          return;        apiDelete(title);      });

$('#mw-content-text ul li a').each(function {       var title = $(this).attr('title');	if (title.split('-').length == 1)	  return;        if (title.slice(0,7) == 'Thread:' || title.slice(0,13) == 'Board Thread:') {          apiDelete(title);          $(this).css({'color':'grey','text-decoration':'line-through'}).removeAttr('href');        }      }); }

function doBlock { var duration = prompt('Please state the block duration','2 weeks'), reason = prompt('Please state the block reason','Vandalism'); new mw.Api.post({       format: 'json',        action: 'block',        user: username,        expiry: duration,        nocreate: 0,        autoblock: 0,        token: token,        reason: reason        }) .done(function(d) {          if (!d.error) {            console.log(username+' has been blocked successfully!');            deleteRollback;          }           else {            alert('Failed to block '+username+': '+ d.error.code);          }        }) .fail(function {         alert('Failed to block '+username+'!');        }); }   function doAll { doRollback; doDelete; doBlock; $('#form-main').closeModal; setTimeout((function{ location.reload; }), 1000);   }  } }) (this.jQuery, this.mediaWiki);