Difference between revisions of "MediaWiki:Gadget-purgetab.js"

From CryGaia Wiki
Jump to: navigation, search
(Created page with "* * Add "Purge" content action link. * * Dependencies: mediawiki.util * * @source www.mediawiki.org/wiki/Snippets/Purge_action * @revision 2014-05-14: $( function (...")
 
 
Line 2: Line 2:
 
  * Add "Purge" content action link.
 
  * Add "Purge" content action link.
 
  *
 
  *
  * Dependencies: mediawiki.util
+
  * Dependencies: mediawiki.util, mediawiki.api, mediawiki.notify
 
  *
 
  *
  * @source www.mediawiki.org/wiki/Snippets/Purge_action
+
  * @source https://www.mediawiki.org/wiki/Snippets/Purge_action
  * @revision 2014-05-14
+
  * @revision 2016-05-22
 
  */
 
  */
 
$( function () {
 
$( function () {
    if ( !$( '#ca-purge' ).length && mw.config.get( 'wgIsArticle' ) ) {
+
if ( $( '#ca-purge' ).length || !mw.config.get( 'wgIsArticle' ) ) return;
        mw.util.addPortletLink(
+
var node = mw.util.addPortletLink(
            'p-cactions',
+
'p-cactions',
            mw.util.wikiScript() + '?' + $.param({ title: mw.config.get( 'wgPageName' ), action: 'purge' }),
+
mw.util.getUrl( null, { action: 'purge' } ),
            mw.config.get( 'skin' ) === 'vector' ? 'Purge' : '*',
+
mw.config.get( 'skin' ) === 'vector' ? 'Purge' : '*',
            'ca-purge',
+
'ca-purge',
            'Purge the server cache of this page',
+
'Purge the server cache of this page',
            '*'
+
'*'
        );
+
);
    }
+
$(node).on( 'click', function (e) {
} );
+
new mw.Api().post( { action: 'purge', titles: mw.config.get( 'wgPageName' ) } ).then(function () {
 +
location.reload();
 +
}, function () {
 +
mw.notify( 'Purge failed', { type: 'error' } );
 +
});
 +
e.preventDefault();
 +
});
 +
});

Latest revision as of 00:49, 25 June 2018

/**
 * Add "Purge" content action link.
 *
 * Dependencies: mediawiki.util, mediawiki.api, mediawiki.notify
 *
 * @source https://www.mediawiki.org/wiki/Snippets/Purge_action
 * @revision 2016-05-22
 */
$( function () {
	if ( $( '#ca-purge' ).length || !mw.config.get( 'wgIsArticle' ) ) return;
	var node = mw.util.addPortletLink(
		'p-cactions',
		mw.util.getUrl( null, { action: 'purge' } ),
		mw.config.get( 'skin' ) === 'vector' ? 'Purge' : '*',
		'ca-purge',
		'Purge the server cache of this page',
		'*'
	);
	$(node).on( 'click', function (e) {
		new mw.Api().post( { action: 'purge', titles: mw.config.get( 'wgPageName' ) } ).then(function () {
			location.reload();
		}, function () {
			mw.notify( 'Purge failed', { type: 'error' } );
		});
		e.preventDefault();
	});
});