User:PerfektesChaos/js/resultListSort/r.js

/// mw:User:PerfektesChaos/js/resultListSort/r.js /// 2012-10-29 PerfektesChaos@de.wikipedia /// Fingerprint:#0#32ACE8D6# /// @license GPL [//www.mediawiki.org/w/COPYING](+GFDL,LGPL,CC-BY-SA) /// (function(mw,$){ "use strict"; var RLS; if(typeof mw.libs.resultListSort!=="object"||!mw.libs.resultListSort){ mw.libs.resultListSort={};} RLS=mw.libs.resultListSort; RLS.vsn=1.10; RLS.type="resultListSort"; RLS.canonicals=[ "Contributions","LinkSearch","Newpages","Recentchanges","Search","Watchlist","Whatlinkshere","BrokenRedirects","Deadendpages","Fewestrevisions","DoubleRedirects","Lonelypages","Longpages","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=-1; RLS.modeSumm=-2; RLS.modeURL=-3; RLS.modeUser=-4; RLS.unsorted=["Search","LinkSearch","Whatlinkshere"]; if(typeof RLS.debugging!=="object"){ RLS.debugging={loud:true,say:"RLS"};} RLS.texts={ "byName":{"en":"Sort results","de":"Sortiere Ergebnisse"},"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"} }; RLS.factory=function(access,action,ahead){ var s="by"+access; var show=this.texts[s][this.slang]; if(!show){ show=this.texts[s].en;} mw.util.addPortletLink("p-cactions",this.script+":mw.libs.resultListSort.fresh("+(action?action:"")+");"+"void(0);",show,"ca-sort-by"+access,show+" * resultListSort "+this.vsn,null,(ahead?"#"+ahead:null)); }; 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{ if(!this.slang){ this.slang=mw.config.get("wgUserLanguage").toLowerCase; switch(this.slang){ case "de": case "de-at": case "de-ch": case "de-formal": case "als": case "nds": this.slang="de"; break; default: this.slang="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.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){ if(o.hasOwnProperty(s)){ k=o[s]; if(k){ s=s.replace(/_/," "); this.space2num[s]=k; re=re+(re?"|":"")+s;}}} this.reNS=new RegExp("^("+re+"):","i");} }; 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{ if(RLS.find(RLS.auto,RLS.unsorted)){ RLS.fresh;} if(RLS.find((RLS.portlet===undefined?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.fresh=function(alter){ var g,i,n,$lis; var select=false; var $l=false; switch(RLS.specialPage){ case "Contributions": RLS.mode=RLS.modeContr; select="#mw-content-text ul"; break; case "LinkSearch": RLS.mode=(alter?RLS.modeURL:RLS.modeLink2); select="ol.special"; break; case "Newpages": RLS.mode=(alter?alter:RLS.modeDirect); select="#mw-content-text ul"; break; case "Recentchanges": case "Watchlist": RLS.mode=(alter?alter:RLS.modeDirect); select=".special"; if(!RLS.lean){ $l=mw.util.$content.find("#mw-content-text"); $l.find("h4").remove; $l.find(".mw-changeslist-date").remove; RLS.lean=true;} break; case "Recentchangeslinked": RLS.mode=RLS.modeDirect; select=".special"; break; case "Search": RLS.mode=RLS.modeSRH; select=".mw-search-results"; break; case "Whatlinkshere": RLS.mode=RLS.modeDirect; select="#mw-whatlinkshere-list"; break;} if(select){ $l=mw.util.$content.find(select); if($l.length){ $lis=$l.children("li"); n=$lis.length; if(n>1){ g=new Array(n); RLS.fiat; for(i=0;i<n;i++){ g[i]=RLS.fair($lis.eq(i));} g.sort(RLS.first); $lis.detach; for(i=0;i<n;i++){ $l.append(g[i][0]);}}}} }; RLS.furnish=function{ this.favorite; this.factory("Name",0,null); switch(this.specialPage){ case "LinkSearch": this.factory("URL",this.modeURL,null); break; case "Newpages": this.factory("User",this.modeUser,null); this.factory("Size",this.modeSize,null); this.factory("Summary",this.modeSumm,null); break; case "Recentchanges": case "Watchlist": this.factory("User",this.modeUser,null); this.factory("Summary",this.modeSumm,null); break;} }; if(!RLS.loaded){ RLS.loaded=true; if(mw.config.get("wgNamespaceNumber")===-1){ $(document).ready(function{ RLS.specialPage=mw.config.get("wgCanonicalSpecialPageName"); mw.loader.using(["user","mediawiki.util"],RLS.fire); });}} mw.loader.state("ext.gadget.resultListSort","ready"); }(mediaWiki,jQuery)); /// EOF resultListSort/r.js