MediaWiki:User Tags.js

/** * Displays the user groups on the main user and main user talk pages. * @author Becasita * @contact User talk:Becasita */ ( function _gadgetShowUserGroupsTags( $, mw, console ) {	"use strict";

var ShowUserGroupsTags = { GROUPS: { blocked: 'Blocked', Bot: 'Bot', AW_Staff: 'Staff', Translator: 'Translator', CVU: 'CVU', Bureaucrat: 'Bcrat', Administrator: 'Admin', SocialModerator: 'Social mod', ContentModerator: 'Content mod', Rollback: 'Rollback' },

config: mw.config.get( [			'wgNamespaceNumber',			'wgTitle'		] ),

$container: $( ' ', {			id: 'user-group-tags'		} ),

addTag: function( group ) { ShowUserGroupsTags.$container.append(				$( ' ', { id: 'user-group-tag__' + group, 'class': 'user-group-tag', text: ShowUserGroupsTags.GROUPS[ group ] } )			);		},

addTags: function( data ) { ( data.query.users[ 0 ].groups || [] ).forEach( function( group ) {				if ( ShowUserGroupsTags.GROUPS[ group ] ) {					ShowUserGroupsTags.addTag( group );				}			} );

if ( data.query.users[ 0 ].blockexpiry ) { ShowUserGroupsTags.addTag( 'blocked' ); }		},

fail: function { mw.log( '[Gadget] ShowUserGroupsTags - Failed to get user groups.', arguments ); },

execute: function { new mw.Api .get( {					action: 'query',					list: 'users',					ususers: ShowUserGroupsTags.config.wgTitle,					usprop: [						'groups',						'blockinfo'					].join( '|' )				} ) .done( ShowUserGroupsTags.addTags ) .fail( ShowUserGroupsTags.fail ) ;		},

init: function { if ( ~[ 2, 3 ].indexOf( ShowUserGroupsTags.config.wgNamespaceNumber ) ) { $( '#firstHeading' ).append( ShowUserGroupsTags.$container ); $( '#profile-top' ).append( ShowUserGroupsTags.$container );

mw.loader.using( 'mediawiki.api' ).done( ShowUserGroupsTags.execute ); }		}	};

$( ShowUserGroupsTags.init );

} )( window.jQuery, window.mediaWiki, window.console );