User:PerfektesChaos/js/resultListSort/r.js

/// mw:User:PerfektesChaos/js/resultListSort/r.js /// 2013-10-14 PerfektesChaos@de.wikipedia /// Fingerprint:#0#C23C0B1E# /// @license GPL [//www.mediawiki.org/w/COPYING](+GFDL,LGPL,CC-BY-SA) /// (function(mw,$){ "use strict"; var RLS="resultListSort"; if(typeof mw.libs[RLS]!=="object"||!mw.libs[RLS]){ mw.libs[RLS]={};} mw.libs[RLS].vsn=1.32; mw.libs[RLS].type=RLS; RLS=mw.libs[RLS]; if(!RLS.loaded){ RLS.support="User:PerfektesChaos/js/"+RLS.type; RLS.doc=""+RLS.support+""; 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.script="javascript"; RLS.modeDirect=0; RLS.modeContr=1; RLS.modeLink2=2; RLS.modeSRH=3; RLS.modeSize=21; RLS.modeSumm=22; RLS.modeURL=23; RLS.modeUser=24; RLS.modeGroup=30; RLS.modeColumn=-1; RLS.unsorted=["Search","LinkSearch","Whatlinkshere"]; RLS.pgGroup={}; RLS.config={}; RLS.texts={ "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"},"OL":{"en":"As list","de":"Als Liste"},"^show":{"en":"Result-List-Sort","de":"Result-List-Sort"},"^suffix":{"en":"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={ "de":"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" };} 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.config.fetch=function{ var n,s,scope=" auto portlet casing group ",vals=RLS.prego.fetch(RLS.type); for(s in vals){ if(scope.indexOf(" "+s+" ")>0){ RLS[s]=vals[s]; if(typeof RLS[s]==="string"){ RLS[s]=RLS[s].split(" "); n=RLS[s].length; if(n<=1){ switch(s){ case "auto": if(n){ if(RLS[s]==="*"){ RLS[s]=true;} }else{ RLS[s]=false;} break; case "portlet": if(n){ switch(RLS[s][0]){ case "": RLS[s]=true; break; case "0": RLS[s]=false; break;} }else{ RLS[s]=true;} break;}}}}} }; RLS.config.fiat=function(access){ var r="",v=RLS[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{ this.supply="preferencesGadgetOptions"; this.signature="ext.gadget."+this.supply; if(!mw.loader.getState(this.signature)){ mw.loader.implement(this.signature,["//en.wikipedia.org/w/index.php?title=User:PerfektesChaos/js/"+this.supply+"/r.js&action=raw&ctype=text/javascript&maxage=604800&smaxage=10003&*"],{},{});} return this.signature; }; RLS.config.form=function{ var dialog; RLS.favorite; this.fetch; dialog={script:RLS.type,show:RLS.texts["^show"][RLS.slang],support:this.favorite,suffix:RLS.texts["^suffix"][RLS.slang],opts:[{signature:"auto",type:"text",show:RLS.texts["^^auto"][RLS.slang],suffix:RLS.texts["^^auto+"][RLS.slang],val:this.fiat("auto")},{signature:"portlet",type:"text",show:RLS.texts["^^portlet"][RLS.slang],suffix:RLS.texts["^^portlet+"][RLS.slang],val:this.fiat("portlet") },{signature:"casing",type:"checkbox",show:RLS.texts["^^casing"][RLS.slang],val:(RLS.casing?true:false)},{signature:"group",type:"checkbox",show:RLS.texts["^^group"][RLS.slang],val:(RLS.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<n;i++){ $i=$grab.eq(i); $i.detach; $li=$(" "); $li.append($i); RLS.$list.append($li);} this.$part.append(RLS.$list);} }; RLS.factory=function(access,action){ var dom; var s=(action<0?access:"by"+access); var script=this.script+":mw.libs.resultListSort.flip("+action+");void(0);"; var show=this.texts[s][this.slang]; var signal=show+" * resultListSort "+this.vsn; var slot=(action<0?"ca-format-"+access:"ca-sort-by"+access); if(!show){ show=this.texts[s].en;} dom=mw.util.addPortletLink("p-cactions",script,show,slot,signal,null,null); if(!this.controls){ this.controls={};} if(!this.controls[action]){ this.controls[action]={lazy:false,dom:dom,text:show}; }else{ this.controls[action].lazy=false;} }; RLS.fair=function($access){ var g; var k=0; var m=0; var n=0; var p; var s=this.fetch($access); if(s){ if(RLS.mode!==RLS.modeURL){ g=this.reNS.exec(s); if(g){ p=g[1].toLowerCase; n=this.space2num[p]; s=s.substr(p.length+1); if(RLS.group){ m=n%2; n=(n-m)/ 2;}} if(RLS.casing){ s=s.toLowerCase;} if(RLS.mode===RLS.modeContr){ p=$access.children("a").attr("href"); p=/[&?]oldid=([0-9]+)(?:&.*)?$/.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);}} s=this.userlang[s]; this.slang=(s?s:"en");} }; RLS.fetch=function($access){ var j=0; var r=false; var sub="a"; var $s=false; switch(this.mode){ case this.modeContr: case this.modeDirect: $s=$access; 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.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.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){ if($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"); var $list=$(""); $content.find("h4").remove; $content.find(".mw-changeslist-date").remove; $content.find("ul.special").each(function{ var $ul=$(this); $ul.children.each(function{ var $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.dom; if(control){ control.setAttribute("style","display:none");}}}} }; RLS.find=function(album,allow){ var i; var o=album; var r=false; switch(typeof o){ case "number": case "string": r=(o===this.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]===this.specialPage); if(r){ break;}} }else{ r=o[this.specialPage];}} break;} return r; }; RLS.fire=function{ var low; RLS.prego=mw.libs[RLS.config.supply]; if(RLS.specialPage==="Gadgets"){ if(RLS.prego){ RLS.config.form;} }else{ if(RLS.prego){ RLS.config.fetch;} if(RLS.find(RLS.auto,RLS.unsorted)){ RLS.fresh;} low=(RLS.portlet===undefined||RLS.portlet===true); if(RLS.find((low?RLS.canonicals:RLS.portlet),RLS.canonicals)){ 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]<arg2[2]){ r=-1; }else{ r=1;}} return r; }; RLS.flat=function{ var i,k,n,$div,$item,$li,$ol,$rows,$table,$tr; switch(this.specialPage){ case "Allpages": k=".mw-allpages-table-chunk"; break; case "Prefixindex": k="#mw-prefixindex-list-table"; break;} $div=mw.util.$content.find("#mw-content-text"); $table=$div.find(k); $rows=$table.find("tbody").children("tr"); n=$rows.length; if(n){ $ol=$(" "); for(i=0;i<n;i++){ $tr=$rows.eq(i).children; for(k=0;k<$tr.length;k++){ $li=$(" "); $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){ if(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(!control.$control){ control.$control=$(control.dom);} if(action<0){ control.$control.detach; }else{ if(!control.$a){ control.$a=control.$control.find("a"); control.$greyed=$(" "+control.text+" ");} if(mw.config.get("skin")==="vector"){ control.$greyed.css("font-size","0.8em");} 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; switch(RLS.specialPage){ case "Contributions": case "PendingChanges": RLS.mode=RLS.modeContr; 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="#resultListSort";} break; case "Recentchangeslinked": RLS.mode=RLS.modeDirect; s=".special"; break; case "Search": 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){ if(i===n){ $l=RLS.recent[i]; s="block"; }else{ s="none";} RLS.recent[i].attr("style","display:"+s);} }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"); if(RLS.$div){ $l=RLS.recent[RLS.mode]; for(i=0;i<n;i++){ $l.append(g[i][0].clone);} }else{ $l.detach; $l=RLS.recent[RLS.mode]; for(i=0;i<n;i++){ $l.append(g[i][0]);} RLS.$div=$(" "); RLS.$div.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 "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;} }; if(!RLS.loaded){ RLS.loaded=true; if(mw.config.get("wgNamespaceNumber")===-1){ RLS.config.fire; mw.hook("wikipage.content").add(function{ RLS.specialPage=mw.config.get("wgCanonicalSpecialPageName"); mw.loader.using(["user","user.options","mediawiki.user","mediawiki.util",RLS.config.signature],RLS.fire); });} mw.loader.state("ext.gadget.resultListSort","ready");} }(window.mediaWiki,window.jQuery)); /// EOF resultListSort/r.js