User:Dross/common.js

/** * Fix links like User:Example@somewiki on Special:Log and Special:Recentchanges * @author VasilievVV, 2008-2010 * @author Kalan, 2008 * @author Splarka, 2008 * @author Krinkle, 2012 * Imported from https://meta.wikimedia.org/wiki/MediaWiki:Gadget-CentralAuthInterlinkFixer.js and modified by 開拓者 for Miraheze, 2018. */ /*global mediaWiki, jQuery */ /*jshint browser:true */ (function (mw, $) {	'use strict';	function host(id) {		var url=id.replace(/(.*)wiki/,"$1.miraheze.org")		return url;	}

function fixCrosswikiLinks { $('* a.new').each(function {			var bits, wiki, user, hostName,				$el = $(this),				txt = $el.text;			if (txt.indexOf('@') !== -1 && txt.indexOf('/') === -1 && /^User\:/i.test(txt)) {				bits = txt.split('@');				user = bits.shift.replace(/^\s*User:(.+)\s*$/g, '$1');				wiki = bits.join('@');				if (wiki === 'global') {					$el.attr('href', mw.config.get('wgScript') + '?title=Special:CentralAuth&target=' + encodeURIComponent(user));				} else {					hostName = host(wiki);					$el.attr('href', '//' + hostName + '/wiki/User:' + encodeURIComponent(user));				}				if (wiki !== 'metawiki') {					$el.removeClass('new external').addClass('extiw');				}				$el.attr('title', txt);			}		}); }

if (mw.config.get('wgCanonicalSpecialPageName') === 'Log' || mw.config.get('wgCanonicalSpecialPageName') === 'Recentchanges') { mw.hook('wikipage.content').add(fixCrosswikiLinks); } }(mediaWiki, jQuery));