MediaWiki:Gadget-protectionLocks.js

// Page protection indicators // jshint jquery:true, esversion:5 /* globals require, module, mediaWiki, mw, OO */ 'use strict';

function getImageURL(name, store, size) { var encodedName = mw.util.wikiUrlencode(name); return "/media/" + store + "/"		+ encodedName; }

function mimicIndicator(id, link, imgName, imgStore, title) { var encodedLink = mw.util.getUrl(link); return $(" ") .attr("id", "mw-indicator-" + id) .addClass("mw-indicator") .append($("")			.attr({ "href": encodedLink, "title": title, "class": "image" }).append($(" ") .attr({				"alt": title,				"src": getImageURL(imgName, imgStore, 29),				"width": "29",				"height": "29"				}) )		); }

$(function {	var protectionLevelData = mw.config.get("wgRestrictionEdit");	var moveProtectionLevelData = mw.config.get("wgRestrictionMove");	if (protectionLevelData === null) {		// Null on nonexistent or special pages. Avoids a crash there.		return;	}	if (mw.config.get("wgAction") !== "view") {		// No need to display the indicator when viewing history or editing the page		return;	}	if (mw.config.get("wgIsMainPage")) {		// The indicator lock breaks formatting on the main page due to the level 1 header being hidden		return;	}	var protectionLevel = protectionLevelData[0];	if (protectionLevel === "autoconfirmed") {		mimicIndicator( "protection-semi", "Terraria Wiki:Autoconfirmed users", "Silver Lock.png", "7/78",			"This page is protected from being edited by unregistered or new users." ).appendTo($(".mw-indicators"));	} else if (protectionLevel === "sysop") {		mimicIndicator( "protection-full", "Terraria Wiki:Administrators", "Gold Lock.png", "5/55",			"This page is fully protected from being edited by regular users." ).appendTo($(".mw-indicators"));	}	if (moveProtectionLevelData[0] === "sysop") {		mimicIndicator( "protection-move", "Terraria Wiki:Protecting", "Green Lock.png", "a/ab", "This page is fully protected from being moved by regular users." ).appendTo($(".mw-indicators"));	} });