MediaWiki:MassNullEdit/code.js

// /*
 * Mass Null Edit
 * @description Null edit listed multiple pages. Similar to Ajax Batch Delete.
 * Scripts used to help create:
 * https://dev.wikia.com/wiki/NullEditButton/code.js
 * https://dev.wikia.com/wiki/AjaxBatchDelete/code.js
 * https://dev.wikia.com/wiki/ChatBlockButton/code.js
 * @author Ozuzanna

if ($('#t-mne').length) return; var FormMNE = '\  \ \     Enter the name of each page you want to null edit on a separate line. Remember to include the namespace too if it is not in main. \      \ Any errors encountered will appear below \ \ ',  delay = window.nullEditDelay || 1000; userbtn = window.nullEditUserButton; $('#my-tools-menu').prepend(' Mass Null Edit'); //Optional user drop-down button if (userbtn == true) { $('#AccountNavigation > li > .subnav > li:last-child').after(     $('').append('Mass Null Edit')    ); } $('#t-mne').click(function (ev) {    ev.preventDefault;    $.showCustomModal('Mass Null Edit', FormMNE, { id: 'null-edit', width: 500, buttons: [{ message: 'Cancel', handler: function { $('#null-edit').closeModal; }     }, {          message: 'Add category contents', defaultButton: true, handler: function { addCategoryContents; }     }, {          id: 'startButton', message: 'Initiate', defaultButton: true, handler: function { init; }     }]    });   //Autocomplete support for Special:WhatLinksHere      if (mw.config.get('wgCanonicalSpecialPageName') === "Whatlinkshere") {         var thread =  '/'+mw.util.wikiUrlencode(wgFormattedNamespaces[1201])+':', // "/Thread:" in wiki lang             wall =  '/'+mw.util.wikiUrlencode(wgFormattedNamespaces[1200])+':', // "/Message_wall:" in wiki lang             board =  '/'+mw.util.wikiUrlencode(wgFormattedNamespaces[2000])+':', // "/Board:" in wiki lang             special =  '/'+mw.util.wikiUrlencode(wgFormattedNamespaces[-1])+':'; // "/Special:" in wiki lang         $('#mw-whatlinkshere-list a').each(function { link = $(this).prop("href"); page = $(this).text; if (link.indexOf(special) != -1 || link.indexOf('action=edit') != -1 || link.indexOf(thread) != -1 || link.indexOf(wall) != -1 || link.indexOf(board) != -1 ) return; $('#text-null-edit').append(page+"\n"); });     }  });   function init { var txt = document.getElementById('text-null-edit'), pages = txt.value.split('\n'), page = pages[0]; document.getElementById('startButton').setAttribute('disabled','disabled'); if (page === '' ) { document.getElementById('startButton').removeAttribute("disabled"); $.showCustomModal('Finished!', 'Nothing left to do, or next line is blank.', {          id: 'null-edit-complete',           width: 200,           buttons: [{              message: 'Close',              defaultButton: true,              handler: function {                $('#null-edit-complete').closeModal;              }           }]        }); } else { nullEdit(page); }     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-null-edit').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 nullEdit(pageNullEdit) { new mw.Api.post({    format: 'json',     action: 'edit',     title: pageNullEdit,     token: mw.user.tokens.get('editToken'),     prependtext: ''     }) .done(function(d) {       if (!d.error) {         console.log('Null edit of '+pageNullEdit+' successful!');       } else {         console.log('Failed to null edit '+pageNullEdit+': '+ d.error.code);	 $('#text-error-output').append('Failed to null edit '+pageNullEdit+': '+d.error.code+' ');       }     }) .fail(function {      console.log('Failed to null edit '+pageNullEdit+'!');       $('#text-error-output').append('Failed to null edit '+pageNullEdit+': unknownerror ');     }); setTimeout(init,delay); } }) (this.jQuery, this.mediaWiki);
 * (function($, mw) {