User:Zppix/Test/MediaWiki:Gadget-CentralAuthInterlinkFixer.js: Difference between revisions
Content added Content deleted
(rv that part, apparently broken) |
(Test1) |
||
(16 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
/** |
|||
// Fix links like User:Example@somewiki. Author: VasilievVV, with modifications by Kalan and attempted rewrite by Splarka |
|||
* Fix links like User:Example@somewiki on Special:Log and Special:Recentchanges |
|||
function fixCrosswikiLinks() { |
|||
* @author VasilievVV, 2008-2010 |
|||
function host(id) { |
|||
* @author Kalan, 2008 |
|||
if(id == 'mediawikiwiki') { |
|||
* @author Splarka, 2008 |
|||
return 'mediawiki.org'; |
|||
* @author Krinkle, 2012 |
|||
} else if(id == 'foundationwiki') { |
|||
*/ |
|||
return 'wikimediafoundation.org'; |
|||
/*global mediaWiki, jQuery */ |
|||
} |
|||
/*jshint browser:true */ |
|||
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$/; |
|||
(function (mw, $) { |
|||
if(wikimedia.test(id)) { |
|||
'use strict'; |
|||
var r = id; |
|||
function host(id) { |
|||
r = r.replace(/ /, '-'); |
|||
var wikimedia, idNoSpaces; |
|||
r = r.replace(/wiki$/, ".wikimedia.org"); |
|||
if (id === 'metawiki') { |
|||
return r; |
|||
return 'meta.miraheze.org'; |
|||
} |
|||
} |
|||
var idNoSpaces = (id.match(/(arbcom enwiki|labswikimedia|pa uswikimedia|wg enwiki)$/)) ? id.replace(/ /, '.') : id.replace(/ /g, '-'); |
|||
if (id === 'testwiki') { |
|||
idNoSpaces = idNoSpaces.replace(/(wiki([mp]edia|quote|source|books|news|versity)|wiktionary)/, '.$1.org'); |
|||
return 'publictestwiki.com'; |
|||
idNoSpaces = idNoSpaces.replace(/wiki$/, '.wikipedia.org'); |
|||
} |
|||
if(idNoSpaces.indexOf('.org') != -1) return idNoSpaces |
|||
if (id === 'wikidatawiki') { |
|||
return false; |
|||
return 'wikidata.org'; |
|||
} |
|||
} |
|||
wikimedia = /^(advisory|auditcom|board|chair|chapcom|collab|comcom|commons|exec|grants|incubator|internal|login|meta|office|otrs wiki|quality|spcom|species|strategy|steward|wikimaniateam|wikimania20\d\d)wiki$/; |
|||
var docobj = document.getElementById('bodyContent') || document.getElementById('content') || document.getElementById('mw_content') || document.body |
|||
if (wikimedia.test(id)) { |
|||
var li = docobj.getElementsByTagName('li'); |
|||
return id.replace(/ /g, '-').replace(/_/g, '-').replace(/wiki$/, '.wikimedia.org'); |
|||
for(var i=0;i<li.length;i++) { |
|||
} |
|||
var a = getElementsByClassName(li[i],'a','new'); |
|||
idNoSpaces = id.match(/(arbcom enwiki|labswikimedia|pa uswikimedia|wg enwiki)$/) ? id.replace(/ /g, '.') : id.replace(/ /g, '-'); |
|||
for(var j=0;j<a.length;j++) { |
|||
idNoSpaces = idNoSpaces |
|||
var atxt = getText(a[j]); |
|||
.replace(/(wiki([mp]edia|quote|source|books|news|versity)|wiktionary)/, '.$1.org') |
|||
if(atxt.indexOf('@') != -1 && atxt.indexOf('/') == -1 && /^User\:/i.test(atxt)) { |
|||
.replace(/wiki$/, '.wikipedia.org'); |
|||
var bits = atxt.split('@',2); |
|||
if (idNoSpaces.indexOf('.org') !== -1) { |
|||
var user = encodeURIComponent(bits[0].replace(/^\s*User:(.+)\s*$/g, '$1')); |
|||
return idNoSpaces; |
|||
var wiki = bits[1]; |
|||
} |
|||
if(wiki == 'global') { |
|||
return false; |
|||
a[j].setAttribute('href', wgScript + '?title=Special:CentralAuth&target=' + 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 |
function fixCrosswikiLinks() { |
||
$('body li a').each(function () { |
|||
if (object.nodeType == 3) return object.nodeValue; |
|||
var bits, wiki, user, hostName, |
|||
var txt = []; |
|||
$el = $(this), |
|||
var i=0; |
|||
txt = $el.text(); |
|||
while(object.childNodes[i]) { |
|||
if (txt.indexOf('@') !== -1 && txt.indexOf('/') === -1 && /^User\:/i.test(txt)) { |
|||
txt[txt.length] = getText(object.childNodes[i]); |
|||
bits = txt.split('@'); |
|||
i++; |
|||
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') { |
|||
mw.hook('wikipage.content').add(fixCrosswikiLinks); |
|||
} |
|||
}(mediaWiki, jQuery)); |
Latest revision as of 22:46, 22 May 2021
/**
* 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 */
/*jshint browser:true */
(function (mw, $) {
'use strict';
function host(id) {
var wikimedia, idNoSpaces;
if (id === 'metawiki') {
return 'meta.miraheze.org';
}
if (id === 'testwiki') {
return 'publictestwiki.com';
}
if (id === 'wikidatawiki') {
return 'wikidata.org';
}
wikimedia = /^(advisory|auditcom|board|chair|chapcom|collab|comcom|commons|exec|grants|incubator|internal|login|meta|office|otrs wiki|quality|spcom|species|strategy|steward|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') {
mw.hook('wikipage.content').add(fixCrosswikiLinks);
}
}(mediaWiki, jQuery));