User:Zppix/Test/MediaWiki:Gadget-CentralAuthInterlinkFixer.js: Difference between revisions
Content added Content deleted
(remove 'external' class as well (in the old version the class was overritten, thereby removing all classses which broke certain other scripts) -) |
(wikidatawiki has a separate domain, add exception) |
||
Line 17: | Line 17: | ||
if (id === 'foundationwiki') { |
if (id === 'foundationwiki') { |
||
return 'wikimediafoundation.org'; |
return 'wikimediafoundation.org'; |
||
} |
|||
if (id === 'wikidatawiki') { |
|||
return 'wikidatawiki.org'; |
|||
} |
} |
||
wikimedia = /^(advisory|auditcom|board|chair|chapcom|collab|comcom|commons|exec|grants|incubator|internal|meta|office|otrs wiki|quality|spcom|species|wikimaniateam|wikimania20\d\d)wiki$/; |
wikimedia = /^(advisory|auditcom|board|chair|chapcom|collab|comcom|commons|exec|grants|incubator|internal|meta|office|otrs wiki|quality|spcom|species|wikimaniateam|wikimania20\d\d)wiki$/; |
Revision as of 19:12, 20 November 2012
/**
* 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
*/
/*global mediaWiki, jQuery */
/*jslint browser:true, regexp:true */
(function (mw, $) {
'use strict';
function host(id) {
var wikimedia, idNoSpaces;
if (id === 'mediawikiwiki') {
return 'mediawiki.org';
}
if (id === 'foundationwiki') {
return 'wikimediafoundation.org';
}
if (id === 'wikidatawiki') {
return 'wikidatawiki.org';
}
wikimedia = /^(advisory|auditcom|board|chair|chapcom|collab|comcom|commons|exec|grants|incubator|internal|meta|office|otrs wiki|quality|spcom|species|wikimaniateam|wikimania20\d\d)wiki$/;
if (wikimedia.test(id)) {
return id.replace(/ /g, '-').replace(/_/g, '-').replace(/wiki$/, '.wikimedia.org');
}
idNoSpaces = id.match(/(arbcom enwiki|labswikimedia|pa uswikimedia|wg enwiki)$/) ? id.replace(/ /g, '.') : id.replace(/ /g, '-');
idNoSpaces = idNoSpaces
.replace(/(wiki([mp]edia|quote|source|books|news|versity)|wiktionary)/, '.$1.org')
.replace(/wiki$/, '.wikipedia.org');
if (idNoSpaces.indexOf('.org') !== -1) {
return idNoSpaces;
}
return false;
}
function fixCrosswikiLinks() {
$('body li a').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);
if (hostName) {
$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') {
$(document).ready(fixCrosswikiLinks);
}
}(mediaWiki, jQuery));