User:Tark/common.js: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
mNo edit summary
mNo edit summary
 
Line 177: Line 177:


// Begin Purge link
// Begin Purge link
// Adapted from https://www.mediawiki.org/wiki/MediaWiki:Gadget-purgetab.js
var purgeLink = {
if (mw.config.get("wgIsArticle")) {
    init: function () {
    mw.util.addPortletLink(
        if (mw.config.get("wgIsArticle")) {
        "p-views",
            var purgeBtn = mw.util.addPortletLink("p-cactions",
        mw.util.wikiScript() + "?" + $.param({ title: mw.config.get("wgPageName"), action: "purge" }),
                mw.util.wikiScript() + "?" + $.param({ title: mw.config.get("wgPageName"), action: "purge" }),
        mw.config.get("skin") === "vector" ? "Purge cache" : "*",
                "Purge",
        "ca-purge",
                "ca-purge",
        "Purge the server cache of this page",
                "Purge the server cache of this page"
         "*"
            );
    );
 
}
            // Quick Purge
            var qpurgeBtn = mw.util.addPortletLink("p-views",
                "#",
                "Quick Purge",
                "ca-purge",
                "Quickly purge the server cache of this page (skips confirmation)"
            );
 
            qpurgeBtn.classList.add("collapsible");
            qpurgeBtn.addEventListener("click", purgeLink.handleQpurge.bind(this));
        }
    },
    handleQpurge: function (event) {
        event.preventDefault();
 
        new mw.Api().post({ action: "purge", titles: mw.config.get("wgPageName") }).then(function (data) {
            mw.notify("Quick Purge: Success!", { type: "success" });
         }).catch(function (error, data) {
            mw.notify("Quick Purge: " + (data.error ? data.error.info : error), { type: "error" });
        });
    },
};
$(purgeLink.init);
// End Purge link
// End Purge link


Navigation menu