MediaWiki:Gadget-RefreshTab.js

Página de Interface do MediaWiki
Revisão de 22h15min de 30 de junho de 2022 por Forte (discussão | contribs) (Criou a página com "→‎* * Gadget to add tools to the toolbar for purging pages: ( function ( $, mw ) { $( function () { var link, strings = { long: { purge: 'Soft cache refresh', hpurge: 'Hard cache refresh', nulled: 'Null edit' }, short: { purge: '*', hpurge: '**', nulled: '***' }, help: { purge: 'Purge cache for this page', hpurge: 'Purge cache for this page everywhere it appears', nulled: 'Perform a null edi...")
(dif) ← Edição anterior | Revisão atual (dif) | Versão posterior → (dif)

Nota: Após publicar, você pode ter que limpar o "cache" do seu navegador para ver as alterações.

  • Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
  • Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
  • Internet Explorer/Edge: PressioneCtrl enquanto clica Recarregar, ou Pressione Ctrl-F5
  • Opera: Pressione Ctrl-F5.
/**
 * Gadget to add tools to the toolbar for purging pages
 */

( function ( $, mw ) {

	$( function () {

		var link,

			strings = {
				long: {
					purge: 'Soft cache refresh',
					hpurge: 'Hard cache refresh',
					nulled: 'Null edit'
				},
				short: {
					purge: '*',
					hpurge: '**',
					nulled: '***'
				},
				help: {
					purge: 'Purge cache for this page',
					hpurge: 'Purge cache for this page everywhere it appears',
					nulled: 'Perform a null edit on this page'
				}
			},

			stringType = ( mw.user.options.get( 'skin' ) === 'vector' ) ? 'long' : 'short',

			errorLog = function ( msg ) {
				/* eslint-disable-next-line no-console */
				console.error( msg );
			},

			afterPurgeFunction = function () {
				location.reload();
			},

			httpErrorHandler = function ( code, details ) {
				var mesg;
				switch ( code ) {
					case 'http':
						mesg = 'HTTP error: ' + details.xhr.statusText;
						break;
					case 'ok-but-empty':
						mesg = 'Received empty response.';
						break;
					default:
						mesg = details.error.info;
				}
				mw.util.jsMessage( '<b>Hard purge failed</b>: ' + mesg );
				errorLog( arguments );
			},

			doPurge = function ( hard ) {
				mw.loader.using( 'mediawiki.api' ).done( function () {
					var params = {
						action: 'purge',
						pageids: mw.config.get( 'wgArticleId' )
					};
					if ( hard ) {
						params.forcerecursivelinkupdate = 1;
						params.redirects = 1;
					}
					new mw.Api()
						.post( params )
						.then( afterPurgeFunction, httpErrorHandler );
				} );
			},

			doNullEdit = function () {
				mw.loader.using( 'mediawiki.api' ).done( function () {
					new mw.Api().post( {
						action: 'edit',
						pageid: mw.config.get( 'wgArticleId' ),
						appendtext: '',
						watchlist: 'nochange',
						nocreate: '1',
						token: mw.user.tokens.get( 'csrfToken' )
					} )
						.then( afterPurgeFunction, httpErrorHandler );
				} );
			};

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

		link = mw.util.addPortletLink(
			'p-cactions', '#', strings[ stringType ].purge,
			'ca-purge', strings.help.purge, '*'
		);

		link.addEventListener( 'click', function ( ev ) {
			doPurge( false );
			ev.preventDefault();
		}, false );

		link = mw.util.addPortletLink(
			'p-cactions', '#', strings[ stringType ].hpurge,
			'ca-purge-forcerecursivelinkupdate', strings.help.hpurge, ','
		);

		link.addEventListener( 'click', function ( ev ) {
			doPurge( true );
			ev.preventDefault();
		}, false );

		link = mw.util.addPortletLink(
			'p-cactions', '#', strings[ stringType ].nulled,
			'ca-nulledit', strings.help.nulled, '0'
		);

		link.addEventListener( 'click', function ( ev ) {
			doNullEdit();
			ev.preventDefault();
		}, false );

	} );

/* eslint-disable-next-line no-undef */
}( jQuery, mediaWiki ) );