Benutzer:Netaction/WikiPraise.js
Erscheinungsbild
Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
// WikiPraise by Thomas Schmidt (netAction.de) for Wikimedia Deutschland
// Copyright (c) 2011, Wikimedia Deutschland
// Redistribution and use, with or without modification, are permitted,
// provided that the above copyright notice is retained.
// <nowiki>
// The strings for every user's language:
const WikiTrustLangMsgs = {
'en': {
MenueTitle: 'WikiPraise',
ServerNotRespond: 'Error: Server does not respond.',
WrittenInRev: 'Written in rev.',
ClickToFix: 'Click to fix this box.',
Author: 'Author',
UserLink2:'talk',
UserLink3:'contribs',
TooltipTitle:'WikiPraise',
InfoText:'This is the WikiPraise view. Hover your mouse over the text and see who wrote that part of the article. Click to fix the box.',
Loading:'Loading...',
WikipediaErrorReturned:'<h2>Error!</h2><p>The Wikipedia server respondet with an error message. Please <a href="http://de.wikipedia.org/w/index.php?title=Benutzer_Diskussion:Netaction/WikiPraise">contact us</a>.</p>',
WikitrustErrorReturned:'<h2>Error!</h2><p>The WikiTrust server respondet with the error message "#1#". Please [http://de.wikipedia.org/w/index.php?title=Benutzer_Diskussion:Netaction/WikiPraise contact us].</p>'
},
'de-at': {
MenueTitle: 'WikiPraise',
ServerNotRespond: 'Fehler: Der Server antwortet nicht.',
WrittenInRev: 'Geschrieben in Ver.',
ClickToFix: 'Klick zum Fixieren!',
Author: 'Autor',
UserLink2:'Diskussion',
UserLink3:'Beiträge',
TooltipTitle:'WikiPraise',
InfoText:'Dies ist der WikiPraise-Ansicht. Fahre mit der Maus über den Text um zu sehen, wer diesen Teil schrieb. Ein Klick fixiert die Box.',
Loading:'Lade...'
},
'de': {
MenueTitle: 'WikiPraise',
ServerNotRespond: 'Fehler: Der Server antwortet nicht.',
WrittenInRev: 'Geschrieben in Ver.',
ClickToFix: 'Klick zum Fixieren!',
Author: 'Autor',
UserLink2:'Diskussion',
UserLink3:'Beiträge',
TooltipTitle:'WikiPraise',
InfoText:'Dies ist der WikiPraise-Ansicht. Fahre mit der Maus über den Text um zu sehen, wer diesen Teil schrieb. Ein Klick fixiert die Box.',
Loading:'Lade...'
},
'de-ch': {
MenueTitle: 'WikiPraise',
ServerNotRespond: 'Fehler: Der Server antwortet nicht.',
WrittenInRev: 'Geschrieben in Ver.',
ClickToFix: 'Klick zum Fixieren!',
Author: 'Autor',
UserLink2:'Diskussion',
UserLink3:'Beiträge',
TooltipTitle:'WikiPraise',
InfoText:'Dies ist der WikiPraise-Ansicht. Fahre mit der Maus über den Text um zu sehen, wer diesen Teil schrieb. Ein Klick fixiert die Box.',
Loading:'Lade...'
},
'fr': {
MenueTitle: 'WikiPraise',
ServerNotRespond: 'cas d\'erreur',
WrittenInRev: 'version',
ClickToFix: 'Klick zum Fixieren!',
Author: 'auteur',
UserLink2:'discuter',
UserLink3:'contributions',
TooltipTitle:'WikiPraise',
InfoText:'Dies ist der WikiPraise-Ansicht. Fahre mit der Maus über den Text um zu sehen, wer diesen Teil schrieb. Ein Klick fixiert die Box.',
Loading:'Lade...'
},
'es': {
MenueTitle: 'WikiPraise',
ServerNotRespond: 'error',
WrittenInRev: 'versión',
ClickToFix: 'Klick zum Fixieren!',
Author: 'autor',
UserLink2:'Discusión',
UserLink3:'contribuciones',
TooltipTitle:'WikiPraise',
InfoText:'Dies ist der WikiPraise-Ansicht. Fahre mit der Maus über den Text um zu sehen, wer diesen Teil schrieb. Ein Klick fixiert die Box.',
Loading:'Lade...'
}
}
function WTgetMsg(msg) {
var lang = window.mediaWiki.user.options.values.language;
if (!(lang in WikiTrustLangMsgs)) lang = 'en';
if (!(msg in WikiTrustLangMsgs[lang])) lang = 'en';
return WikiTrustLangMsgs[lang][msg];
}
// The url parts for every language version of Wikipedia
const WikiTrustLangURLs = {
'en': { UserLink1: '/wiki/User:',UserLink2: '/wiki/User_talk:',UserLink3: '/wiki/Special:Contributions/'},
'de': { UserLink1: '/wiki/Benutzer:',UserLink2: '/wiki/Benutzer_Diskussion:',UserLink3: '/wiki/Spezial:Beiträge/'},
'fr': { UserLink1: '/wiki/Utilisateur:',UserLink2: '/wiki/Discussion_utilisateur:',UserLink3: '/wiki/Sp%C3%A9cial:Contributions/'}
}
function WTgetURL(msg) {
var variant = window.mediaWiki.user.options.values.variant;
if (!(variant in WikiTrustLangURLs)) variant = 'en';
if (!(msg in WikiTrustLangURLs[variant])) variant = 'en';
return WikiTrustLangURLs[variant][msg];
}
$(function() {
// Are we reading an article at the moment?
// Yes, Vector style:
if (($("li#ca-view").hasClass("selected")) && ($("li#ca-nstab-main").hasClass("selected"))) {
$("li#ca-history").after('<li id="WikiTrustButton"><span>'+
'<a href="#StartWikiTrust">'+WTgetMsg('MenueTitle')+'</a></span></li>');
$("li#WikiTrustButton span a").click(function(){ WikiTrustLoad(); });
}
// Yes, Monobook style:
if ((mw.config.get('skin')=="monobook") &&
($("li#ca-nstab-main").hasClass("selected")) &&
(!$("li#ca-history").hasClass("selected"))
) {
$("li#ca-history").after('<li id="WikiTrustButton">'+
'<a href="#StartWikiTrust">'+WTgetMsg('MenueTitle')+'</a></li>');
$("li#WikiTrustButton a").click(function(){ WikiTrustLoad(); });
}
// WikiTrust Deeplink used?
if(window.location.hash.slice(1) == "StartWikiTrust") { WikiTrustLoad(); }
});
$.ajaxSetup({
error:function() {
$('#bodyContent').html('<h2>'+WTgetMsg('ServerNotRespond')+'</h2>');
$("#content").fadeTo('slow', 1); // show content
}
});
function WikiTrustLoad() {
// We can not live without some styling:
$("head").append('<style type="text/css" charset="utf-8">'+
'span.wikitrustinfo { color:#333; cursor:pointer; } '+
'span.wikitrustinfo.active { color:black; background-color:#CFDEE4; } '+
'div#WikiTrustTooltip { position:absolute; top:100px; left:5px; background-color:#eee; width:143px; padding:4px; z-index:100; border:1px solid #93B5C0; font-size:80%; box-shadow:3px 3px 8px #666; }'+
'.skin-monobook div#WikiTrustTooltip { font-size:110%; }'+
'div#WikiTrustTooltip.fixed { border:3px solid #648793; }'+
'p#WikiTrustTooltipTitle { background-color:#93B5C0; margin:-4px -4px 0 -4px; text-align:center; color:white; }'+
'.fixed p#WikiTrustTooltipTitle { background-color:#648793; color:white; }'+
'.fixed div#WikiTrustCloseButton { position:absolute; right:0; top:0; cursor:pointer; color:white; z-index:110; }'+
'#WikiTrustInfotext { border: 1px solid #aaa; padding: 5px; line-height: 1.5em; margin: .5em 1em 0em 0em; text-align: center; clear: both; }'+
'#WikiTrustLoading { position:absolute; left:50%; top:50%; width:100px; height:20px; margin-left:-50px; margin-top:-25px; background-color:#eee; box-shadow:3px 3px 8px #666; border:1px solid #93B5C0; z-index:200; padding:20px; text-align:center; }'+
'</style>'
);
// save DIVs above content:
$('#bodyContent').data('siteSub',$('#siteSub').clone().wrap('<div></div>').parent().html())
.data('contentSub',$('#contentSub').clone().wrap('<div></div>').parent().html())
.data('jump-to-nav',$('#jump-to-nav').clone().wrap('<div></div>').parent().html())
.data('mw-fr-revisiontag-old',$('#mw-fr-revisiontag-old').clone().wrap('<div></div>').parent().html());
// try find this revision's ID in the URL:
var currentID=RegExp('[?&]oldid=([^&#]*)').exec(window.location.search);
// if there is no ID in the URL we take the latest version:
if (currentID) currentID=currentID[1]; else currentID=mw.config.get('wgCurRevisionId');
$("li#ca-view").removeClass("selected");
$("li#WikiTrustButton").addClass("selected");
$("#content").fadeTo('slow', 0.3); // the user has to wait
// Get the WikiCode of this article:
$('body').prepend('<div id="WikiTrustLoading">'+
WTgetMsg('Loading')+'</div>');
$.getJSON('http://'+window.mediaWiki.user.options.values.variant+'.collaborativetrust.com/'+
'WikiTrust/RemoteAPI?method=wikimarkup&'+
'pageid='+mw.config.get('wgArticleId')+'&revid='+currentID+'&callback=?',
function(data) {
if (data['error']) {
data=WTgetMsg('WikitrustErrorReturned').replace(/#1#/,data['error']);
} else data = data['text'];
data = decodeURIComponent(escape(data)); // WHY???
var genericHandler = function (match, trval, oid, username, txt) {
// trval: trust value and not used
// oid: version of change
var replace = '<span class="wikitrustinfo versionid-'+ oid +
' username-' +encodeURIComponent(username) +'"'+
// ' title="Click to fix the left box"'+
'>'+ txt + '</span>';
return replace;
};
// First, clean tags around links
var templates = /\{\{#t:(\d+),(\d+),([^}]+)\}\}(\s*)\[\[([^\]]+)\]\](\s*)(?=\{\{#t:|$)/mg;
data = data.replace(templates,
function (match, p1, p2, p3, p4, p5, p6) {
return p4 + genericHandler(match, p1, p2, p3, '[['+p5+']]') + p6;
});
// And also clean tags after a semi-colon
var semicolons = /^(;\s*)\{\{#t:(\d+),(\d+),([^}]+)\}\}(\s*[^\{<]*?)(?=\{|<|$)/mg;
data = data.replace(semicolons,
function (match, p1, p2, p3, p4, p5) {
return p1 + genericHandler(match, p2, p3, p4, p5);
});
// Now let's transform into HTML code:
$.ajax({
type:"POST",
url:'http://'+window.mediaWiki.user.options.values.variant+'.wikipedia.org/w/api.php',
data:'action=parse&format=json&text='+encodeURIComponent(data),
dataType:"json",
success:function(data){
data=data['parse']['text']['*'];
if (data.indexOf("<p>undefined</p>")==0) {
data=WTgetMsg('WikipediaErrorReturned');
}
// Fix edit section links
data = data.replace(/<span class="editsection"([^>]*)>(.*?) title="(.*?)"/g,
function (match, one, two, three) {
three = three.replace(/\{\{#t:\d+,\d+,[^}]+\}\}/g, '');
return '<span class="editsection"'+one+'>'+two+' title="'+three+'"';
});
// Fix trust tags with plain text after
var plaintxt = /\{\{#t:(\d+),(\d+),([^}]+)\}\}([^\{<]*)(?=\{\{#t|<|$)/g;
data = data.replace(plaintxt, genericHandler);
// And eliminate any remaining trust tags
// This line is not neccessary but to be sure:
data = data.replace(/\{\{#t:\d+,\d+,[^}]+\}\}/g, '');
// We're ready to put the new content into DOM:
$('#bodyContent').html(data);
// Put the tooltip into DOM:
$('<div id="WikiTrustTooltip"></div>').hide().prependTo('body');
// ### breathe life into content with all the triggers:
// first: If the user hovers content, show box with author's name:
$('span.wikitrustinfo').hover(function() {
if ($('#WikiTrustTooltip').hasClass('fixed')) return;
var versionid=RegExp('versionid-([^ ]*)').exec($(this).attr("class"));
if (versionid) versionid=versionid[1]; else return;
var username=RegExp('username-([^ ]*)').exec($(this).attr("class"));
if (username) username=decodeURIComponent(username[1]); else return;
$('span.versionid-'+versionid).addClass('active');
$('#WikiTrustTooltip').show().css({'top' : $(this).offset().top})
.html('<p id="WikiTrustTooltipTitle">'+WTgetMsg('TooltipTitle')+'</p>'+
'<p>'+WTgetMsg('Author')+': '+
'<a href="'+WTgetURL('UserLink1')+username+'">'+username+'</a>'+
'<br />'+
'(<a href="'+WTgetURL('UserLink2')+username+'">'+WTgetMsg('UserLink2')+'</a> | '+
'<a href="'+WTgetURL('UserLink3')+username+'">'+WTgetMsg('UserLink3')+'</a>)'+
'<p/>'+
'<p>'+
WTgetMsg('WrittenInRev')+' '+
'<a href="/w/index.php?'+
'title='+encodeURIComponent(mw.config.get('wgPageName'))+'&'+
'action=historysubmit&diff=prev&oldid='+versionid+'">'+
versionid+'</a>'+
'<p/>'+
'<p class="infotext">'+
WTgetMsg('ClickToFix')+
'</p>');
});
// second: If the user leaves content, hide box:
$('span.wikitrustinfo').mouseleave(function() {
if ($('#WikiTrustTooltip').hasClass('fixed')) return;
$('span.wikitrustinfo').removeClass('active');
$('#WikiTrustTooltip').hide();
});
// third: On click keep the box where it is:
$('span.wikitrustinfo').click(function() {
if ($('#WikiTrustTooltip').hasClass('fixed')) {
$('#WikiTrustTooltip').removeClass('fixed').fadeOut();
$('span.wikitrustinfo').removeClass('active');
return false;
}
$('#WikiTrustTooltip .infotext').hide();
$('#WikiTrustTooltip').addClass('fixed').append('<div id="WikiTrustCloseButton">⨯</div>');
return false;
});
// fourth: unfix box if user clicks elsewhere:
$('#bodyContent').click(function() {
$('#WikiTrustTooltip').removeClass('fixed');
$('span.wikitrustinfo').removeClass('active');
$('#WikiTrustTooltip').fadeOut();
});
// fifth: unfix box if user clicks in box (X):
$('#WikiTrustTooltip').click(function() { $('#bodyContent').click(); });
// Restore DIV elements above content:
$('#bodyContent').prepend('<div id="WikiTrustInfotext" class="noprint">'+
WTgetMsg('InfoText')+'</div>');
$('#bodyContent').prepend($('#bodyContent').data('mw-fr-revisiontag-old'));
$('#bodyContent').prepend($('#bodyContent').data('jump-to-nav'));
$('#bodyContent').prepend($('#bodyContent').data('contentSub'));
$('#bodyContent').prepend($('#bodyContent').data('siteSub'));
$("#content").fadeTo('slow', 1); // show new content
$('#WikiTrustLoading').fadeOut();
} // success function
}); // second ajax call
}); // first ajax call
}
// </nowiki>