// <nowiki>
// isolating this until I can debug it. Then I'll add it to NPPLinks.js
mw.loader.using( ['mediawiki.util', 'mediawiki.api'] ).then( function () {
return; // this code doesn't work because `require` is not available here.
// this code borrowed from https://www.mediawiki.org/wiki/API:Purge
var request = require('request').defaults({jar: true}),
url = "https://en.wikipedia.org/w/api.php";
function purge(title) {
var params = {
action: "purge",
titles: title,
format: "json"
};
request.post({ url: url, form: params }, function (error, res, body) {
if (error) {
return;
}
console.log(body);
});
}
// end borrowed code
function escapeDoubleQuotes(input) {
return input.replace(/"/g, '"');
}
let pageName = mw.config.get('wgPageName'); // has underscores instead of spaces. has namespace prefix
let underscores = encodeURIComponent(pageName);
let links = `<li><a onclick="purge("`+escapeDoubleQuotes(pageName)+`");">Purge (for orphan check)</a></li>`;
// using this ugly monstrosity because mw.util.addPortletLink does not support adding entire menus, and the parent script needs to add a menu
$('#p-navigation').after(`
<nav id="p-purge-button" class="mw-portlet mw-portlet-purge-button vector-menu vector-menu-portal portal" aria-labelledby="p-purge-button-label" role="purge-button">
<h3 id="p-purge-button-label" class="vector-menu-heading">
<span>Purge Test</span>
</h3>
<div class="vector-menu-content">
<ul class="vector-menu-content-list">
`+links+`
</ul>
</div>
</nav>
`);
});
// </nowiki>