MediaWiki:Gadget-PurgeTab.js

/* MediaWiki:Gadget-PurgeTab.js * * Gadget to add tools to the toolbar for purging pages */

$(function {	if (!mw.config.get('wgArticleId')) {		return;	}

let purgePortlet = mw.util.addPortletLink(		'p-cactions', '#', 'Purge', 'ca-purge',		'Purge cache for this page', '*'	); $(purgePortlet).on('click', e => {		doPurge(false);		e.preventDefault;	});

let hardpurgePortlet = mw.util.addPortletLink(		'p-cactions', '#', 'Hard purge', 'ca-purge-hardpurge',		'Purge with forced recursive-link table update', ','	); $(hardpurgePortlet).on('click', e => {		doPurge(true);		e.preventDefault;	});

let nulleditPortlet = mw.util.addPortletLink(		'p-cactions', '#', 'Null edit', 'ca-nulledit',		'Perform a null edit on this page', '0'	); $(nulleditPortlet).on('click', e => {		doNullEdit;		e.preventDefault;	}); });

function doPurge (hard) { let params = { action: 'purge', pageids: mw.config.get('wgArticleId') };	if (hard) { params.forcerecursivelinkupdate = 1; params.redirects = 1; }	new mw.Api.post(params) .catch(httpErrorHandler) .then( => location.reload); }

function doNullEdit { new mw.Api.postWithEditToken({		action: 'edit',		pageid: mw.config.get('wgArticleId'),		appendtext: '',		watchlist: 'nochange',		nocreate: '1',	}) .catch(httpErrorHandler) .then( => location.reload); }

function httpErrorHandler (code, details) { let msg; switch (code) { case 'http': msg = 'HTTP error: ' + details.xhr.statusText; break; case 'ok-but-empty': msg = 'Received empty response.'; break; default: msg = details.error.info; }	mw.notify(msg, {title: 'Purge failed', type: 'error', tag: 'purge'}); }