MediaWiki:Common.js/staff-tagger.js

/* Code to tag userpages with staff message boxes */ $('span#tag-user > a[href*="prepend="].text').click(function(e) { 	"use strict";	if (!/sysop|soap|staff|helper|wiki-manager|content-team-member|util/.test(mw.config.get('wgUserGroups').join('\n'))) {		return;	}	e.preventDefault;	var rank = prompt('Please enter a staff rank to tag the user with', 'rollback');	var user = $(this).parent.attr('data-user');	var rank2;	function getSection(rank) {		var matches = {			'bureaucrat': 4,			'sysop': 5,			'codeeditor': 6,			'content-moderator': 8,			'threadmoderator': 10,			'rollback': 11,		};

return matches[rank] || null; }	var aliases = { 'bur': 'bureaucrat', 'bcrat': 'bureaucrat', 'bureau': 'bureaucrat', 'bureaucrat': 'bureaucrat', 'crat': 'bureaucrat', 'b': 'bureaucrat', 'admin': 'administrator', 'adm': 'administrator', 'ad': 'administrator', 'administrator': 'administrator', 'administr': 'administrator', 'sysop': 'administrator', 'ce' : 'code editor', 'codeeditor' : 'code editor', 'code editor' : 'code editor', 'code' : 'code editor', 'code edit' : 'code editor', 'c e' : 'code editor', 'cd edit' : 'code editor', 'cde edit' : 'code editor', 'codeedit' : 'code editor', 'cdeedit' : 'code editor', 'cde edtr' : 'code editor', 'cdeedtr' : 'code editor', 'content': 'content moderator', 'cont': 'content moderator', 'cont mod': 'content moderator', 'cont moderator': 'content moderator', 'content mod': 'content moderator', 'content moderator': 'content moderator', 'c moderator': 'content moderator', 'c mod': 'content moderator', 'cm': 'content moderator', 'content-moderator': 'content moderator', 'd mod': 'discussions moderator', 'd moderator': 'discussions moderator', 'disc mod': 'discussions moderator', 'disc moderator': 'discussions moderator', 'discuss m': 'discussions moderator', 'discuss mod': 'discussions moderator', 'discuss moderator': 'discussions moderator', 'disc m': 'discussions moderator', 'discussions m': 'discussions moderator', 'discussions mod': 'discussions moderator', 'discussions moderator': 'discussions moderator', 'dm': 'discussions moderator', 'thread-moderator': 'discussions moderator', 'threadmoderator': 'discussions moderator', 'th': 'discussions moderator', 'th m': 'discussions moderator', 'thr mod': 'discussions moderator', 'thread mod': 'discussions moderator', 't mod': 'discussions moderator', 'rollback': 'rollback', 'roll': 'rollback', 'rollb': 'rollback', 'rb': 'rollback', 'rollbacker': 'rollback', 'rback': 'rollback', 'b': 'bot', 'bot': 'bot', 'robot': 'bot', 'bt': 'bot', };

if (rank.match(/.+?\s*[\,\|\;]\s*.+/)) { rank = rank.split(/\s*[\,\|\;]\s*/); rank2 = aliases[rank[1]]; rank = aliases[rank[0]]; } else { rank2 = null; rank = aliases[rank]; }

new mw.Api.post({		action: 'edit',		minor: true,		bot: true,		watchlist: 'nochange',		title: 'User:' + user,		summary: 'Adding message box to userpage',		prependtext: '',		token: mw.user.tokens.values.editToken,	}).always(function(data) {

if (data.edit) { console.log("[StaffTagger]: Successfully tagged", user, 'With rank "' + rank + '"');

new mw.Api.post({				action: 'protect',				bot: true,				watchlist: 'nochange',				title: 'User:' + user,				protections: ( rank2 ? rank2 !== "threadmoderator" && rank2 !== "rollback" && rank2 !== "bot" : rank !== "threadmoderator" && rank !== "rollback" && rank !== "bot" ) 					? 'edit=sysop|move=sysop' 					: 'edit=autoconfirmed|move=autoconfirmed',				expiry: 'infinite',				reason: 'Protecting wiki staff userpage',				token: mw.user.tokens.values.editToken,			}).always(function(data) {

if (data.protect) {

console.log("[StaffTagger]: Successfully protected ", user + '\'s userpage'); new mw.Api.get({							action: 'query',							list: 'users',							ususers: user,							ustoken: 'userrights',						}).always(function(data) {							var usToken = data.query.users[0].userrightstoken;							if (data.query) {

new mw.Api.post({									"action": "userrights",									"format": "json",									"user": user,									"add": rank + (rank2 ? "|" + rank2 : ""),									"expiry": "infinite",									"reason": "Per request to be staff: Hypixel_SkyBlock_Wiki_talk:Requests_to_be_staff",									"token": usToken,								}).always(function(data) {

if (data.userrights) { console.log('[StaffTagger]: Successfully added ranks!'); if (rank2) { new mw.Api.post({												"action": "userrights",												"format": "json",												"user": user,												"add": rank + (rank2 ? "|" + rank2 : ""),												"expiry": "infinite",												"reason": "Per request to be staff: Hypixel_SkyBlock_Wiki_talk:Requests_to_be_staff",												"token": usToken,											}).always(function(data) {												if (data.userrights) {													console.log('[StaffTagger]: Successfully added second rank!');												} else {													console.warn('[StaffTagger]: Failed to add ranks: ' + data);												}											}); new mw.Api.post({												action: "edit",												section: getSection(rank),												appendtext: '\n*',												token: mw.user.tokens.values.editToken,												title: 'Hypixel_SkyBlock_Wiki:Staff',												summary: 'Adding ' + user + ' to the staff list per request to be staff: Hypixel_SkyBlock_Wiki_talk:Requests_to_be_staff",												minor: 1,												bot: 1,												watchlist: 'nochange',											}).always(function(data) {

if (data.edit) { console.log('[StaffTagger]: Successfully added ' + user + ' to staff member list');

new mw.Api.post({														action: "edit",														section: getSection(rank2),														appendtext: '\n*',														token: mw.user.tokens.values.editToken,														title: 'Hypixel_SkyBlock_Wiki:Staff',														summary: 'Adding ' + user + ' to the staff list per request to be staff: Hypixel_SkyBlock_Wiki_talk:Requests_to_be_staff",														minor: 1,														bot: 1,														watchlist: 'nochange',													}).always(function(data) {														if (data.userrights) {															console.log('[StaffTagger]: Successfully added ' + user + ' to staff member list');															mw.hook('hsw.gadget.staffColorsUpdater').fire(function(updater) { updater; console.log('[StaffTagger]: Updating Staff colors...'); });														} else {															console.warn('[StaffTagger]: Failed to Add user to staff member list: ' + data);														}													}); } else { console.warn('[StaffTagger]: Failed to Add user to staff member list: ' + data); }											});										} else {											new mw.Api.post({ action: "edit", section: getSection(rank), appendtext: '\n*', token: mw.user.tokens.values.editToken, title: 'Hypixel_SkyBlock_Wiki:Staff', summary: 'Adding ' + user + ' to the staff list per request to be staff: Hypixel_SkyBlock_Wiki_talk:Requests_to_be_staff", minor: 1, bot: 1, watchlist: 'nochange', }).always(function(data) {

if (data.edit) { console.log('[StaffTagger]: Successfully added ' + user + ' to staff member list'); } else { console.warn('[StaffTagger]: Failed to Add user to staff member list: ' + data); }											});										}									} else {										console.warn('[StaffTagger]: Failed to give ranks: ' + data);									}								}); } else { console.warn("[StaffTagger]: API error in getting user rights token: " + data, '(API Error code \"' + data + '\")'); }						});				} else {					console.warn("[StaffTagger]: API error in protecting ", user + '\'s userpage:', data, '(API Error code \"' + data + '\")');				}			}); } else { console.warn('[StaffTagger]: API Error in Tagging', user + ':', data, '(API Error code "' + data + '")'); }	}); });