มีเดียวิกิ:Gadget-PurgeTab.js

จาก วิกิซอร์ซ

หมายเหตุ: หลังเผยแพร่ คุณอาจต้องล้างแคชเว็บเบราว์เซอร์ของคุณเพื่อดูการเปลี่ยนแปลง

  • ไฟร์ฟอกซ์ / ซาฟารี: กด Shift ค้างขณะคลิก Reload หรือกด Ctrl-F5 หรือ Ctrl-R (⌘-R บนแมค)
  • กูเกิล โครม: กด Ctrl-Shift-R (⌘-Shift-R บนแมค)
  • อินเทอร์เน็ตเอกซ์พลอเรอร์ และ Edge: กด Ctrl ค้างขณะคลิก Refresh หรือกด Ctrl-F5
  • โอเปร่า: กด Ctrl-F5
jQuery(document).ready(function () {

	if (!mw.config.get('wgArticleId'))
		return;
	var link;

	link = mw.util.addPortletLink(
		'p-cactions', mw.util.getUrl(mw.config.get('wgPageName'), { 'action': 'purge' }),
		(mw.user.options.get( 'skin' ) == 'vector' ) ? "Purge" : "*",
		'ca-purge', "Purge cache for this page", '*'
	);

	link = mw.util.addPortletLink(
	// not sure if raw link is valid for extra params  Using wikiScript instead of getUrl
		'p-cactions', mw.util.wikiScript('api') + '?action=purge&titles=' + mw.config.get('wgPageName') + '&forcerecursivelinkupdate=1&redirects=1',
		(mw.user.options.get( 'skin' ) == 'vector' ) ? "Hard purge" : "**",
		'ca-purge-forcerecursivelinkupdate', "Purge with forced recursive-link table update", ','
	);

	link.addEventListener('click', function (ev) {
		mw.loader.using( 'mediawiki.api' ).done(function() {
			( new mw.Api() ).post({
				action: 'purge',
				pageids: mw.config.get('wgArticleId'),
				forcerecursivelinkupdate: 1,
				redirects: 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.notify('<b>Hard purge failed</b>: ' + mesg);
				console.error(arguments);
			} );
		} );
		ev.preventDefault();
	}, false);

	link = mw.util.addPortletLink(
		'p-cactions', 'javascript:void window.warranty',
		(mw.user.options.get( 'skin' ) == 'vector' ) ? "Null edit" : "***",
		'ca-nulledit', "Null edit", '0'
	);

	link.addEventListener('click', function (ev) {
		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(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.notify('<b>Null edit failed</b>: ' + mesg);
				console.error(arguments);
			} );
		} );
		ev.preventDefault();
	}, false);

} );