MediaWiki:Gadget-purgetab.js
Jump to navigation
Jump to search
Note: You may have to bypass your browser’s cache to see the changes. In addition, after saving a sitewide CSS file such as MediaWiki:Common.css, it will take 5-10 minutes before the changes take effect, even if you clear your cache.
- Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
- Konqueror and Chrome: click Reload or press F5;
- Opera: clear the cache in Tools → Preferences;
- Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.
- The following documentation is located at MediaWiki:Gadget-purgetab.js/documentation. [edit]
- This script is a part of the
purgetab
gadget (edit definitions)- Description (edit): Add a "*" tab to the top of the page (or under "view" in the sidebar), which purges the page's cache when followed.
- Useful links: subpage list • links • redirects
See also: Special:Gadgets.
// {{documentation}}
jQuery(document).ready(function() {
if (!mw.config.get('wgArticleId'))
return;
var link;
var portletIdToAdd = $("#p-cactions").length != 0 ? "p-cactions" : "p-views";
link = mw.util.addPortletLink(
portletIdToAdd, mw.util.getUrl(mw.config.get('wgPageName'), {
'action': 'purge'
}),
(mw.config.get('skin') == "vector") ? "Purge" : "*",
'ca-purge', "Purge cache for this page", '*'
);
var api = new mw.Api();
link = mw.util.addPortletLink(
portletIdToAdd, mw.util.getUrl(mw.config.get('wgPageName'), {
'action': 'purge',
'forcelinkupdate': 1
}), // not sure if raw link works...
(mw.config.get('skin') == "vector") ? "Hard purge" : "**",
'ca-purge-forcelinkupdate', "Purge with forced link table update", ','
);
link.addEventListener('click', function(ev) {
api.post({
action: 'purge',
pageids: mw.config.get('wgArticleId'),
forcelinkupdate: 1
}).then(function() {
location.reload();
}, 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);
console.error(arguments);
});
ev.preventDefault();
}, false);
link = mw.util.addPortletLink(
portletIdToAdd, 'javascript:void window.warranty',
(mw.config.get('skin') == "vector") ? "Null edit" : "***",
'ca-nulledit', "Null edit", '0'
);
link.addEventListener('click', function(ev) {
api.post({
action: 'edit',
pageid: mw.config.get('wgArticleId'),
appendtext: '',
watchlist: 'nochange',
nocreate: '1',
token: mw.user.tokens.get('csrfToken')
}).then(function() {
location.reload();
}, 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>Null edit failed</b>: ' + mesg);
console.error(arguments);
});
ev.preventDefault();
}, false);
});