MediaWiki:Gadget-purgeTab.js

/** * Add "Purge" content action link. * * Dependencies: mediawiki.api, mediawiki.language mediawiki.util * * @source https://www.mediawiki.org/wiki/Snippets/Purge_action * @revision 2016-05-22 */ $( function {	var messages = ( function  { var translations = { en: { tabName: 'Purge', tabDescription: 'Purge the server cache of this page', errorMessage: 'Purge failed' },			fr: { tabName: 'Purger', tabDescription: 'Purger le cache serveur de cette page', errorMessage: 'Purge échouée' },                       pl: { tabName: 'Odśwież', tabDescription: 'Usuń dla tej strony dane z pamięci podręcznej serwera', errorMessage: 'Odświeżenie nieudane' },                       mk: { tabName: 'Превчитај', tabDescription: 'Исчистете го опслужувачкиот меѓусклад на страницава', errorMessage: 'Превчитувањето не успеа' }		},		chain = mw.language.getFallbackLanguageChain, len = chain.length, ret = {}, i = len - 1; while ( i >= 0 ) { if ( translations.hasOwnProperty( chain[ i ] ) ) { $.extend( ret, translations[ chain[ i ] ] ); }			i = i - 1; }		return ret; } );

if ( $( '#ca-purge' ).length || mw.config.get( 'wgNamespaceNumber' ) < 0 ) { return; }	var node = mw.util.addPortletLink(		'p-cactions',		mw.util.getUrl( null, { action: 'purge' } ),		messages.tabName,		'ca-purge',		messages.tabDescription	); $( node ).on( 'click', function ( e ) {		new mw.Api.post( { action: 'purge', titles: mw.config.get( 'wgPageName' ) } )		.then( function { location.reload; }, function { mw.notify( messages.errorMessage, { type: 'error' } ); } );		e.preventDefault;	} ); } );