MediaWiki:TagRightsManagement.js

/** * Allow managing user groups from Cosmos header tags. * * @author Universal Omega */

function removeGroups(group){ mw.loader.using(['mediawiki.api'], function { var params = {		action: 'userrights',		user: mw.config.get("wgPageName").replace('User:', ).replace('User_profile:',),		remove: group,		reason: 'removed ' + mw.config.get("wgPageName").replace('User:', ).replace('User_profile:',) + ' from the ' + group + ' group',		format: 'json'	},	api = new mw.Api;

api.postWithToken( 'userrights', params ).done( function ( data ) {       alert(group + ' successfully removed from ' + mw.config.get("wgPageName").replace('User:', ).replace('User_profile:',)) } ); }); } function showall{ mw.loader.using(['mediawiki.api'], function { $('.tag').hide; var params = { action: 'query', list: 'users', ususers: mw.config.get("wgPageName").replace('User:', ).replace('User_profile:',), usprop: 'groups', format: 'json' },	api = new mw.Api;

api.get( params ).done( function ( data ) { var groups = data.query.users[0].groups,   g; for ( g in groups ) { if(groups[g] !== 'bureaucrat' && groups[g] !== 'autoconfirmed' && groups[g] !== '*' && groups[g] !== 'user' && groups[g] !== 'founder' && groups[g] !== 'owner' && groups[g] !== 'content_moderators' && groups[g] !== 'checkuser' && groups[g] !== 'steward' && groups[g] !== 'interwiki-admin' && groups[g] !== 'oversight' && groups[g] !== 'globalsysop' && groups[g] !== 'sysadmin'){      $('.hgroup').append('' + groups[g] + ' '); }    } if(usergroups.sort.join(',') !== removableusergroups.sort.join(',')){   $('.hgroup').append('Show All '); }   $('.hgroup').append('Cancel ');

} ); }); } function showallgroups{ mw.loader.using(['mediawiki.api'], function {

$('.tag').hide; var params = { action: 'query', list: 'users', ususers: mw.config.get("wgPageName").replace('User:', ).replace('User_profile:',), usprop: 'groups', format: 'json' },	api = new mw.Api;

api.get( params ).done( function ( data ) { var groups = data.query.users[0].groups,   g; for ( g in groups ) { if(groups[g] !== '*' && groups[g] !== 'user' && groups[g] !== 'founder' && groups[g] !== 'owner' && groups[g] !== 'content_moderators'){      $('.hgroup').append('' + groups[g] + ' ');    } } var globalparams = {		action: 'query',		meta: 'globaluserinfo',		guiuser: mw.config.get("wgPageName").replace('User:', ).replace('User_profile:',),		guiprop: 'groups',		format: 'json'	},	api = new mw.Api;

api.get( globalparams ).done( function ( data ) { var globalgroups = data.query.globaluserinfo.groups,   gg; for ( gg in globalgroups ) { if(globalgroups[gg] !== '*' && globalgroups[gg] !== 'user' && globalgroups[gg] !== 'founder' && globalgroups[gg] !== 'owner' && globalgroups[gg] !== 'content_moderators'){      $('.hgroup').append('' + globalgroups[gg] + ' ');    }    } $('.hgroup').append('Cancel ');

}); } ); }); } function addGroups(group){ var params = {		action: 'userrights',		user: mw.config.get("wgPageName").replace('User:', ).replace('User_profile:',),		add: group,		reason: 'added ' + mw.config.get("wgPageName").replace('User:', ).replace('User_profile:',) + ' to the ' + group + ' group',		format: 'json'	},	api = new mw.Api;

api.postWithToken( 'userrights', params ).done( function ( data ) {       alert(group + ' successfully added to ' + mw.config.get("wgPageName").replace('User:', ).replace('User_profile:',))

} ); } function allGroups{ mw.loader.using(['mediawiki.api'], function { $('.tag').hide;

var params = { action: "query", meta: "siteinfo", siprop: 'usergroups', format: "json" }, api = new mw.Api;

api.get( params ).done( function ( data ) { var groups = data.query.usergroups,   g; for ( g in groups ) { if(groups[g].name !== 'bureaucrat' && groups[g].name !== 'autoconfirmed' && groups[g].name !== '*' && groups[g].name !== 'user' && groups[g].name !== 'founder' && groups[g].name !== 'owner' && groups[g].name !== 'content_moderators' && groups[g].name !== 'checkuser' && groups[g].name !== 'steward' && groups[g].name !== 'interwiki-admin' && groups[g].name !== 'oversight' && groups[g].name !== 'globalsysop' && groups[g].name !== 'sysadmin' && window.usergroups.includes(groups[g].name) === false){      $('.hgroup').append('' + groups[g].name + ' '); }    } if(window.usergroups.length > 0){     $('.hgroup').append('Current Groups '); }  $('.hgroup').append('Cancel ');

} ); }); } function revertTags{ $('.tag').show; $('.tag.tag-all,.tag.tag-all-groups,.tag-all_groups').remove; if((window.removableusergroups.length > 0) || (!mw.config.get('wgUserGroups').includes('bureaucrat') && !window.usergroups.length > 0)){ $('.tag-show-all_groups').remove; }

} $(function{ mw.loader.using(['mediawiki.api'], function { var params = { action: 'query', list: 'users', ususers: mw.config.get("wgPageName").replace('User:', ).replace('User_profile:',), usprop: 'groups', format: 'json' },	api = new mw.Api;

api.get( params ).done( function ( data ) { var groups = data.query.users[0].groups,   g;    window.usergroups=[], window.removableusergroups = []; for ( g in groups ) { if(groups[g] !== '*' && groups[g] !== 'user'){    window.usergroups.push(groups[g]); } if(groups[g] !== 'bureaucrat' && groups[g] !== 'autoconfirmed' && groups[g] !== '*' && groups[g] !== 'user' && groups[g] !== 'founder' && groups[g] !== 'owner' && groups[g] !== 'content_moderators' && groups[g] !== 'checkuser' && groups[g] !== 'steward' && groups[g] !== 'interwiki-admin' && groups[g] !== 'oversight' && groups[g] !== 'globalsysop' && groups[g] !== 'sysadmin'){    window.removableusergroups.push(groups[g]); }    } var globalparams = {		action: 'query',		meta: 'globaluserinfo',		guiuser: mw.config.get("wgPageName").replace('User:', ).replace('User_profile:',),		guiprop: 'groups',		format: 'json'	},	api = new mw.Api;

api.get( globalparams ).done( function ( data ) { var globalgroups = data.query.globaluserinfo.groups,   gg; for ( gg in globalgroups ) { if(globalgroups[gg] !== '*' && globalgroups[gg] !== 'user'){    window.usergroups.push(globalgroups[gg]); } if(globalgroups[gg] !== 'bureaucrat' && globalgroups[gg] !== 'autoconfirmed' && globalgroups[gg] !== '*' && globalgroups[gg] !== 'user' && globalgroups[gg] !== 'founder' && globalgroups[gg] !== 'owner' && globalgroups[gg] !== 'content_moderators' && globalgroups[gg] !== 'checkuser' && globalgroups[gg] !== 'steward' && globalgroups[gg] !== 'interwiki-admin' && globalgroups[gg] !== 'oversight' && globalgroups[gg] !== 'globalsysop' && globalgroups[gg] !== 'sysadmin'){    window.removableusergroups.push(globalgroups[gg]); }    }

if(mw.config.get('wgUserGroups').includes('bureaucrat')){

if(window.removableusergroups.length > 0){ $('.hgroup').append('Remove Groups '); }    $('.hgroup').append('Add Groups '); if(window.usergroups.length > 0 && !window.removableusergroups.length > 0){ $('.hgroup').append('Show All '); } }else if(window.usergroups.length > 0){ $('.hgroup').append('All Groups '); } }); }); }); }); mw.util.addCSS('[onclick="revertTags;"]{\n   background-color:red !important;\n}\n[onclick="allGroups;"]{\n    background-color:green !important;\n}\n[onclick="showall;"],[onclick="showallgroups;"]{\n    background-color:blue !important;\n}\n.tag-all-groups,.tag-all,.tag-remove_groups,.tag-add_groups,[onclick="showallgroups;"]{\n    cursor:pointer;\n}\n.tag-all-groups:not([onclick="revertTags;"]):not([onclick="allGroups;"]):hover{\n    color:green;\n}\n.tag-all:not([onclick="revertTags;"]):not([onclick="allGroups;"]):hover{\n    color:red;\n}\n[class*="team_lead"] ~ .tag-remove_groups,[class*="team_lead"] ~ .tag-add_groups{\n    display:none;\n}');