Jump to content

User:Ilmari Karonen/metarightslog.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Add a link to the user rights log on meta into the toolbox on user and user talk pages
// as well as on Special:Log and Special:Contributions.

$(function () {
    var userName = "";
    if ( wgCanonicalNamespace == "User" || wgCanonicalNamespace == "User_talk" ) {
        if ( wgTitle.indexOf("/") >= 0 ) return;
        userName = wgTitle;
    }
    else if ( wgCanonicalNamespace == "Special" && wgCanonicalSpecialPageName == "Log" ) {
        var pageField = document.getElementById("page");
        if ( !pageField || pageField.value.substring(0,5) != "User:") return;
        userName = pageField.value.substring(5);
    }
    else if ( wgCanonicalNamespace == "Special" &&
              ( wgCanonicalSpecialPageName == "Contributions" ||
                wgCanonicalSpecialPageName == "DeletedContributions" ) ) {
        var contribsForm = document.forms[0];  // an ID or a name would be nice...
        if ( !contribsForm || !contribsForm.elements["target"] ) return;
        userName = contribsForm.elements["target"].value;
    }
    if ( !userName ) return;

    var metaPrefix = ( wgServer == "https://secure.wikimedia.org" ? wgServer + "/wikipedia/meta" : "http://meta.wikimedia.org" );
    mw.util.addPortletLink( "p-tb", metaPrefix + "/wiki/Special:Log?page=User:" + encodeURIComponent(userName) + "@enwiki",
                    "Meta user rights", "t-metarightslog", "User rights changes made by stewards for \"" + userName + "@enwiki\"" );
});