MediaWiki:Gadget-protectionLocks.js
Jump to navigation
Jump to search
- In other languages
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': 'This page is semi-protected so that only autoconfirmed users can edit it.',
'directoreditprotected': 'This page is directors-only protected so that only directors can edit it.',
'sysop': 'This page is fully protected so that only administrators can edit it.',
'interface': 'This page is fully protected because it provides interface text on this wiki.'
},
moveProtectionLevelDescriptions: {
'directoreditprotected': 'This page is directors-only protected so that only directors can move it.',
'sysop': 'This page is move-protected so that only administrators can move it.'
},
uploadProtectionLevelDescriptions: {
'directoreditprotected': 'This page is fully protected so that only directors can reupload it.',
'sysop': 'This page is move-protected so that only administrators can reupload it.'
},
protectionLevelLinks: {
'autoconfirmed': 'Minecraft Wiki:Autoconfirmed users',
'directoreditprotected': 'Minecraft Wiki:Directors',
'sysop': 'Minecraft Wiki:Administrators',
'interface': 'Minecraft Wiki:Administrators'
}
};
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);