MediaWiki:Gadget-CentralAuthInterlinkFixer.js

// Fix links like User:Example@somewiki. Author: VasilievVV, with modifications by Kalan and attempted rewrite by Splarka function fixCrosswikiLinks { function host(id) { if(id == 'mediawikiwiki') { return 'mediawiki.org'; } else if(id == 'foundationwiki') { return 'wikimediafoundation.org'; }   var 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)) { var r = id; r = r.replace(/ /, '-'); r = r.replace(/wiki$/, ".wikimedia.org"); return r;   } var idNoSpaces = (id.match(/(arbcom enwiki|labswikimedia|pa uswikimedia|wg enwiki)$/)) ? id.replace(/ /, '.') : id.replace(/ /g, '-'); idNoSpaces = idNoSpaces.replace(/(wiki([mp]edia|quote|source|books|news|versity)|wiktionary)/, '.$1.org'); idNoSpaces = idNoSpaces.replace(/wiki$/, '.wikipedia.org'); if(idNoSpaces.indexOf('.org') != -1) return idNoSpaces return false; } var docobj = document.getElementById('bodyContent') || document.getElementById('content') || document.getElementById('mw_content') || document.body var li = docobj.getElementsByTagName('li'); for(var i=0;i<li.length;i++) { var a = getElementsByClassName(li[i],'a','new'); for(var j=0;j<a.length;j++) { var atxt = getText(a[j]); if(atxt.indexOf('@') != -1 && atxt.indexOf('/') == -1 && /^User\:/i.test(atxt)) { var bits = atxt.split('@',2); var user = encodeURIComponent(bits[0].replace(/^\s*User:(.+)\s*$/g, '$1')); var wiki = bits[1]; if(wiki == 'global') { a[j].setAttribute('href','http://toolserver.org/~vvv/sulutil.php?user=' + user); } else { var hostName = host(wiki) if(!hostName) continue; a[j].setAttribute('href','http://' + hostName + '/wiki/User:' + user); }       a[j].className = (wiki=='metawiki') ? '' : 'extiw' a[j].setAttribute('title',atxt); }   }  } } if(wgCanonicalSpecialPageName == 'Log' || wgCanonicalSpecialPageName == 'Recentchanges') addOnloadHook(fixCrosswikiLinks)

function getText(object) { if (object.nodeType == 3) return object.nodeValue; var txt = []; var i=0; while(object.childNodes[i]) { txt[txt.length] = getText(object.childNodes[i]); i++; } return txt.join(''); }