ElEditors, Interface administrators, Administrators
70,778
edits
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
* Add "Purge" content action link. | * Add "Purge" content action link. | ||
* | * | ||
* Dependencies: mediawiki. | * Dependencies: mediawiki.util, mediawiki.api | ||
* | * | ||
* @source https://www.mediawiki.org/wiki/Snippets/Purge_action | * @source https://www.mediawiki.org/wiki/Snippets/Purge_action | ||
* @revision | * @revision 2020-04-04 | ||
*/ | */ | ||
$( function () { | $( function () { | ||
if ( $( '#ca-purge' ).length || mw.config.get( 'wgNamespaceNumber' ) < 0 ) return; | |||
if ( $( '#ca-purge' ).length || mw.config.get( 'wgNamespaceNumber' ) < 0 ) | |||
var node = mw.util.addPortletLink( | var node = mw.util.addPortletLink( | ||
'p-cactions', | 'p-cactions', | ||
mw.util.getUrl( null, { action: 'purge' } ), | mw.util.getUrl( null, { action: 'purge' } ), | ||
'Purge', | |||
'ca-purge', | 'ca-purge', | ||
'Purge the server cache of this page' | |||
); | ); | ||
$( node ).on( 'click', function ( e ) { | $( node ).on( 'click', function ( e ) { | ||
new mw.Api().post( { | new mw.Api().post( { action: 'purge', titles: mw.config.get( 'wgPageName' ) } ).then( function () { | ||
location.reload(); | location.reload(); | ||
}, function () { | }, function () { | ||
mw.notify( | mw.notify( 'Purge failed', { type: 'error' } ); | ||
} ); | } ); | ||
e.preventDefault(); | e.preventDefault(); | ||
} ); | } ); | ||
} ); | } ); |