User:Mabdul/fixlinks1.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 mit dem Abarbeiten von NowCommons bzw. JetztSVG fortfahren? Zum Umbiegen von Links auf eine frei definierbare Seite gehe zuerst in die Linkliste. Zum Löschen von Verlinkungen klicke auf RemoveLinks.")){ 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(/\bFile\:/,); var getuser = generate_flauser; var getimage = imageusage[i].getAttribute('title'); if(getimage.search(/Category\:Wikibook\:File/) != -1) continue; if(getimage=='Wikibook:Grafikwerkstatt') continue; if(getimage=='Wikibook: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) { var counter = 0; var movefrom = wgPageName; if(wgCanonicalSpecialPageName == "Whatlinkshere") 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++){ if(counter < 10) { var getuser = generate_flauser; var gettime = generate_flatime; if (linklist1[i]) { var getimage = linklist1[i].getAttribute('title'); var testvar = true; if(getimage.search(/Category\:Wikibook\:File/) != -1) testvar = false; if(getimage=='Wikibook:Grafikwerkstatt') testvar = false; if(getimage=='Wikibook:WikiProjekt SVG/Wunschliste') testvar = false; if(testvar) { var url = mw.config.get('wgServer')+mw.config.get('wgScript')+"?title="+getimage+"&action=edit&replace="+encodeURIComponent(movefrom)+"&replacewith="+encodeURIComponent(moveto)+"&fixlinkstype="+fixlinkstype+"&flauser="+encodeURIComponent(getuser)+"&flatime="+encodeURIComponent(gettime); url = encodeURI(url); window.open(url); counter++; }    }     if (linklist2[i]) { var getimage = linklist2[i].getAttribute('title'); var testvar = true; if(getimage.search(/Category\:Wikibook\:File/) != -1) testvar = false; if(getimage=='Wikibook:Grafikwerkstatt') testvar = false; if(getimage=='Wikibook:WikiProjekt SVG/Wunschliste') testvar = false; if(testvar) { var url = mw.config.get('wgServer')+mw.config.get('wgScript')+"?title="+getimage+"&action=edit&replace="+encodeURIComponent(movefrom)+"&replacewith="+encodeURIComponent(moveto)+"&fixlinkstype="+fixlinkstype+"&flauser="+encodeURIComponent(getuser)+"&flatime="+encodeURIComponent(gettime); url = encodeURI(url); window.open(url); counter++; }    }     if (linklist3[i] && !linklist) { var getimage = linklist3[i].getAttribute('title'); var testvar = true; if(getimage.search(/Category\:Wikibook\:File/) != -1) testvar = false; if(getimage=='Wikibook:Grafikwerkstatt') testvar = false; if(getimage=='Wikibook:WikiProjekt SVG/Wunschliste') testvar = false; if(testvar) { var url = mw.config.get('wgServer')+mw.config.get('wgScript')+"?title="+getimage+"&action=edit&replace="+encodeURIComponent(movefrom)+"&replacewith="+encodeURIComponent(moveto)+"&fixlinkstype="+fixlinkstype+"&flauser="+encodeURIComponent(getuser)+"&flatime="+encodeURIComponent(gettime); url = encodeURI(url); window.open(url); counter++; }    }    } else { 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(/\\\[\\\[(Bild:|Image:|File:|File:)/g, ''); }      if (FLUrlParameters["fixlinkstype"] != 'deletelinks') replacer = new RegExp(replacer, 'gi'); //alert(replacer); //alert(replacewith); if(FLUrlParameters["fixlinkstype"] == 'nowcommons'){ document.editform.wpSummary.value = "Die File [[File:"+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 File [[File:"+decodeURIComponent(decodeURIComponent(FLUrlParameters["replace"]))+"]] ist nun als SVG unter [[File:"+decodeURIComponent(replacewith)+"]] zu finden."; } else if (FLUrlParameters["fixlinkstype"] == 'linklist') { document.editform.wpSummary.value = "Linkfix ("+decodeURIComponent(decodeURIComponent(FLUrlParameters["replace"])).replace(/\[\[/,'')+" → "+decodeURIComponent(replacewith)+")"; replacewith = 'Image:|File:|File:)/, );      } else if (FLUrlParameters["fixlinkstype"] == 'deletelinks') {         document.editform.wpSummary.value = "Links von [["+decodeURIComponent(decodeURIComponent(FLUrlParameters["replace"])).replace(/\[\[/,)+" wurden gelöscht.";         replacer = '\(\\[\\[\)\?\(Bild:|Image:|File:|File:|bild:|image:|File:|file:\)\?' + replacer + '\.\*\(\\]\\]\)\?';         //alert(replacer);         replacer = new RegExp(replacer, 'i');         //alert(replacer);       } else {         document.editform.wpSummary.value = "Die File [[File:"+decodeURIComponent(decodeURIComponent(FLUrlParameters["replace"]))+"]] wurde durch die File [[File:"+decodeURIComponent(replacewith)+"]] ersetzt.";       }       document.editform.wpMinoredit.checked=true;       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"]) $(fixlinks); if(wgNamespaceNumber==6)  {  $(function   {     mw.util.addPortletLink('p-tb', "javascript:fixlinksimages;", "FixLinks", 't-fixlinks', 'fix Links', ,  document.getElementById('t-whatlinkshere'));  }); } if(wgCanonicalSpecialPageName == "Whatlinkshere") {  $(function   {     mw.util.addPortletLink('p-tb', "javascript:fixlinkslinklist(1);", "FixLinks", 't-fixlinks', 'fix Links', ,  document.getElementById('t-upload'));  }); } if(wgNamespaceNumber==6 || wgCanonicalSpecialPageName == "Whatlinkshere")  {  $(function   {     mw.util.addPortletLink('p-tb', "javascript:fixlinkslinklist(2);", "RemoveLinks", 't-removelinks', 'entferne Links', ,  document.getElementById('t-whatlinkshere'));  }); }