User:MrAwesome8/BatchCreate/code2.js

/* if ($('#t-bc').length) return; var ug = mw.config.get("wgUserGroups").join(' '); if (ug.indexOf('sysop') + ug.indexOf('vstf') + ug.indexOf('staff') + ug.indexOf('helper') > -4) { var FormHTML = '\  \ \     Reason for creating: \  \ \       Protect for admin only?  \ \     Put the name of each page you want to create on a separate line. \        \ Any errors encountered will appear below: \  \ \ ',  token = mw.user.tokens.get('editToken'), delay = window.batchCreateDelay || 1000; //Support for Monobook if (mw.config.get('skin') === 'monobook') { mw.util.addPortletLink('p-tb', '#', 'Batch Create', 't-bc'); }  else { $('#my-tools-menu').prepend(' Batch Create'); } $('#t-bc').click(function  {    $.showCustomModal('Ajax Batch Create', FormHTML, { id: 'form-mass-create', width: 500, buttons: [{ message: 'Cancel', handler: function { $('#form-mass-create').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-create'), createReason = document.getElementById('create-reason').value, pages = txt.value.split('\n'), currentPage = pages[0]; if (!createReason) { 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-create-complete',           width: 200,           buttons: [{              message: 'Close',              defaultButton: true,              handler: function {                 $('#mass-create-complete').closeModal;              }           }]        }); }      else { process(currentPage,createReason); }     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-create').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: 'create',      watchlist: 'nochange',      title: page,      reason: reason,      token: token      }) .done(function(d) {        if (!d.error) {          console.log('Creation 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 create '+page+': '+ d.error.code);          $('#text-error-output').append('Failed to create '+page+': '+d.error.code+' ');        }      }) .fail(function {       console.log('Failed to create '+page+': unknownerror');        $('#text-error-output').append('Failed to create '+page+': unknownerror ');      }); setTimeout(init,delay); } } }) (this.jQuery, this.mediaWiki); //
 * Ajax Batch Create
 * @description Create listed multiple pages
 * Based on Batch Delete
 * http://dev.wikia.com/wiki/AjaxBatchDelete
 * Does not need to go to Special:BlankPage to use
 * Includes the option to protect after creating
 * Includes the option to grab a whole category's contents
 * @author MrAwesome8, Ozuzanna
 * (function($, mw) {