MediaWiki:AddUserRightsTag/code.js

/** * AddUserRightsTag.js * * Adds easy way to add user rights on the masthead * @author: w:User:Algorithmz */ $(function {   var config = mw.config.get([ 'skin', 'wgUserLanguage', 'wgNamespaceNumber', 'wgCanonicalSpecialPageName', 'wgUserName', 'wgTitle' ]);   if([2, 3, 500, 1200, -1].indexOf(config.wgNamespaceNumber) === -1) {        return;    }    function getUser {        switch(config.wgCanonicalSpecialPageName) {            case 'Contributions': return config.wgTitle.split('/')[1];            case 'Following':            case 'UserActivity':                return config.wgUserName;            default: return wgTitle;        }    }    function init(text) {        switch (config.skin) {            case 'oasis':            case 'wikia':                $('')                    .attr({ class: 'tag', href: '/wiki/Special:UserRights/' + getUser })                   .text(text)                    .css({ float: 'right', color: 'inherit', marginTop: '5px', marginRight: '-15px' })                   .appendTo('.UserProfileMasthead hgroup');                break;            case 'monobook':                $('')                    .attr('href', '/wiki/Special:UserRights/' + getUser)                    .text('[' + text + ']')                        .css({ float: 'right', fontSize: '13px' })                   .appendTo('#firstHeading');                break;        }    }    mw.loader.using('mediawiki.api').then(function { new mw.Api.get({           action: 'query',            meta: 'allmessages',            ammessages: 'userrights',            amlang: config.wgUserLanguage        }).done(function(d) {            if(!d.error) {                init(d.query.allmessages[0]['*']);            }        }); }); });