User:EvaK/monobook.js

// User:Krimpet/CH2.js importScript('User:Krimpet/CH2.js'); // includePage('Benutzer:DerHexer/fixlinks.js'); // token functions function generate_flauser { return encodeURIComponent(wgUserName); } function validate_flauser (flauser) { var retval = false; if (flauser == encodeURIComponent(encodeURIComponent(generate_flauser)) ) retval = true; return retval; } function generate_flatime { var arbitrary_datestamp = Date.UTC(2008,10,1,0,0,0,0); // 1.11.2008 var current_date = new Date; var current_timestamp = current_date.getTime; return ( Math.floor((current_timestamp - arbitrary_datestamp) / 1000) ); } function validate_flatime (flatime) { var retval = false; var timediff = generate_flatime - flatime; if ((timediff >= 0) && (timediff < 45)) retval = true; return retval; } // get URL parameters (used for page type variables) var FLUrlParameters = new Array ; readparams; function readparams { var asReadInUrlParameters; var asReadInUrlParameter; // Get URL parameters asReadInUrlParameters = location.search.substring(1, location.search.length).split("&"); for (i = 0; i < asReadInUrlParameters.length; i++) { asReadInUrlParameter = asReadInUrlParameters[i].split("="); FLUrlParameters[decodeURIComponent(asReadInUrlParameter[0])] = asReadInUrlParameter[1]; } } // Funktion zum Öffnen der Links function fixlinksimages { if(confirm("Möchtest du fortfahren?")){ var req; if (req = sajax_init_object) { var text = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&format=xml&list=imageusage&iulimit=500&iutitle='+wgPageName; req.open("GET", text, false); req.send(""); var imageusage = req.responseXML.getElementsByTagName("iu"); }  for(i=0;i<10;i++){ if (!imageusage[i]) continue; var replacewith = document.getElementById('Vorlage_NowCommons'); var fixlinkstype = 'nowcommons'; if(!replacewith) { var replacewith = document.getElementById('Vorlage_JetztSVG'); fixlinkstype = 'svg'; }    if(!replacewith) continue; replacewith = replacewith.getElementsByTagName('td')[1].getElementsByTagName('a')[0].getAttribute('title').replace(/\bcommons.File./,).replace(/\bDatei\:/,); var getuser = generate_flauser; var getimage = imageusage[i].getAttribute('title'); if(getimage=='Wikipedia:Grafikwerkstatt') continue; if(getimage=='Wikipedia:WikiProjekt SVG/Wunschliste') continue; var gettime = generate_flatime; var url = mw.config.get('wgServer')+mw.config.get('wgScript')+"?title="+getimage+"&action=edit&replace="+encodeURIComponent(wgTitle)+"&replacewith="+encodeURIComponent(replacewith)+"&fixlinkstype="+encodeURIComponent(fixlinkstype)+"&flauser="+encodeURIComponent(getuser)+"&flatime="+encodeURIComponent(gettime); url = encodeURI(url); window.open(url); if(i==9 && imageusage.length>10) { document.getElementById('firstHeading').setAttribute('class', 'recentlyrestored'); document.getElementById('firstHeading').setAttribute('style', 'text-decoration: blink; background-color:red;'); document.getElementById('firstHeading').innerHTML = 'Es sind noch Einbindungen vorhanden! Skript noch einmal ausführen!'; }  }  } } function fixlinkslinklist(gettype) { /*if(confirm("Möchtest du fortfahren?")){ var movefrom = document.getElementById('contentSub').getElementsByTagName('a')[0].innerHTML; var req3; if (req3 = sajax_init_object) { var text = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&format=xml&redirects&titles='+movefrom; req3.open("GET", text, false); req3.send(""); var moveto = req3.responseXML.getElementsByTagName("page"); if (moveto) { moveto = moveto[0].getAttribute('title'); } else { alert("Konnte kein Weiterleitungsziel finden."); } }*/  var movefrom = document.getElementById('contentSub').getElementsByTagName('a')[0].innerHTML; if (gettype == '1') { var moveto = prompt('Wohin sollen die Links gefixt werden?'); } else { var moveto = 'DELETE'; } if(moveto && (moveto !== '') && (moveto !== movefrom)) { var req2; if (req2 = sajax_init_object) { var text = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&format=xml&list=backlinks&bllimit=500&blfilterredir=nonredirects&blnamespace=0|4|6|10|12|14|100&bltitle='+movefrom; req2.open("GET", text, false); req2.send(""); var linklist1 = req2.responseXML.getElementsByTagName("bl"); }  var req3; if (req3 = sajax_init_object) { var text = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&format=xml&list=imageusage&iulimit=500&iufilterredir=nonredirects&iunamespace=0|4|6|10|12|14|100&iutitle='+movefrom; req3.open("GET", text, false); req3.send(""); var linklist2 = req3.responseXML.getElementsByTagName("iu"); }  var req4; if (req4 = sajax_init_object) { var text = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&format=xml&list=embeddedin&eilimit=500&eifilterredir=nonredirects&einamespace=0|4|6|10|12|14|100&eititle='+movefrom; req4.open("GET", text, false); req4.send(""); var linklist3 = req4.responseXML.getElementsByTagName("ei"); }  if (gettype=='1') { var fixlinkstype = 'linklist'; } else { var fixlinkstype = 'deletelinks'; } for(i=0;i<10;i++){ var getuser = generate_flauser; var gettime = generate_flatime; var linklist = ''; if(linklist1[i] && !linklist) linklist = linklist1[i]; if(linklist2[i] && !linklist) linklist = linklist2[i]; if(linklist3[i] && !linklist) linklist = linklist3[i]; if(!linklist) continue; var url = mw.config.get('wgServer')+mw.config.get('wgScript')+"?title="+linklist.getAttribute('title')+"&action=edit&replace="+encodeURIComponent(movefrom)+"&replacewith="+encodeURIComponent(moveto)+"&fixlinkstype="+fixlinkstype+"&flauser="+encodeURIComponent(getuser)+"&flatime="+encodeURIComponent(gettime); url = encodeURI(url); window.open(url); if(i==9 && linklist.length>10) { document.getElementById('firstHeading').setAttribute('class', 'recentlyrestored'); document.getElementById('firstHeading').setAttribute('style', 'text-decoration: blink; background-color:red;'); document.getElementById('firstHeading').innerHTML = 'Es sind noch Einbindungen vorhanden! Skript noch einmal ausführen!'; }  }  } //} } // Funktion zum Ändern der Artikelinhalte function fixlinks{ if (validate_flauser(FLUrlParameters["flauser"])) { if (validate_flatime(FLUrlParameters["flatime"])) { var replacewith = decodeURIComponent(decodeURIComponent(decodeURIComponent(FLUrlParameters["replacewith"]))); var replacer = decodeURIComponent(decodeURIComponent(FLUrlParameters["replace"])).replace(/[\s_\.]/g,'.').replace(/\(/,'\\(').replace(/\)/,'\\)'); if (FLUrlParameters["fixlinkstype"] == 'linklist' || FLUrlParameters["fixlinkstype"] == 'deletelinks') { replacer = '\\[\\['+replacer; replacer = replacer.replace(/\\\[\\\[(Datei:|File:)/, ''); }      if (FLUrlParameters["fixlinkstype"] != 'deletelinks') replacer = new RegExp(replacer, 'ig'); //alert(replacer); //alert(replacewith); if(FLUrlParameters["fixlinkstype"] == 'nowcommons'){ document.editform.wpSummary.value = "Die Datei [[Datei:"+decodeURIComponent(decodeURIComponent(FLUrlParameters["replace"]))+"]] ist nun auf Commons unter commons:File:"+decodeURIComponent(replacewith)+" zu finden."; } else if (FLUrlParameters["fixlinkstype"] == 'svg') { document.editform.wpSummary.value = "Die Datei [[Datei:"+decodeURIComponent(decodeURIComponent(FLUrlParameters["replace"]))+"]] ist nun als SVG unter [[Datei:"+decodeURIComponent(replacewith)+"]] zu finden."; } else if (FLUrlParameters["fixlinkstype"] == 'linklist') { document.editform.wpSummary.value = "Links vom Artikel "+decodeURIComponent(decodeURIComponent(FLUrlParameters["replace"])).replace(/\[\[/,'')+" wurden auf "+decodeURIComponent(replacewith)+" korrigiert."; replacewith = 'File:)/, );      } else if (FLUrlParameters["fixlinkstype"] == 'deletelinks') {         document.editform.wpSummary.value = "Links von [["+decodeURIComponent(decodeURIComponent(FLUrlParameters["replace"])).replace(/\[\[/,)+" wurden gelöscht.";         replacer = '\(\\[\\[\)\?\(Datei:|File:\)\?' + replacer + '\.\*\?\(\\]\\]\)\?';         replacer = new RegExp(replacer, 'ig');         //alert(replacer);       } else {         document.editform.wpSummary.value = "Die Datei [[Datei:"+decodeURIComponent(decodeURIComponent(FLUrlParameters["replace"]))+"]] wurde durch die Datei [[Datei:"+decodeURIComponent(replacewith)+"]] ersetzt.";       }       document.editform.wpMinoredit.checked=false;       if (FLUrlParameters["fixlinkstype"] != 'deletelinks') { document.editform.wpTextbox1.value = document.editform.wpTextbox1.value.replace(replacer, replacewith); } else { document.editform.wpTextbox1.value = document.editform.wpTextbox1.value.replace(replacer, ); }       document.editform.wpDiff.click;       //document.editform.wpSave.click;       //window.setTimeout(function { window.close; }, 1000);     } else {       alert("Token zur automatischen Speicherung ist abgelaufen.");     }   } } if(FLUrlParameters["replace"] && FLUrlParameters["replacewith"]) addOnloadHook(fixlinks); if(wgNamespaceNumber==6)  {  addOnloadHook(function   {     mw.util.addPortletLink('p-tb', "javascript:fixlinksimages;", "FixLinks", 't-fixlinks', 'fix Links', ,  document.getElementById('t-whatlinkshere'));  }); } if(wgCanonicalSpecialPageName == "Whatlinkshere") {  addOnloadHook(function   {     mw.util.addPortletLink('p-tb', "javascript:fixlinkslinklist(1);", "FixLinks", 't-fixlinks', 'fix Links', ,  document.getElementById('t-upload'));  }); } if(wgNamespaceNumber==6 || wgCanonicalSpecialPageName == "Whatlinkshere")  {  addOnloadHook(function   {     mw.util.addPortletLink('p-tb', "javascript:fixlinkslinklist(2);", "RemoveLinks", 't-removelinks', 'entferne Links', ,  document.getElementById('t-whatlinkshere'));  }); } // Reiter für Dateien nach Commons verschieben if (wgNamespaceNumber == 6) addOnloadHook(function  {    var url = "http://toolserver.org/~magnus/commonshelper.php?interface=en&language=en&project=wikipedia&commonsense=1&remove_categories=1&tusc_user=EvaK&reallydirectupload=1&image=" + encodeURIComponent(wgTitle);    mw.util.addPortletLink("p-cactions", url, "→C", "ca-tocommons", "Per Bot nach Commons verschieben"); });