Benutzer:Sargoth/addOTRS.js

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

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
// Ursprünglich eine Kopie von [[Benutzer:DerHexer/addotrs.js]]
//
// Modernisiert, erweitert und anderweitig verwurstet

/** extract a URL parameter from the current URL 
 * From [[en:User:Lupin/autoedit.js]]
 *
 * paramName  : the name of the parameter to extract
 */
function getParamValue(paramName) 
{
  url = document.location.href;
  var cmdRe=RegExp( '[&?]' + paramName + '=([^&]*)' );
  var m=cmdRe.exec(url);
  if (m) 
  {
    try 
    {
      return decodeURIComponent(m[1]);
    } 
    catch (someError) 
    {
    }
  }
  return null;
}

if(!usersignature) 
  var usersignature = "\~\~\~\~";

var monthnames = new Array('Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember');
 
// OTRS gilt für Artikel (NS 0 / 1), Benutzer(unter)seiten (NS 2/3) und Bilder (NS 6)
if ((wgNamespaceNumber == 0)||(wgNamespaceNumber == 1)||
    (wgNamespaceNumber == 2)||(wgNamespaceNumber == 3)||
    (wgNamespaceNumber == 6))
{
  addOnloadHook(function() 
  { 
    var node = document.getElementById('t-whatlinkshere');
    if (skin == "vector")
      mw.util.addPortletLink('p-cactions', "javascript:add_otrs(0);", "OTRS", 't-otrs', 'OTRS-Freigabe nach Wiederherstellung', '');
    else
      mw.util.addPortletLink('p-tb', "javascript:add_otrs(0);", "OTRS", 't-otrs', 'OTRS-Freigabe nach Wiederherstellung', '', node);

    // Bei Bildern gibt es noch ein paar Optionen
    if (wgNamespaceNumber == 6)
    {
    if (skin == "vector")
    {
      mw.util.addPortletLink('p-cactions', "javascript:add_otrs(1);", "OTRS-nosubst", 't-otrsnosubst', 'OTRS-Freigabe eintragen ohne Botarbeit danach', '');
      mw.util.addPortletLink('p-cactions', "javascript:add_otrsaufschub();", "OTRS-Aufschub", 't-otrsaufschub', 'OTRS-Aufschub eintragen', '');
    } else {
      mw.util.addPortletLink('p-tb', "javascript:add_otrs(1);", "OTRS-nosubst", 't-otrsnosubst', 'OTRS-Freigabe eintragen ohne Botarbeit danach', '');
      mw.util.addPortletLink('p-tb', "javascript:add_otrsaufschub();", "OTRS-Aufschub", 't-otrsaufschub', 'OTRS-Aufschub eintragen', '');
    }
      if (wgAction == 'edit')
      {
        mw.util.addPortletLink('p-tb', "javascript:add_template();","{"+"{Information|..}"+"}", 't-otrs', 'Vorlage:Information eintragen', '',  node);
        mw.util.addPortletLink('p-tb', "javascript:add_license('Bild-CC-by-sa/3.0/de');", "+CC-by-sa", 't-ccbysa', 'Lizenz CC-by-sa eintragen', '',  node);
        mw.util.addPortletLink('p-tb', "javascript:add_license('Bild-GFDL-Neu');", "+GFDL", 't-bildgfdl', 'Lizenz Bild-GFDL-Neu eintragen', '',  node);
      }
    }
  });
}

if ((getParamValue("otrs-subst")== "true") && (wgAction=='edit'))
  window.setTimeout('add_otrs2(0)', 500);
else if ((getParamValue("otrs-nosubst")== "true") && (wgAction=='edit'))
  window.setTimeout('add_otrs2(1)', 500);
else if ((getParamValue("otrsaufschub") == "true")  && (wgAction=='edit'))
  window.setTimeout('add_otrsaufschub2()', 500);

function add_otrs(type) 
{
  if (wgAction != 'edit')
  {
    if(wgNamespaceNumber == 0) 
      linktoaddotrs = 'Diskussion:'+encodeURIComponent(wgTitle);
    else if (wgNamespaceNumber == 2) 
      linktoaddotrs = 'Benutzer Diskussion:'+encodeURIComponent(wgTitle);
    else
      linktoaddotrs = encodeURIComponent(mw.config.get('wgPageName'));
 
    if (type == 0)
      location.href = "http://de.wikipedia.org/w/index.php?title=" + linktoaddotrs + "&action=edit&otrs-subst=true";
    else
      location.href = "http://de.wikipedia.org/w/index.php?title=" + linktoaddotrs + "&action=edit&otrs-nosubst=true";
  } else {
    add_otrs2(type);
  }
}

function add_otrsaufschub() 
{
  if (wgAction != 'edit')
    location.href = "http://de.wikipedia.org/w/index.php?title=" + encodeURIComponent(mw.config.get('wgPageName')) + "&action=edit&otrsaufschub=true";
  else
    add_otrsaufschub2();
}
 
function add_otrs2(type) 
{
  var counter = 0;
  while(counter != 3) 
  {
    var ticketnummer=prompt('Ticketnummer:','').trim();
    if (ticketnummer.search(/[^\d] /) == -1) 
    {
      counter = 3;

      var otrs_datum = ticketnummer.match(/\b(\d{4})(\d{2})(\d{2})/);
      var otrsyear = RegExp.$1;
      var otrsmonth = RegExp.$2;
      var otrsday = RegExp.$3;

      if(otrsday.search(/0[0-9]/)!=-1) 
        otrsday = otrsday.match(/0([0-9])/)[1];
      if(otrsmonth.search(/0[0-9]/)!=-1) 
        otrsmonth = monthnames[parseInt(otrsmonth.match(/0([0-9])/)[1])-1]; 
      else
        otrsmonth = monthnames[parseInt(otrsmonth)-1]; 

      if ((wgNamespaceNumber == 1) || (wgNamespaceNumber == 3))
      {
        // OTRS für Texte

        otrs_text = "{"+"{subst:OTRS-Freigabe|" + otrsday + ". " + otrsmonth + " " + otrsyear + "|" + 
                    ticketnummer + "|" + usersignature + "}"+"}";

        document.editform.wpSummary.value = "OTRS-Freigabe";
        document.editform.wpWatchthis.checked=false;

        var text = document.editform.wpTextbox1.value;
        document.editform.wpTextbox1.value = otrs_text + '\n' + text;
      } else {
        // OTRS für Bilder

        if (type == 0)
          // Nach Löschung mit subst: und review
          otrs_text = "{"+"{subst:OTRS-review|" + otrsday + ". " + otrsmonth + " " + otrsyear + "|" + ticketnummer + "|" + usersignature + "}"+"}";
        else
          // Ohne Löschung brauchts kein review
          otrs_text = "{"+"{OTRS|" + otrsday + ". " + otrsmonth + " " + otrsyear + "|" + ticketnummer + "|" + usersignature + "}"+"}";

        document.editform.wpSummary.value = "OTRS-Freigabe";
        document.editform.wpWatchthis.checked=false;

        var foundduep = false;
        var text = document.editform.wpTextbox1.value;
        if(text.search(/Datei\überpr\üfung/)!=-1 || text.search(/D\ÜP/)!=-1) 
          foundduep = true;

        var replacedlicence = text.match(/\|Genehmigung\s?\=([^\n]*)(\n)/);
        replacedlicence = RegExp.$2.toString()+RegExp.$1.toString();
        text = text.replace(/\|Genehmigung\s?\=[^\n]*/, "|Genehmigung = " + otrs_text)
        text = text.replace(/\{\{Datei\überpr\üfung[^\n]*\n/g, '');
        text = text.replace(/\{\{[lL]\öschen[^\n]*\(CE[S]?T\)\s*/g, '');
        text = text.replace(/\{\{[lL]\öschen[^\}\n]*\}\}\b/g, '');
        text = text.replace(/\{\{SLA[^\n]*\(CE[S]?T\)\s*/g, '');
        text = text.replace(/\{\{SLA[^\}\n]*\}\}\s*/g, '');
        text = text.replace(/\{\{D\ÜP[^\n]*\(CE[S]?T\)\s*/g, '');
        text = text.replace(/\{\{D\ÜP[^\}\n]*\}\}\s*/g, '');
        if(foundduep) 
          text = text.replace(/(\n)\}\}(\n)/, '$1$2');

        text = text.replace(/\=\=[^\n]*Verwendung[^\n]des[^\n]Bildes[^\*]*(\*\[\[[^\]]*\]\])*\s*/g, '');
        text = text.replace(/\=\= Beschreibung, Quelle[^\n]*/,'');
        if (text.search(/\=\=.*Lizenz/)==-1)
          text = text +'\n'+replacedlicence;
        else 
          text = text.replace(/\=\=.*Lizenz[^\n]*/,replacedlicence.toString());

        document.editform.wpTextbox1.value = text;
      }
    } else {
      counter = counter + 1;
    } 	
  }
}
   
function add_otrsaufschub2() 
{
  var counter = 0;
  while(counter != 3) 
  {
    var ticketnummer=prompt('Ticketnummer:','');
    if (ticketnummer.search(/[^\d] /) == -1) 
    {
      counter = 3;
      var otrsaufschub_text = "{"+"{Dateiüberprüfung (OTRS ausstehend)|" + ticketnummer + "}"+"} " + usersignature;

      document.editform.wpSummary.value = "OTRS-Aufschub";
      document.editform.wpWatchthis.checked=false;

      var text = document.editform.wpTextbox1.value;
      document.editform.wpTextbox1.value = otrsaufschub_text + '\n' + text;
    } else {
      counter = counter + 1;
    }
  }
}

function add_license(vorlage)
{
  if (document.editform.wpTextbox1.value.search(/\=\=.*Lizenz/)==-1)
    document.editform.wpTextbox1.value += "\n\{\{"+vorlage+"\}\}";
  else 
    document.editform.wpTextbox1.value = document.editform.wpTextbox1.value.replace(/\=\=.*Lizenz[^\n]*/,"\n\{\{"+vorlage+"\}\}");
}

function add_template() 
{
  document.editform.wpTextbox1.value = 
     "{"+"{Information\n|Beschreibung=\n|Quelle=\n|Urheber=\n|Datum=\n|Genehmigung=\n|Andere Versionen=\n|Anmerkungen=\n}"+"}\n\n"+
     document.editform.wpTextbox1.value;
}