MediaWiki:Gadget-purgetab.js

Nota: dopo aver pubblicato, potrebbe essere necessario pulire la cache del proprio browser per vedere i cambiamenti.

  • Firefox / Safari: tieni premuto il tasto delle maiuscole Shift e fai clic su Ricarica, oppure premi Ctrl-F5 o Ctrl-R (⌘-R su Mac)
  • Google Chrome: premi Ctrl-Shift-R (⌘-Shift-R su un Mac)
  • Internet Explorer / Edge: tieni premuto il tasto Ctrl e fai clic su Aggiorna, oppure premi Ctrl-F5
  • Opera: premi Ctrl-F5.
/**
 * Add "Purge" content action link.
 *
 * Dependencies: mediawiki.util, mediawiki.api
 *
 * @source https://www.mediawiki.org/wiki/Snippets/Purge_action
 * @revision 2016-05-22
 */
$( function () {
	if ( $( '#ca-purge' ).length || !mw.config.get( 'wgIsArticle' ) ) return;
	
	// bottone per purge
	var node = mw.util.addPortletLink(
		'p-cactions',
		mw.util.getUrl( null, { action: 'purge' } ),
		mw.config.get( 'skin' ).startsWith('vector') ? 'Purge' : '*',
		'ca-purge',
		'Pulisci la cache lato server di questa pagina',
		'*'
	);
	$(node).on( 'click', function (e) {
		new mw.Api().post( { action: 'purge', titles: mw.config.get( 'wgPageName' ) } ).then(function () {
			location.reload();
		}, function () {
			mw.notify( 'Purge failed', { type: 'error' } );
		});
		e.preventDefault();
	});
	$(".animazione").css("color","#0b0080").on( 'click', function (e) {
		new mw.Api().post( { action: 'purge', titles: mw.config.get( 'wgPageName' ) } ).then(function () {
			location.reload();
		}, function () {
			mw.notify( 'Purge failed', { type: 'error' } );
		});
		e.preventDefault();
	});
	
	// bottone per salvataggio a vuoto
	if (mw.config.get('wgCanonicalNamespace') != 'Index') {
		var node2 = mw.util.addPortletLink(
			'p-cactions',
			'#',
			mw.config.get( 'skin' ).startsWith('vector') ? 'Rebuild' : '*',
			'ca-rebuild',
			'Esegui un salvataggio a vuoto di questa pagina, per forzarne l\'aggiornamento',
			null
		);
		
		$(node2).on( 'click', function (e) {
			var testo = $.ajax({
				url: "/w/index.php?action=raw&title=" + mw.config.get( 'wgPageName' ),
				async: false
				}).responseText;
				
			$.ajax({
		    	url: mw.util.wikiScript( 'api' ),
		    	data: {
		        	format: 'json',
		        	action: 'edit',
		        	title: mw.config.get( 'wgPageName' ),
		        	summary: 'Salvataggio a vuoto',
		        	text: testo,
		        	token: mw.user.tokens.get('csrfToken')
		    	},
		    	dataType: 'json',
		    	type: 'POST',
		    	success: function( data ) {
					console.log('Salvataggio a vuoto effettuato');
					location.reload();
				},
				error: function( xhr ) {
					console.log('Salvataggio a vuoto fallito');
				}
			});
			e.preventDefault();
		});
	}
	
	links = $();
	if (mw.config.get('wgCategories').includes('Lavoro sporco') || mw.config.get('wgCategories').includes('Lavoro sporco su Wikidata')) {
		$("#mw-content-text li a:not(.new)[href^='/wiki/']").each(function() {
			titolo = $(this).attr('title');
			href = $(this).attr('href').replace('/wiki/', '');
			if (typeof titolo == 'undefined') {
				titolo = href;
			}
			if (typeof titolo != 'undefined' && titolo.indexOf('Speciale:') !== 0 && href.indexOf('/w/index.php') !== 0) {
				link = $('<a class="rebuildButton" href="javascript:void(0)" title="Salvataggio a vuoto di questa pagina (rebuild)" data-title="' + titolo.replace(/"/g, '&quot;') + '">[R]</a>');
				$(this).after(link).after(' ');
				links = links.add(link);
			}
		});
	}
	
	$(links).on( 'click', function (e) {
		var testo = $.ajax({
			url: "/w/index.php?action=raw&title=" + $(this).data('title'),
			async: false
			}).responseText;
			
		$.ajax({
	    	url: mw.util.wikiScript( 'api' ),
	    	data: {
	        	format: 'json',
	        	action: 'edit',
	        	title: $(this).data('title'),
	        	summary: 'Salvataggio a vuoto',
	        	text: testo,
	        	token: mw.user.tokens.get('csrfToken')
	    	},
	    	dataType: 'json',
	    	type: 'POST',
	    	success: function( data ) {
				console.log('Salvataggio a vuoto effettuato');
			},
			error: function( xhr ) {
				console.log('Salvataggio a vuoto fallito');
			}
		});
		e.preventDefault();
	});
});