Autres langues
Autres actions
m (Fixing bug in display of refresh options) |
m (1 version importée) |
(Aucune différence)
|
Dernière version du 24 juin 2023 à 14:05
/**
* 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: 'Soft refresh',
hpurge: 'Hard refresh',
nulled: 'Null edit'
},
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 ) );