User:PerfektesChaos/js/resultListSort/r.js

/// User:PerfektesChaos/js/resultListSort/r.js /// 2017-11-16 PerfektesChaos@de.wikipedia /// Documentation:mw:User:PerfektesChaos/js/resultListSort /// Fingerprint:#0#333A158E# /// @license GPL [//www.mediawiki.org/w/COPYING](+GFDL,LGPL,CC-BY-SA) /// (function(mw,$){ "use strict"; var Version=3.5,RLS="resultListSort",Export={signature:"ext.gadget."+RLS,support:"User:PerfektesChaos/js/"+RLS,type:RLS,vsn:Version}; RLS={config:{params:{auto:false,casing:false,group:false,portlet:true}},pgGroup:{},type:RLS,xBytes:false,xChange:false}; Export.doc=""+Export.support+""; function features{ $.extend(RLS,Export); RLS.canonicals=[ "Contributions","LinkSearch","Newpages","Recentchanges","Search","Watchlist","Whatlinkshere","Allpages","Prefixindex","BrokenRedirects","Deadendpages","DoubleRedirects","Fewestrevisions","Lonelypages","Longpages","PagesWithProp","PendingChanges","Protectedpages","Protectedtitles","Shortpages","Uncategorizedcategories","Uncategorizedimages","Uncategorizedpages","Uncategorizedtemplates","Unusedcategories","Unusedimages","Unusedtemplates","Wantedcategories","Wantedfiles","Wantedpages","Wantedtemplates"]; RLS.modeDirect=0; RLS.modeLink2=1; RLS.modeSRH=2; RLS.modeContr=10; RLS.modeDate=11; RLS.modeDiff=12; RLS.modeMark=13; RLS.modeSize=21; RLS.modeSumm=22; RLS.modeURL=23; RLS.modeUser=24; RLS.modeChange=25; RLS.modeKBytes=26; RLS.modeGroup=30; RLS.modeColumn=-1; RLS.unsorted=["Search","LinkSearch","Whatlinkshere"]; RLS.gui={greyed:false,skin:false}; RLS.texts={ "byChange":{"en":"Sort by change time","de":"Sortiere nach Änderungszeit"}, "byDiff":{"en":"Sort by changed bytes","de":"Sortiere nach geänderten Bytes"}, "byMark":{"en":"Sort by mark","de":"Sortiere nach Markierung"}, "byName":{"en":"Sort results","de":"Sortiere Ergebnisseiten"}, "bySize":{"en":"Sort by size","de":"Sortiere nach Größe"}, "bySummary":{"en":"Sort by summary","de":"Sortiere nach BK"}, "byURL":{"en":"URL Sort","de":"Sortiere nach URL"}, "byUser":{"en":"Sort by user","de":"Sortiere nach Benutzer"}, "dmy":{"en":"dmy","da":"dmyt", "fr":"dmyt","nl":"dmyt"}, "dmyt":{"en":"dmyt"},"dmyts":{"en":"dmyts"}, "mdy":{"en":"mdy2","it":"mdy2"}, "ymd":{"en":"ymd","da":"ymd2", "fr":"ymd2","nl":"ymd2"}, "ISO 8601":{"en":"ISO 8601"},"OL":{"en":"As list", "de":"Als Liste"},"sizeSeq":{"en":[1,2]}, "unitKB":{"en":"KB","fr":"Kio"}, "unitMB":{"en":"MB"},"Months":{"en":"-", "da":"S","de":"S", "it":"S","nl":"S", "pl":"S"},"^show":{"en":"Result-List-Sort", "de":"Result-List-Sort"},"^suffix":{"en":"&#8211; Sort result lists on special pages", "de":"&#8211; Ergebnislisten auf Spezialseiten sortieren"},"^^auto":{"en":"Perform sorting automatically on selected special pages.", "de":"Automatische Sortierung für bestimmte Spezialseiten"},"^^auto+":{"en":" "+"Space sparated list"+" of canonical special page names "+"Empty list:"+" Manual triggering only "+" &#8211;"+" sort every unsorted page ", "de":" Leerzeichen-getrennte Liste von kanonischen Namen Leere Liste: Gesonderte Aktivierung &#8211; alle unsortierten Seiten sortieren "}, "^^portlet":{"en":"Create portlet link.","de":"Portlet-Link einfügen"}, "^^portlet+":{"en":" "+"Space sparated list"+" of canonical specialpage names "+"Empty list:"+" all supported pages "+" &#8211;"+" Do not create portlet link. ", "de":" Leerzeichen-getrennte Liste von kanonischen Namen Leere Liste: Immer Portlet-Link &#8211; keine Portlet-Links "}, "^^casing":{"en":"Perform case-insensitive sorting.","de":"Groß- und Kleinschreibung bei Sortierung ignorieren"}, "^^group":{"en":"Keep page together with talk page.","de":"Seite mit Diskussionsseite zusammenhalten"} }; RLS.userlang={ "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" };} function find(album,allow){ var i,o=album,r=false; switch(typeof o){ case "number": case "string": r=(o===RLS.specialPage); break; case "boolean": if(!o){ break;} o=allow; case "object": if(o){ if(typeof o.length==="number"){ for(i=0;i<o.length;i++){ r=(o[i]===RLS.specialPage); if(r){ break;}} }else{ r=o[RLS.specialPage];}} break;} return r;} function fire{ mw.hook(RLS.config.supply+".ready").add(RLS.fire);} function firing{ mw.loader.using(["user","user.options","mediawiki.user","mediawiki.util"],fire);} function first{ mw.loader.state(Export.signature,"ready"); if(typeof mw.libs[RLS.type]==="object"){ RLS.config.first(mw.libs[RLS.type]);} mw.libs[RLS.type]=Export; if(mw.config.get("wgNamespaceNumber")===-1){ RLS.specialPage=mw.config.get("wgCanonicalSpecialPageName"); RLS.config.fire; features; mw.hook(RLS.type+".before").add(RLS.config.first); mw.hook("wikipage.content").add(firing); }else{ mw.hook(RLS.type+".ready").fire(Export);}} function fullstop(activity){ if(typeof activity==="object"&&activity){ if(typeof activity.preventDefault==="function"){ activity.preventDefault;} if(typeof activity.stopPropagation==="function"){ activity.stopPropagation;}}} RLS.config.favorite=function{ var r; RLS.favorite; switch(RLS.slang){ case "de": r="de.wikipedia.org"; break; default: r="www.mediawiki.org";} return "//"+r+"/wiki/"+RLS.support; }; RLS.config.fetch=function{ var cnf=RLS.config,scope=" auto portlet casing group ",vals=RLS.prego.fetch(RLS.type),n,s; for(s in vals){ if(scope.indexOf(" "+s+" ")>0){ cnf[s]=vals[s]; if(typeof cnf[s]==="string"){ cnf[s]=cnf[s].split(" "); n=cnf[s].length; if(n<=1){ switch(s){ case "auto": if(n){ if(cnf[s]==="*"){ cnf[s]=true;} }else{ cnf[s]=false;} break; case "portlet": if(n){ switch(cnf[s][0]){ case "": cnf[s]=true; break; case "0": cnf[s]=false; break;} }else{ cnf[s]=true;} break;}}}}} }; RLS.config.fiat=function(access){ var r="",v=RLS.config[access]; switch(access){ case "auto": switch(v){ case undefined: case false: case null: break; case true: r="*"; break; default: if(typeof v==="object"){ r=v.join(" ");} break;} break; case "portlet": switch(v){ case false: case null: r="0"; break; case undefined: case true: break; default: if(typeof v==="object"){ r=v.join(" ");} break;} break;} return r; }; RLS.config.fire=function{ var maxage,s,signature; this.supply="preferencesGadgetOptions"; signature="ext.gadget."+this.supply; if(!mw.loader.getState(signature)){ mw.loader.state(signature,"loading"); maxage=3; if(Version>0){ s="r"; maxage=maxage+604800; }else{ s="d"; maxage=maxage+1000;} mw.loader.load("https://en.wikipedia.org/w/index.php?title=User:PerfektesChaos/js/"+this.supply+"/"+s+".js&action=raw&bcache=1&maxage="+maxage+"&ctype=text/javascript","text/javascript");} }; RLS.config.first=function(assign){ var p,s; if(typeof assign==="object"&&assign){ p=RLS.config.params; for(s in p){ if(typeof assign[s]!=="undefined"){ RLS.config[s]=assign[s];}}} }; RLS.config.form=function{ var dialog; RLS.favorite; this.fetch; dialog={script:RLS.type,show:RLS.finest("^show"),support:this.favorite,suffix:RLS.finest("^suffix"),opts:[{signature:"auto",type:"text",show:RLS.finest("^^auto"),suffix:RLS.finest("^^auto+"),val:this.fiat("auto")},{signature:"portlet",type:"text",show:RLS.finest("^^portlet"),suffix:RLS.finest("^^portlet+"),val:this.fiat("portlet") },{signature:"casing",type:"checkbox",show:RLS.finest("^^casing"),val:(this.casing?true:false)},{signature:"group",type:"checkbox",show:RLS.finest("^^group"),val:(this.group?true:false)} ]}; RLS.prego.form(dialog); }; RLS.pgGroup.find=function{ var $grab,set=mw.util.getParamValue("enhanced"); if(set){ this.less=(set==="1"); }else{ this.$part=mw.util.$content.find("#mw-content-text"); $grab=this.$part.find(".mw-enhanced-rc"); if($grab.length){ this.less=true; }else if(mw.user.options.get("usenewrc")){ this.less=true; }else{ this.less=false;}} return this.less; }; RLS.pgGroup.first=function{ var i,n,$grab,$i,$li; if(!this.$part){ this.$part=mw.util.$content.find("#mw-content-text");} $grab=this.$part.find("div table.mw-enhanced-rc"); n=$grab.length; if(n){ RLS.$list=$(""); for(i=0;i"); $li.append($i); RLS.$list.append($li);} this.$part.append(RLS.$list);} }; RLS.factory=function(access,action){ var s=(action<0?access:"by"+access),show=RLS.finest(s),signal=show+" * "+this.type+" "+this.vsn,slot=(action<0?"ca-format-"+access:"ca-sort-by"+access),dom=mw.util.addPortletLink("p-cactions","#",show,slot,signal,null,null),$ctl=$(dom); $ctl.click(function(event){fullstop(event); RLS.flip(action); }); if(!this.controls){ this.controls={};} if(!this.controls[action]){ this.controls[action]={lazy:false,$control:$ctl,text:show}; }else{ this.controls[action].lazy=false;} }; RLS.fair=function($access){ var k=0,m=0,n=0,s=this.fetch($access),g,i,p,x; if(s){ switch(RLS.mode){ case this.modeURL: break; case this.modeChange: case this.modeDate: g=this.xChange.re.exec(s); if(g){ if(this.xChange.order){ p=this.xChange.order; x=new Array(6); for(i=0;i<p.length;i++){ x[p[i]]=g[i+1];} p=this.xChange.trslMonths; for(i=1;i<12;i++){ if(x[1]===p[i]){ if(i<10){ x[1]="0"+i; }else{ x[1]=i+"";} break;}} if(x[2].length===1){ x[2]="0"+x[2];} }else{ g.shift; x=g;} p=x.join(""); s=""; for(i=0;i<p.length;i++){ s=s+String.fromCharCode(105-p.charCodeAt(i));}} break; case this.modeKBytes: g=this.xBytes.reKB.exec(s); if(g){ s=parseInt(g[1],10)*1000; }else{ g=this.xBytes.reMB.exec(s); if(g){ s=parseInt(g[1],10)*1000000; }else{ s=-1;}} break; case this.modeDiff: case this.modeMark: break; default: g=this.reNS.exec(s); if(g){ p=g[1].toLowerCase; n=this.space2num[p]; s=s.substr(p.length+1); if(RLS.config.group){ m=n%2; n=(n-m)/ 2;}} if(RLS.config.casing){ s=s.toLowerCase;} if(RLS.mode===RLS.modeContr){ if(typeof this.reOldid!=="object"){ this.reOldid=new RegExp("[&?]oldid=([0-9]+)(?:&.*)?$");} p=$access.children("a").attr("href"); p=this.reOldid.exec(p); if(p){ k=parseInt(p[1],10);}}} }else{ s="";} return[$access,n,s,m,k]; }; RLS.favorite=function{ var s; if(!this.slang){ s=mw.config.get("wgUserLanguage").toLowerCase; if(s.length>4){ if(s.charCodeAt(2)===45){ s=s.substr(0,2);}} if(typeof this.userlang[s]==="string"){ this.slang=this.userlang[s]; }else{ this.slang=s;}} }; RLS.fetch=function($access){ var j=0,r=false,sub="a",$s=false; switch(this.mode){ case this.modeContr: case this.modeDirect: $s=$access; break; case this.modeDate: r=$access.children(".mw-changeslist-date").text; break; case this.modeDiff: sub=".mw-plusminus-pos,.mw-plusminus-neg"; r=$access.children(sub).text; if(r){ if(typeof this.reNumber!=="object"){ this.reNumber=new RegExp("[^-0-9]","gi");} r=r.replace(this.reNumber,""); r=parseInt(r,10);} break; case this.modeGroup: $s=$access.children.children.children.eq(0).children; $s=$s.eq(($s.length===2?1:2)); $s=$s.children.children.eq(0); sub=false; break; case this.modeLink2: $s=$access; j=1; break; case this.modeMark: if($access.children(".newpage").length){ r=0; }else if($access.children(".minoredit").length){ r=9; }else{ r=1;} break; case this.modeSize: r=$access.children(".mw-newpages-length").text; if(r){ r=r.replace(/\[?([.0-9]+)[^0-9].*/,"$1"); r="           ".substr(0,13-r.length)+r;} break; case this.modeSRH: $s=$access.children(".mw-search-result-heading"); break; case this.modeChange: case this.modeKBytes: r=$access.children(".mw-search-result-data").text; break; case this.modeSumm: r=$access.children(".comment").text; break; case this.modeURL: r=$access.children("a").attr("href"); break; case this.modeUser: $s=$access.children(".mw-userlink"); sub=false; break;} if($s&&$s.length){ if(sub){ $s=$s.children(sub); if(j){ $s=$s.eq(j);}} r=$s.attr("title");} return r; }; RLS.fiat=function{ var k,o,re,s; if(!this.reNS){ o=mw.config.get("wgNamespaceIds"); re=""; this.space2num={}; for(s in o){ k=o[s]; if(k){ s=s.replace(/_/," "); this.space2num[s]=k; re=re+(re?"|":"")+s;}} this.reNS=new RegExp("^("+re+"):","i");} }; RLS.filter=function{ var $content=mw.util.$content.find("#mw-content-text"),$list=$(""),$li,$ul; $list.attr({"id":RLS.type}); $content.find("h4").remove; $content.find(".mw-changeslist-date").remove; $content.find("ul.special").each(function{ $ul=$(this); $ul.children.each(function{ $li=$(this); $li.detach; $list.append($li); return true; }); $ul.remove; return true; }); $content.append($list); }; RLS.finalize=function{ var control; if(RLS.controls){ for(control in RLS.controls){ control=RLS.controls[control]; if(control){ control.$control.hide;}}} }; RLS.finest=function(ask){ var t=this.texts[ask],r; if(typeof t[this.slang]==="string"){ r=t[this.slang]; }else{ r=t.en;} return r; }; RLS.fire=function{ var p,s; if(typeof mw.libs[RLS.config.supply]==="object"){ RLS.prego=mw.libs[RLS.config.supply]; }else{ RLS.prego=false;} Export.flip=RLS.flip; Export.fresh=RLS.fresh; mw.hook(RLS.type+".ready").fire(Export); if(RLS.specialPage==="Blankpage"){ if(RLS.prego){ RLS.config.form;} }else{ if(RLS.prego){ RLS.config.fetch;} p=RLS.config.params; for(s in p){ if(typeof RLS.config[s]==="undefined"){ RLS.config[s]=p[s];}} if(find(RLS.config.auto,RLS.unsorted)){ RLS.fresh;} if(RLS.config.portlet===true){ p=true; }else{ p=find(RLS.config.portlet,RLS.canonicals);} if(p){ RLS.furnish;}} }; RLS.first=function(arg1,arg2){ var r=arg1[1]-arg2[1]; if(!r){ if(arg1[2]===arg2[2]){ if(arg1[3]===arg2[3]){ r=arg1[4]-arg2[4]; }else{ r=arg1[3]-arg2[3];} }else if(arg1[2]"); for(i=0;i"); $item=$tr.eq(k).children; $item.detach; $li.append($item); $ol.append($li);}} $div.append($ol); $table.remove;} }; RLS.flip=function(action){ var control,key; if(this.controls){ for(key in this.controls){ control=this.controls[key]; if(control&&control.lazy){ control.lazy=false; control.$greyed.detach; control.$control.append(control.$a); break;}} }else{ this.controls={};} control=this.controls[action]; if(control){ control.lazy=true; if(action<0){ control.$control.detach; }else{ if(!control.$a){ if(!this.gui.greyed){ this.gui.greyed={"color":"#808080","padding":"0.5em", "white-space":"nowrap"}; if(!this.gui.skin){ this.gui.skin=mw.config.get("skin");} if(this.gui.skin==="vector"){ this.gui.greyed["font-size"]="0.8em";}} control.$a=control.$control.find("a"); control.$greyed=$(" "); control.$greyed.css(this.gui.greyed).text(control.text);} control.$control.empty; control.$control.append(control.$greyed);}} if(action<0){ this.flat; }else{ this.fresh(action);} }; RLS.fresh=function(alter){ var g,i,n,s,$l,$recent; switch(RLS.specialPage){ case "Contributions": case "PendingChanges": RLS.mode=(alter?alter:RLS.modeContr); RLS.further; s="#mw-content-text ul"; break; case "LinkSearch": RLS.mode=(alter?alter:RLS.modeLink2); s="ol.special"; break; case "Newpages": RLS.mode=(alter?alter:RLS.modeDirect); s="#mw-content-text ul"; break; case "PagesWithProp": RLS.mode=(alter?alter:RLS.modeDirect); s="ol.special"; break; case "Recentchanges": case "Watchlist": RLS.mode=(alter?alter:RLS.modeDirect); if(!RLS.lean){ RLS.pgGroup.first; RLS.filter; RLS.lean=true;} if(RLS.pgGroup.less){ RLS.mode=RLS.modeGroup; }else{ s="#"+RLS.type;} break; case "Recentchangeslinked": RLS.mode=RLS.modeDirect; s=".special"; break; case "Search": if(alter){ RLS.mode=alter; RLS.further; }else{ RLS.mode=RLS.modeSRH;} s=".mw-search-results"; break; case "Whatlinkshere": RLS.mode=RLS.modeDirect; s="#mw-whatlinkshere-list"; break; default: if(RLS.find(RLS.specialPage,RLS.canonicals)){ s="ol.special"; }else{ s=false;}} if(RLS.$list===undefined&&s){ $l=mw.util.$content.find(s); if($l.length){ RLS.$list=$l;}} if(RLS.$list){ $l=false; if(RLS.recent){ n=RLS.mode+""; for(i in RLS.recent){ $recent=RLS.recent[i]; if(i===n){ $recent.show; $l=true; }else{ $recent.hide;}} }else{ RLS.recent={};} if(!$l){ $l=RLS.$list.children("li"); n=$l.length; if(n>1){ g=new Array(n); RLS.fiat; for(i=0;i"); $recent.attr({"id":RLS.type+"_"+RLS.mode}); RLS.recent[RLS.mode+""]=$recent; if(RLS.$div){ $l=$recent; for(i=0;i<n;i++){ $l.append(g[i][0].clone);} }else{ $l.detach; $l=$recent; for(i=0;i<n;i++){ $l.append(g[i][0]);} RLS.$div=$(" "); RLS.$div.attr({"id":RLS.type}).insertBefore(RLS.$list); RLS.$list.remove;} RLS.$div.append($l); RLS.$list=$l; }else{ RLS.$list=false;}}} }; RLS.furnish=function{ this.favorite; if(this.specialPage==="Prefixindex"||this.specialPage==="Allpages"){ this.factory("OL",this.modeColumn); }else{ this.factory("Name",this.modeDirect);} switch(this.specialPage){ case "Contributions": this.factory("Change",this.modeDate); this.factory("Summary",this.modeSumm); this.factory("Diff",this.modeDiff); this.factory("Mark",this.modeMark); break; case "LinkSearch": this.factory("URL",this.modeURL); break; case "Newpages": this.factory("User",this.modeUser); this.factory("Size",this.modeSize); this.factory("Summary",this.modeSumm); break; case "Recentchanges": case "Watchlist": if(!this.pgGroup.find){ this.factory("User",this.modeUser); this.factory("Summary",this.modeSumm);} break; case "Search": this.factory("Change",this.modeChange); this.factory("Size",this.modeKBytes); break;} }; RLS.further=function{ var i,k,o,re,s,scheme,x; switch(this.mode){ case this.modeChange: case this.modeDate: if(!this.xChange){ this.xChange={}; scheme=mw.user.options.get("date"); if(!scheme||scheme==="default"){ scheme=mw.config.get("wgDefaultDateFormat");} x=this.xChange; o={dmyt:[2,1,0,3,4],dmyts:[2,1,0,3,4,5],dmy:[3,4,2,1,0],mdy:[1,2,0,3,4],mdy2:[3,4,1,2,0],ymd:[3,4,0,1,2],ymd2:[0,1,2,3,4],"ISO 8601":false}; scheme=RLS.finest(scheme); x.order=o[scheme]; if(x.order){ s="[0-6][0-9]"; re=["2[012][0-9][0-9]","\\S+\\W?","[0-3]?[0-9]",s,s,s]; s=""; for(i=0;i<x.order.length;i++){ k=x.order[i]; switch(k){ case 0: case 1: case 2: case 3: if(s){ s=s+"\\s";} break; case 4: case 5: s=s+":"; break;} s=s+"("+re[k]+")"; switch(k){ case 0: switch(scheme){ case "dmyt": case "dmyts": case "mdy": s=s+"(?:,|\\s\\W+)?"; break;} break; case 2: s=s+"\\W?"; switch(scheme){ case "ymd2": s=s+"(?:\\s\\W+)?"; break;} break; case 4: switch(scheme){ case "dmy": case "mdy2": case "ymd": s=s+",?"; break;}}} x.re=new RegExp(s+"$"); s="wgMonthNames"; if(RLS.finest("Months")==="S"){ s=s+"Short";} x.trslMonths=mw.config.get(s); }else{ x.re=new RegExp("\\s(2[012][0-9][0-9])-([01]?[0-9])-([0-3]?[0-9])[ T](..):(..):(..)$");}} break; case this.modeKBytes: if(!this.xBytes){ s="^([0-9]+)\\s+"; this.xBytes={ reKB:new RegExp(s+RLS.finest("unitKB")),reMB:new RegExp(s+RLS.finest("unitMB")) };} break;} }; if(mw.loader.getState(Export.signature)!=="ready"){ first;} }(window.mediaWiki,window.jQuery)); /// EOF resultListSort/r.js