User:Awesome Aasim/DetectProtectionLevels.js

/**
 * All icons used in this script (linked here for attribution and for WhatLinksHere):
 * [[File:Move-protection-shackle.svg]]
 * [[File:Upload-protection-shackle.svg]]
 * [[File:Semi-protection-unlocked.svg]]
 * [[File:Full-protection-unlocked.svg]]
 * [[File:Extended-protection-unlocked.svg]]
 * [[File:Template-protection-unlocked.svg]]
 * [[File:Semi-protection-shackle.svg]]
 * [[File:Full-protection-shackle.svg]]
 * [[File:Extended-protection-shackle.svg]]
 * [[File:Template-protection-shackle.svg]]
 * [[File:Generic-protected-shackle.svg]]
 * [[File:Create-protection-unlocked.svg]]
 * [[File:Create-protection-shackle.svg]]
 * <nowiki>
 **/
$(document).ready(function() {
	var userGroups = mw.config.get("wgUserGroups");
	var protImage = "";
	var altProtImage1 = "";
	var altProtImage2 = "";
	var subsection = "";
	// can move
	try {
		var moveProtectionLevels = mw.config.get("wgRestrictionMove");
		var canMove = false;
		if (moveProtectionLevels.length === 0) {
			canMove = true;
		} else {
			for (var i = 0; i < userGroups.length; i++) {
				if (userGroups[i] === moveProtectionLevels[0]) {
					canMove = true;
				}
			}
		}
		if (canMove) {
		//show the locks in their unlocked state
		} else {
			subsection = "move";
			protImage = "//upload.wikimedia.org/wikipedia/en/thumb/4/44/Move-protection-shackle.svg/20px-Move-protection-shackle.svg.png";
			altProtImage2 = "//upload.wikimedia.org/wikipedia/en/thumb/4/44/Move-protection-shackle.svg/40px-Move-protection-shackle.svg.png";
		}
	} catch (Error) {
		console.error(Error);
	}
	// can upload
	try {
		var uploadProtectionLevels = mw.config.get("wgRestrictionUpload");
		var canUpload = false;
		if (uploadProtectionLevels.length === 0) {
			canUpload = true;
		} else {
			for (i = 0; i < userGroups.length; i++) {
				if (userGroups[i] === uploadProtectionLevels[0]) {
					canUpload = true;
				}
			}
		}
		if (canUpload) {
			//show the locks in their unlocked state
		} else {
			protImage = "//upload.wikimedia.org/wikipedia/en/thumb/d/d7/Upload-protection-shackle.svg/20px-Upload-protection-shackle.svg.png";
			altProtImage2 = "//upload.wikimedia.org/wikipedia/en/thumb/d/d7/Upload-protection-shackle.svg/40px-Upload-protection-shackle.svg.png";
			subsection = "upload";
		}
	} catch (Error) {
		console.error(Error);
	}
	// can edit
	try {
		var editProtectionLevels = mw.config.get("wgRestrictionEdit");
		var canEdit = false;
		if (editProtectionLevels.length === 0) {
			canEdit = true;
		} else {
			for (i = 0; i < userGroups.length; i++) {
				if (userGroups[i] === editProtectionLevels[0]) {
					canEdit = true;
				}
			}
		}
		if (canEdit) {
			//show the locks in their unlocked state
			switch (editProtectionLevels[0]) {
				case "autoconfirmed":  protImage = "//upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Semi-protection-unlocked.svg/20px-Semi-protection-unlocked.svg.png";
				altProtImage2 = "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Semi-protection-unlocked.svg/40px-Semi-protection-unlocked.svg.png";
				subsection = "semi";
				break;
				case "sysop":  protImage = "//upload.wikimedia.org/wikipedia/commons/thumb/4/40/Full-protection-unlocked.svg/20px-Full-protection-unlocked.svg.png";
				altProtImage2 = "//upload.wikimedia.org/wikipedia/commons/thumb/4/40/Full-protection-unlocked.svg/40px-Full-protection-unlocked.svg.png";
				subsection = "full";
				break;
				case "extendedconfirmed":  protImage = "//upload.wikimedia.org/wikipedia/commons/thumb/d/db/Extended-protection-unlocked.svg/20px-Extended-protection-unlocked.svg.png";
				altProtImage2 = "//upload.wikimedia.org/wikipedia/commons/thumb/d/db/Extended-protection-unlocked.svg/40px-Extended-protection-unlocked.svg.png";
				subsection = "extended";
				break;
				case "templateeditor":  protImage = "//upload.wikimedia.org/wikipedia/en/thumb/5/5a/Template-protection-unlocked.svg/20px-Template-protection-unlocked.svg.png";
				altProtImage2 = "//upload.wikimedia.org/wikipedia/en/thumb/5/5a/Template-protection-unlocked.svg/40px-Template-protection-unlocked.svg.png";
				subsection = "template";
				break;
			}
		} else {
			switch (editProtectionLevels[0]) {
				case "autoconfirmed":  protImage = "//upload.wikimedia.org/wikipedia/en/thumb/1/1b/Semi-protection-shackle.svg/20px-Semi-protection-shackle.svg.png";
				altProtImage2 = "//upload.wikimedia.org/wikipedia/en/thumb/1/1b/Semi-protection-shackle.svg/40px-Semi-protection-shackle.svg.png";
				subsection = "semi";
				break;
				case "sysop":  protImage = "//upload.wikimedia.org/wikipedia/en/thumb/4/44/Full-protection-shackle.svg/20px-Full-protection-shackle.svg.png";
				altProtImage2 = "//upload.wikimedia.org/wikipedia/en/thumb/4/44/Full-protection-shackle.svg/40px-Full-protection-shackle.svg.png";
				subsection = "full";
				break;
				case "extendedconfirmed":  protImage = "//upload.wikimedia.org/wikipedia/en/thumb/8/8c/Extended-protection-shackle.svg/20px-Extended-protection-shackle.svg.png";
				altProtImage2 = "//upload.wikimedia.org/wikipedia/en/thumb/4/44/Full-protection-shackle.svg/40px-Full-protection-shackle.svg.png";
				subsection = "extended";
				break;
				case "templateeditor":  protImage = "//upload.wikimedia.org/wikipedia/en/thumb/5/53/Template-protection-shackle.svg/20px-Template-protection-shackle.svg.png";
				altProtImage2 = "//upload.wikimedia.org/wikipedia/en/thumb/5/53/Template-protection-shackle.svg/40px-Template-protection-shackle.svg.png";
				subsection = "template";
				break;
				default:  protImage = "//upload.wikimedia.org/wikipedia/en/thumb/9/99/Generic-protected-shackle.svg/20px-Generic-protected-shackle.svg.png";
				altProtImage2 = "//upload.wikimedia.org/wikipedia/en/thumb/9/99/Generic-protected-shackle.svg/40px-Generic-protected-shackle.svg.png";
				break;
			}
		}
	} catch (Error) {
		console.error(Error);
	}
	// can create
	try {
		var createProtectionLevels = mw.config.get("wgRestrictionCreate");
		var canCreate = false;
		if (createProtectionLevels.length === 0) {
			canCreate = true;
		} else {
			for (i = 0; i < userGroups.length; i++) {
				if (userGroups[i] === createProtectionLevels[0]) {
					canCreate = true;
				}
			}
		}
		if (canCreate) {
		//show the locks unlocked
			if (createProtectionLevels.length > 0) {
				subsection = "create";
				protImage = "//upload.wikimedia.org/wikipedia/commons/thumb/8/86/Create-protection-unlocked.svg/20px-Create-protection-unlocked.svg.png";
				altProtImage2 = "//upload.wikimedia.org/wikipedia/commons/thumb/8/86/Create-protection-unlocked.svg/40px-Create-protection-unlocked.svg.png";
			} 
        } else {
			subsection = "create";
			protImage = "//upload.wikimedia.org/wikipedia/en/thumb/0/02/Create-protection-shackle.svg/20px-Create-protection-shackle.svg.png";
			altProtImage2 = "//upload.wikimedia.org/wikipedia/en/thumb/0/02/Create-protection-shackle.svg/40px-Create-protection-shackle.svg.png";
        }
	} catch (Error) {
		console.error(Error);
	}
	if (protImage.length > 0) {
		if ($("#mw-indicator-pp-default").length > 0) $("#mw-indicator-pp-default").html("<span><a title=\"This page is protected.\" href=\"/wiki/Wikipedia:Protection_policy#" + subsection + "\"><img height=\"20\" src=\"" + protImage + "\" srcset=\"" + altProtImage2 + " 2x\" alt=\"Protected page lock\"></a></span>");
		else $(".mw-indicators").append("<div class=\"mw-indicator\" id=\"mw-indicator-pp-default\"><span><a title=\"This page is protected.\" href=\"/wiki/Wikipedia:Protection_policy#" + subsection + "\"><img height=\"20\" src=\"" + protImage + "\" srcset=\"" + altProtImage2 + " 2x\" alt=\"Protected page lock\"></a></span></div>");
	}
});
//</nowiki>

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.