User:Jacce/global.js

// \    \  ',  token = mw.user.tokens.get('editToken'), delay = window.batchDeleteDelay || 1000; //Support for Monobook if (mw.config.get('skin') === 'monobook') { mw.util.addPortletLink('p-tb', '#', 'Batch Delete', 't-bd'); }  else { $('#my-tools-menu').prepend(' Batch Delete'); } $('#t-bd').click(function  {    $.showCustomModal('Ajax Batch Delete', FormHTML, { id: 'form-mass-delete', width: 500, buttons: [{ message: 'Cancel', handler: function { $('#form-mass-delete').closeModal; }     }, {          message: 'Add category contents', defaultButton: true, handler: function { addCategoryContents; }     }, {          id: 'startButton', message: 'Initiate', defaultButton: true, handler: function { init; }     }]    });  });    function init { var txt = document.getElementById('text-mass-delete'), deleteReason = document.getElementById('delete-reason').value, pages = txt.value.split('\n'), currentPage = pages[0]; if (!deleteReason) { alert('Please state a reason!'); return; }     document.getElementById('startButton').setAttribute('disabled','disabled'); if (!currentPage) { document.getElementById('startButton').removeAttribute("disabled"); $.showCustomModal('Finished!', 'Nothing left to do, or next line is blank.', {          id: 'mass-delete-complete',           width: 200,           buttons: [{              message: 'Close',              defaultButton: true,              handler: function {                 $('#mass-delete-complete').closeModal;              }           }]        }); }      else { process(currentPage,deleteReason); }     pages = pages.slice(1,pages.length); txt.value = pages.join('\n'); }   function addCategoryContents { var category = prompt('Please enter the category name (no category prefix):'); new mw.Api.get({     action: 'query',      list: 'categorymembers',      cmtitle: "Category:"+category,      cmlimit: 5000      }) .done(function(d) {       if (!d.error) {          var data = d.query;	  for (var i in data.categorymembers) {            $('#text-mass-delete').append(data.categorymembers[i].title+'\n');          }        }        else {          $('#text-error-output').append('  Failed to get contents of '+ category +' : '+ d.error.code +'  ');        }      }) .fail(function {       $('#text-error-output').append('  Failed to get contents of '+ category +'  ');      }); }    function process(page,reason) { new mw.Api.post({     format: 'json',      action: 'delete',      watchlist: 'nochange',      title: page,      reason: reason,      token: token      }) .done(function(d) {        if (!d.error) {          console.log('Deletion of '+page+' successful!');          if (document.getElementById('protect-check').checked) {            new mw.Api.post({ format: 'json', action: 'protect', expiry: 'infinite', protections: 'create=sysop', watchlist: 'nochange', title: page, reason: reason, token: token })           .done(function(d) { if (!d.error) { console.log('Protection of '+page+' successful!'); }              else { console.log('Failed to protect '+page+': '+ d.error.code); $('#text-error-output').append('Failed to protect '+page+': '+d.error.code+' '); }           })            .fail(function { console.log('Failed to protect '+page+': unknownerror'); $('#text-error-output').append('Failed to protect '+page+': unknownerror '); });         }        } 	else {          console.log('Failed to delete '+page+': '+ d.error.code);          $('#text-error-output').append('Failed to delete '+page+': '+d.error.code+' ');        }      }) .fail(function {       console.log('Failed to delete '+page+': unknownerror');        $('#text-error-output').append('Failed to delete '+page+': unknownerror ');      }); setTimeout(init,delay); } } }) (this.jQuery, this.mediaWiki); //