User:Void/blockSync.js

/** * This script automates syncronizing the local block table to match global blocks. * This is only necessary if someone accidentally drops all IP blocks from the block table. * Note: This is slow. * * WARNING: THIS SCRIPT AUTO RUNS ON LOAD! DO NOT LOAD THIS SCRIPT UNLESS YOU HAVE TO */ /* jslint strict:false */ //

var api = new mw.Api;

function fetchBlocks( more ) { var data = { action: 'query', format: 'json', list: 'globalblocks', bgdir: 'newer', bglimit: 'max', bgprop: 'address|timestamp|expiry|reason', };	if( more && more.continue ) { data.continue = more.continue; data.bgstart = more.bgstart; }

api.get( data, {success: processBlocks} ); }

function processBlocks( data ) { var blocks = data.query.globalblocks; var bIndex = 0;

function prepBlock { if( bIndex >= blocks.length ) { if( data.continue ) { return fetchBlocks( data.continue ); // End of data, more to get }			return; // Fin }		var block = blocks[bIndex]; bIndex++;

return doBlock( block.address, block.reason, block.expiry, prepBlock ); }

function doBlock( target, reason, expiry, callback ) { api.postWithEditToken({			action: "block",			user: target,			expiry: expiry,			reason: reason,			anononly: 1,			nocreate: 1,		}, {			success: callback		}); }

prepBlock; }

// fetchBlocks;

//