User:Zppix/Test/MediaWiki:Gadget-CentralAuthInterlinkFixer.js: Difference between revisions
Content deleted Content added
No edit summary |
2012 rewrite |
||
Line 6: | Line 6: | ||
* @author Krinkle, 2012 |
* @author Krinkle, 2012 |
||
*/ |
*/ |
||
/*global |
/*global mediaWiki, jQuery */ |
||
/*jslint browser:true, regexp:true */ |
|||
⚫ | |||
(function (mw, $) { |
|||
⚫ | |||
'use strict'; |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
⚫ | |||
⚫ | |||
} |
|||
⚫ | |||
⚫ | |||
return id.replace(/ /g, '-').replace(/_/g, '-').replace(/wiki$/, '.wikimedia.org'); |
|||
⚫ | |||
} |
|||
} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
.replace(/wiki$/, '. |
return id.replace(/ /g, '-').replace(/_/g, '-').replace(/wiki$/, '.wikimedia.org'); |
||
} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
⚫ | |||
⚫ | |||
.replace(/wiki$/, '.wikipedia.org'); |
|||
⚫ | |||
⚫ | |||
return idNoSpaces; |
|||
} |
|||
⚫ | |||
⚫ | |||
function fixCrosswikiLinks() { |
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').addClass('extiw'); |
|||
} |
|||
} |
|||
$el.attr('title', txt); |
|||
} |
|||
} |
|||
}); |
|||
} |
} |
||
if (mw.config.get('wgCanonicalSpecialPageName') === 'Log' || mw.config.get('wgCanonicalSpecialPageName') === 'Recentchanges') { |
if (mw.config.get('wgCanonicalSpecialPageName') === 'Log' || mw.config.get('wgCanonicalSpecialPageName') === 'Recentchanges') { |
||
$(document).ready(fixCrosswikiLinks); |
|||
} |
} |
||
}(mediaWiki, jQuery)); |