User:PerfektesChaos/js/localEdit/r.js

/// User:PerfektesChaos/js/localEdit/r.js /// 2018-08-24 PerfektesChaos@de.wikipedia /// Fingerprint:#0#35C19827# /// @license GPL [//www.mediawiki.org/w/COPYING](+GFDL,LGPL,CC-BY-SA) /// (function(mw,$){ "use strict"; var vsn=0.3,WLE; if(typeof mw.libs.localEdit!=="object"||!mw.libs.localEdit){ mw.libs.localEdit={};} WLE=mw.libs.localEdit; WLE.vsn=vsn; WLE.type="localEdit"; WLE.scan="*.txt; *.text; *.wiki"; WLE.suffix="txt"; if(!WLE.lang){ WLE.lang={};} if(!WLE.pageImport){ WLE.pageImport={};} if(typeof WLE.debugging!=="object"){ WLE.debugging={loud:true,say:"localEdit"};} WLE.lang.texts={ "BrowserType":{"en":"Browser type", "de":"Browser-Typ"}, "AddOn":{"en":"Add-on", "de":"Add-On"}, "ConfirmLosses":{"en":"Really loose edits?", "de":"Wirklich Änderungen verlieren?"}, "DirBase":{"en":"Base directory (local)", "de":"Stammverzeichnis (lokal)"}, "DirSub":{"en":"Sub directory for project", "de":"Unterverzeichnis für Projekt"}, "Edit":{"en":"Start editing local file", "de":"Bearbeitung lokaler Dateien beginnen"}, "FileExtFilter":{"en":"File extensions (Filter)", "de":"Datei-Erweiterungen (Filter)"}, "FileExtNew":{"en":"File extension (create)", "de":"Datei-Erweiterung (Neuanlage)"}, "HeadlineConfig":{"en":"Personal options", "de":"Persönliche Einstellungen"}, "ImportPage":{"en":"Import from page", "de":"Seitentext importieren"}, "ImportPageAbort":{"en":"Abort", "de":"Abbrechen"}, "ImportPageClear":{"en":"Empty edit area first", "de":"Erst Bearbeitungsfeld leeren"}, "ImportPageFire":{"en":"Import", "de":"Importieren"}, "installed-false":{"en":"Not active", "de":"Nicht aktiv"}, "installed-true":{"en":"Active", "de":"Aktiviert"}, "NamePage":{"en":"Page name:", "de":"Seitenname:"}, "OldID":{"en":"Optional revision", "de":"Optional/alternativ Version"}, "OpenFile":{"en":"Open file", "de":"Datei öffnen"}, "SaveFile":{"en":"Save file", "de":"Datei speichern"}, "SaveFileAs":{"en":"Save file as", "de":"Datei speichern unter"}, "URLform":{"en":"URL format", "de":"URL-Format"}, "URLformfix":{"en":"Fix it", "de":"Verbessern"} }; WLE.lang.trans={ "de":"de", "de-at":"de", "de-ch":"de", "de-formal":"de", "als":"de", "bar":"de", "dsb":"de", "frr":"de", "gsw":"de", "hsb":"de", "ksh":"de", "lb":"de", "nds":"de", "pdc":"de", "pdt":"de", "pfl":"de", "sli":"de", "stq":"de", "vmf":"de" }; WLE.pageImport.fault=function{ WLE.pageImport.flop; }; WLE.lang.favorite=function{ var s; if(!this.slang){ s=mw.config.get("wgUserLanguage").toLowerCase; s=this.trans[s]; if(s){ this.slang=s; }else{ this.slang="en";}} }; WLE.lang.feature=function(apply){ var e,r; if(!this.slang){ this.favorite;} e=this.texts[apply]; if(e){ r=e[this.slang]; if(!r){ r=e.en; if(!r){ r="???"+apply+"???";}} }else{ r="***"+apply+"***";} return r; }; WLE.pageImport.fiat=function{ this.$throbber.attr("style","display:block;float:right;"); mw.loader.using(["mediawiki.api"],this.find); }; WLE.pageImport.fill=function{ var g,l=true,s=WLE.pageImport.$name.val; if(!WLE.reTrim){ WLE.reTrim=new RegExp("^[ \t]*(.+[^ \t])?[ \t]*$","");} if(s){ g=WLE.reTrim.exec(s); if(g){ s=g[1]; WLE.pageImport.$name.val(s); l=false;}} s=WLE.pageImport.$vsn.val; if(s){ g=WLE.reTrim.exec(s); if(g){ s=g[1]; WLE.pageImport.$vsn.val(s); if(!WLE.reNum){ WLE.reNum=new RegExp("^[1-9][0-9]*$","");} l=(!WLE.reNum.test(s));}} WLE.pageImport.$fire.prop("disabled",l); }; WLE.pageImport.find=function{ var q=new mw.Api,s=WLE.pageImport.$vsn.val,w={action:"query",prop:"revisions",rvlimit:"1",rvprop:"content"}; if(s){ w.revids=s; }else{ if(!WLE.pageImport.reSpU){ WLE.pageImport.reSpU=new RegExp(" ","g");} s=WLE.pageImport.$name.val; s=s.replace(WLE.pageImport.reSpU,"_"); w.titles=s;} q.get(w).done(WLE.pageImport.found).fail(WLE.pageImport.fault); }; WLE.pageImport.found=function(arrived){ var pid,q=(typeof arrived==="object"); if(q){ q=arrived.query; if(q){ q=q.pages; if(q){ for(pid in q){ q=q[pid]; if(q){ WLE.feed(q.revisions[0]["*"]); WLE.suggest=q.title;} break;}}}} WLE.pageImport.flop; }; WLE.pageImport.flop=function{ this.$div.attr("style","display:none"); }; WLE.pageImport.form=function{ var launch=true,s=WLE.feed(false); if(s){ if(!WLE.reWS){ WLE.reWS=new RegExp("[^ \t\n]","");} launch=(!WLE.reWS.test(s));} if(launch){ this.$div=WLE.$editform.find("#LocalEditPageImportDiv"); if(this.$div.length){ this.$form=this.$div.find("#LocalEditPageImportForm"); if(!this.$form.length){ s=" "+WLE.lang.feature("NamePage")+"   "+WLE.forward("ImportPageFire",false)+" "+WLE.lang.feature("OldID")+"     "+WLE.forward("ImportPageAbort",true)+" "; this.$form=$(s); this.$div.append(this.$form); s="//upload.wikimedia.org/wikipedia/commons/d/de/Ajax-loader.gif"; s=""; this.$throbber=$(s); this.$div.prepend(this.$throbber); this.$name=this.$form.find("#pageImportName"); this.$name.mouseleave(this.fill); this.$name.blur(this.fill); this.$vsn=this.$form.find("#pageImportVsn"); this.$vsn.mouseleave(this.fill); this.$vsn.blur(this.fill); this.$fire=this.$div.find("#WLE_select_ImportPageFire");} this.$form.attr("style","display:block"); this.$throbber.attr("style","display:none"); this.$div.attr("style","border: solid 3px #0000FF;padding: 0.4em;"); this.fill;} }else{ window.alert(WLE.lang.feature("ImportPageClear"));} }; WLE.face=function{ var icon=-1,s,scan="",start="",suffix="",system="",$div,$edit,$table; WLE.flat(false); $div=$(" "); WLE.first($div); if($.client){ system=$.client.profile.layout; if("gecko".indexOf(system)>=0){ icon=1;}} if(WLE.opt&&typeof WLE.opt==="object"){ if(typeof WLE.opt.scan==="string"){ WLE.scan=WLE.opt.scan;} if(typeof WLE.opt.suffix==="string"){ WLE.suffix=WLE.opt.suffix;}} $edit=$(window.document).find("#ca-edit"); if($edit.length){ $edit=$edit.find("a"); if($edit.length){ start=$edit.attr("href"); if(start){ start=start.replace(/\x27/g,"&#39;") .replace(/"+WLE.lang.feature("Edit")+"";}}} WLE.specific=mw.config.get("wgDBname")+"."+mw.config.get("wgUserName"); s=" "; $table=$(s); $div.prepend($table); }; WLE.factory=function(access,assign){ var pictures="Red_x","ba"],["Neutral","bd"],["Yes_check","fb",picture=pictures[access+1],symbol=picture[0],sucks=picture[1]; return ""; }; WLE.feed=function(apply){ var r=false; if(this.$textarea){ if(typeof apply==="string"){ this.$textarea.val(apply); r=apply;} if(this.wikEd&&window.wikEd.turnedOn&&window.wikEd.useWikEd&&window.wikEd.UpdateFrame&&window.wikEd.UpdateTextarea){ if(apply){ window.wikEd.UpdateFrame; }else{ window.wikEd.UpdateTextarea;}} if(!apply){ r=this.$textarea.val; this.suggest=false;}} return r; }; WLE.fetch=function(action,add){ var i,n,elemt=window.document.getElementById("LocalEditDiv"),event=window.document.createEvent("Events"); event.initEvent("wikilocaleditButton",true,false); elemt.setAttribute("action",action); if(add){ n=add.length; for(i=0;i<n;i++){ elemt.setAttribute(add[i][0],add[i][1]);}} elemt.dispatchEvent(event); }; WLE.filled=function{ WLE.feed(true); }; WLE.fire=function{ var s=mw.config.get("wgAction"); switch(s){ case "view": mw.loader.using(["user","mediawiki.user","mediawiki.util","jquery.client"],WLE.face); break; case "edit": case "submit": WLE.form(s); window.document.addEventListener("wikilocaleditFilled",WLE.filled,true); break;} }; WLE.fired=function(action){ var cb,low,plus=[]; switch(action){ case "ImportPage": WLE.pageImport.form; break; case "ImportPageAbort": WLE.pageImport.flop; break; case "ImportPageFire": WLE.pageImport.fiat; break; case "OpenFile": WLE.feed(false); low=false; cb=mw.util.$content.find("#ANSI"); if(cb.length){ low=cb.prop("checked");} plus.push(["lowcode",low]); case "SaveFileAs": if(WLE.scan){ plus.push(["scan",WLE.scan]);} if(WLE.suffix){ plus.push(["suffix",WLE.suffix]);} if(WLE.suggest){ plus.push(["suggest",WLE.suggest]);} case "DirSub": if(!WLE.specific){ WLE.specific=mw.config.get("wgDBname")+"."+mw.config.get("wgUserName");} plus.push(["specific",WLE.specific]); case "Abort": case "SaveFile": switch(action){ case "Abort": case "SaveFile": case "SaveFileAs": WLE.feed(false); break;} break;} if(!plus.length){ plus=false;} WLE.fetch(action,plus); }; WLE.first=function($assign){ this.$top=$("#mw-content-text"); if(this.$top.length){ this.$top.prepend($assign); }else{ this.$top=$("#bodyContent"); if(!this.$top.length){ this.$top=$("#article"); if(!this.$top.length){ this.$top=$("#content"); if(!this.$top.length){ this.$top=mw.util.$content;}}} this.$top.before($assign);} }; WLE.fix=function(aim){ var r; if(aim){ r=this.iconURL; }else if(window.location.pathname.substr(0,6)==="/wiki/"){ this.iconURL=1; r=" "; }else{ this.iconURL=-1; r=""+this.lang.feature("URLformfix")+"";} return r; }; WLE.flat=function(after){ var s=".cn-fundraiser-banner,#mw-js-message,#siteNotice,#fundraising\n#ca-nstab-user,#ca-edit,#ca-view,#ca-history,#ca-move,.noarticletext,#newarticletext\n{display: none ! important;}"; if(after){ s=".editOptions\n{margin-top: 10px;"+(this.wikEd?"background-color: transparent;":"")+" margin-bottom: 10px;}#editnotice-ns-2,.previewnote,\nDIV.mw-tos-summary,SPAN#wpSummaryLabel,DIV#editpage-copywarn,A#mw-editform-cancel,.editHelp,A[target=\"helpwindow\"],\nINPUT#wpDiff,INPUT#wpSave,INPUT#wpSummary,.editCheckboxes,.cancelLink,#enhanced-diff-live-button,#wikEdEditHelp,#wikEdLocalDiff,#wikEdSummaryInputWrapper,#thresholdSave,\n"+s;} mw.util.addCSS(s); }; WLE.folder=function(action){ var show=" * "; return ""+this.force(action,show,true)+" "; }; WLE.force=function(action,assign,able){ return ""+assign+" "; }; WLE.form=function(action){ var s,$elt,$form,$h1,$ta; this.flat(true); $form=mw.util.$content.find("#editform"); if($form.length){ $ta=$form.find("#wpTextbox1"); if($ta.length){ if(!$ta.attr("readonly")){ this.$editform=$form; this.$textarea=$ta; if(action==="edit"){ $ta.text("");} $elt=$form.find("#wpPreview"); if($elt.length){ s=" \nANSI:"+WLE.forward("OpenFile",true)+WLE.forward("ImportPage",true)+WLE.forward("SaveFile",false)+WLE.forward("SaveFileAs",true)+" "; $elt.after($(s));}}}} $h1=mw.util.$content.find("#firstHeading"); if($h1.length){ $h1.text(this.wgTitle); $h1.css("border","solid 2px #0000FF"); $h1.css("text-align","center"); $h1.css("background-color","#D0FFFF");} s=" "; this.first($(s)); }; WLE.forward=function(action,able){ return this.force(action,this.lang.feature(action),able); }; WLE.wikEd=function{ return(window.wikEd&&typeof window.wikEd==="object"&&!window.wikEd.disabled); }; if(!WLE.loaded){ WLE.loaded=true; if(mw.config.get("wgNamespaceNumber")===2){ WLE.wgTitle=mw.config.get("wgTitle"); if(WLE.wgTitle===mw.config.get("wgUserName")+"/LocalEdit"){ $(WLE.fire);}} mw.loader.state({"ext.gadget.localEdit":"ready"});} }(window.mediaWiki,window.jQuery)); /// EOF /localEdit/r.js