Jump to content

User:Novem Linguae/Scripts/Links.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Novem Linguae (talk | contribs) at 13:13, 28 March 2021 (add rename log). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
// <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>
		`;
	}
	
	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>