User:Novem Linguae/Scripts/Links.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Novem Linguae/Scripts/Links. |
// <nowiki>
/*
This script adds a left menu below the toolbox, and includes some links:
- users
- common.js
- global.js
- Global auth (good for seeing what global permissions people have)
- users and articles
- subpages
- rename log
This script also adds "Pending changes" to the left main menu.
*/
function getFirstMatch(string, regex) {
let matches = string.match(regex);
if ( matches && matches[1] ) {
return matches[1];
}
return '';
}
$(function() {
mw.util.addPortletLink(
'p-navigation',
mw.util.getUrl('Special:PendingChanges'),
'Pending changes' // can't put comma here, silent error
);
let pageName = mw.config.get('wgPageName');
let username = getFirstMatch(pageName, /(?:User:|User_talk:)([^/]+).*/);
let userLinks = '';
if ( username ) {
username = 'User:' + username;
let usernameURI = encodeURIComponent(username.replace(/_/g, ' ').replace(/^User:/, ''));
userLinks = `
<li><a href="/wiki/`+username+`/common.js">common.js</a></li>
<li><a href="https://meta.wikimedia.org/wiki/`+username+`/global.js">global.js</a></li>
<li><a href="/wiki/Special:CentralAuth?target=`+usernameURI+`">Central auth</a></li>
<li><a href="https://meta.wikimedia.org/wiki/Special:Log?type=renameuser&user=&page=`+usernameURI+`&oldname=&wpdate=&tagfilter=">Rename log</a></li>
<li><a href="https://en.wikipedia.org/wiki/Special:Log?type=renameuser&user=&page=`+usernameURI+`%7Eenwiki&wpdate=&tagfilter=">Rename log (~enwiki)</a></li>
`;
// All modern renames seem to be put into both en:Special:Log->User rename log AND meta:Special:Log->User rename log.
// One older rename was put only into meta:Special:Log->User rename log.
// Another older rename was put only into en:Special:Log->User rename log, and was complicated by the fact that ~enwiki had been added to the end of it.
// Spaces vs underscores don't seem to matter. User: or no User: doesn't seem to matter.
}
let parentName = pageName + '/';
let subpageLinks = '';
if ( pageName.includes('/') ) {
parentName = getFirstMatch(pageName, /^([^\/]+\/)/);
}
subpageLinks = `
<li><a href="/wiki/Special:PrefixIndex/`+parentName+`">Subpages</a></li>
`;
$('#p-tb').after(`
<nav id="p-user-links" class="mw-portlet mw-portlet-user-links vector-menu vector-menu-portal portal" aria-labelledby="p-user-links-label" role="user-links">
<h3 id="p-user-links-label" class="vector-menu-heading">
<span>More tools</span>
</h3>
<div class="vector-menu-content">
<ul class="vector-menu-content-list">
`+userLinks+`
`+subpageLinks+`
</ul>
</div>
</nav>
`);});
// </nowiki>