Jump to content

User:Jafeluv/global.js

From Meta, a Wikimedia project coordination wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/**
 * Forces left-to-right layout and editing on RTL wikis.
 * @see https://meta.wikimedia.org/wiki/Force_ltr
 * @update-token [[File:pathoschild/forceltr.js]]
 */
mw.loader.load('//tools-static.wmflabs.org/meta/scripts/pathoschild.forceltr.js');

// Enable IP range contribs and wildcards.
mw.loader.load('//en.wikipedia.org/w/index.php?title=MediaWiki:Gadget-contribsrange.js&action=raw&ctype=text/javascript');

// Markblocked script.
mw.loader.load('//ru.wikipedia.org/w/index.php?title=MediaWiki:Gadget-markblocked.js&action=raw&ctype=text/javascript');

// Contribs, SULinfo and Luxo tabs for Vector.
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Jafeluv/ContribsTabVector.js&action=raw&ctype=text/javascript');

// Wikidata link checking
mw.loader.load('//www.wikidata.org/w/index.php?title=User:Yair_rand/checksitelinks.js&action=raw&ctype=text/javascript');

// Reference tooltips
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Yair_rand/ReferenceTooltips.js&action=raw&ctype=text/javascript');
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Yair rand/ReferenceTooltips.css&action=raw&ctype=text/css', 'text/css');

// Get wiki-specific information
if(mw.config.exists('wgServer')) {
	var server = mw.config.get('wgServer');
	var langCode = server.substring(2, server.indexOf('.', 2));
	var wikiCode = server.substring(2 + langCode.length + 1, server.indexOf('.org'));
}

// Replace Special:Upload links in redlinked files
$("a[href*='wpDestFile']").not("a[href*='wpForReUpload\=1']")
	.each(function() {
		this.href = this.href.replace(/title=.*\&wpDestFile=/, "title=File:").replace(/\/wiki\/.*\?wpDestFile=/, "/wiki/File:");
	});

// Add interwiki toolbox for watchlist and contributions
function addInterwikiToolboxes() {
	var navigationElement = $('.portal').get(0);
	var interwikiElement = document.getElementById('p-tb').cloneNode(true);
	interwikiElement.id = 'p-interwiki';
	interwikiElement.innerHTML = '<h3><img src="//upload.wikimedia.org/wikipedia/commons/thumb/8/81/Wikimedia-logo.svg/12px-Wikimedia-logo.svg.png"> Interwiki</h3><div class=body><ul></ul></div>';
	navigationElement.parentNode.insertBefore(interwikiElement, navigationElement.nextSibling);
}

// Add custom interwiki links to toolbar.
function addInterwikiLinks(canonicalPageName) {
	addInterwikiToolboxes();
	if(langCode + wikiCode != 'enwikipedia')
		mw.util.addPortletLink('p-interwiki', '//en.wikipedia.org/wiki/' + canonicalPageName, 'English', '', 'English', '');
	if(langCode + wikiCode != 'fiwikipedia')
		mw.util.addPortletLink('p-interwiki', '//fi.wikipedia.org/wiki/' + canonicalPageName, 'Suomi', '', 'Suomi', '');
	if(langCode != 'commons')
		mw.util.addPortletLink('p-interwiki', '//commons.wikimedia.org/wiki/' + canonicalPageName, 'Commons', '', 'Wikimedia Commons', '');
	if(langCode != 'meta')
		mw.util.addPortletLink('p-interwiki', '//meta.wikimedia.org/wiki/' + canonicalPageName, 'Meta', '', 'Meta-Wiki', '');

	// Expand toolboxes by default
	document.getElementById('p-interwiki').getElementsByTagName('div')[0].style.display = 'block';
}

// Add interwiki links to toolbox for watchlist, contributions and userspace.
$(function( $ ) {
	if(mw.config.get('wgCanonicalSpecialPageName') == 'Watchlist')
		addInterwikiLinks('Special:Watchlist');
	else if(mw.config.get('wgCanonicalSpecialPageName') == 'Contributions')
		addInterwikiLinks('Special:Contributions/Jafeluv');
	else if(mw.config.get('wgCanonicalSpecialPageName') == 'Recentchanges')
		addInterwikiLinks('Special:RecentChanges');
	else if(mw.config.get('wgCanonicalNamespace') == 'User' && mw.config.get('wgTitle') == 'Jafeluv')
		addInterwikiLinks('User:Jafeluv');
	else if(mw.config.get('wgCanonicalNamespace') == 'User_talk' && mw.config.get('wgTitle') == 'Jafeluv')
		addInterwikiLinks('User_talk:Jafeluv');
});

// Autofill userpage on creation
// <nowiki>
jQuery( document ).ready( function( $ ) {
	if (document.title.indexOf('Creating ') != -1 && mw.config.get('wgCanonicalNamespace') == 'User' && mw.config.get('wgTitle') == 'Jafeluv') {
		document.editform.wpTextbox1.value = '{{#babel:' + langCode + '-0}}\n{{subst:#ifexist:Template:Softredirect|{{Softredirect|meta:User:Jafeluv}}|→ [[meta:User:Jafeluv]]}}';
		document.editform.wpSummary.value = '→ [[meta:User:Jafeluv]]';
		document.editform.wpWatchthis.checked = true;
	}
});
// </nowiki>

// Add toolbox.
function addToolbox(name, id) {
	var toolboxElement = document.getElementById("p-tb");
	var closeElement = toolboxElement.cloneNode(true);
	closeElement.id = id;
	closeElement.innerHTML = "<h3>" + name + "</h3><div class=body><ul></ul></div>";
	toolboxElement.parentNode.insertBefore(closeElement, toolboxElement.nextSibling);
}