MediaWiki:Gadget-protectionLocks.js

提供: Minecraft Wiki
ナビゲーションに移動 検索に移動
他言語版

注意: 保存した後、ブラウザのキャッシュをクリアしてページを再読み込みする必要があります。

  • Firefox / Safari: ⇧ Shift を押しながら「再読み込み」をクリックするか、Ctrl + F5 または Ctrl + R を押してください(Macでは ⌘ Cmd + R
  • Google Chrome: Ctrl + ⇧ Shift + R を押してください(Macでは ⌘ Cmd + ⇧ Shift + R
  • Internet Explorer: Ctrl を押しながら「最新の情報に更新」をクリックするか、Ctrl + F5 を押してください
  • Opera: 「ツール → 設定」からキャッシュをクリアしてください。
// Page protection indicators
;(function($, mw) {
	'use strict';

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

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

	function mimicIndicator(id, link, imgName, imgStore, 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, imgStore, 25),
				'srcset': getImageThumbnailURL(imgName, imgStore, 38) +
					' 1.5x, ' +
					getImageThumbnailURL(imgName, imgStore, 50) +
					' 2x',
				'width': '25',
				'height': '25'
				})
			))));
	}

	const protectionLevel = protectionLevelData[0];
	if (protectionLevel === 'autoconfirmed') { // [[File:Semi-protected page lock.png]]
		mimicIndicator(
			'protection-semi',
			'Minecraft Wiki:登録利用者',
			'Semi-protected page lock.png',
			'9/9b',
			'このページは半保護されているため、登録利用者のみが編集することができます。'
		).appendTo($('.mw-indicators'));
	} else if (protectionLevel === 'directoreditprotected') { // [[File:Director-protected page lock.png]]
		mimicIndicator(
			'protection-director',
			'Minecraft Wiki:Director',
			'Director-protected page lock.png',
			'8/85',
			'This page is directors-only protected so that only directors can edit it.'
		).appendTo($('.mw-indicators'));
	} else if (protectionLevel === 'sysop') { // [[File:Fully-protected page lock.png]]
		mimicIndicator(
			'protection-full',
			'Minecraft Wiki:管理者',
			'Fully-protected page lock.png',
			'4/49',
			'このページは保護されているため、管理者のみが編集することができます。'
		).appendTo($('.mw-indicators'));
	}
})(window.jQuery, window.mediaWiki);