Ця сторінка повністю захищена, оскільки містить текст інтерфейсу цієї вікі.

MediaWiki:Gadget-protectionLocks.js

Матеріал з Minecraft Wiki
Перейти до навігації Перейти до пошуку
Іншими мовами

Note: After saving, you have to bypass your browser's cache to see the changes.

Google Chrome, Firefox, Microsoft Edge, and Safari: Hold down the Shift key and click the Reload toolbar button.
For details and instructions about other browsers, see Wikipedia:Bypass your cache.

// Page protection indicators
;(function($, mw) {
	'use strict';

	const i18n = {
		protectionLevelDescriptions: {
			'autoconfirmed': 'Ця сторінка є напівзахищеною, тому редагувати її можуть лише користувачі з автопідтвердженням.',
			'directoreditprotected': 'Ця сторінка захищена лише для директорів, тому тільки директори можуть її редагувати.',
			'sysop': 'Ця сторінка повністю захищена, тому лише адміністратори можуть її редагувати.',
			'interface': 'Ця сторінка повністю захищена, оскільки містить текст інтерфейсу цієї вікі.'
		},
		moveProtectionLevelDescriptions: {
			'directoreditprotected': 'Ця сторінка захищена лише для директорів, тому тільки директори можуть її перейменовувати.',
			'sysop': 'Ця сторінка захищена від перейменування, тому лише адміністратори можуть її перейменовувати.'
		},
		uploadProtectionLevelDescriptions: {
			'directoreditprotected': 'Ця сторінка повністю захищена, тому тільки директори можуть її перезавантажувати.',
			'sysop': 'Ця сторінка захищена від перейменування, тому тільки адміністратори можуть її перезавантажити.'
		},
		protectionLevelLinks: {
			'autoconfirmed': 'Minecraft Wiki:Автопідтверджені користувачі',
			'directoreditprotected': 'Minecraft Wiki:Директори',
			'sysop': 'Minecraft Wiki:Адміністратори',
			'interface': 'Minecraft Wiki:Адміністратори'
		}
	};

	const config = mw.config.get([
		'wgRestrictionEdit',
		'wgRestrictionMove',
		'wgRestrictionCreate',
		'wgNamespaceNumber',
		'wgIsMainPage',
		'wgAction'
	]);
	const editProtectionLevelData = config.wgRestrictionEdit;
	const moveProtectionLevelData = config.wgRestrictionMove;
	const createProtectionLevelData = config.wgRestrictionCreate;
	if (
		// Null on nonexistent or special pages. Avoids a crash there.
		(!editProtectionLevelData && !createProtectionLevelData) || config.wgIsMainPage ||
		// No need to display the indicator when viewing history or editing the page
		config.wgAction !== 'view') {
		return;
	}

	function getImageThumbnailURL(name, size) {
		const encodedName = mw.util.wikiUrlencode(name);
		return '/images/' +
			encodedName;
	}

	function mimicIndicator(id, link, imgName, title) {
		const encodedLink = mw.util.getUrl(link);
		return $('<div class="mw-indicator">').attr({
				'id': 'mw-indicator-' + id
			}).append($('<div class="mw-parser-output">')
			.append($('<span typeof="mw:File">')
			.append($('<a>')
			.attr({
				'href': encodedLink,
				'title': title
			}).append($('<img>')
				.attr({
				'alt': title,
				'src': getImageThumbnailURL(imgName, 25),
				'srcset': getImageThumbnailURL(imgName, 38) +
					' 1.5x, ' +
					getImageThumbnailURL(imgName, 50) +
					' 2x',
				'width': '25',
				'height': '25'
				})
			))));
	}

	const editProtectionLevel = editProtectionLevelData ? editProtectionLevelData[0] : null;
	const moveProtectionLevel = moveProtectionLevelData ? moveProtectionLevelData[0] : null;
	const createProtectionLevel = createProtectionLevelData ? createProtectionLevelData[0] : null;
	if (config.wgNamespaceNumber === 6 && (editProtectionLevel === 'directoreditprotected' || createProtectionLevel === 'directoreditprotected')) { // [[File:Upload-protected page lock.svg]]
		mimicIndicator(
			'protection-director-upload',
			i18n.protectionLevelLinks.directoreditprotected,
			'Upload-protected page lock.svg',
			i18n.uploadProtectionLevelDescriptions.directoreditprotected
		).appendTo($('.mw-indicators'));
	} else if (config.wgNamespaceNumber === 6 && (editProtectionLevel === 'sysop' || createProtectionLevel === 'sysop')) {
		mimicIndicator(
			'protection-full-upload',
			i18n.protectionLevelLinks.sysop,
			'Upload-protected page lock.svg',
			i18n.uploadProtectionLevelDescriptions.sysop
		).appendTo($('.mw-indicators'));
	} else if (editProtectionLevel === 'autoconfirmed' || createProtectionLevel === 'autoconfirmed') { // [[File:Semi-protected page lock.svg]]
		mimicIndicator(
			'protection-semi',
			i18n.protectionLevelLinks.autoconfirmed,
			'Semi-protected page lock.svg',
			i18n.protectionLevelDescriptions.autoconfirmed
		).appendTo($('.mw-indicators'));
	} else if (editProtectionLevel === 'directoreditprotected' || createProtectionLevel === 'directoreditprotected') { // [[File:Director-protected page lock.svg]]
		mimicIndicator(
			'protection-director',
			i18n.protectionLevelLinks.directoreditprotected,
			'Director-protected page lock.svg',
			i18n.protectionLevelDescriptions.directoreditprotected
		).appendTo($('.mw-indicators'));
	} else if (editProtectionLevel === 'sysop' || createProtectionLevel === 'sysop') { // [[File:Fully-protected page lock.svg]]
		mimicIndicator(
			'protection-full',
			i18n.protectionLevelLinks.sysop,
			'Fully-protected page lock.svg',
			i18n.protectionLevelDescriptions.sysop
		).appendTo($('.mw-indicators'));
	} else if (moveProtectionLevel) { // [[File:Move-protected page lock.svg]]
		mimicIndicator(
			'protection-move',
			i18n.protectionLevelLinks[moveProtectionLevel],
			'Move-protected page lock.svg',
			i18n.moveProtectionLevelDescriptions[moveProtectionLevel]
		).appendTo($('.mw-indicators'));
	} else if (config.wgNamespaceNumber === 8) { // [[File:Interface-protected page lock.svg]]
		mimicIndicator(
			'protection-interface',
			i18n.protectionLevelLinks.interface,
			'Interface-protected page lock.svg',
			i18n.protectionLevelDescriptions.interface
		).appendTo($('.mw-indicators'));
	}
})(window.jQuery, window.mediaWiki);