User:HottieBottie/wikia.js

/* * Redirect not existent categories to edit page */

if(wgCanonicalNamespace == 'Category' && wgAction != 'edit' && wgArticleId === 0) window.location = '?action=edit';

/* * If we are editing the page, auto create */ if(wgCanonicalNamespace == 'Category' && wgAction == 'edit' && wgArticleId === 0) { $(document).ready(function {		// Set the text of the page content		$('#wpTextbox1').val('');		// Set the summary		$('#wpSummary,#wpSummaryEnhanced').val('Creating category page');		// Then submit		$('#editform').submit;	}); }

/* * Call API function */ function callAPI(data, method, callback) { data['format'] = 'json'; $.ajax({		data: data,		dataType: 'json',		url: wgScriptPath + '/api.php',		type: method,		cache: false,		success: function(response) {			if(response.error)				alert('API error: ' + response.error.info);			else 				callback(response);		},		error: function(xhr, error) {			alert('AJAX error: ' + error);		}	}); } /* * Automatic create all pages */ if(wgPageName == 'Special:WantedCategories') addOnloadHook(addMassCreate);

function addMassCreate { $('.AdminDashboardArticleHeader').prepend('Mass Create'); }

/* * Create the pages here */ function createCatPage(pagename) { callAPI({		'action': 'query',		'prop': 'info|revisions',		'intoken': 'edit',		'titles': pagename	}, 'GET', function(response) {		var page = response.query.pages[-1];		callAPI({ 'minor': 'yes', 'bot': 'yes', 'summary': 'Mass creating category pages as per Special:WantedCategories', 'action': 'edit', 'title': pagename, 'basetimestamp': page.starttimestamp, 'startimestamp': page.starttimestamp, 'token': page.edittoken, 'text': '' }, 'POST', function(response) {			console.log('Created page: ' + pagename); });	}); }

/* * Mass call createCatPage */ function massCreate { $('a.newcategory').each(function {		createCatPage($(this).attr('title'));	}); }