MediaWiki:Gadget-RefreshTab.js

Página de la interfaz de MediaWiki

Nota: Después de publicar, quizás necesite actualizar la caché de su navegador para ver los cambios.

  • Firefox/Safari: Mantenga presionada la tecla Shift mientras pulsa el botón Actualizar, o presiona Ctrl+F5 o Ctrl+R (⌘+R en Mac)
  • Google Chrome: presione Ctrl+Shift+R (⌘+Shift+R en Mac)
  • Internet Explorer/Edge: mantenga presionada Ctrl mientras pulsa Actualizar, o presione Ctrl+F5
  • Opera: Presiona Ctrl+F5.
/**
 * Gadget to add tools to the toolbar for purging pages
 */

( function ( $, mw ) {

	$( function () {

		var link,

			strings = {
				long: {
					purge: 'Renovación suave de caché',
					hpurge: 'Renovación profunda de caché',
					nulled: 'Edición nula'
				},
				short: {
					purge: '*',
					hpurge: '**',
					nulled: '***'
				},
				help: {
					purge: 'Purgar la caché de esta página',
					hpurge: 'Purgar la caché de esta página en todos los lugares en los que aparece',
					nulled: 'Realizar una edición nula en esta página'
				}
			},

			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 ) );