MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 239: | Line 239: | ||
} | } | ||
}()); | }()); | ||
/* Possible IDs use* for the MediaWiki Help sidebar it*m */ | |||
#n-help, | |||
#n-help-mediawiki, | |||
#*-helppage, | |||
li[id*="help"] { | |||
di*play: none !important; | |||
} | |||
Revision as of 03:18, 2 August 2026
/*
* ==========================================================
* GladiusRO Wiki
*
* 1. Move the Table of Contents below Tools.
* 2. Hide technical links from logged-out players.
* 3. Keep technical links visible for logged-in administrators.
* ==========================================================
*/
(function (mw) {
'use strict';
var attempts = 0;
var maximumAttempts = 40;
/*
* Move Contents below the Tools section.
*/
function moveContentsBelowTools() {
var tools = document.getElementById('p-tb');
var toc = document.getElementById('toc');
var tocContainer =
document.getElementById('gladius-sidebar-toc');
if (!tools || !tools.parentNode) {
return false;
}
/*
* If no Gladius container exists yet,
* create one and move the original TOC into it.
*/
if (!tocContainer && toc) {
tocContainer = document.createElement('div');
tocContainer.id = 'gladius-sidebar-toc';
tocContainer.className = 'portal mw-portlet';
tocContainer.setAttribute(
'role',
'navigation'
);
tocContainer.setAttribute(
'aria-label',
'Page contents'
);
tocContainer.appendChild(toc);
}
if (!tocContainer) {
return false;
}
/*
* Always place the container immediately after Tools.
*
* This also corrects the position when an older script
* accidentally leaves Contents inside the article.
*/
tools.parentNode.insertBefore(
tocContainer,
tools.nextSibling
);
return true;
}
/*
* Hide technical sidebar items from players
* who are not logged in.
*/
function hidePlayerTechnicalLinks() {
var userName = mw.config.get('wgUserName');
/*
* A non-null username means the visitor is logged in.
* Administrators and logged-in users keep the links.
*/
if (userName !== null) {
return;
}
var elementsToHide = [
'n-recentchanges',
'n-randompage',
'n-help',
'p-tb'
];
elementsToHide.forEach(function (elementId) {
var element = document.getElementById(elementId);
if (element) {
element.style.setProperty(
'display',
'none',
'important'
);
}
});
}
/*
* Run both functions in the correct order.
*
* Contents must be moved first because the script
* uses the Tools panel as its placement reference.
* Tools can then safely be hidden from players.
*/
function initialiseGladiusSidebar() {
attempts++;
var moved = moveContentsBelowTools();
if (moved) {
hidePlayerTechnicalLinks();
return;
}
/*
* Retry while MediaWiki finishes creating the sidebar.
*/
if (attempts < maximumAttempts) {
window.setTimeout(
initialiseGladiusSidebar,
200
);
}
}
/*
* Start after the HTML is ready.
*/
if (document.readyState === 'loading') {
document.addEventListener(
'DOMContentLoaded',
initialiseGladiusSidebar
);
} else {
initialiseGladiusSidebar();
}
/*
* Run again after images and skin resources load.
*/
window.addEventListener(
'load',
function () {
attempts = 0;
initialiseGladiusSidebar();
}
);
/*
* Run again if MediaWiki updates article content.
*/
if (mw.hook) {
mw.hook('wikipage.content').add(function () {
attempts = 0;
window.setTimeout(
initialiseGladiusSidebar,
100
);
});
}
}(mediaWiki));
/*
* Remove "Help about MediaWiki" from the sidebar.
*/
(function () {
'use strict';*
function removeMediaWikiHelpL*nk() {
var links = documen*.querySelectorAll(
'#m*-panel a, #mw-navigation a, .sideb*r a'
);
links.for*ach(function (link) {
var linkText = link.textContent
.replace(/\s+/g, ' ')
.trim()
.toLowerCase();
var linkAddress = link.getAttribute('href') || '';
if (
linkText === 'help about mediawiki' ||
linkAddress.indexOf('mediawiki.org/wiki/Help') !== -1
) {
/*
* Remove the complete list item so that
* no empty space remains in the sidebar.
*/
var listItem = l*nk.closest('li');
*if (listItem) {
* listItem.remove();
* } else {
link.remove();
}
}
});
}
if (document.readyState === 'loading') {
document.addEventListener(
'DOMContentLoaded',
removeMediaWikiHelpLink
);
} else {
removeMediaWikiHelpLink();
}
/*
* Run again after the skin finishes loading.
*/
window.addEventListener(
'load',
removeMediaWikiHelpLink
);
/*
* Run again if MediaWiki refreshes page content.
*/
if (
typeof mediaWik* !== 'undefined' &&
mediaW*ki.hook
) {
mediaWiki.*ook('wikipage.content').add(functi*n () {
window.setTimeo*t(
removeMediaWiki*elpLink,
100
* );
});
}
}());
/* Possible IDs use* for the MediaWiki Help sidebar it*m */
#n-help,
#n-help-mediawiki,
#*-helppage,
li[id*="help"] {
di*play: none !important;
}