MediaWiki:Gadget-PurgeTab.js
Jump to navigation
Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Cmd-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (Cmd-Shift-R on a Mac)
- Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Clear the cache in Tools → Preferences
For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/* MediaWiki:Gadget-PurgeTab.js
*
* Gadget to add tools to the toolbar for purging pages
*/
$(function () {
if (mw.config.get('wgCanonicalNamespace') === "File" && mw.config.get('wgArticleId') === 0) {
// Active on File: pages for non-existent files too.
// FIXME: This logic is pretty awkward.
} else if (!mw.config.get('wgArticleId')) {
return;
}
let purgePortlet = mw.util.addPortletLink(
'p-cactions', '#', 'Purge', 'ca-purge',
'Purge cache for this page', '*'
);
$(purgePortlet).on('click', e => {
doPurge(false);
e.preventDefault();
});
let hardpurgePortlet = mw.util.addPortletLink(
'p-cactions', '#', 'Hard purge', 'ca-purge-hardpurge',
'Purge with forced recursive-link table update', ','
);
$(hardpurgePortlet).on('click', e => {
doPurge(true);
e.preventDefault();
});
let nulleditPortlet = mw.util.addPortletLink(
'p-cactions', '#', 'Null edit', 'ca-nulledit',
'Perform a null edit on this page', '0'
);
$(nulleditPortlet).on('click', e => {
doNullEdit();
e.preventDefault();
});
});
function doPurge (hard) {
let params = {
action: 'purge',
pageids: mw.config.get('wgArticleId')
};
if (hard) {
params.forcerecursivelinkupdate = 1;
params.redirects = 1;
}
new mw.Api().post(params)
.catch(httpErrorHandler)
.then(() => location.reload());
}
function doNullEdit () {
new mw.Api().postWithEditToken({
action: 'edit',
pageid: mw.config.get('wgArticleId'),
appendtext: '',
watchlist: 'nochange',
nocreate: '1',
})
.catch(httpErrorHandler)
.then(() => location.reload());
}
function httpErrorHandler (code, details) {
let msg;
switch (code) {
case 'http':
msg = 'HTTP error: ' + details.xhr.statusText;
break;
case 'ok-but-empty':
msg = 'Received empty response.';
break;
default:
msg = details.error.info;
}
mw.notify(msg, {title: 'Purge failed', type: 'error', tag: 'purge'});
}