The official discord link if you wish to join the discord: https://discord.gg/j5RKwCvAFu
Support the wiki on our official Ko-Fi page or Patreon page!
MediaWiki:Gadget-protectionLocks.js: Difference between revisions
From The Codex
GiverOfThePeace (talk | contribs) (Created page with "// Code adopted from Minecraft Wiki ( https://minecraft.wiki/w/MediaWiki:Gadget-protectionLocks.js ) // 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...") |
GiverOfThePeace (talk | contribs) (Protected "MediaWiki:Gadget-protectionLocks.js" ([Edit=Allow only administrators] (indefinite))) m |
(No difference)
|
Latest revision as of 16:37, 30 January 2024
// Code adopted from Minecraft Wiki ( https://minecraft.wiki/w/MediaWiki:Gadget-protectionLocks.js )
// 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 'https://commons.wiki.gg/images/' + store + '/' + encodedName;
}
function mimicIndicator(id, imgName, imgStore, title) {
return $('<div class="mw-indicator">').attr({
'id': 'mw-indicator-' + id
}).append($('<div class="mw-parser-output">')
.append($('<span typeof="mw:File">')
.append($('<a>')
.attr({
'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') {
mimicIndicator(
'protection-semi',
'Template-badinfo.svg',
'6/66',
'This page is semi-protected so that only registered users can edit it.'
).appendTo($('.mw-indicators'));
} else if (protectionLevel === 'sysop') {
mimicIndicator(
'protection-full',
'Protected.svg',
'8/86',
'This page is fully protected so that only administrators can edit it.'
).appendTo($('.mw-indicators'));
}
})(window.jQuery, window.mediaWiki);