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
  • Internet Explorer/Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
  • Opera: Strg+F5
/* irset.js */
// <nowiki>

var IRSet = {
  /* the items of our sidebar */
  sidebarElements: new Array(
                              // first column
                              new Array(
                                         // addSLA (SLA+)
                                         new Array(
                                                    function() {
                                                      return !IRSet.isSpecial();
                                                    },
                                                    new Array( "SLA+",
                                                               function() { IRSet.addSLA(); }
                                                             )
                                                  )
                                       ),
                              // second column
                              new Array(
                                        // Logbücher
                                        new Array(
                                                   function() {
                                                     return !IRSet.isSpecial();
                                                   },
                                                   new Array( "Logbücher",
                                                               function() { IRSet.specialLog(); }
                                                            )
                                                  )
                                        )
                            ),

  /* users who want a simple sla script */
  onlySLAUsers: new Array( "Meister-Lampe" ),

  /* does this user only want a simple sla script? */
  onlySLA: function() {
    var ret = false;
    for (var user in IRSet.onlySLAUsers) {
      if (IRSet.onlySLAUsers[user] == wgUserName) {
        ret = true;
      }
    }
    return ret;
  },

  /* is this page a special page? */
  isSpecial: function() {
    return (wgCanonicalNamespace == "Special");
  },

  /* are we in edit mode? */
  isEdit: function() {
    return (wgAction == "edit");
  },

  /* are we in submit mode? */
  isSubmit: function() {
    return (wgAction == "submit");
  },

  /* trim a string */
  trim : function(str) {
    return str.replace(/^\s+/, '').replace(/\s+$/, '');
  },

  /* open this page in edit mode */
  openEdit: function(app) {
    var url = mw.config.get('wgServer') + mw.config.get('wgScript') + "?title=" + encodeURIComponent(mw.config.get('wgPageName')) + "&action=edit&" + app;
    window.location = url;
  },

  /* parse the URL and return the GET param */
  getURLParam: function(key) {
    var nkey = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + nkey + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null) {
      return "";
    } else {
      return results[1];
    }
  },

  /* create the sidebar and fill it */
  init: function() {
    if (IRSet.onlySLA()) {
      IRSet.createSLAButton();
    } else {
      IRSet.createSidebar();
    }

    if (IRSet.trim(IRSet.getURLParam("irsla")) == "1" && IRSet.trim(IRSet.getURLParam("irreason")) != "") {
      IRSet.doSLA(IRSet.trim(unescape(IRSet.getURLParam("irreason"))));
    }
  },

  /* create the SLA button */
  createSLAButton: function() {
    var a   = document.createElement("a");
    a.textContent   = "SLA+";
    a.onclick       = function() { IRSet.addSLA(); };
    a.style.cursor  = "default";
    var li  = document.createElement("li");
    li.appendChild(a);
    li.className = "collapsible";
    var watch = document.getElementById('ca-watch') ||
	document.getElementById('ca-unwatch');
    if (!watch) {
	return;
    }
    watch.parentNode.insertBefore(li, watch);
  },

  /* create the sidebar */
  createSidebar: function() {
    var div       = document.createElement("div");
    div.id        = "p-irset";
    div.className = "portal";

    var heading       = document.createElement("h5");
    heading.innerHTML = "Tools";
    div.appendChild(heading);

    var body       = document.createElement("div");
    body.className = "body";
    div.appendChild(body);

    var ul = document.createElement("ul");
    body.appendChild(ul);

    var addedSomething = false;

    for (var i in IRSet.sidebarElements) {
      var item = IRSet.sidebarElements[i];

      var li = document.createElement("li");

      var addedItem = false;

      for (var j in item) {
        var link = item[j];

        try {
          if (link[0]()) {
            var a          = document.createElement("a");
            a.textContent  = link[1][0];
            a.onclick      = link[1][1];
            a.style.cursor = "default";
            li.appendChild(a);
            addedItem = true;
            addedSomething = true;
          }
        } catch (e) {

        }

        if (addedItem) {
          ul.appendChild(li);
        }
      }
    }

    var navi = document.getElementById('p-navigation');
    if (!navi) {
      error("There seems to be no navigation ...");
    }
    if (addedSomething) {
      navi.parentNode.insertBefore(div, navi);
    }
  },

  /* add a SLA to the current page */
  addSLA: function() {
    var defreason = "Kein Artikel";
    var reason = prompt("SLA-Grund:", defreason);
    if (IRSet.trim(reason) != "") {
      if (IRSet.isEdit() || IRSet.isSubmit()) {
        IRSet.doSLA(reason);
      } else {
        IRSet.openEdit("irsla=1&irreason=" + escape(reason));
      }
    }
  },

  /* really add SLA */
  doSLA: function(reason) {
    if (!document.getElementById("wpTextbox1").value.match(/{{(Löschen|SLA)\|.+?}}/) && document.getElementById("wpTextbox1").value != "") {
      IRSet.insertAtBegin("{{Löschen|1=''" + IRSet.trim(reason) + " --~~~~''}}\n\n", "SLA: " + IRSet.trim(reason), true);
    }
  },

  /* open the Logbuch special page */
  specialLog: function() {
    var url = mw.config.get('wgServer') + mw.config.get('wgScript') + "?title=Spezial:Logbuch&page=" + escape(wgPageName);
    window.location = url;
  },

  /* insert the given string at the beginning of the page */
  insertAtBegin: function(code, summary, save) {
    if (IRSet.isEdit() || IRSet.isSubmit()) {
      var textbox = document.getElementById("wpTextbox1");
      var value = textbox.value;
      var newvalue = code + value;
      textbox.value = newvalue;
      document.getElementById("wpSummary").value = summary;
      if (save) {
        document.getElementById("wpSave").click();
      }
    }
  }
}

$(IRSet.init);

//</nowiki>