Hoppa till innehållet

MediaWiki:Gadget-GroupIndicators.js

Från Wikipedia

OBS: Efter du har publicerat sidan kan du behöva tömma din webbläsares cache för att se ändringarna.

  • Firefox / Safari: Håll ned Skift och klicka på Uppdatera sidan eller tryck Ctrl-F5 eller Ctrl-R (⌘-R på Mac)
  • Google Chrome: Tryck Ctrl-Skift-R (⌘-Skift-R på Mac)
  • Edge Håll ned Ctrl och klicka på Uppdatera eller tryck Ctrl-F5.
  • Opera: Tryck Ctrl-F5.
$( function () {
	'use strict';
	var v = mw.config.get();
	var username = v.wgRelevantUserName;
	var text = 'This user is ';
	var autopatrolled = 'autopatrolled.';
	var rollbacker = 'a rollbacker.';
	var bot = 'a bot (with a bot flag).';
	var sysop = 'a sysop.';
	var bureaucrat = 'a bureaucrat.';
	var checkuser = 'a checkuser.';
	var oversight = 'an oversighter.';
	var interfaceadmin = 'an interface admin.';
	var globalrollbacker = 'a global rollbacker.';
	var globalbot = 'a global bot (with global bot status).';
	var globalabusefilterhelper = 'a global abuse filter helper';
	var globalsysop = 'a global sysop.';
	var globalinterfaceeditor = 'a global interface editor.';
	var steward = 'a steward.';
	var height = 20;
	var dfw = 200;
	var dfh = 200;
	var classes = 'mw-indicator gadget-groupindicator';
	var id = 'mw-indicator-group-';
	var indicators = $( '.mw-indicators' ).first();
	var local;
	var global;
	if ( username ) {
		if ( v.wgUserLanguage === 'sv' ) {
			text = 'Den här användaren är ';
			autopatrolled = 'autopatrullerad.';
			rollbacker = 'tillbakarullare.';
			bot = 'en robot (med robotstatus).';
			sysop = 'administratör.';
			bureaucrat = 'byråkrat.';
			checkuser = 'IP-kontrollant.';
			oversight = 'censor.';
			interfaceadmin = 'gränssnittsadministratör.';
			globalrollbacker = 'global tillbakarullare.';
			globalbot = 'en global robot (med global robot-status).';
			globalabusefilterhelper = 'global missbruksfilter-hjälpare';
			globalsysop = 'global administratör.';
			globalinterfaceeditor = 'global gränssnittsredigerare.';
			steward = 'steward.';
		}
		indicators.prepend( '<span class="gadget-groupindicator-local"></span><span class="gadget-groupindicator-global"></span>' );
		local = $( '.gadget-groupindicator-local' );
		global = $( '.gadget-groupindicator-global' );
		( new mw.Api() ).get( {
			action: 'query',
			list: 'users',
			usprop: 'groups',
			ususers: username,
			formatversion: 2
		} ).done( function( data ) {
			var q = data.query;
			var groups;
			if ( q ) {
				groups = q.users[ 0 ].groups;
				if ( groups ) {
					if ( groups.indexOf( 'autopatrolled' ) !== -1 ) {
						local.append( '<a href="//commons.wikimedia.org/wiki/File:Wikipedia_Autopatrolled.svg" class="' + classes + '" id="' + id + 'autopatrolled"><img src="//upload.wikimedia.org/wikipedia/commons/a/a2/Wikipedia_Autopatrolled.svg" height="' + height + '" title="' + text + autopatrolled + '"></a>' );
					}
					if ( groups.indexOf( 'rollbacker' ) !== -1 ) {
						local.append( '<a href="//commons.wikimedia.org/wiki/File:Wikipedia_Rollbacker.svg" class="' + classes + '" id="' + id + 'rollbacker"><img src="//upload.wikimedia.org/wikipedia/commons/e/e7/Wikipedia_Rollbacker.svg" height="' + height + '" title="' + text + rollbacker + '"></a>' );
					}
					if ( groups.indexOf( 'bot' ) !== -1 ) {
						local.append( '<a href="//commons.wikimedia.org/wiki/File:Robot_icon.svg" class="' + classes + '" id="' + id + 'bot"><img src="//upload.wikimedia.org/wikipedia/commons/0/05/Robot_icon.svg" height="' + height + '" title="' + text + bot + '"></a>' );
					}
					if ( groups.indexOf( 'sysop' ) !== -1 ) {
						local.append( '<a href="//commons.wikimedia.org/wiki/File:Wikipedia_Administrator.svg" class="' + classes + '" id="' + id + 'sysop"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/d/d1/Wikipedia_Administrator.svg/20px-Wikipedia_Administrator.svg.png" height="' + height + '" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/d/d1/Wikipedia_Administrator.svg/30px-Wikipedia_Administrator.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/d/d1/Wikipedia_Administrator.svg/40px-Wikipedia_Administrator.svg.png 2x" title="' + text + sysop + '" data-file-width="' + dfw + '" data-file-height="' + dfh + '"></a>' );
					}
					if ( groups.indexOf( 'bureaucrat' ) !== -1 ) {
						local.append( '<a href="//commons.wikimedia.org/wiki/File:Wikipedia_bureaucrat.svg" class="' + classes + '" id="' + id + 'bureaucrat"><img src="//upload.wikimedia.org/wikipedia/commons/9/95/Wikipedia_bureaucrat.svg" height="' + height + '" title="' + text + bureaucrat + '"></a>' );
					}
					if ( groups.indexOf( 'checkuser' ) !== -1 ) {
						local.append( '<a href="//commons.wikimedia.org/wiki/File:Wikipedia_Checkuser.svg" class="' + classes + '" id="' + id + 'checkuser"><img src="//upload.wikimedia.org/wikipedia/commons/b/b5/Wikipedia_Checkuser.svg" height="' + height + '" title="' + text + checkuser + '"></a>' );
					}
					if ( groups.indexOf( 'oversight' ) !== -1 ) {
						local.append( '<a href="//commons.wikimedia.org/wiki/File:Oversight_logo.png" class="' + classes + '" id="' + id + 'oversight"><img src="//upload.wikimedia.org/wikipedia/commons/0/06/Oversight_logo.png" height="' + height + '" title="' + text + oversight + '"></a>' );
					}
					if ( groups.indexOf( 'interface-admin' ) !== -1 ) {
						local.append( '<a href="//commons.wikimedia.org/wiki/File:Wikipedia_Interface_administrator.svg" class="' + classes + '" id="' + id + 'interface-admin"><img src="//upload.wikimedia.org/wikipedia/commons/e/eb/Wikipedia_Interface_administrator.svg" height="' + height + '" title="' + text + interfaceadmin + '"></a>' );
					}
				}
			}
		} );
		( new mw.Api() ).get( {
			action: 'query',
			meta: 'globaluserinfo',
			guiprop: 'groups',
			guiuser: username,
			formatversion: 2
		} ).done( function( data ) {
			var q = data.query;
			var groups;
			if ( q ) {
				groups = q.globaluserinfo.groups;
				if ( groups ) {
					if ( groups.indexOf( 'global-rollbacker' ) !== -1 ) {
						global.append( '<a href="//commons.wikimedia.org/wiki/File:Meta-Wiki_Global_rollback-2000px.png" class="' + classes + '" id="' + id + 'globalrollbacker"><img src="//upload.wikimedia.org/wikipedia/commons/a/a1/Meta-Wiki_Global_rollback-2000px.png" height="' + height + '" title="' + text + globalrollbacker + '"></a>' );
					}
					if ( groups.indexOf( 'global-bot' ) !== -1 ) {
						global.append( '<a href="//commons.wikimedia.org/wiki/File:Robot_icon.svg" class="' + classes + '" id="' + id + 'globalbot"><img src="//upload.wikimedia.org/wikipedia/commons/0/05/Robot_icon.svg" height="' + height + '" title="' + text + globalbot + '"></a>' );
					}
					if ( groups.indexOf( 'abusefilter-helper' ) !== -1 ) {
						global.append( '<a href="//commons.wikimedia.org/wiki/File:AbuseFilterHelpersIcon.svg" class="' + classes + '" id="' + id + 'globalabusefilterhelper"><img src="//upload.wikimedia.org/wikipedia/commons/e/e1/AbuseFilterHelpersIcon.svg" height="' + height + '" title="' + text + globalabusefilterhelper + '"></a>' );
					}
					if ( groups.indexOf( 'global-sysop' ) !== -1 ) {
						global.append( '<a href="//commons.wikimedia.org/wiki/File:Meta-Wiki_Global_sysop-2000px.png" class="' + classes + '" id="' + id + 'globalsysop"><img src="//upload.wikimedia.org/wikipedia/commons/5/57/Meta-Wiki_Global_sysop-2000px.png" height="' + height + '" width="' + height + '" title="' + text + globalsysop + '"></a>' );
					}
					if ( groups.indexOf( 'global-interface-editor' ) !== -1 ) {
						global.append( '<a href="//commons.wikimedia.org/wiki/File:InterfaceEditorIcon.png" class="' + classes + '" id="' + id + 'globalinterfaceeditor"><img src="//upload.wikimedia.org/wikipedia/commons/d/da/InterfaceEditorIcon.png" height="' + height + '" title="' + text + globalinterfaceeditor + '"></a>' );
					}
					if ( groups.indexOf( 'steward' ) !== -1 ) {
						global.append( '<a href="//commons.wikimedia.org/wiki/File:Wikimedia-logo.svg" class="' + classes + '" id="' + id + 'steward"><img src="//upload.wikimedia.org/wikipedia/commons/8/81/Wikimedia-logo.svg" height="' + height + '" width="' + height + '" title="' + text + steward + '"></a>' );
					}
				}
			}
		} );
	}
} );