Zum Inhalt springen

Benutzer:Schnark/js/personendaten.js/normdaten.js

aus Wikipedia, der freien Enzyklopädie
Dies ist eine alte Version dieser Seite, zuletzt bearbeitet am 3. Dezember 2013 um 13:06 Uhr durch Schnark (Diskussion | Beiträge) (nicht bei alten Versionen ausführen). Sie kann sich erheblich von der aktuellen Version unterscheiden.

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
//Dokumentation unter [[Benutzer:Schnark/js/personendaten/normdaten]] <nowiki>
/*global mediaWiki: false, escape: false */
/*jshint sub: true */
(function($, mw){

var extrahiere = function (regex, text) { //liefert erste Klammer des regulären Ausdrucks
   return (regex.exec(text) === null ? '' : regex.exec(text)[1]);
};

var normdaten = {
version: '4.18',

tE: false,

$pd: {length: 0}, $nd: {length: 0},

gnd_fehlt_vorschlag: false, //statt leerer GND ein "fehlt" vorschlagen
ist_person: false, //Normdaten zu einer Person -> umfangreicheres Interface
dnbportal: '', //GND in DNB-Portal-Vorlage, falls abweichend von GND
checkdate: '', //Inhalt von GNDCheck

comment_nd_neu: '+Normdaten',
comment_nd_erw: 'Normdaten ergänzt',
comment_nd_korr: 'Normdaten korrigiert',
comment_nd_akt: 'Normdaten auf neue Version umgestellt',

disableExternal: false, //kein Skript von VIAF.org/id.ndl.go.jp laden
full: 0, //0: leere Parameter löschen, 1: leere Parameter behalten, 2: meisten leere Parameter behalten
alwaysShowEdit: false, //Bearbeiten-Schaltfläche immer anzeigen

autocorr: {
 gnd_fehlt: function (gnd) {
    return normdaten.format_gnd(gnd, true);
 },
 gnd: function (gnd) {
    return normdaten.format_gnd(gnd);
 },
 lccn: function (lccn) {
    return normdaten.format_lccn(lccn, true);
 },
 nospace: function (viaf) {
    return viaf.replace(/\s/g, '');
 },
 typ: function (typ) {
    typ = typ.replace(/\s/g, '').toLowerCase().substr(0, 1);
    if ('pkvwsg'.indexOf(typ || '?') === -1) {
       typ = '';
    }
    return typ;
 }
},

add_interface: function (data) {
   if (normdaten.ist_person) {
      normdaten.add_interface_person(data);
   } else {
      normdaten.add_interface_other(data);
   }
},
add_interface_person: function (data) {
    var title, PDFn = normdaten.getPDFn(), $name, $anamen;

    normdaten.tE.addInput('gnd', {text: '<code>GND</code> (Person)', val: data.gnd, autofill: true, autocorr: normdaten.autocorr.gnd_fehlt}).html(
       mw.html.element('a', {id: 'pen-show-gnd', href: '#', title: 'Datensatz zu dieser GND-Nummer (in neuem Tab)'}, '?') + '&nbsp;' +
       mw.html.element('a', {id: 'pen-loesche-gnd', href: '#', title: 'GND entfernen'}, 'x') + '&nbsp;' +
       mw.html.element('a', {id: 'pen-suche-viaf', href: '#', title: 'Suche nach VIAF-Nummer zu dieser GND (in neuem Tab)'}, '→VIAF'));

    normdaten.tE.addInput('gndname', {text: '<code>GND</code> (Name)', val: data.gndname, /* autofill: true, */ autocorr: normdaten.autocorr.gnd}).html(
       mw.html.element('a', {id: 'pen-show-gndname', href: '#', title: 'Datensatz zu dieser GND-Nummer (in neuem Tab)'}, '?') + '&nbsp;' +
       mw.html.element('a', {id: 'pen-loesche-gndname', href: '#', title: 'GND entfernen'}, 'x') + '&nbsp;' +
       mw.html.element('a', {id: 'pen-vertausche-gnd', href: '#', title: 'GND und GNDName vertauschen'}, '↔'));

    normdaten.tE.addInput('lccn', {text: '<code>LCCN</code>', val: data.lccn, autofill: true, autocorr: normdaten.autocorr.lccn}).html(
       mw.html.element('a', {id: 'pen-show-lccn', href: '#', title: 'Datensatz zu dieser LCCN-Nummer (in neuem Tab)'}, '?') + '&nbsp;' +
       mw.html.element('a', {id: 'pen-loesche-lccn', href: '#', title: 'LCCN entfernen'}, 'x'));

    normdaten.tE.addInput('ndl', {text: '<code>NDL</code>', val: data.ndl, /*autofill: true, */ autocorr: normdaten.autocorr.nospace}).html(
       mw.html.element('a', {id: 'pen-show-ndl', href: '#', title: 'Datensatz zu dieser NDL-Nummer (in neuem Tab)'}, '?') + '&nbsp;' +
       mw.html.element('a', {id: 'pen-loesche-ndl', href: '#', title: 'NDL entfernen'}, 'x'));

    normdaten.tE.addInput('viaf', {text: '<code>VIAF</code>', val: data.viaf, autofill: true, autocorr: normdaten.autocorr.nospace}).html(
       mw.html.element('a', {id: 'pen-show-viaf', href: '#', title: 'Datensatz zu diser VIAF-Nummer (in neuem Tab)'}, '?') + '&nbsp;' +
       mw.html.element('a', {id: 'pen-loesche-viaf', href: '#', title: 'VIAF entfernen'}, 'x'));

    normdaten.tE.addInput('sonstige', {text: 'Sonstige', val: data.sonstige});

    title = encodeURIComponent(mw.config.get('wgTitle').replace(/ \(.*$/, ''));
    normdaten.tE.addFootitem(mw.html.element('a', {title: 'Suche nach VIAF (in neuem Tab)', target: '_blank',
                                  href: 'http://www.viaf.org/viaf/search?query=local.names+all+%22' +
                                    title + '%22&stylesheet=/viaf/xsl/results.xsl&sortKeys=holdingscount'},
                            'VIAF'));
    normdaten.tE.addFootitem(mw.html.element('a', {title: 'Suche nach GND (in neuem Tab)', target: '_blank',
                                  href: 'https://portal.d-nb.de/opac.htm?method=simpleSearch&query=' +
                                    title.replace(/%20/g, '+')},
                            'DNB'));
    normdaten.tE.addFootitem(mw.html.element('a', {title: 'Suche nach NDL (in neuem Tab)', target: '_blank',
                                  href: 'http://id.ndl.go.jp/auth/ndla/?qw=' + title},
                            'NDL'));
    normdaten.tE.addFootitem(mw.html.element('a', {title: 'Bitte um Individualisierung einer GND, Meldung von Fehlern (in neuem Tab)', target: '_blank',
                                  href: mw.util.getUrl('Wikipedia:PND/Fehlermeldung'), id: 'pd-nd-pndf'},
                            'WP:PND/F'));
    if (normdaten.checkdate) {
       normdaten.tE.addFootitem(mw.html.element('a', {id: 'pen-datum-aktualisieren', title: 'Datum der letzten Überprüfung von ' +
                                                           normdaten.checkdate + ' auf aktuelles Datum aktualisieren', href: '#'},
                                'Datum aktualisieren'));
       $('#pen-datum-aktualisieren').click(normdaten.datum_aktualisieren);
    }

  normdaten.tE.get$('gnd').addClass('noime');
  normdaten.tE.get$('gndname').addClass('noime');
  normdaten.tE.get$('lccn').addClass('noime');
  normdaten.tE.get$('ndl').addClass('noime');
  normdaten.tE.get$('viaf').addClass('noime');
  normdaten.tE.get$('sonstige').addClass('noime');

  $('#pen-show-gnd').click(normdaten.show_gnd);
  $('#pen-loesche-gnd').click(function(){normdaten.loeschen('gnd'); return false;});
  $('#pen-suche-viaf').click(normdaten.suche_viaf);
  $('#pen-show-gndname').click(normdaten.show_gndname);
  $('#pen-loesche-gndname').click(function(){normdaten.loeschen('gndname'); return false;});
  $('#pen-vertausche-gnd').click(normdaten.vertausche_gnd);
  $('#pen-show-lccn').click(normdaten.show_lccn);
  $('#pen-loesche-lccn').click(function(){normdaten.loeschen('lccn'); return false;});
  $('#pen-show-ndl').click(normdaten.show_ndl);
  $('#pen-loesche-ndl').click(function(){normdaten.loeschen('ndl'); return false;});
  $('#pen-show-viaf').click(normdaten.show_viaf);
  $('#pen-loesche-viaf').click(function(){normdaten.loeschen('viaf'); return false;});

  normdaten.start_ajax();
  PDFn = normdaten.getPDFn();
  if (PDFn) {
     $name = PDFn.get$('name');
     if ($name !== null) {
        $name.change(function () {
              normdaten.start_ajax(true);
        });
     }
     $anamen = PDFn.get$('alternativnamen');
     if ($anamen !== null) {
        $anamen.change(function () {
                normdaten.start_ajax(true);
        });
     }
  }
  normdaten.tE.get$('gnd').change(normdaten.start_ajax);
  normdaten.tE.get$('lccn').change(normdaten.start_ajax);
  normdaten.tE.get$('viaf').change(normdaten.start_ajax);
},
add_interface_other: function (data) {
   normdaten.tE.addInput('typ', {text: '<code>TYP</code>', val: data.typ, autofill: true, autocorr: normdaten.autocorr.typ});
   normdaten.tE.addInput('gnd', {text: '<code>GND</code>', val: data.gnd, autofill: true, autocorr: normdaten.autocorr.gnd}).html(
      mw.html.element('a', {id: 'pen-show-gnd', href: '#', title: 'Datensatz zu dieser GND-Nummer (in neuem Tab)'}, '?') + '&nbsp;' +
      mw.html.element('a', {id: 'pen-loesche-gnd', href: '#', title: 'GND entfernen'}, 'x') /*+ '&nbsp;' +
      mw.html.element('a', {id: 'pen-suche-viaf', href: '#', title: 'Suche nach VIAF-Nummer zu dieser GND (in neuem Tab)'}, '→VIAF')*/);
   normdaten.tE.addInput('lccn', {text: '<code>LCCN</code>', val: data.lccn, autofill: true, autocorr: normdaten.autocorr.lccn}).html(
      mw.html.element('a', {id: 'pen-show-lccn', href: '#', title: 'Datensatz zu dieser LCCN-Nummer (in neuem Tab)'}, '?') + '&nbsp;' +
      mw.html.element('a', {id: 'pen-loesche-lccn', href: '#', title: 'LCCN entfernen'}, 'x'));
    normdaten.tE.addInput('ndl', {text: '<code>NDL</code>', val: data.ndl, /*autofill: true, */ autocorr: normdaten.autocorr.nospace}).html(
       mw.html.element('a', {id: 'pen-show-ndl', href: '#', title: 'Datensatz zu dieser NDL-Nummer (in neuem Tab)'}, '?') + '&nbsp;' +
       mw.html.element('a', {id: 'pen-loesche-ndl', href: '#', title: 'NDL entfernen'}, 'x'));
   normdaten.tE.addInput('viaf', {text: '<code>VIAF</code>', val: data.viaf, autofill: true, autocorr: normdaten.autocorr.nospace}).html(
      mw.html.element('a', {id: 'pen-show-viaf', href: '#', title: 'Datensatz zu diser VIAF-Nummer (in neuem Tab)'}, '?') + '&nbsp;' +
      mw.html.element('a', {id: 'pen-loesche-viaf', href: '#', title: 'VIAF entfernen'}, 'x'));

   normdaten.tE.addInput('sonstige', {text: 'Sonstige', val: data.sonstige});

   var title = encodeURIComponent(mw.config.get('wgTitle').replace(/ \(.*$/, ''));
   normdaten.tE.addFootitem(mw.html.element('a', {title: 'Suche nach GND (in neuem Tab)', target: '_blank',
                                 href: 'https://portal.d-nb.de/opac.htm?method=simpleSearch&query=' +
                                   title.replace(/%20/g, '+')},
                           'DNB'));

   normdaten.tE.setList('typ', [['Person', 'p'], ['Körperschaft', 'k'], ['Veranstaltung', 'v'], ['Werk', 'w'], ['Sachbegriff', 's'], ['Geografikum', 'g']], 'Mögliche Typen');
   normdaten.tE.setSuggestions('typ', data.typ_sugg);
   if (normdaten.dnbportal) {
      normdaten.tE.setSuggestions('gnd', normdaten.dnbportal);
   }

   normdaten.tE.get$('typ').addClass('noime');
   normdaten.tE.get$('gnd').addClass('noime');
   normdaten.tE.get$('lccn').addClass('noime');
   normdaten.tE.get$('ndl').addClass('noime');
   normdaten.tE.get$('viaf').addClass('noime');
   normdaten.tE.get$('sonstige').addClass('noime');

   $('#pen-show-gnd').click(normdaten.show_gnd);
   $('#pen-loesche-gnd').click(function(){normdaten.loeschen('gnd'); return false;});
   //$('#pen-suche-viaf').click(normdaten.suche_viaf);
   $('#pen-show-lccn').click(normdaten.show_lccn);
   $('#pen-loesche-lccn').click(function(){normdaten.loeschen('lccn'); return false;});
   $('#pen-show-ndl').click(normdaten.show_ndl);
   $('#pen-loesche-ndl').click(function(){normdaten.loeschen('ndl'); return false;});
   $('#pen-show-viaf').click(normdaten.show_viaf);
   $('#pen-loesche-viaf').click(function(){normdaten.loeschen('viaf'); return false;});

   normdaten.start_ajax();
   normdaten.tE.get$('gnd').change(normdaten.start_ajax);
   //normdaten.tE.get$('lccn').change(normdaten.start_ajax);
   normdaten.tE.get$('viaf').change(normdaten.start_ajax);
},

parseND: function (text) {
  var nd = extrahiere(/\{\{Normdaten\s*\|([^{}]*(?:\{\{[^{}]*\}\}[^{}]*)*)\}\}/, text.replace(/<!--.*?-->/g, ''))
             .replace(/\{\{[^{}]*\}\}|\[\[[^\[\]]*\]\]/g, function (c) {
               return c.replace(/\|/g, '~~~');
             }),
      params = nd.split('|'),
      data = {},
      i, index;
  //Normdaten auslesen
  for (i = 0; i < params.length; i++) {
      params[i] = params[i].replace(/~~~/g, '|');
      index = params[i].indexOf('=');
      if (index > -1) {
         data[params[i].substr(0, index).replace(/^\s+|\s+$/, '')] = params[i].substr(index + 1).replace(/^\s+|\s+$/, '');
      }
  }

  data['REMARK'] = extrahiere(/\{\{Normdaten\s*\|(?:[^{}]*(?:\{\{[^{}]*\}\}[^{}]*)*)\}\}[ ]*<!--\s*(.*? *)\s*-->/, text) + (data['REMARK'] || '');

  if ('PND' in data) {
     data['TYP'] = 'p';
     data['GND'] = data['PND'];
  }
  if (!('TYP' in data) && ('LCCN' in data || 'NDL' in data || 'VIAF' in data)) {
     data['TYP'] = 'p';
  }

  normdaten.checkdate = data['GNDCheck'];

  normdaten.dnbportal = extrahiere(/\{\{DNB-Portal\|([^|}]*)/, text);

  if (data['TYP'] === 'p' || (!data['TYP'] && (data['GNDName'] || data['GNDfehlt']))) {
     normdaten.ist_person = true;
  }

  if (normdaten.ist_person) {
     return normdaten.evalND_person(data);
  } else {
     return normdaten.evalND_other(data);
  }
},

evalND_person: function (data) {
  var gnd = data['GND'] || (data['GNDfehlt'] ? 'fehlt' : ''),
      gndname = data['GNDName'] || '',
      lccn = data['LCCN'] || '',
      ndl = data['NDL'] || '',
      viaf = data['VIAF'] || '',
      sonstige = normdaten.sonstige_parameter(data);

  if (gnd === 'fehlt') {
     normdaten.gnd_fehlt_vorschlag = true;
  }

  if (normdaten.dnbportal === gnd || normdaten.dnbportal === gndname) {
     normdaten.dnbportal = ''; //löschen
  }

  return {gnd: gnd, gndname: gndname, lccn: lccn, ndl: ndl, viaf: viaf, sonstige: sonstige};
},
evalND_other: function (data) {
  var typ = data['TYP'] || '',
      typ_sugg = [],
      gnd = data['GND'] || '',
      lccn = data['LCCN'] || '',
      ndl = data['NDL'] || '',
      viaf = data['VIAF'] || '',
      sonstige = normdaten.sonstige_parameter(data);

  //TODO Typ an Kategorien erkennen?
  if (gnd === '') {
     if (data['GKD']) {
        typ_sugg = ['k', 'v', 'g'];
        gnd = data['GKD'];
     } else if (data['SWD']) {
        typ_sugg = ['s', 'w', 'g'];
        gnd = data['SWD'];
     }
  }

  if (normdaten.dnbportal === gnd) {
     normdaten.dnbportal = ''; //löschen
  }

  return {typ: typ, gnd: gnd, lccn: lccn, ndl: ndl, viaf: viaf, sonstige: sonstige, typ_sugg: typ_sugg};
},

sonstige_parameter: function (data) {
  return 'REMARK' in data && data['REMARK'] !== '' ? 'REMARK=' + data['REMARK'] : ''; //FIXME
},

neuer_text: function (text, data) {
  var alte_nd = extrahiere(/(\{\{Normdaten\s*\|[^{}]*(?:\{\{[^{}]*\}\}[^{}]*)*\}\})/, text.replace(/<!--.*?-->/g, '')), alt_text = text, neue_nd,
      pos, comment = false;
  text.replace(/<!--(.*?)-->/g, function (c) {
      return '<!--' + c.replace(/\{\{/g, '{~~~{') + '-->';
  }); //auskommentierte Normdaten schützen
  text = text.replace(/\n*\{\{Normdaten\s*\|[^{}]*(?:\{\{[^{}]*\}\}[^{}]*)*\}\}[ ]*(?:<!--\s*.*?\s*-->)?/, ''); //alte Normdaten entfernen
  text.replace(/\{~~~\{/g, '{{');

  if (normdaten.ist_person) {
     neue_nd = normdaten.neuer_text_person(data);
  } else {
     neue_nd = normdaten.neuer_text_other(data);
  }

  if (!(/\d/.test(neue_nd)) && alte_nd === '') { //keine Zahl: ganz leer
     neue_nd = '';
  }

  if (neue_nd !== '') {
     pos = text.indexOf('{{SORTIERUNG');
     if (pos === -1) {
        pos = text.indexOf('{{DEFAULTSORT');
     }
     if (pos === -1) {
        pos = text.indexOf('[[Kategorie:');
     }
     if (pos === -1) {
        pos = text.indexOf('{{Personendaten');
     }
     if (pos === -1) {
        pos = text.length;
     }
     text = text.substr(0, pos) + neue_nd + '\n\n' + text.substr(pos);
  }

  if (alte_nd === '' && (neue_nd.indexOf('{{Normdaten') > -1)) {
     comment = normdaten.comment_nd_neu;
  } else if (alte_nd.indexOf('TYP=') === -1 && neue_nd.indexOf('TYP=') > -1) {
     comment = normdaten.comment_nd_akt;
  } else if (alte_nd.replace(/[^|]/g).length < neue_nd.replace(/[^|]/g).length) {
     comment = normdaten.comment_nd_erw;
  } else if (alt_text !== text) {
     comment = normdaten.comment_nd_korr;
  }

  return {text: text, comment: comment};
},
neuer_text_person: function (data) {
  var nd = '{{Normdaten';
  nd += '|TYP=p';
  if (data.gnd === 'fehlt') {
     if (normdaten.full) {
        nd += '|GND=';
     }
  } else {
     if (data.gnd || normdaten.full) {
        nd += '|GND=' + data.gnd;
     }
  }
  if (data.lccn || normdaten.full) {
     nd += '|LCCN=' + data.lccn;
  }
  if (data.ndl || normdaten.full === 1) {
     nd += '|NDL=' + data.ndl;
  }
  if (data.viaf || normdaten.full) {
     nd += '|VIAF=' + data.viaf;
  }
  if (data.gndname) {
     nd += '|GNDName=' + data.gndname;
  }
  if (data.gnd === 'fehlt') {
     nd += '|GNDfehlt=ja';
  }
  if ((data.gndname || (data.gnd === 'fehlt'))) {
     nd += '|GNDCheck=' + normdaten.isodate(normdaten.checkdate || '');
  }
  if (data.sonstige) {
     nd += '|' + data.sonstige;
  }
  nd += '}}';
  return nd;
},
neuer_text_other: function (data) {
  var nd = '{{Normdaten';
  if (data.typ) {
     nd += '|TYP=' + data.typ;
  }
  if (data.gnd || normdaten.full) {
     nd += '|GND=' + data.gnd;
  }
  if (data.lccn || normdaten.full === 1) {
     nd += '|LCCN=' + data.lccn;
  }
  if (data.ndl || normdaten.full === 1) {
     nd += '|NDL=' + data.ndl;
  }
  if (data.viaf || normdaten.full) {
     nd += '|VIAF=' + data.viaf;
  }
  if (data.sonstige) {
     nd += '|' + data.sonstige;
  }
  nd += '}}';
  return nd;
},

start_ajax: function (dontremove) { //startet alle AJAX-Dinge
  if (dontremove !== true) {
     normdaten.add_suggestions({gnd: null, lccn: null, ndl: null, viaf: null});
  }
  var data = normdaten.tE.getVal();

  if (data.gnd + data.lccn + data.viaf !== '' && normdaten.ist_person) { //bei Nicht-Personen hat VIAF ganz komische GND
     normdaten.sync_get();
  }

  if (data.gnd === '') {
     if (normdaten.dnbportal) {
        normdaten.add_list('gnd', 'dnbportal', [['{{DNB-Portal}}', normdaten.dnbportal]]);
     }
     normdaten.gndsugg_get();
  }
  if (data.ndl === '') {
     normdaten.ndlsugg_get();
  }
  if (data.viaf === '') {
     normdaten.viafsugg_get();
  }
  normdaten.wikidata_get();
},

old_lists: {},
add_list: function (feld, typ, list) {
   if (!(feld in normdaten.old_lists)) {
      normdaten.old_lists[feld] = {};
   }
   normdaten.old_lists[feld][typ] = list;
   var complete_list = [], i;
   for (typ in normdaten.old_lists[feld]) {
       for (i = 0; i < normdaten.old_lists[feld][typ].length; i++) {
           complete_list.push(normdaten.old_lists[feld][typ][i]);
       }
   }
   normdaten.tE.setList(feld, complete_list);
   return complete_list.length;
},

cacheFn: null,
getPDFn: function () {
   if (normdaten.cacheFn === null) {
      normdaten.cacheFn = normdaten.tE.getFunctions('Benutzer:Schnark/js/personendaten.js');
   }
   return normdaten.cacheFn;
},
cacheName: null,
getName: function () {
   if (!normdaten.ist_person) {
      return normdaten.tE.getTitle().replace(/ \(.+\)$/, '');
   }
   var PDFn = normdaten.getPDFn(), name = null, $name;
   if (PDFn) {
      name = PDFn.getVal('name');
   }
   if (name !== null) {
      return name;
   } else {
      if (normdaten.cacheName === null) {
         $name = normdaten.$pd.find('td').eq(1);
         if ($name.length === 1) {
            normdaten.cacheName = $name.text().replace(/^\s+/, '').replace(/\s+$/, '');
         } else {
            name = normdaten.tE.getTitle().replace(/ \(.+\)$/, '');
            var pos = name.lastIndexOf(' ');
            if (pos === -1) {
               normdaten.cacheName = name;
            } else {
               normdaten.cacheName = name.substr(pos + 1) + ', ' + name.substr(0, pos);
            }
         }
      }
      return normdaten.cacheName;
   }
},
cacheANamen: null,
getANamen: function () {
   var PDFn = normdaten.getPDFn(), anamen = null, $anamen;
   if (PDFn) {
      anamen = PDFn.getVal('alternativnamen');
   }
   if (anamen !== null) {
      return anamen;
   } else {
      if (normdaten.cacheANamen === null) {
         $anamen = normdaten.$pd.find('td').eq(3);
         if ($anamen.length === 1) {
            normdaten.cacheANamen = $anamen.text().replace(/^\s+/, '').replace(/\s+$/, '');
         } else {
            anamen = '';
         }
      }
      return normdaten.cacheANamen;
   }
},
getNameForNDL: function () {
   var anamen = normdaten.getANamen().split(';'), i;
   for (i = 0; i < anamen.length; i++) {
       if (/[\u3000-\u9FFF]/.test(anamen[i])) {
          return anamen[i].replace(/ \(.*\)$/, '').replace(/^(.*), (.*)$/, '$2 $1').replace(/[\s\u3000]/g, '');
       }
   }
   return normdaten.getName().replace(/^(.*), (.*)$/, '$2 $1');
},

gndsugg_get: function () {
  var url = '//toolserver.org/~apper/pndtest/test.php?name='; //aus </nowiki>[[Benutzer:APPER/PNDJS]]<nowiki>

  url += escape(normdaten.getName()) + '&rand=' + Math.floor(Math.random()*1000000) + '&wgPageName=' + mw.config.get('wgPageName'); //muss escape sein!
  if (mw.config.get('wgServer') === 'http://localhost') {
     window.addPNDoffer("Unter WP:PND/F gemeldet: <a href='//de.wikipedia.org/wiki/Wikipedia:PND/Fehlermeldung/August_2012'>August 2012</a>");
     window.addPNDoffer("<a href=\"http://dispatch.opac.d-nb.de/DB=4.1/PPN?PPN=130586552\">Brooks, Albert (1947-)</a><br /><a href=\"http://dispatch.opac.d-nb.de/DB=4.1/PPN?PPN=118529579\">Einstein, Albert (1879-1955)</a>");
  } else {
     mw.loader.load(url);
  }
},
gndsugg_recv: function (data) {
  var pndf = /<a href='(.*)'>(.*)<\/a>/.exec(data), list = [], i, gnd, text;
  if (pndf) {
     $('#pd-nd-pndf').attr('href', pndf[1]).text('WP:PND/F (gemeldet: ' + pndf[2] + ')');
     return;
  }
  data = data.split('<br />');
  for (i = 0; i < data.length; i++) {
      gnd = extrahiere(/PPN=([^"]*)/, data[i]);
      text = extrahiere(/>([^<]*)</, data[i]);
      if (gnd && text) {
         list.push([text, gnd]);
      }
  }
  i = normdaten.add_list('gnd', 'apper', list);
  if (i) {
     normdaten.gnd_fehlt_vorschlag = true;
  }
},

ndlsugg_get: function () {
  if (normdaten.disableExternal) {
     return window.normdaten_ndl_callback(null);
  }
  var sparql = 'PREFIX rda: <http://RDVocab.info/ElementsGr2/>\n' +
               'PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n' +
               'PREFIX xl: <http://www.w3.org/2008/05/skos-xl#>\n' +
               'PREFIX ndl: <http://ndl.go.jp/dcndl/terms/>\n' +
               'SELECT ?uri1 ?birth ?death ?label1 ?label2 WHERE {\n' +
               '?uri1 foaf:primaryTopic ?uri2.\n' +
               '?uri1 xl:prefLabel [xl:literalForm ?label1;].\n' +
               'OPTIONAL { ?uri1 xl:prefLabel [ndl:transcription ?label2;]. }\n' +
               'OPTIONAL { ?uri2 rda:dateOfBirth ?birth. }\n' +
               'OPTIONAL { ?uri2 rda:dateOfDeath ?death. }\n' +
               '?uri2 foaf:name "' + normdaten.getNameForNDL().replace(/"/g, '') + '".\n' +
               '}',
      url = 'http://id.ndl.go.jp/auth/ndla?query=' + encodeURIComponent(sparql) + '&output=json&callback=normdaten_ndl_callback';
  if (mw.config.get('wgServer') === 'http://localhost') {
     window.normdaten_ndl_callback({"head":{"vars":["uri1","birth","death","label1","label2"]},"results":{"bindings":[{"uri1":{"type":"uri","value":"http://id.ndl.go.jp/auth/ndlna/01162161"},"birth":{"type":"literal","value":"1957"},"label1":{"type":"literal","value":"野田,佳彦"},"label2":{"type":"literal","value":"ノダ,ヨシヒコ","xml:lang":"ja-Kana"}},{"uri1":{"type":"uri","value":"http://id.ndl.go.jp/auth/ndlna/01162161"},"birth":{"type":"literal","value":"1957"},"label1":{"type":"literal","value":"野田,佳彦"},"label2":{"type":"literal","value":"Noda, Yoshihiko","xml:lang":"ja-Latn"}},{"uri1":{"type":"uri","value":"http://id.ndl.go.jp/auth/ndlna/00438728"},"birth":{"type":"literal","value":"1879"},"death":{"type":"literal","value":"1955"},"label1":{"type":"literal","value":"Einstein, Albert, 1879-1955"}}]}}); //Albert Einstein + Yoshihiko Noda, Zeichencodierung ist falsch, macht aber nichts
  } else {
     mw.loader.load(url);
  }
},
ndlsugg_recv: function (data) {
  if (!data || !data.results || !data.results.bindings) {
     return;
  }
  var list = [], i, birth, death, uri, label1, label2, date, label, ndl;
  for (i = 0; i < data.results.bindings.length; i++) {
      birth = data.results.bindings[i].birth;
      death = data.results.bindings[i].death;
      uri = data.results.bindings[i].uri1;
      label1 = data.results.bindings[i].label1;
      label2 = data.results.bindings[i].label2;
      if (uri && uri.value) {
         ndl = uri.value.substr(31);
      }
      date = ' (' + (birth && birth.value ? birth.value : '') + '–' + (death && death.value ? death.value : '') + ')';
      if (date === ' (–)') {
         date = '';
      }
      label = (label1 && label1.value) ? label1.value : '';
      if (label2 && label2.value && label2['xml:lang'] === 'ja-Latn') {
         label = label2.value;
      }
      if (!(/\d/).test(label)) {
         label += date;
      }
      if (label && ndl) {
         list.push([label, ndl]);
      }
  }
  normdaten.add_list('ndl', 'ndl', list);
},

viaf_chache: null,
viaf_get: function (name, f) { //TODO hoffen auf ndl
  if (normdaten.disableExternal) {
     return window[f](null);
  }
  name = encodeURIComponent(name.toLowerCase());
  if (mw.config.get('wgServer') === 'http://localhost') {
     normdaten.viaf_chache = {"query":name,"result":[{"term":"Einstein, Albert, 1879-1955","viafid":"75121530","nlicyr":"000161006","ptbnp":"26339","nla":"000036582360","nliheb":"000278691","nlilat":"000042773","nkc":"jn19990002019","egaxa":"vtls000837931","bne":"xx834035","bnf":"11901607","bav":"adv10181679","selibr":"184709","dnb":"118529579","lc":"n79022889"},{"term":"Einstein, Albert, 1879-1955 (Spirit)","viafid":"46409037","lc":"no2001021472"},{"term":"Einstein, Albert","viafid":"75121530","nlicyr":"000161006","ptbnp":"26339","nla":"000036582360","nliheb":"000278691","nlilat":"000042773","nkc":"jn19990002019","egaxa":"vtls000837931","bne":"xx834035","bnf":"11901607","bav":"adv10181679","selibr":"184709","dnb":"118529579","lc":"n79022889"},{"term":"Einstein, Albert Lawrence, 1947-","viafid":"118902208","bne":"xx1085471","bnf":"14030953","dnb":"130586552","lc":"n87921590"},{"term":"Einstein, Albert, 1947-","viafid":"118902208","bne":"xx1085471","bnf":"14030953","dnb":"130586552","lc":"n87921590"}]};
  }
  if (normdaten.viaf_chache !== null && normdaten.viaf_chache.query === name) {
     window[f](normdaten.viaf_chache);
  } else {
     mw.loader.load('//viaf.org/viaf/AutoSuggest?query=' + name + '&callback=' + f);
  }
},
viaf_recv: function (data, f_name, f) {
  var neu_name = '', name;
  if (data && data.query && data.result === null && normdaten.ist_person) { //kein Treffer? -> variieren
     name = data.query;
     if (name.indexOf(',') === -1) {
        if (name.indexOf(' ') !== -1) { //mit Komma probieren
           neu_name = name.replace(/ /, ', ');
        }
     } else {
        neu_name = name.replace(/,\s*\S+/, ',').replace(/,$/, ''); //ein Vorname weniger
     }
  }
  if (neu_name !== '') {
     normdaten.viaf_get(neu_name, f_name);
  } else {
     normdaten.viaf_chache = data;
     f(data);
  }
},

viafsugg_get: function () {
  normdaten.viaf_get(normdaten.getName(), 'normdaten_viaf_callback_sugg');
},
viafsugg_recv: function (data) {
  if (!data || !data.result) {
     return;
  }
  var list = [], i;
  for (i = 0; i < data.result.length; i++) {
      if (!normdaten.ist_person || data.result[i].term.indexOf(' | ') === -1) { //Werke
         list.push([data.result[i].term, data.result[i].viafid]);
      }
  }
  normdaten.add_list('viaf', 'viaf', list);
},

sync_get: function () {
  normdaten.viaf_get(normdaten.getName(), 'normdaten_viaf_callback_sync');
},
sync_recv: function (data) { //empfängt Daten
  var suggestions = {gnd: null, lccn: null, viaf: null}, matches = [], i, nd = normdaten.tE.getVal(), e, m = {gnd: [], lccn: [], viaf: []};
  if (!data || !data.result) {
     return normdaten.add_suggestions(suggestions);
  }
  for (i = 0; i < data.result.length; i++) {
      e = data.result[i];
      if (e.dnb === undefined) e.dnb = '?';
      if (e.dnb !== '?') e.dnb = normdaten.format_gnd(e.dnb);
      if (e.lc === undefined) e.lc = '?';
      if (e.lc !== '?') e.lc = normdaten.format_lccn(e.lc, true);
      if (e.viafid === undefined) e.viafid = '?'; //sollte nicht passieren
      if (e.dnb === nd.gnd || e.dnb === nd.gndname || e.lc === nd.lccn || e.viafid === nd.viaf) {
         matches.push(e);
      }
  }
  for (i = 0; i < matches.length; i++) {
      if (matches[i].dnb !== '?' && $.inArray(matches[i].dnb, m.gnd) === -1) {
         m.gnd.push(matches[i].dnb);
      }
      if (matches[i].lc !== '?' && $.inArray(matches[i].lc, m.lccn) === -1) {
         m.lccn.push(matches[i].lc);
      }
      if (matches[i].viafid !== '?' && $.inArray(matches[i].viafid, m.viaf) === -1) {
         m.viaf.push(matches[i].viafid);
      }
  }
  if (m.gnd.length) {
     normdaten.gnd_fehlt_vorschlag = true;
  }
  if (m.gnd.length > 0 && m.gnd.length < m.viaf.length) {
     m.gnd.push(normdaten.gnd_fehlt_vorschlag ? 'fehlt' : '');
  }
  if (m.lccn.length > 0 && m.lccn.length < m.viaf.length) {
     m.lccn.push('');
  }

  if (nd.gndname) {
     i = $.inArray(nd.gndname, m.gnd);
     if (i !== -1) {
        m.gnd.splice(i, 1);
     }
  }

  if (m.gnd.length === 0) {
     suggestions.gnd = normdaten.gnd_fehlt_vorschlag ? 'fehlt' : '';
  } else {
     suggestions.gnd = m.gnd;
  }
  if (m.lccn.length === 0) {
     suggestions.lccn = '';
  } else {
     suggestions.lccn = m.lccn;
  }
  if (m.viaf.length === 0) {
     suggestions.viaf = '';
  } else {
     suggestions.viaf = m.viaf;
  }

  normdaten.add_suggestions(suggestions);
},

wikidata_get: function () {
  if (normdaten.disableExternal) {
     return window.normdaten_wikidata_callback(null);
  }
  var url = '//www.wikidata.org/w/api.php?action=wbgetentities&format=json&sites=dewiki&props=claims&languages=de&callback=normdaten_wikidata_callback&titles=';
  url += encodeURIComponent(normdaten.tE.getTitle());
  if (mw.config.get('wgServer') === 'http://localhost') {
     window.normdaten_wikidata_callback({"entities":{"Q937":{"id":"Q937","type":"item","claims":{"P214":[{"id":"q937$B7F821E9-5E5C-4D51-A153-4CA8A47B6941","mainsnak":{"snaktype":"value","property":"P214","datavalue":{"value":"75121530","type":"string"}},"type":"statement","rank":"normal","references":[]}],"P227":[{"id":"q937$285984A2-0D2C-42E7-9D82-7D5BC0F5E114","mainsnak":{"snaktype":"value","property":"P227","datavalue":{"value":"118529579","type":"string"}},"type":"statement","rank":"normal","references":[]}],"P244":[{"id":"q937$9BA2796D-01EE-4037-9910-029BA945CABA","mainsnak":{"snaktype":"value","property":"P244","datavalue":{"value":"n79022889","type":"string"}},"type":"statement","rank":"normal","references":[]}]}}},"success":1}); //Albert Einstein, reduziert (ohne references, ohne Nicht-Normdaten)
  } else {
     mw.loader.load(url);
  }
},
wikidata_recv: function (data) {
   if (!data || !data.entities || !data.success) {
      return;
   }
   var q, d, i, list, v, curdata = normdaten.tE.getVal();
   for (q in data.entities) {
       d = data.entities[q];
   }
   d = d.claims;
   if (!d) {
      return;
   }
   if (d.P227) {
      list = [];
      for (i = 0; i < d.P227.length; i++) {
          v = d.P227[i].mainsnak.datavalue.value;
          if (v !== curdata.gnd) {
             list.push(['Wikidata', v]);
          }
      }
      if (list.length) {
         normdaten.add_list('gnd', 'wikidata', list);
      }
   }
   if (d.P244) {
      list = [];
      for (i = 0; i < d.P244.length; i++) {
          v = normdaten.format_lccn(d.P244[i].mainsnak.datavalue.value, true);
          if (v !== curdata.lccn) {
             list.push(['Wikidata', v]);
          }
      }
      if (list.length) {
         normdaten.add_list('lccn', 'wikidata', list);
      }
   }
   if (d.P349) {
      list = [];
      for (i = 0; i < d.P349.length; i++) {
          v = d.P349[i].mainsnak.datavalue.value;
          if (v !== curdata.ndl) {
             list.push(['Wikidata', v]);
          }
      }
      if (list.length) {
         normdaten.add_list('ndl', 'wikidata', list);
      }
   }
   if (d.P214) {
      list = [];
      for (i = 0; i < d.P214.length; i++) {
          v = d.P214[i].mainsnak.datavalue.value;
          if (v !== curdata.viaf) {
             list.push(['Wikidata', v]);
          }
      }
      if (list.length) {
         normdaten.add_list('viaf', 'wikidata', list);
      }
   }
},

add_suggestions: function (sugg) {
   normdaten.tE.setSuggestions('gnd', sugg.gnd);
   normdaten.tE.setSuggestions('lccn', sugg.lccn);
   if (normdaten.ist_person && sugg.ndl !== undefined) {
      normdaten.tE.setSuggestions('ndl', sugg.ndl);
   }
   normdaten.tE.setSuggestions('viaf', sugg.viaf);
},

isodate: function (datum) { //formatiert datum als yyyy-mm-dd
  var match, jahr, monat, tag, jetzt;
  if (datum !== '') {
     if (/^\d{4}-\d{2}-\d{2}$/.test(datum)) {
        return datum;
     }
     match = /^\s*(\d\d?)(?:\W+)(\w+)(?:\W+)(\d{2}(?:\d{2})?)\s*$/.exec(datum);
     if (match) {
        tag = Number(match[1]);
        jahr = Number(match[3]);
        if (jahr < 100) {
           jahr += 2000;
        }
        monat = match[2].toLowerCase();
        if (monat.indexOf('feb') === 0) monat = '2';
        if (monat.indexOf('mär') === 0) monat = '3';
        if (monat.indexOf('apr') === 0) monat = '4';
        if (monat.indexOf('mai') === 0) monat = '5';
        if (monat.indexOf('jun') === 0) monat = '6';
        if (monat.indexOf('jul') === 0) monat = '7';
        if (monat.indexOf('aug') === 0) monat = '8';
        if (monat.indexOf('sep') === 0) monat = '9';
        if (monat.indexOf('okt') === 0) monat = '10';
        if (monat.indexOf('nov') === 0) monat = '11';
        if (monat.indexOf('dez') === 0) monat = '12';
        if (/\D/.test(monat)) monat = '1';
        monat = Number(monat);
     }
  }
  if (!jahr) {
     jetzt = new Date();
     jahr = jetzt.getFullYear();
     monat = jetzt.getMonth() + 1;
     tag = jetzt.getDate();
  }
  return String(jahr) + '-' + (String(monat + 100)).substr(1) + '-' + (String(tag + 100)).substr(1);
},

format_gnd: function (gnd, fehlt) {
   gnd = gnd.replace(/\s+/g, '').replace(/x/, 'X');
   if (!fehlt || gnd === '' || (/^\d+X?$/).test(gnd)) {
      return gnd;
   }
   return 'fehlt';
},
//formatiert eine LCCN
//gliederung === false: ohne Schrägstriche, mit führenden 0
//           === true:  mit  Schrägstrichen, ohne führende 0
format_lccn: function (lccn, gliederung) {
   lccn = lccn.toLowerCase().replace(/\s+/g, '').replace(/-/g, '/').replace(/\D+$/, '');
   if (lccn === '') {
      return '';
   }
   var pos = lccn.lastIndexOf('/'), nullen, treffer;
   if (pos > -1) {
      nullen = '000000'.substr(0, 6 - (lccn.length - pos - 1)); //führende 0
      lccn = lccn.replace(/\/([^\/]*)$/, nullen + '$1').replace(/\//g, '');
   }
   if (!gliederung) {
      return lccn;
   }
   treffer = /([a-z]*)(\d*)(\d{6})$/.exec(lccn);
   if (treffer === null) {
      return '';
   }
   return treffer[1] + '/' + treffer[2] + '/' + treffer[3].replace(/^0*/, '');
},
show_gnd: function () {
   var gnd = normdaten.tE.getVal('gnd'), url, title;
   if (gnd) {
      url = 'http://d-nb.info/gnd/' + gnd;
   } else {
      title = encodeURIComponent(mw.config.get('wgTitle').replace(/ \(.*$/, ''));
      url = 'https://portal.d-nb.de/opac.htm?method=simpleSearch&query=' + title.replace(/%20/g, '+');
   }
   open(url);
   return false;
},
show_gndname: function () {
   var gnd = normdaten.tE.getVal('gndname'), url, title;
   if (gnd) {
      url = 'http://d-nb.info/gnd/' + gnd;
   } else {
      title = encodeURIComponent(mw.config.get('wgTitle').replace(/ \(.*$/, ''));
      url = 'https://portal.d-nb.de/opac.htm?method=simpleSearch&query=' + title.replace(/%20/g, '+');
   }
   open(url);
   return false;
},
show_lccn: function () {
   var lccn = normdaten.format_lccn(normdaten.tE.getVal('lccn'), false), url, title;
   if (lccn) {
      url = 'http://errol.oclc.org/laf/' + lccn + '.html';
   } else {
      title = encodeURIComponent(mw.config.get('wgTitle').replace(/ \(.*$/, ''));
      url = 'http://id.loc.gov/search/?q=' + title.replace(/%20/g, '+');
   }
   open(url);
   return false;
},
show_ndl: function () {
   var ndl = normdaten.tE.getVal('ndl'), url, title;
   if (ndl) {
      url = 'http://id.ndl.go.jp/auth/ndlna/' + ndl;
   } else {
      title = encodeURIComponent(mw.config.get('wgTitle').replace(/ \(.*$/, ''));
      url = 'http://id.ndl.go.jp/auth/ndla/?qw=' + title;
   }
   open(url);
   return false;
},
show_viaf: function () {
   var viaf = normdaten.tE.getVal('viaf'), url, title;
   if (viaf) {
      url = 'http://viaf.org/viaf/' + viaf;
   } else {
      title = encodeURIComponent(mw.config.get('wgTitle').replace(/ \(.*$/, ''));
      url = 'http://www.viaf.org/viaf/search?query=local.names+all+%22' + title + '%22&stylesheet=/viaf/xsl/results.xsl&sortKeys=holdingscount';
   }
   open(url);
   return false;
},
vertausche_gnd: function () {
   var gnd1 = normdaten.tE.getVal('gnd'),
       gnd2 = normdaten.tE.getVal('gndname');
   if (gnd1 === 'fehlt') {
      gnd1 = '';
   }
   normdaten.tE.setVal('gnd', gnd2);
   normdaten.tE.setVal('gndname', gnd1);
   return false;
},
suche_viaf: function () {
   var url = 'http://viaf.org/viaf/search?query=local.personalNames+all+%22';
   url += normdaten.tE.getVal('gnd');
   url += '%22+and+local.sources+any+%22dnb%22&stylesheet=/viaf/xsl/results.xsl&sortKeys=holdingscount&maximumRecords=100';
   open(url);
   return false;
},
loeschen: function (id) {
   normdaten.tE.setVal(id, '');
},
datum_aktualisieren: function () {
   var $link = $('#pen-datum-aktualisieren');
   $link.replaceWith(mw.html.element('b', {title: 'Datum wurde zum Aktualisieren vorgemerkt'}, new mw.html.Raw($link.html())));
   normdaten.checkdate = normdaten.isodate('');
   return false;
},

//Anbindung an templateEditor
tEHasLoaded: false,
waitForTE: function (f) {
  function f2 (tE) {
    normdaten.tEHasLoaded = true;
    mw.hook('userjs.schnark-templateEditor.load').remove(f2);
    f(tE);
  }
  mw.hook('userjs.schnark-templateEditor.load').add(f2);
},
loadTE: function () {
  if (normdaten.tEHasLoaded) {
     return;
  }
  //</nowiki>[[Benutzer:Schnark/js/templateEditor.js]]<nowiki>
  mw.loader.load('//de.wikipedia.org/w/index.php?title=Benutzer:Schnark/js/templateEditor.js&action=raw&ctype=text/javascript');
},

lookForND: function () {
   normdaten.$pd = $('#Vorlage_Personendaten');
   normdaten.$nd = $('#normdaten');
   if (normdaten.$pd.length === 1) {
      normdaten.ist_person = true;
   }
   if (normdaten.$nd.length === 1 || (normdaten.$nd.length === 0 && normdaten.alwaysShowEdit)) {
      normdaten.loadTE();
      if (normdaten.initok) { //tE schon erfolgreich geladen
         normdaten.init();
      } else {
         normdaten.initok = true;
      }
   }
},

register: function (tE) {
   var ret = tE.register('Benutzer:Schnark/js/personendaten.js/normdaten.js', 'nd', normdaten.version, {
      onStart: normdaten.onStart,
      onReady: normdaten.onReady,
      onFinish: normdaten.onFinish});
   if (ret) {
      normdaten.tE = ret;
      if (normdaten.initok) { //Normdaten schon gefunden
         mw.hook('wikipage.content').add(normdaten.init);
      } else {
         normdaten.initok = true;
      }
   }
},

start: function () {
  $('#ndeditbutton').remove();
  var $div = $('<div>');
  if (normdaten.$nd.length) {
     normdaten.$nd.after($div);
  } else {
     $('#catlinks').after($div);
  }
  normdaten.tE.start({headline: 'Bearbeiten der Normdaten', $: $div});
},

onStart: function (script) {
  $('#ndeditbutton').remove();
  normdaten.ist_person = true; //Da ohnehin nur bei personendaten.js gestartet wird
  return (script.id === 'Benutzer:Schnark/js/personendaten.js') ? 1 : 0;
},

onReady: function () {
var text = normdaten.tE.getText(), nd = normdaten.parseND(text);
normdaten.add_interface(nd);
},

onFinish: function () {
var text = normdaten.tE.getText(),
    nd = normdaten.tE.getVal(),
    ret = normdaten.neuer_text(text, nd);
   if (ret.comment) {
      normdaten.tE.addComment(ret.comment);
   }
/* if (!ret.minor) {
      normdaten.tE.setNotMinor();
   }*/
   normdaten.tE.setText(ret.text);
},

//initialisieren
initialised: false,
initok: false,
init: function () {
  if (normdaten.initialised) {
     return;
  }
  normdaten.initialised = true;
  var button = mw.html.element('input', {id: 'ndeditbutton', type: 'button', value: normdaten.$nd.length ? 'Bearbeiten' : 'Normdaten einfügen', 'class': 'noprint'}), $el;
  if (normdaten.$nd.length) {
     $el = normdaten.$nd.append(button);
  } else {
     $el = $((normdaten.alwaysShowEdit === true) ? '#catlinks' : normdaten.alwaysShowEdit).after(button);
  }
  $('#ndeditbutton').click(normdaten.start);
}

};

//globale Funktion für APPER und VIAF-Callbacks
window.addPNDoffer = function (offer) {
  normdaten.gndsugg_recv(offer);
};
window.normdaten_ndl_callback = function (data) {
  normdaten.ndlsugg_recv(data);
};
window.normdaten_viaf_callback_sugg = function (data) {
  normdaten.viaf_recv(data, 'normdaten_viaf_callback_sugg', normdaten.viafsugg_recv);
};
window.normdaten_viaf_callback_sync = function (data) {
  normdaten.viaf_recv(data, 'normdaten_viaf_callback_sync', normdaten.sync_recv);
};
window.normdaten_wikidata_callback = function (data) {
  normdaten.wikidata_recv(data);
};

$(document).trigger('loadWikiScript', ['Benutzer:Schnark/js/personendaten.js/normdaten.js', normdaten]);
mw.hook('userjs.schnark-normdaten.load').fire(normdaten);

if (mw.config.get('wgNamespaceNumber') === 0 && window.location.search.indexOf('oldid') === -1 ) {
   normdaten.waitForTE(normdaten.register);
   mw.hook('wikipage.content').add(normdaten.lookForND);
}

})(jQuery, mediaWiki);
//</nowiki>