_ _    _ _____  ___   __                       
 __      _(_) | _(_)___ / ( _ ) / /_   ___ ___  _ __ ___  
 \ \ /\ / / | |/ / | |_ \ / _ \| '_ \ / __/ _ \| '_ ` _ \ 
  \ V  V /| |   <| |___) | (_) | (_) | (_| (_) | | | | | |
   \_/\_/ |_|_|\_\_|____/ \___/ \___(_)___\___/|_| |_| |_|

Benutzer:Wurgl/8Schwestern.js

In diesem Artikel werden wir uns eingehend mit dem Thema Benutzer:Wurgl/8Schwestern.js befassen und seine Ursprünge, Entwicklung und Relevanz heute analysieren. Von seinen ersten Auftritten bis zu seinen Auswirkungen auf die heutige Gesellschaft war Benutzer:Wurgl/8Schwestern.js in verschiedenen Bereichen ein Thema von großem Interesse und Diskussionen. In den nächsten Zeilen werden wir seinen Einfluss auf verschiedene Aspekte des täglichen Lebens sowie seine Beziehung zu anderen relevanten Themen untersuchen. Um eine umfassende Vision zu bieten, werden wir uns mit den verschiedenen Perspektiven und Meinungen rund um Benutzer:Wurgl/8Schwestern.js befassen, mit dem Ziel, ein breiteres und bereicherndes Verständnis zu vermitteln.
// <nowiki>
var EightSisters = {
  queryPageProps      : {
    action: 'query',
    prop: ,
    ppprop: 'wikibase_item',
    elquery: 'commons.wikimedia.org',
    pageids: mw.config.get('wgArticleId'),
  },
  api : 0,
  qId : '',
  redirCatFrom : null,
  redirCatTo : null,
  haveAny : false,
  addWeblinks : -1,
  sisterData : {
    0 : { tmpl : 'Commons',     sitelink : 'commonswiki',   property : 'P935', pagelnk: 'https://commons.wikimedia.orghttps://wiki386.com/de/' },
    1 : { tmpl : 'Commonscat',                              property : 'P373', pagelnk: 'https://commons.wikimedia.orghttps://wiki386.com/de/Category:' },
    2 : { tmpl : 'Wikibooks',   sitelink : 'dewikibooks',                      pagelnk: 'https://de.wikibooks.orghttps://wiki386.com/de/' },
    3 : { tmpl : 'Wikispecies', sitelink : 'specieswiki',                      pagelnk: 'https://species.wikimedia.orghttps://wiki386.com/de/' },
    4 : { tmpl : 'Wikiquote',   sitelink : 'dewikiquote',                      pagelnk: 'https://de.wikiquote.orghttps://wiki386.com/de/' },
    5 : { tmpl : 'Wikisource',  sitelink : 'dewikisource',                     pagelnk: 'https://de.wikisource.orghttps://wiki386.com/de/' },
    6 : { tmpl : 'Wikiversity', sitelink : 'dewikiversity',                    pagelnk: 'https://de.wikiversity.orghttps://wiki386.com/de/' },
    7 : { tmpl : 'Wikivoyage',  sitelink : 'dewikivoyage',                     pagelnk: 'https://de.wikivoyage.orghttps://wiki386.com/de/' },
    8 : { tmpl : 'Wiktionary',  sitelink : 'dewiktionary',                     pagelnk: 'https://de.wiktionary.orghttps://wiki386.com/de/' }
   },

  execute : function () {
    if(mw.config.get('wgNamespaceNumber') != 0 &&
       mw.config.get('wgNamespaceNumber') != 14)
      return;
    if(mw.config.get('wgNamespaceNumber') == 14) {
      EightSisters.sisterData = { tmpl: 'Themenkategorie Welterbe',        pagelnk: 'https://commons.wikimedia.orghttps://wiki386.com/de/Category:', add: 1, param: 5,            data: 'v' };
      EightSisters.sisterData = { tmpl: 'Kategorie Curling',               pagelnk: 'https://commons.wikimedia.orghttps://wiki386.com/de/Category:', add: 1, param: 'Commonscat', data: null }; // Nur bei "nein" dieses entfernen
      EightSisters.sisterData = { tmpl: 'Kategorie Eishockey',             pagelnk: 'https://commons.wikimedia.orghttps://wiki386.com/de/Category:', add: 1, param: 'Commonscat', data: null }; // Nur bei "nein" dieses entfernen
      EightSisters.sisterData = { tmpl: 'Kategorie Filmjahr nach Jahr',    pagelnk: 'https://commons.wikimedia.orghttps://wiki386.com/de/Category:', add: 1, param: 'Commonscat', data: 'pv' }; // C&C Wert einsetzen
      EightSisters.sisterData = { tmpl: 'Kategorie Filmjahr nach Jahr',    pagelnk: 'https://commons.wikimedia.orghttps://wiki386.com/de/Category:', add: 0, param: 'Commons',    data: 'pv' }; // C&C Wert einsetzen
      EightSisters.sisterData = { tmpl: 'Kategorie Jahrhundert',           pagelnk: 'https://commons.wikimedia.orghttps://wiki386.com/de/Category:', add: 1, param: 'Commonscat', data: 'pv' }; // Cat Wert einsetzen
      EightSisters.sisterData = { tmpl: 'Kategorie Raumfahrer nach Staat', pagelnk: 'https://commons.wikimedia.orghttps://wiki386.com/de/Category:', add: 1, param: 'Commonscat', data: /Astronauts+from+/, hint: 'Commonstitel' }; // Cat Inhalt: "Astronauts from " rausnehmen
      EightSisters.sisterData = { tmpl: 'Kategorie Raumfahrt nach Staat',  pagelnk: 'https://commons.wikimedia.orghttps://wiki386.com/de/Category:', add: 1, param: 'Commonscat', data: 'pv', hint: 'Commonstitel' }; // Cat & Tite Wert einsetzenl
      EightSisters.sisterData = { tmpl: 'Musikgruppe als Thema',           pagelnk: 'https://commons.wikimedia.orghttps://wiki386.com/de/Category:', add: 1, param: 'Commonscat', data: 'pv' }; // C&C Wert einsetzen
      EightSisters.sisterData = { tmpl: 'Musikgruppe als Thema',           pagelnk: 'https://commons.wikimedia.orghttps://wiki386.com/de/Category:', add: 0, param: 'Commons',    data: 'pv' }; // C&C Wert einsetzen
      EightSisters.sisterData = { tmpl: 'Person als Thema',                pagelnk: 'https://commons.wikimedia.orghttps://wiki386.com/de/Category:', add: 1, param: 'Commonscat', data: 'pv' }; // C&C Wert einsetzen
      EightSisters.sisterData = { tmpl: 'Person als Thema',                pagelnk: 'https://commons.wikimedia.orghttps://wiki386.com/de/Category:', add: 0, param: 'Commons',    data: 'pv' }; // C&C Wert einsetzen
      EightSisters.sisterData = { tmpl: 'Kategorie Ereignis nach Jahr',    pagelnk: 'https://commons.wikimedia.orghttps://wiki386.com/de/Category:', add: 1, param: 'Commonscat', data: 'pv' }; // C&C Wert einsetzen
      EightSisters.sisterData = { tmpl: 'Kategorie Ereignis nach Jahr',    pagelnk: 'https://commons.wikimedia.orghttps://wiki386.com/de/Category:', add: 0, param: 'Commons',    data: 'pv' }; // C&C Wert einsetzen
      // EightSisters.sisterData = { tmpl: 'KsPB-Allgemein-Kategorien und Commons',pagelnk:'https://commons.wikimedia.orghttps://wiki386.com/de/Category:',add: 1,param:'Commonscat',data: 'pv', hint: 'Commonstitel' }; // C&C Wert einsetzen
    }
    var action = mw.config.get('wgAction');
    if(action != 'edit' && action != 'submit')
      return;
    var message = mw.config.get('wgEditMessage');
    if(message != 'editing')
      return;

    if($('#wpTextbox1').textSelection('getContents').search(RegExp('{{\\s*chwesterprojekte\\s*'/*}*/)) != -1)
      return;

    var lang = mw.config.get('wgPageContentLanguage');
    EightSisters.api = new mw.Api();
    EightSisters.queryWikidataId(EightSisters.api, EightSisters.gotWikidataId, EightSisters.queryPageProps);
  },

  gotWikidataId : function(data) {
    var pages = data.query.pages;
    var extLink = null;
    for(var p in pages) {
      if(pages.pageprops && pages.pageprops.wikibase_item)
        EightSisters.qId = pages.pageprops.wikibase_item;
      if(pages.extlinks) {
        for(var e in pages.extlinks) {
          if(pages.extlinks) {
            var url = pages.extlinks;
            var pos;
            if((pos = url.lastIndexOf('?')) != -1)
              url = url.substring(0, pos);
            if((pos = url.lastIndexOf('wiki/Category:')) != -1)
              url = url.substring(pos + 5);
            url = decodeURIComponent(url.replaceAll('_', ' '));
            extLink = url;
          }
        }
      }
    }
    // console.log('ExternalLinks: ' + extLink);
    if(EightSisters.qId != '') {
      var siteLinks = '';
      for(var key in Object.keys(EightSisters.sisterData)) {
        if(EightSisters.sisterData.sitelink)
          if(siteLinks == '')
            siteLinks += EightSisters.sisterData.sitelink;
          else
            siteLinks += '|' + EightSisters.sisterData.sitelink;
      }
      fetch('https://www.wikidata.org/w/api.php?action=wbgetentities&format=json&ids=' + EightSisters.qId + '&props=sitelinks&sitefilter=' + siteLinks + '&formatversion=2&origin=*').then(function(response) {
          // console.log("1 Response" + response);
          return response.json();
        }).then(function(response) {
          // console.log("2 Response" + response);
          for(var c in response.entities) {
            if(response.entities.sitelinks)
              for(var key in Object.keys(EightSisters.sisterData)) {
                if(EightSisters.sisterData.sitelink && response.entities.sitelinks.sitelink]) {
                  if(key == 0 && response.entities.sitelinks.sitelink].title.startsWith('Category:'))
                    EightSisters.sisterData.commonsData = response.entities.sitelinks.sitelink].title.substring(9);
                  else
                    EightSisters.sisterData.commonsData = response.entities.sitelinks.sitelink].title;
                  EightSisters.haveAny = true;
                }
              }
          }
          fetch('https://www.wikidata.org/w/api.php?action=wbgetclaims&format=json&entity=' + EightSisters.qId + '&formatversion=2&origin=*').then(function(response) {
              // console.log("1 Response" + response);
              return response.json();
            }).then(function(response) {
              // console.log("2 Response" + response);
              if(response.claims) {
                for(var key in Object.keys(EightSisters.sisterData)) {
                  if(EightSisters.sisterData.property && response.claims.property])
                    for(var cc in response.claims.property]) {
                      if(response.claims.property].rank != 'deprecated') {
                        if(key == 0 && EightSisters.sisterData.commonsData != null && EightSisters.sisterData.commonsData != response.claims.property].mainsnak.datavalue.value) {
                          console.log("Sitelink (" + EightSisters.sisterData.commonsData + ") is different to Property " + EightSisters.sisterData.property + " (" + response.claims.property].mainsnak.datavalue.value + ")");
                        }
                        else if(!EightSisters.sisterData.commonsData) {
                          EightSisters.sisterData.commonsData = response.claims.property].mainsnak.datavalue.value;
                          EightSisters.haveAny = true;
                        }
                        break;
                      }
                    }
                }
              }
              if(extLink == 0)
                EightSisters.analyseText(true);
              else
                fetch('https://commons.wikimedia.org/w/api.php?action=query&format=json&prop=revisions&titles=' + extLink + '&formatversion=2' + "&rvprop=content&rvslots=main&origin=*").then(function(response) {
                    // console.log("1 Response" + response);
                    return response.json();
                  }).then(function(response) {
                    // console.log("3 Response" + JSON.stringify(response));
                    if(response.query && response.query.pages) {
                      for(var p in response.query.pages) {
                        // console.log("p: " + JSON.stringify(response.query.pages));
                        if(response.query.pages.revisions) {
                          var revs = response.query.pages.revisions;
                          for(var r in revs) {
                            // console.log("r: " + JSON.stringify(revs.slots.main.content));
                            if(revs.slots.main.content) {
                              var c = revs.slots.main.content;
                              var found = c.match(RegExp('{{\\s*ategory+redirect\\s*\\|(Category:)?(?<p1>*)}}'));
                              // console.log("found: " + JSON.stringify(found));
                              if(found && found.groups) {
                                EightSisters.redirCatFrom = extLink;
                                var found1 = found.groups.p1.match(RegExp('1=(?<p1>*)'));
                                if(found && found.groups)
                                  EightSisters.redirCatTo = found1.groups.p1;
                                else {
                                  var pos = found.groups.p1.indexOf('|');
                                  if(pos != -1)
                                    EightSisters.redirCatTo = found.groups.p1.substring(0, pos);
                                  else
                                    EightSisters.redirCatTo = found.groups.p1;
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                    EightSisters.analyseText(true);
                });
            });
        });
    }
  },

  analyseText : function(initial) {
    var $textbox = $('#wpTextbox1');
    var text = $textbox.textSelection('getContents');
    EightSisters.addWeblinks = -1;
    var weblinkPos = -1;
    var canInsert = true;
    if(mw.config.get('wgNamespaceNumber') != 14) {
      var sections = text.match(/\n==.*\n/g);
      if(sections) {
        for(var i = sections.length - 1; i >= 0; -- i) {
          if(sections.indexOf('Weblink') != -1) {
            weblinkPos = text.lastIndexOf(sections) + sections.length;
            break;
          }
        }
        if(weblinkPos == -1)
          for(var i = sections.length - 1; i >= 0; -- i) {
            if(sections.indexOf('Siehe auch') != -1) {
              weblinkPos = text.lastIndexOf(sections) + sections.length;
              break;
            }
          }
        if(weblinkPos == -1)
          for(var i = sections.length - 1; i >= 0; -- i) {
            if(sections.indexOf('Verweise') != -1) {
              weblinkPos = text.lastIndexOf(sections) + sections.length;
              break;
            }
          }
      }

      if(weblinkPos == -1) {
        weblinkPos = text.lastIndexOf('<references');
        if(weblinkPos != -1) {
          weblinkPos = text.substring(0, weblinkPos).lastIndexOf('\n==');
          EightSisters.addWeblinks = weblinkPos;
        }

        if(weblinkPos == -1) {
          var minWeblinkPos = 0;
          if(sections)
            minWeblinkPos = text.indexOf(sections);
          var pos = text.indexOf('{{Normdaten', minWeblinkPos); // }}
          if(pos != -1)
            weblinkPos = pos;
          if((pos = text.indexOf('{{Navi', minWeblinkPos)) != -1 && (weblinkPos == -1 || pos < weblinkPos)) // }}
            weblinkPos = pos;
          if((pos = text.indexOf('[[Kategorie', minWeblinkPos)) != -1 && (weblinkPos == -1 || pos < weblinkPos))
            weblinkPos = pos;
          if((pos = text.indexOf('{{DEFAULTSORT', minWeblinkPos)) != -1 && (weblinkPos == -1 || pos < weblinkPos)) // }}
            weblinkPos = pos;
          if((pos = text.indexOf('{{SORTIERUNG', minWeblinkPos)) != -1 && (weblinkPos == -1 || pos < weblinkPos)) // }}
            weblinkPos = pos;
          if((pos = text.indexOf('{{Hinweis ', minWeblinkPos)) != -1 && (weblinkPos == -1 || pos < weblinkPos)) // }}
            weblinkPos = pos;
          if((pos = text.indexOf('{{Hinweis|', minWeblinkPos)) != -1 && (weblinkPos == -1 || pos < weblinkPos)) // }}
            weblinkPos = pos;
          if(weblinkPos != -1)
            EightSisters.addWeblinks = weblinkPos;
        }
      }
    }
    else {
      if((pos = text.indexOf('[[Kategorie')) != -1) {
        weblinkPos = pos;
        while(text.substring(weblinkPos - 2, weblinkPos) == '\n\n')
          -- weblinkPos;
      }
      else if((pos = text.lastIndexOf(/*{{*/'}}')) != -1) {
        weblinkPos = pos + 2;
        if(text.substring(weblinkPos, weblinkPos + 1) == '\n')
          ++ weblinkPos;
      }
    }

    for(var key in Object.keys(EightSisters.sisterData)) {
      var tmplPos;
      for(var from = 0;;) {
        tmplPos = text.substring(from).search(RegExp("{{\\s*.tmpl.substring(0, 1) + EightSisters.sisterData.tmpl.substring(0, 1).toLowerCase() + "]" + EightSisters.sisterData.tmpl.substring(1).replaceAll(' ', '+') + /*{*/'\\s*'));
        if(tmplPos == -1)
          break;
        if(EightSisters.inRefOrComment(text, tmplPos)) {
          from += tmplPos + 2;
        }
        else {
          tmplPos += from;
          break;
        }
      }
      EightSisters.sisterData.foundAt = tmplPos;
      if(tmplPos != -1) {
        if(mw.config.get('wgNamespaceNumber') != 14) {
          var sectionPos = text.substring(0, tmplPos).lastIndexOf('==\n');
          if(weblinkPos == -1)
            weblinkPos = sectionPos;
          else if(weblinkPos != sectionPos + 3) {
            console.log("Mismatch position of " + EightSisters.sisterData.tmpl + " (" + weblinkPos + ") and position of section Weblinks (" + (sectionPos + 3) + ")");
            // canInsert = false;
          }
        }
        EightSisters.sisterData.tmplpos = tmplPos;
        EightSisters.sisterData.endpos = text.indexOf('\n', tmplPos) + 1;
        if(key == 1) {
          var tmpl = text.substring(EightSisters.sisterData.tmplpos, EightSisters.sisterData.endpos);
          var found = tmpl.match(RegExp('{{\\s*ommonscat\\s*\\|(?<p1>*)'));
          if(found && found.groups && ('Category:' + found.groups.p1) == EightSisters.redirCatFrom) {
            EightSisters.sisterData.show = true;
          }
          else {
            var found = tmpl.match(RegExp('{{\\s*ommonscat\\s*}}'));
            if(found && EightSisters.redirCatFrom && EightSisters.redirCatTo)
              EightSisters.sisterData.show = true;
          }
        }
      }
      else {
        EightSisters.sisterData.tmplpos = -1;
        EightSisters.sisterData.endpos = -1;
        if(initial == true && EightSisters.sisterData.commonsData)
          EightSisters.sisterData.show = true;
      }
    }

    if(mw.config.get('wgNamespaceNumber') == 14) {
      for(key = 9; key < Object.keys(EightSisters.sisterData).length; ++ key) {
        if(EightSisters.sisterData.foundAt != -1) {
          if(EightSisters.sisterData.add].commonsData == null) {
            EightSisters.sisterData.foundAt = -1;
            continue;
          }
          EightSisters.sisterData.show = false;
          var endPos = text.indexOf(/*{{*/'}}', EightSisters.sisterData.foundAt + 2);
          if(endPos !== -1) {
            var found = false;
            var tmplStart = endPos;
            var tmplEnd = endPos;
            var params = text.substring(EightSisters.sisterData.foundAt + 2, endPos).split('|');
            var pos = EightSisters.sisterData.foundAt + 2 + params.length;
            var nIdx = 0; // index of unnamed parameters
            for(var fndPIdx = 1; fndPIdx < params.length; ++ fndPIdx) {
              var matches;
              if((matches = params.match(RegExp('^\\s*' + EightSisters.sisterData.param + '\\s*=\\s*(.*)$', 's'))) != null) {
                // if matches == null, just Commons=
                if(EightSisters.sisterData.data == null) {
                  if(matches != null && matches.trim() == 'nein') {
                    found = true;
                    tmplStart = pos;
                    tmplEnd = pos + params.length + 1;
                    break;
                  }
                }
                else {
                  if(matches == null || matches == '') {
                    tmplStart = pos;
                    tmplEnd = pos + params.length + 1;
                    if(params.endsWith('\n'))
                      -- tmplEnd;
                  }
                  else {
                    found = true;
                    break;
                  }
                }
              }
              if(typeof(params) == 'number') {
                if(params.indexOf('=') == -1) {
                  ++ nIdx;
                  if(nIdx == EightSisters.sisterData.param) {
                    if(params.trim() == '') {
                      tmplStart = pos;
                      tmplEnd = pos + params.length + 1;
                      if(params.endsWith('\n'))
                        -- tmplEnd;
                    }
                    else {
                      found = true;
                      break;
                    }
                  }
                }
              }
              pos += params.length + 1; // +1 for the '|'
              /* DEBUG* */ if(fndPIdx == params.length - 1 && pos != endPos) console.log('*** pos ' + pos + ' is not equal to expected endpos ' + endpos);
            }

            if(EightSisters.sisterData.data == null) {
              if(found == true) {
                EightSisters.sisterData.tmplpos = tmplStart;
                EightSisters.sisterData.tmplend = tmplEnd;
                EightSisters.sisterData.foundAt = -1;
                EightSisters.sisterData.show = true;
              }
            }
            else if(found == false) {
              EightSisters.sisterData.tmplpos = tmplStart;
              EightSisters.sisterData.tmplend = tmplEnd;
              EightSisters.sisterData.foundAt = -1;
              EightSisters.sisterData.show = true;
            }
            EightSisters.sisterData.add].show = false;
          }
          else
            EightSisters.sisterData.show = false;
        }
        else
          EightSisters.sisterData.show = false;
      }
    }
    var haveAny = false;
    for(var key in Object.keys(EightSisters.sisterData)) {
      if(EightSisters.sisterData.show == true) {
        haveAny = true;
      }
    }

    if(weblinkPos == -1) {
      console.log("position of section Weblinks not found");
      canInsert = false;
    }
    for(var key in Object.keys(EightSisters.sisterData)) {
      if(EightSisters.sisterData.endpos == -1)
        EightSisters.sisterData.endpos = weblinkPos;
    }

    var displKey;
    if(canInsert == true && haveAny == true && initial == true) {
      var innerHtml = '<div id="chSisters" class="oo-ui-layout oo-ui-labelElement oo-ui-fieldLayout oo-ui-fieldLayout-align-top editOptions" style="border-radius: 0.25em 0.25em 0.25em 0.25em; margin-bottom:0.5em"><div class="oo-ui-layout oo-ui-horizontalLayout">';
      var section = '';
      if(mw.config.get('wgNamespaceNumber') != 14)
        section = ' im Abschnitt Weblinks';

      for(var key in Object.keys(EightSisters.sisterData)) {
        if(EightSisters.sisterData.show) {
          var addLabel = '';
          if(key == 0 && EightSisters.sisterData.tmplpos != -1) {
            addLabel = ' <span style="font-weight: bold">Achtung!</span> {{Commonscat|…}} ist schon vorhanden';
          }
          else if(key == 1 && EightSisters.sisterData.tmplpos != -1) {
            addLabel = ' <span style="font-weight: bold">Achtung!</span> {{Commons|…}} ist schon vorhanden';
          }

          if(key >= 9) {
            if(key > 9 && EightSisters.sisterData.tmpl == EightSisters.sisterData.tmpl && EightSisters.sisterData.show == false)
              addLabel = ' <span style="font-weight: bold">Achtung!</span> {{' + EightSisters.sisterData.param  + '|…}} ist schon vorhanden';
            if(key + 1 < Object.keys(EightSisters.sisterData) && EightSisters.sisterData.tmpl == EightSisters.sisterData.tmpl && EightSisters.sisterData.show == false)
              addLabel = ' <span style="font-weight: bold">Achtung!</span> {{' + EightSisters.sisterData.param  + '|…}} ist schon vorhanden';
          }

          var template = EightSisters.makeTemplate(key, true);

          var doAdd = '';
          var doAdd2 = '+ ';
          if(key >= 9)
            doAdd = 'hinzufügen';
          else if(key == 1 && EightSisters.sisterData.tmplpos != -1) {
            doAdd = 'korrigieren';
            doAdd2 = '± ';
            addLabel += ' (Weiterleitung auflösen)';
          }
          else
            doAdd = 'ergänzen';
          innerHtml += '<div id="editpage-addEightSisters' + key + '" class="oo-ui-layout oo-ui-labelElement oo-ui-fieldLayout oo-ui-fieldLayout-align-inline">' +
              '<div class="oo-ui-fieldLayout-body" id="bodyEightSisters' + key + '" >' +
                '<a class="editMenus-button" title="EightSisters' + key + '" id="buttonEightSisters' + key + '"style="text-decoration: none; white-space: nowrap;">' +
                  '<img data-id="' + key + '" title="Vorlage ' + EightSisters.sisterData.tmpl + section + ' ' + doAdd + '" alt="' + EightSisters.sisterData.tmpl + '" src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/f6/OOjs_UI_icon_check-constructive.svg/18px-OOjs_UI_icon_check-constructive.svg.png" width="18" height="18" style="cursor:pointer">' +
                '</a>' +
                '<span class="oo-ui-fieldLayout-header" id="headerEightSisters' + key + '">' +
                  '<label id="labelEightSisters' + key + '" title="Vorlage:' + EightSisters.sisterData.tmpl + section + ' ' + doAdd + '" for="AddEightSisters' + key + '" class="oo-ui-labelElement-label oo-ui-optionWidget" disabled="true">' + doAdd2 + template + addLabel +
                  '</label>' +
                '</span>' +
              '</div>' +
            '</div>';
        }
      }
      innerHtml += '</div></div>';
      var e = document.getElementById('wpSummaryLabel').parentElement;
      e.insertAdjacentHTML('beforebegin', innerHtml);

      for(var key in Object.keys(EightSisters.sisterData)) {
        if(EightSisters.sisterData.show) {
          document.getElementById('buttonEightSisters' + key).addEventListener('click', EightSisters.addTemplate);
        }
      }
    }
  },

  inRefOrComment : function(text, tmplPos) {
    var refStart = text.substring(0, tmplPos).lastIndexOf('<ref');
    if(refStart != -1) {
      if(text.substring(refStart, tmplPos).match(/<ref*\/>/) == false &&
         text.substring(refStart, tmplPos).indexOf('</ref') == -1)
        return true;
    }
    var commentStart = text.substring(0, tmplPos).lastIndexOf('<!--');
    if(commentStart != -1) {
      if(text.substring(commentStart, tmplPos).indexOf('-->') == -1)
        return true;
    }
    return false;
  },

  makeTemplate : function(key, withLink) {
    var template;
    if(withLink == true)
      template = '{{<a href="' + EightSisters.sisterData.pagelnk + EightSisters.sisterData.add : key].commonsData + '">' + EightSisters.sisterData.tmpl + '</a>'; // }}
    else
      template = '{{' + EightSisters.sisterData.tmpl; // }}
    if(key >= 9) {
      if(typeof(EightSisters.sisterData.param) == 'number')
        template += '|…|' + EightSisters.sisterData.add].commonsData;
      else if(EightSisters.sisterData.data == 'pv')
        template += '|…|' + EightSisters.sisterData.param + '=' + EightSisters.sisterData.add].commonsData;
      else if(EightSisters.sisterData.data == null)
        template += '|…<s>' + $('#wpTextbox1').textSelection('getContents').substring(EightSisters.sisterData.tmplpos, EightSisters.sisterData.tmplend) + '</s>';
      else if(EightSisters.sisterData.data instanceof RegExp)
        template += '|…|' + EightSisters.sisterData.param + '=' + EightSisters.sisterData.add].commonsData.replace(EightSisters.sisterData.data, '');
      else
        template += '|…|?';
    }
    else {
      var title = mw.config.get('wgTitle');
      if(title != EightSisters.sisterData.commonsData) {
        if(key == 1 && EightSisters.sisterData.tmplpos != -1) {
          template += '|' + EightSisters.redirCatTo;
        }
        else {
          template += '|' + EightSisters.sisterData.commonsData + '|';
          if(mw.config.get('wgNamespaceNumber') != 14) {
            if(title.endsWith(')')) {
              var brPos = title.lastIndexOf(' (');
              if(brPos != -1)
                template += title.substring(0, brPos);
              else
                template += title;
            }
            else
              template += title;
          }
          else {
            template += '{{SEITENNAME}}'
          }
        }
      }
    }
    return template + /*{{*/'}}';
  },

  addTemplate : function(event) {
    EightSisters.analyseText(false);
    var img = event.target;
    if(!img.attributes)
      img = img.firstChild;
    var targetKey = img.attributes.value;
    var insertFrom = 0;
    var insertTo = 0;
    var $textbox = $('#wpTextbox1');
    var text = $textbox.textSelection('getContents');
    var template;
    if(EightSisters.sisterData.foundAt != -1) {
      if(targetKey != 1)
        return;
      var tmpl = text.substring(EightSisters.sisterData.tmplpos, EightSisters.sisterData.endpos);
      var found = tmpl.match(RegExp('{{\\s*ommonscat\\s*\\|(?<p1>*)'));
      if(!found || !found.groups || ('Category:' + found.groups.p1) != EightSisters.redirCatFrom) {
        var found = tmpl.match(RegExp('{{\\s*ommonscat\\s*(?<p1>}})'));
        if(!found || !EightSisters.redirCatFrom || !EightSisters.redirCatTo)
          return;
        insertFrom = text.indexOf(found.groups.p1, EightSisters.sisterData.tmplpos);
        insertTo = insertFrom;
        template = '|' + EightSisters.redirCatTo;
      }
      else {
        insertFrom = text.indexOf(found.groups.p1, EightSisters.sisterData.tmplpos);
        insertTo = insertFrom + found.groups.p1.length;
        template = EightSisters.redirCatTo;
      }
    }
    else {
      if(targetKey >= 9) {
        insertFrom = EightSisters.sisterData.tmplpos;
        insertTo = EightSisters.sisterData.tmplend;
      }
      else {
        if(EightSisters.addWeblinks == -1) {
          for(var key = 0; key <= targetKey; ++ key) {
            if(insertFrom < EightSisters.sisterData.endpos)
              insertFrom = EightSisters.sisterData.endpos;
          }
        }
        else
          insertFrom = EightSisters.addWeblinks;
        insertTo = insertFrom;
      }
      if(targetKey >= 9) {
        if(typeof(EightSisters.sisterData.param) == 'number')
          template = '|' + EightSisters.sisterData.add].commonsData;
        else if(EightSisters.sisterData.data == 'pv')
          template = '|' + EightSisters.sisterData.param + '=' + EightSisters.sisterData.add].commonsData;
        else if(EightSisters.sisterData.data == null)
          template = '';
        else if(EightSisters.sisterData.data instanceof RegExp)
          template = '|' + EightSisters.sisterData.param + '=' + EightSisters.sisterData.add].commonsData.replace(EightSisters.sisterData.data, '');
        else
          return;
      }
      else
        template = EightSisters.makeTemplate(targetKey, false) + '\n';
    }
    var fixPos = 0;
    var addComment = '';
    if(EightSisters.sisterData.foundAt == -1) {
      if(mw.config.get('wgNamespaceNumber') != 14 && EightSisters.sisterData.foundAt == -1) {
        if(EightSisters.addWeblinks != -1) {
          var newSection;
          if(text.substring(insertFrom - 2, insertFrom) == '\n\n')
            newSection = '== Weblinks ==\n';
          else
            newSection = '\n== Weblinks ==\n';
          for(var key in Object.keys(EightSisters.sisterData)) {
            if(EightSisters.sisterData.tmplpos != -1) {
              newSection += text.substring(EightSisters.sisterData.tmplpos, EightSisters.sisterData.endpos);
              text = text.substring(0, EightSisters.sisterData.tmplpos) + text.substring(EightSisters.sisterData.endpos);
              $textbox.textSelection('setSelection', { start: EightSisters.sisterData.tmplpos, end: EightSisters.sisterData.endpos });
              $textbox.textSelection('replaceSelection', '');
              if(EightSisters.sisterData.tmplpos < insertFrom)
                insertFrom -= EightSisters.sisterData.endpos - EightSisters.sisterData.tmplpos;
            }
            else if(key == targetKey)
              newSection += template;
          }
          if(text.substring(insertFrom, insertFrom + 1) != '\n')
            newSection += '\n';
          template = newSection;
        }
        else {
          if(text.substring(insertFrom, insertFrom + 1) == '\n' && text.substring(insertFrom + 1, insertFrom + 1) != '=')
            template = template.substring(0, template.length - 1);
        }
      }
      else {
        if(targetKey < 9) {
          if(text == '' || text.substring(insertFrom, insertFrom + 1) != '\n')
            template += '\n';
        }
      }

      if(targetKey >= 9 && EightSisters.sisterData.add].tmplpos != null) {
        var from = EightSisters.sisterData.add].tmplpos;
        var to = text.indexOf('}}', from);
        if(to != -1)  {
          to += 2;
          while(to < text.length && (text.substring(to, to + 1) == ' ' || text.substring(to, to + 1) == '\n'))
            ++ to;
        }

        $textbox.textSelection('setSelection', { start: from - 1, end: to });
        $textbox.textSelection('replaceSelection', text.substring(from - 1, from));
        addComment = ' (' + EightSisters.sisterData.param + ' verschoben)';

        if(insertFrom > to) {
          insertFrom -= to - from;
          insertTo -= to - from;
        }
      }
    }

    $textbox.textSelection('setSelection', { start: insertFrom, end: insertTo });
    $textbox.textSelection('replaceSelection', template);
    $textbox.textSelection('setSelection', { start: insertFrom, end: insertFrom + template.length });
    $textbox.textSelection('scrollToCaretPosition');

    e = document.getElementById('wpSummary');
    if(targetKey >= 9) {
      var addText = EightSisters.sisterData.tmpl + ' mit ] ergänzt' + addComment;
      if(e.value == '')
        e.value = addText;
      else {
        if(e.value.indexOf(addText) == -1)
          e.value += ', ' + addText;
      }
    }
    else {
      if(EightSisters.sisterData.foundAt != -1)
        e.value = EightSisters.sisterData.tmpl + ' mit ] korrigiert';
      else if(e.value == '')
        e.value = EightSisters.sisterData.tmpl + ' mit ] hinzugefügt';
      else {
        var parts = e.value.split(',');
        for(var i = 0; i < parts.length; ++ i) {
          if(parts.trim() == EightSisters.sisterData.tmpl)
            return;
          var pos = parts.indexOf(' mit ] hinzugefügt');
          if(pos != -1) {
            var posU = parts.indexOf(' und ');
            if(posU != -1) {
              parts = parts.substring(0, posU) + ', ' + parts.substring(posU + 5);
              pos -= 3;
            }
            if(parts.substring(0, pos) == EightSisters.sisterData.tmpl)
              return;
            parts = parts.substring(0, pos) + ' und ' + EightSisters.sisterData.tmpl + parts.substring(pos);
            e.value = parts.join(', ');
            return;
          }
        }
        e.value += ', ' + EightSisters.sisterData.tmpl + ' mit ] hinzugefügt';
      }
    }
    if(EightSisters.sisterData.hint != null)
      mw.notify('EightSisters: Parameter "' + EightSisters.sisterData.hint + '" eventuell ergänzen', {tag: 'parameter-hint', type: 'warn', autoHideSeconds: 30});
  },

  queryWikidataId : function(api, callback, queryParams) {
    api.get($.extend({}, queryParams, { 'continue': '' })).then(function(data) {
      callback(data);
    }).fail(function(code, data) {
      var extraText;
      if(code === 'http' && data) {
        extraText = (data.xhr && data.xhr.status ? '' : '') +
                    (data.textStatus ? '' + data.textStatus + (data.exception ? ': ' : '') : '') +
                    (data.exception ? '' + data.exception : '');
      }
      else {
        extraText = code + (data && data.error && data.error.info ? ': ' + data.error.info : '');
      }
      mw.notify('EightSisters: Fehler beim Lesen der Wikidata-ID ' + ' (' + extraText + ')', {tag: 'EightSisters-error'});
    });
  }
};
$(EightSisters.execute);
// </nowiki>