MediaWiki:Gadget-minipedia.js
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/**
* Add "Purge" content action link.
*
* Dependencies: mediawiki.util
*
* @source www.mediawiki.org/wiki/Snippets/Purge_action
* @revision 2014-05-14
*/
$.when( mw.loader.using( [ 'mediawiki.util', 'mediawiki.api', 'oojs-ui-core' ] ), $.ready ).then( function () {
// global configuration file
window.MiniPedia = window.MiniPedia || {};
// shortcut for the global configuration file (mp = mini-pedia)
var mp = window.MiniPedia;
// default namespace name
mp.namespace = mp.namespace || 'Mini';
// work only in the main namespace
var ns = mw.config.get( 'wgNamespaceNumber' );
if( ns !== 0 ) {
return;
}
// add a "Minipedia"
var miniVersionPortletLink = mw.util.addPortletLink(
'p-cactions',
'#',
'Mini Version',
'ca-minipedia',
'Open Minipedia',
'n'
);
var pageName = mw.config.get( 'wgPageName' );
var miniPageName = mp.namespace + ':' + pageName;
/**
* Check if a page title already exists
*
* @param title Page title
* @param callback Callback with one boolean argument telling if the page title exists or not
*/
function pageExists( title, callback ) {
// prepare the API request
var request = {
action: 'query',
prop: 'info',
titles: title
};
// make the API request
( new mw.Api() ).get( request ).done( function ( response ) {
// no response no party
if( !response.query ) {
throw 'no response';
}
var page;
for( var i in response.query ) {
page = response.query[i];
if( page.pageid && page.pageid > 0 ) {
// exists
callback( true );
}
}
// does not exist
callback( false );
} );
};
// on the mini toolback click, check if a mini version exists
$( miniVersionPortletLink ).click( function() {
// check if the mini version exists
pageExists( miniPageName, function( miniPageExists ) {
if( miniPageExists ) {
// do something
} else {
// do something else
}
} );
} );
} );