Difference between revisions of "MediaWiki:Gadget-AddArchiveCategory.js"
Jump to navigation
Jump to search
Sfosteriam (talk | contribs) (Add a script to tag the current page with the "Archived" category.) |
(No difference)
|
Revision as of 07:23, 19 February 2025
mw.loader.using(['mediawiki.util', 'mediawiki.api'], function () {
var api = new mw.Api();
function addCategory() {
var text = '[[Category:Archived]]';
api.edit(mw.config.get('wgPageName'), function (revision) {
return {
text: revision.content + '\n' + text,
summary: 'Adding category ' + categoryName,
minor: true
};
}).then(function () {
window.location.reload(); // Reload the page to see the new category
}, function (e) {
mw.notify('Failed to add category: ' + e);
});
}
$(document).ready(function () {
mw.util.addPortletLink(
'p-tb', // sidebar section (portlet id).
'#', // href for the link (will trigger javascript instead)
'Add Archived Category', // link text.
'ca-add-archive-category', // unique identifier for the link.
'Add a category to this page' // tooltip text.
);
$('#ca-add-archive-category').click(function (e) {
e.preventDefault();
addCategory();
});
});
});