MediaWiki:AddBlockUserTag/code.js

/** * AddBlockUserTag * * @Purpose Adds a user masthead tag to easily block users * @Author  TheGoldenPatrik1 */ $(function {   var config = mw.config.get([ 'skin', 'wgUserGroups', 'wgUserLanguage', 'wgNamespaceNumber', 'wgCanonicalSpecialPageName', 'wgUserName', 'wgTitle' ]);   if ( !/(sysop|staff|helper|vstf|global-discussions-moderator)/.test(config.wgUserGroups) ) {       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:Block/' + getUser })                   .text(text)                    .css({ float: 'right', color: 'inherit', marginTop: '15px', marginRight: '-15px' })                   .appendTo('.UserProfileMasthead hgroup');                break;            case 'monobook':                $('')                    .attr('href', '/wiki/Special:Block/' + 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: 'block',            amlang: config.wgUserLanguage        }).done(function(d) {            if(!d.error) {                init(d.query.allmessages[0]['*']);            }        }); }); });