Jump to content

User:PerfektesChaos/js/citoidWikitext/dewiki/r.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/// User:PerfektesChaos/js/citoidWikitext/dewiki.js
/// 2020-02-20 PerfektesChaos@de.wikipedia
/// Fingerprint:#0#458018C3#
/// @license:CC-by-sa/4.0 GPLv3
///<nowiki>
(function(mw){
"use strict";
var Version=4.7,Signature="citoidWikitext",Sub="dewiki",TBIBRC={},TINTQU={},TLITER={},TSPIEG={},WIKI={templates:{}},CITWT,QUERY,fair,fast,favorite,favour,favoured,fiddle,findGoogleBooks,fixed,re2F,reGoogleBooks,urlPatterns;
function facilitated(){
var sign="ext.gadget."+Signature,sub="/"+Sub,signature=sign+sub,s=mw.loader.getState(signature),rls,w;
if(s!=="loaded"&&s!=="ready"){
rls={};
rls[signature]="loaded";
mw.loader.state(rls);
if(typeof mw.libs[Signature]!=="object"||!mw.libs[Signature]){
mw.libs[Signature]={};}
CITWT=mw.libs[Signature];
CITWT.signature=sign;
if(typeof CITWT.vsn==="string"){
CITWT.vsn=CITWT.vsn+" ";
}else{
CITWT.vsn="";}
CITWT.vsn=CITWT.vsn+"w:"+Version;
CITWT.type=Signature;
if(typeof CITWT[Sub]!=="object"||!CITWT[Sub]){
CITWT[Sub]={};}
w=CITWT[Sub];
if(typeof w.templates!=="object"||!w.templates){
w.templates={};}
for(s in WIKI.templates){
w.templates[s]=WIKI.templates[s];}
for(s in WIKI){
if(typeof WIKI[s]!=="object"){
w[s]=WIKI[s];}}
rls[signature]="ready";
mw.loader.state(rls);
mw.hook(Signature+sub+".ready").fire();}}
fair=function(apply){
var r=apply;
if(r){
if(r.indexOf("&#124;")>=0){
if(typeof CITWT.re!=="object"){
CITWT.re={};}
if(r.indexOf(" &#124; ")>=0){
if(typeof CITWT.re.pipesc==="undefined"){
CITWT.re.pipesc=new RegExp(" &#124; ","g");}
r=r.replace(CITWT.re.pipesc,String.fromCharCode(32,8211,32));}
if(!r.indexOf("&#124;")){
if(typeof CITWT.re.pipestart==="undefined"){
CITWT.re.pipestart=new RegExp("^(&#124; *)+");}
r=r.replace(CITWT.re.pipestart,"");}
if(r.lastIndexOf("&#124;")===r.length-6){
if(typeof CITWT.re.pipeterminate==="undefined"){
CITWT.re.pipeterminate=new RegExp("( *&#124;)+$");}
r=r.replace(CITWT.re.pipeterminate,"");}}
if(!r.indexOf("www")){
if(typeof CITWT.re!=="object"){
CITWT.re={};}
if(typeof CITWT.re.wwwSub==="undefined"){
CITWT.re.wwwSub=new RegExp("^(www[0-9]*.?\\.)\\w+\\.\\w+","g");}
r=r.replace(CITWT.re.wwwSub,"");}}
return r;
};
fast=function(all,address){
var r=address,s=address,e,g,i,n;
if(typeof urlPatterns!=="object"){
urlPatterns=[
["//arxiv\\.org/abs/(.+)$","arXiv"],["//adsabs\\.harvard\\.edu/(.+)$","bibcode"],["//portal\\.dnb\\.de/opac.+query=([0-9]+X?)$","DNB"],["//doi\\.org/(10\\.[^ ]+)(?: .*)?$","DOI"],["//dx\\.doi\\.org/(10\\.[^ ]+)(?: .*)?$","DOI"],["jstor\\.org/pss/(.+)$","JSTOR"],["jstor\\.org/stable/([0-9.a-z]+)(?:\\?seq=1.+)?$","JSTOR"],["jstor\\.org/discover/10\\.2307/([0-9.a-z]+)(?:\\?uid=.+)?$","JSTOR"],["www\\.worldcat\\.org/oclc/(.+)$","OCLC"],["ncbi\\.nlm\\.nih\\.gov/pmc/articles/pmc([0-9]+)","PMC"],["ncbi\\.nlm\\.nih\\.gov/pubmed/([0-9]+)","PMID"],["//nbn\\-resolving\\.de/urn:(.+)$","URN"],["//urn\\.nb\\.no/urn:(nbn:.+)$","URN"],["//urn\\.kb\\.se/resolve\\?urn=(.+)$","URN"]];
n=urlPatterns.length;
for(i=1;i<n;i++){
urlPatterns[i][0]=new RegExp(urlPatterns[i][0]);}
}else{
n=urlPatterns.length;}
if(s.indexOf("%2F")>0){
if(typeof re2F!=="object"){
re2F=new RegExp("%2F","ig");}
s=s.replace(re2F,"/");}
for(i=1;i<n;i++){
e=urlPatterns[i];
g=s.match(e[0]);
if(g){
s=e[1];
r=CITWT.opus.fetch(all[0],s);
if(!r){
for(i=1;i<all.length;i++){
if(all[i][0]===s){
r=true;
break;}}
if(!r){
all.push([s,true,g[1]]);}}
r=false;
break;}}
return r;
};
favorite=function(){
return[[QUERY.scheme+"|"+QUERY.seek,false,true]];
};
favour=function(jqXHR,textStatus /*,errorThrown*/){
if(typeof window.console==="object"&&typeof window.console.log==="function"){
window.console.log(Signature+" * "+Sub);
if(textStatus&&typeof textStatus==="object"&&typeof window.console.dir==="function"){
window.console.dir(textStatus);}}
if(QUERY){
QUERY.finish(false);}
};
favoured=function(arrived){
var r;
if(arrived&&typeof arrived==="object"&&typeof arrived.query==="object"&&arrived.query&&typeof arrived.query.pageids==="object"&&arrived.query.pageids[0]&&typeof arrived.query.pageids[0]==="string"&&arrived.query.pageids[0].indexOf("-")<0){
QUERY.priority=true;
r=QUERY.scheme;
}else{
r=false;}
QUERY.finish(r);
if(!r){
QUERY=false;}
};
fiddle=function(assembly){
var n,s,wstm;
if(typeof assembly["ISBN-type"]==="number"&&typeof assembly["ISBN-invalid"]==="boolean"&&!assembly["ISBN-invalid"]&&typeof assembly.year==="number"){
n=assembly["ISBN-type"];
if((assembly.year<2007)===(n===13)){
if(typeof mw.libs.WikiSyntaxTextMod==="object"){
wstm=mw.libs.WikiSyntaxTextMod;
s=assembly.ISBN[0];
if(typeof wstm.util==="object"&&typeof wstm.util.isbn.faith==="function"){
if(n===13){
s=s.substr(4);
}else{
s="978-"+s;}
s=s.substr(0,s.length-1);
n=wstm.util.isbn.faith(s,n);
if(n>=0){
if(n<10){
s=s+n;
}else{
s=s+"X";}
assembly.ISBN[0]=s;}}}}}
};
findGoogleBooks=function(address){
if(!reGoogleBooks){
reGoogleBooks=new RegExp("^https?://books\\.google\\.(?:com|[a-z][a-z])/");}
return reGoogleBooks.test(address);
};
fixed=function(assembly,all,apply){
var isbn=(typeof assembly.ISBN==="object"&&assembly.ISBN.length),r=CITWT.opus.fork(apply),e,i,issn,g,l,re,red,s,v;
switch(typeof assembly.ISSN){
case "string":
issn=assembly.ISSN;
break;
case "object":
if(assembly.ISSN&&typeof assembly.ISSN[0]==="string"){
issn=assembly.ISSN[0];}
break;}
for(i=1;i<r.length;i++){
e=r[i];
l=false;
s=e[0];
v=false;
switch(s){
case "Autor":
v=WIKI.family(assembly,"authors");
if(!v&&typeof assembly.title==="string"&&all.length>1){
g=all[2];
if(g.domain==="dnb.de"&&typeof g.title==="string"&&!g.title.indexOf(assembly.title)){
v=g.title.substr(assembly.title.length);}}
g=WIKI.family(assembly,"contributors");
if(g){
if(v){
v=v+", "+g;
}else{
v=g;}}
break;
case "Hrsg":
case "Herausgeber":
v=WIKI.family(assembly,"editors");
break;
case "Titel":
if(typeof assembly.bookTitle==="string"){
if(typeof assembly.title==="string"){
assembly.chapter=assembly.title;}
assembly.title=assembly.bookTitle;}
v=CITWT.opus.fetch(assembly,"title");
v=fair(v);
break;
case "Sammelwerk":
v=CITWT.opus.fetch(assembly,"publicationTitle");
if(v){
v=fair(v);
if(v==="Frankfurter Allgemeine Zeitung"){
v="[[Frankfurter Allgemeine Zeitung|FAZ]]";}}
break;
case "Reihe":
v=CITWT.opus.fetch(assembly,"seriesTitle");
l=true;
break;
case "Band":
v=CITWT.opus.fetch(assembly,"volume");
break;
case "Nummer":
v=CITWT.opus.fetch(assembly,"issue");
break;
case "Auflage":
if(issn){
l=true;
}else{
v=CITWT.opus.fetch(assembly,"edition");
if(v){
red=new RegExp(" *\\b(Aufl\\.?|Auflage|ed\\.?|Edition)","gi");
v=v.replace(red,"");}}
break;
case "Verlag":
v=CITWT.opus.fetch(assembly,"publisher");
if(v){
re=new RegExp(" *GmbH");
v=v.replace(re,"");}
break;
case "Ort":
if(issn){
l=true;
}else{
v=CITWT.opus.fetch(assembly,"place");}
break;
case "Datum":
case "Jahr":
v=CITWT.opus.fetch(assembly,"date");
if(v&&isbn){
v=v.substr(0,4);}
break;
case "Kapitel":
v=CITWT.opus.fetch(assembly,"chapter");
l=true;
break;
case "Seiten":
v=CITWT.opus.fetch(assembly,"pages");
if(v&&v.indexOf("-")>0){
v=v.replace(/-/g,String.fromCharCode(8211));}
break;
case "Online":
if(typeof assembly.itemType==="string"&&assembly.itemType.indexOf("Article")>0&&typeof assembly.url==="string"){
v=assembly.url;
if(typeof assembly.domain==="string"){
v="["+v+" "+assembly.domain+"]";}
if(!findGoogleBooks(v)){
r.push(["Abruf",true,CITWT.opus.freeze(10)]);}
v=fast(r,v);
if(!v){
l=true;}
}else{
l=true;}
break;
case "Abruf":
l=true;
break;
case "ISBN":
if(issn){
l=true;
}else if(isbn){
if(typeof apply.ISBNformalFalsch==="boolean"&&CITWT.opus.fetch(assembly,"ISBN-invalid")){
v=false;
}else{
v=assembly.ISBN[0];}}
break;
case "ISBNistFormalFalsch":
if(CITWT.opus.fetch(assembly,"ISBN-invalid")){
v="1";}
l=true;
break;
case "ISBNformalFalsch":
if(CITWT.opus.fetch(assembly,"ISBN-invalid")){
if(isbn){
v=assembly.ISBN[0];}
}else{
v=false;}
l=true;
break;
case "ISSN":
v=issn;
if(isbn&&!v){
l=true;}
break;
case "DNB":
case "LCCN":
case "OCLC":
if(isbn){
s="-";}
case "arXiv":
case "DOI":
case "PMC":
case "PMID":
case "URN":
v=CITWT.opus.fetch(assembly,s.toUpperCase());
l=true;
if(v&&s==="PMC"&&v.substr(0,3)==="PMC"){
v=v.substr(3);}
break;
case "Originalsprache":
v=CITWT.opus.fetch(assembly,"originalLang");
break;
case "TitelErg":
case "Originaltitel":
case "Übersetzer":
case "Linktext":
case "URL":
case "Abruf":
case "Sprache":
case "GBS-id":
v="";
break;
case "Seite":
case "Spalten":
case "Typ":
case "Kommentar":
case "record":
case "format":
v="{{{"+s+"|}}}";
break;
default:
if(typeof window.console==="object"&&typeof window.console.log==="function"){
window.console.log("citoidWikitext.dewiki.fixed() p="+s);}}
e.push(v);
if(l&&!v){
r[i]=false;}}
s=CITWT.opus.fetch(assembly,"url");
if(s&&findGoogleBooks(s)){
v=CITWT.opus.fetch(assembly,"domain");
if(v){
r.push(["Online",true,"["+s+" books."+v+"]"]);}}
return r;
};
TBIBRC.template=[["BibRecord",true,true,false],["Autor",true],["Herausgeber",true],["Titel",true],["TitelErg",true],["ISBN",true],["ISBNistFormalFalsch",true],["Jahr",true],["Verlag",true],["Ort",true],["Auflage",true],["Originaltitel",true],["Originalsprache",true],["Übersetzer",true],["Band",true],["Reihe",true],["Nummer",true],["Linktext",true],["URL",true],["Abruf",true],["Sprache",true],["GBS-id",true],["Seite",true],["Seiten",true],["Spalten",true],["Typ",true],["Kapitel",true],["Kommentar",true],["record",true],["format",true]];
TBIBRC.fire=function(assembly,all){
var pass={Kapitel:"chapter",Seiten:"pages"},r,s,supply;
for(s in pass){
supply=pass[s];
if(!CITWT.opus.fetch(assembly,supply)){
assembly[supply]="{{{"+s+"|}}}";}}
fiddle(assembly);
r=fixed(assembly,all,TBIBRC.template);
r=CITWT.opus.fruit(r,0);
return r;
};
TINTQU.template=[["Internetquelle",true,false,false],["url",true],["autor",false],["hrsg",true],["titel",true],["werk",true],["datum",false],["format",false],["sprache",false],["archiv-url",true],["archiv-datum",true],["offline",true],["abruf",true]];
TINTQU.fire=function(assembly){
var r=CITWT.opus.fork(this.template),e,got,i,maker,re,stored,v;
for(i=1;i<r.length;i++){
e=r[i];
v=false;
switch(e[0]){
case "url":
v=CITWT.opus.fetch(assembly,"url");
break;
case "autor":
v=WIKI.family(assembly,"authors");
break;
case "hrsg":
v=CITWT.opus.fetch(assembly,"websiteTitle");
v=fair(v);
maker=i;
break;
case "titel":
v=CITWT.opus.fetch(assembly,"title");
v=fair(v);
break;
case "werk":
v=CITWT.opus.fetch(assembly,"publicationTitle");
if(v){
v=fair(v);
switch(v){
case "Frankfurter Allgemeine Zeitung":
v="[[Frankfurter Allgemeine Zeitung|FAZ]]";
break;
case "Spiegel Online":
v="[[Spiegel Online]]";
break;}
}else{
v=CITWT.opus.fetch(assembly,"domain");}
if(v){
v=v.replace(/^(www.?\.)\w+\.\w+$/,"");
if(v===r[maker][2]){
r[maker][2]=false;}}
break;
case "datum":
v=CITWT.opus.fetch(assembly,"date");
break;
case "format":
v=CITWT.opus.format(assembly);
break;
case "sprache":
v=CITWT.opus.fetch(assembly,"language");
break;
case "archiv-url":
v=CITWT.opus.fetch(assembly,"archive");
if(v){
if(v.indexOf("//web.archive.org/web/")>0){
re="web\\.archive\\.org/web";
}else if(v.indexOf("//archive.is/")>0){
re="archive\\.is";
}else{
re=false;}
if(re){
re=new RegExp("^https?://"+re+"/([12][9012][0-9][0-9])([01][0-9])([0-3][0-9])[0-9]+/");
got=re.exec(v);
if(got){
stored=got[1]+"-"+got[2]+"-"+got[3];}}}
break;
case "archiv-datum":
if(stored){
v=stored;}
break;
case "offline":
break;
case "abruf":
if(!stored){
v=CITWT.opus.freeze(10);}
break;}
e.push(v);}
return r;
};
TLITER.template=[["Literatur",true,true,false],["Autor",true],["Hrsg",false],["Titel",true],["Sammelwerk",false],["Reihe",false],["Band",false],["Nummer",false],["Auflage",false],["Verlag",true],["Ort",true],["Datum",true],["ISBN",false],["ISBNformalFalsch",false],["Kapitel",false],["Seiten",true],["ISSN",false],["Online",false],["Abruf",false],["arXiv",false],["DOI",false],["DNB",false],["LCCN",false],["OCLC",false],["PMC",false],["PMID",false],["URN",false]];
TLITER.fire=function(assembly,all){
var r;
if(assembly.domain==="spiegel.de"){
r=TSPIEG.fire(assembly);
}else{
fiddle(assembly);
r=fixed(assembly,all,TLITER.template);}
if(!r){
r=TINTQU.fire(assembly);}
return r;
};
TSPIEG.template=[["Der Spiegel",false,true],["ID",true],["Autor",false],["Titel",true],["Jahr",true],["Nr",true]];
TSPIEG.fire=function(assembly){
var r=CITWT.opus.fork(this.template),e,i,v;
for(i=1;i<r.length;i++){
e=r[i];
v=false;
switch(e[0]){
case "ID":
if(typeof assembly.url==="string"){
v=assembly.url.replace(/^.+print\/d-(\d+)\.html$/,"$1");}
break;
case "Autor":
v=WIKI.family(assembly,"authors");
if(!v&&typeof assembly.year==="number"&&assembly.year<2000){
r[i]=false;}
break;
case "Titel":
v=CITWT.opus.fetch(assembly,"title");
break;
case "Jahr":
v=CITWT.opus.fetch(assembly,"year");
break;
case "Nr":
v=CITWT.opus.fetch(assembly,"issue");
break;}
e.push(v);}
return r;
};
WIKI.templates.Google_Buch=function(appendix){
var p=CITWT.core.fold(appendix),r="http://books.google.";
if(typeof p.Land==="string"&&p.Land==="US"){
r=r+"com/books?";
}else{
r=r+"de/books?";}
if(typeof p.BuchID==="string"&&p.BuchID){
r=r+"id="+p.BuchID;
if(typeof p.Band==="string"&&p.Band){
r=r+"&pg=RA"+p.Band;}
if(typeof p.Seite==="string"&&p.Seite){
r=r+"&pg=PA"+p.Seite;}
if(typeof p.SeitenID==="string"&&p.SeitenID){
r=r+"&pg="+p.SeitenID;}
}else if(typeof p.Suchbegriff==="string"&&p.Suchbegriff){
r=r+"q="+mw.util.rawurlencode(p.Suchbegriff);
}else{
r=false;}
return r;
};
WIKI.stiff="|book|bookSection|conferencePaper|dictionaryEntry|encyclopediaArticle|journalArticle|magazineArticle|manuscript|newspaperArticle|report|thesis|";
WIKI.family=function(assembly,access){
var e,i,o,r,s;
if(typeof assembly[access]==="object"){
o=assembly[access];
for(i=0;i<o.length;i++){
e=o[i];
if(typeof e==="object"&&e){
if(typeof e.family==="string"){
s=e.family;
}else{
s="";}
if(typeof e.given==="string"){
s=e.given+(s?" ":"")+s;}
if(typeof e.name==="string"){
if(s){
s=s+" ("+e.name+")";
}else{
s=e.name;}}
if(typeof e.extra==="string"){
s=s+" ["+e.extra+"]";}
}else{
s=false;}
if(s){
r=(r?r+", ":"")+s;}}
}else{
r=false;}
return r;
};
WIKI.favorite=function(ask,advance){
var support="|doi|isbn|pmid|",r,scheme,seek;
if(typeof ask.scheme==="string"&&support.indexOf("|"+ask.scheme+"|")>=0){
scheme="Bib"+ask.scheme.toUpperCase();
seek=ask[ask.scheme];
QUERY=ask;
QUERY.finish=advance;
QUERY.priority=false;
QUERY.scheme=scheme;
QUERY.seek=seek;
QUERY.beforeSend="json";
r={jq:{url:mw.util.wikiScript("api")+"?action=query&prop=revisions&indexpageids&format=json&titles=Template:"+scheme+"/"+seek+"&rvlimit=1"},found:favoured,fault:favour
};
}else{
QUERY=false;}
return r;
};
WIKI.fire=function(assigned){
var lit,r,top;
if(QUERY&&QUERY.priority){
r=favorite();
}else if(assigned){
top=assigned[0];
if(CITWT.bibRecord){
if(CITWT.bibRecord.launch){
r=TBIBRC.fire(top,assigned);}
}else{
lit=(top.isbn||typeof top.issn==="string");
if(!lit&&typeof top.itemType==="string"&&WIKI.stiff.indexOf("|"+top.itemType+"|")>=0){
lit=true;}
if(lit&&typeof top.urlQuery==="string"&&top.urlQuery.indexOf("/wiki/")>0){
lit=false;}
if(lit&&typeof top.itemType==="string"&&top.itemType==="encyclopediaArticle"&&typeof top.url==="string"&&top.url.indexOf("/w/index.php?title=")>0){
lit=false;}
if(lit){
r=TLITER.fire(top,assigned);
}else{
r=TINTQU.fire(top);}}}
return r;
};
facilitated();
}(window.mediaWiki,window.jQuery));
/// EOF</nowiki>citoidWikitext/dewiki/r.js