FANDOM


Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Chrome - Windows: Hold the Ctrl key and press the F5 key. OS X: Hold both the ⌘ Cmd and ⇧ Shift keys and press the R key.
  • Safari - Hold down the ⇧ Shift key and click the Reload toolbar button.
  • Firefox - Windows: Hold the Ctrl key, and press F5. OS X: Hold the ⌘ Cmd and ⇧ Shift keys, and then press R.
  • Internet Explorer - Hold the Ctrl key, and press F5 (or click the Refresh button).
//<syntaxhighlight lang="javascript">
/* 
* A modified version of WHAM with a more up-to-date modal, as well as less coding
* Includes functionality to delete forum/message wall threads and selective deleting of pages, which the original doesn't have
* Original "WHAM" - https://dev.wikia.com/wiki/WHAM/code.js 
* @author Ozuzanna 
* @TODO interlang message translations
*/
 
;(function($, mw) {
  var ug = mw.config.get("wgUserGroups");
  if (mw.config.get("wgCanonicalSpecialPageName") === "Contributions" && (ug.indexOf('rollback') + ug.indexOf('sysop') + ug.indexOf('vstf') + ug.indexOf('staff') + ug.indexOf('helper') > -5)) {
 
/* 
* Message wall equivalents list, used to prevent deletion of message walls (causes glitches and not necessary)
* Acquired from https://github.com/Wikia/app/blob/ae6cd75a04ba92270931d8fee70f14d40146091b/extensions/wikia/Wall/Wall.namespaces.php
*/	
    var walls = [ 
	        "Message Wall",
		"Nachrichtenseite",
		"Muro",
                "Viestiseinä",
                "Mur",
                "Üzenőfal",
                "Bacheca",
                "メッセージ ウォール",
                "Prikbord",
                "Tablica wiadomości",
                "Mural de mensagens",
                "Стіна обговорення",
                "Стена обсуждения",
                "留言墙"
    ],
    username = mw.config.get("wgPageName").split("/")[1],
    token = mw.user.tokens.get("editToken"),
    revDel = 0;
 
    if ($('.mw-revdelundel-link').length)
      revDel = 1;
 
    $("#contentSub").append(' <a style="color:red;cursor:pointer" id="contribs-wham" title="Super Tool">快速工具</a>');
 
    $('#contribs-wham').click(function() {
      $.showCustomModal('WHAM!', '', {
        id: 'form-main',
        width: 540,
        buttons: [{
          message: '刪除所有條目',
          defaultButton: true,
          handler: function () {
            doDelete();    
          }	
        },{		 
          message: '刪除選定條目',
          defaultButton: true,
          handler: function () {
            startSelectiveDelete();    
          }
        },{		 
          message: '回退所有編輯',
          defaultButton: true,
          handler: function () {
            doRollback();    
          }
        },{		 
          message: '快速封禁',
          defaultButton: true,
          handler: function () {
            doBlock();    
          }
        },{		 
          message: '以上全部',
          defaultButton: true,
          handler: function () {
            doRollback();
            doDelete();
            doBlock(); 
            closeRefresh();   
          }
        },{
          message: '取消',
          handler: function() {
            closeRefresh();
          }
        }]
      });
      $(".close").click(closeRefresh);
      mw.util.addCSS('.modalWrapper .modalContent .modalToolbar {text-align:left;}');
    });
 
    function apiDelete(page,reason) {
      new mw.Api().post({
      format: 'json',
      action: 'delete',
      title: page,
      reason: reason,
      bot: true,
      token: token
      })
      .done(function(d) { 
        if (!d.error) {
          console.log('刪除'+page+'成功');
        } else {
          console.log('刪除'+page+'失敗: '+ d.error.code);
        }
      })
      .fail(function() {
        console.log('刪除'+page+'失敗');
      });
    }
 
    function closeRefresh() {
      $('#form-main').closeModal();
      setTimeout((function(){
        location.reload();
      }), 5000);
    }
 
    function doRollback() {
      $('.mw-rollback-link a').each(function() {
        var href = $(this).attr('href');
	$.get(href);
        $(this).text('已完成').css({'color':'grey','text-decoration':'line-through'}).removeAttr('href').parents().eq(1).css({'color':'grey','text-decoration':'line-through'}).children().removeAttr('href').css({'color':'grey','text-decoration':'line-through'});
      });
    }
 
    function doDelete() {    
      var deleteReason = prompt('輸入刪除原因','清理');
      if (!deleteReason)
        return;
 
      $('li .newpage ~ a').each(function() {
        var title = $(this).attr('title');
        if (walls.indexOf(title.split(':')[0]) !== -1)
          return;
        apiDelete(title,deleteReason);
        $(this).parent().css({'color':'grey','text-decoration':'line-through'}).children().removeAttr('href').css({'color':'grey','text-decoration':'line-through'});
      });
 
      $('#mw-content-text ul li').each(function() {
        var title = $(this).children('a').first().attr('title');
	if (title.split('-').length == 1 || title.split('/@comment').length == 1)
	  return;   
        apiDelete(title,deleteReason);
        $(this).css({'color':'grey','text-decoration':'line-through'});
      });
    }
 
    function doBlock() {
      var duration = prompt('指明封禁期限','2 weeks'),
      blockReason = prompt('指明封禁期限','破壞');
      if (!duration || !blockReason)
        return;
      new mw.Api().post({
      format: 'json',
      action: 'block',
      user: username,
      expiry: duration,
      nocreate: 0,
      autoblock: 0,
      reason: blockReason,
      bot: true,
      token: token
      })
      .done(function(d) { 
        if (!d.error) {
          console.log('封禁'+username+'成功');
        } 
        else {
          alert('封禁'+username+'失敗: '+ d.error.code);
        }
      })
      .fail(function() {
        alert('封禁'+username+'失敗');
      });
    }
 
    function startSelectiveDelete() {
      var chk = '<input class="selectiveDel" type="checkbox"/> ';
      $('#form-main').closeModal();
      if ($('#btn-wham-del').length && $('#btn-wham-check').length)
        return;
      $('#mw-content-text').find('ul').before('<a class="button" style="cursor:pointer" id="btn-wham-del">Delete Selected</a> <a class="button" style="cursor:pointer" id="btn-wham-check">Check All</a>');
      $('li .newpage ~ a').each(function() {
        if (!$(this).parent().find('input').length)
          $(this).parent().prepend(chk);
      });
      $('#mw-content-text ul li').each(function() {
        var title = $(this).children('a').first().attr('title');
	if (title.split('-').length != 1 && title.split('/@comment').length != 1 && !$(this).find('input').length && title.split(username) != -1)
          $(this).prepend(chk);	
      });
      $('#btn-wham-del').click(function() {
        var deleteReason = prompt('輸入刪除原因','清理');
        if (!deleteReason)
          return;
        $('.selectiveDel').each(function() {
          var chkObj = $(this);
          if (revDel == 0) {
            var title = $(this).parent().find('a').first().attr('title');
          }
          else {
            var title = $(this).parent().children('a').eq(1).attr('title');
          }
          if (chkObj.attr('已勾選') && walls.indexOf(title.split(':')[0]) == -1) {  
            apiDelete(title,deleteReason);
            $(this).parent().css({'color':'grey','text-decoration':'line-through'}).children().removeAttr('href').css({'color':'grey','text-decoration':'line-through'});
          }
        });
        setTimeout((function(){
          location.reload();
        }), 5000);
      });
      $('#btn-wham-check').click(function() {
        var btn = $(this);
        if (btn.text() == '取消勾選全部') {
          $('.selectiveDel').each(function() {
            var chkObj = $(this);
            if (chkObj.attr('已勾選'))
              chkObj.removeAttr('已勾選');        
          });
          btn.text('勾選全部');
        }
        else {
          $('.selectiveDel').each(function() {
            var chkObj = $(this); 
            if (!chkObj.attr('已勾選'))
              chkObj.attr('已勾選','已勾選');        
          });
          btn.text('取消勾選全部'); 
        }
      }); 
    }
}
 
}) (this.jQuery, this.mediaWiki);
//</syntaxhighlight>