MediaWiki:Gadget-modifySidebarLinks.js

// _________________________________________________________________________________________ // |                                                                                         | // |                    === WARNING: GLOBAL GADGET FILE ===                                  | // |                 Changes to this page affect many users. | // | // |_________________________________________________________________________________________| // // First Release 19.12.2019 // Adapted from https://www.mediawiki.org/wiki/Manual:Interface/Sidebar function ModifySidebar( action, section, name, link, pos, acc ) { try { pos = typeof pos !== 'undefined' ? pos : -1; pos = typeof acc !== 'undefined' ? acc : null; switch ( section ) { case 'languages': var target = 'p-lang'; break; case 'toolbox': var target = 'p-tb'; break; case 'navigation': var target = 'p-navigation'; break; default: var target = 'p-' + section; break; }		if ( action == 'add' ) { var node = document.getElementById( target ) .getElementsByTagName( 'div' )[0] .getElementsByTagName( 'ul' )[0]; var aNode = document.createElement( 'a' ); var liNode = document.createElement( 'li' ); aNode.appendChild( document.createTextNode( name ) ); aNode.setAttribute( 'href', link ); if (acc !== null && acc.length === 1) { aNode.setAttribute( 'title', name + " [alt-shift-" + acc + "]"); aNode.setAttribute( 'accesskey', acc ); }			liNode.appendChild( aNode ); liNode.className = 'plainlinks'; if (pos !== -1 && pos >= 0 && pos <= node.children.length) { node.insertBefore(liNode, node.children[pos]); } else { node.appendChild( liNode ); }		}		if ( action == 'remove' ) { var list = document.getElementById( target ) .getElementsByTagName( 'div' )[0] .getElementsByTagName( 'ul' )[0];

var listelements = list.getElementsByTagName( 'li' ); for ( var i = 0; i < listelements.length; i++ ) { if (listelements[i].getElementsByTagName( 'a' )[0].text == name &&					listelements[i].getElementsByTagName( 'a' )[0].href == link) {					list.removeChild( listelements[i] ); }			}		}	} catch( e ) { // let's just ignore what's happened return; } }

function CustomizeModificationsOfSidebar { if ( mw.config.get( 'wgUserGroups', [] ).indexOf( 'sysop' ) === -1 ) { ModifySidebar( 'remove', 'toolbox', 'Special pages', 'https://www.portalsofphereon.com/wiki/Special:SpecialPages' ); }	if ( mw.config.get( 'wgUserGroups', [] ).indexOf( 'user' ) !== -1 ) { ModifySidebar( 'add', 'toolbox', 'Create a new page', 'https://www.portalsofphereon.com/wiki/Special:CreatePage', 0, "c" ); } } if (document.readyState!="loading") CustomizeModificationsOfSidebar; // modern browsers else if (document.addEventListener) document.addEventListener("DOMContentLoaded", CustomizeModificationsOfSidebar);