User:PerfektesChaos/js/pageLinkHelper/r.js

This is an old revision of this page, as edited by PerfektesChaos (talk | contribs) at 19:06, 12 December 2014 (1.4). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/// Gadget-pageLinkHelper.js
/// 2014-12-12 PerfektesChaos@de.wikipedia
/// Fingerprint:#0#A89D5531#
///<nowiki>
(function(mw,$){
"use strict";
var Version=1.4,Sign="pageLinkHelper",Signature="ext.gadget."+Sign,Env,PLH;
function $factory(access){
var space="4px",style="#808080 1px solid",$r=$("<div>");
$r.attr({"class":Sign,"id":access});
style="#808080 1px solid";
$r.css({"border-bottom":style,"border-left":style,
"float":"right","font-family":"monospace",
"margin-bottom":"1em","margin-left":"1em",
"margin-top":space,"padding-bottom":space,
"padding-left":space});
return $r;}
function $float($apply){
var r,$div;
if(typeof Env.$anchor==="undefined"){
Env.$anchor=$("#firstHeading");}
if(Env.$anchor.length){
r=true;
if($apply){
$div=$("."+Sign);
$div.remove();
$div=$("<div>");
$div.css({"clear":"left"});
Env.$anchor.after($div);
Env.$anchor.after($apply);}}
return r;}
function feature(applied){
var r;
if(typeof mw.libs[Sign]==="object"){
PLH=mw.libs[Sign];
if(PLH){
PLH.vsn=Version;
if(typeof PLH[applied]!=="undefined"){
r=PLH[applied];}}}
return r;}
function flip(){
var sign=Sign+"Difflink",$div=$("#"+sign),got,i,id1,id2,j,re,show,$span;
if(!$div.length&&$float()){
if(Env.wgCanonicalSpecialPageName){
re=/\/wiki\/[^:]+:[^\/]+\/(\d+)(?:\/(\.+))?$/;
got=re.exec(window.___location.pathname);
if(got){
id1=got[1];
id2=got[2];}
}else{
id1=Env.diff;
id2=Env.oldid;}
if(id1){
i=parseInt(id1,10);
if(id2){
if(isNaN(i)){
i=id1;
id1=id2;
id2=i;
}else{
j=parseInt(id2,10);
if(!isNaN(j)){
if(i>j){
id2=i;
id1=j;}}}
if(id2==="prev"){
id2=false;}
}else if(isNaN(i)){
id1=false;}}
if(id1){
show="[["+mw.config.get("wgFormattedNamespaces")["-1"]+":Diff/"+id1+(id2?"/"+id2:"")+"]]";
$span=$("<span>");
$span.text(show);
$div=$factory(sign);
$div.append($span);
$float($div);}}}
function freeze(){
var sign=Sign+"Permalink",$div=$("#"+sign),show,special,swift,$a,$br,$spanBeg,$spanEnd;
if(!$div.length&&$float()){
Env.wgPageName=mw.config.get("wgPageName");
if(Env.curid){
Env.curid=parseInt(Env.curid,10);
}else{
Env.curid=mw.config.get("wgArticleId");}
if(Env.oldid){
Env.oldid=parseInt(Env.oldid,10);
}else{
Env.oldid=mw.config.get("wgCurRevisionId");}
$div=$factory(sign);
special=mw.config.get("wgFormattedNamespaces")["-1"]+":Redirect/";
swift="?title="+mw.util.wikiUrlencode(Env.wgPageName);
$spanBeg=$("<span>");
$spanBeg.text("[[");
$spanEnd=$("<span>");
$spanEnd.text("]]");
$a=$("<a>");
if(Env.oldid){
$div.append($spanBeg.clone());
show=special+"revision/"+Env.oldid;
$a.attr({"href":mw.util.getUrl(show)+swift});
$a.text(show);
$div.append($a);
$div.append($spanEnd.clone());
$br=$("<br />");
$div.append($br);
$a=$("<a>");}
$div.append($spanBeg);
show=special+"page/"+Env.curid;
$a.attr({"href":mw.util.getUrl(show)+swift});
$a.text(show);
$div.append($a);
$div.append($spanEnd);
$float($div);
freezer(false);}}
function freezer(assign){
var $portlet=$("#t-permalink"),show,support,$a,$span;
if($portlet.length){
support=Sign+" "+Version;
if(assign){
$a=$("<a>");
$a.attr({"title":support});
$a.click(freeze);
$a.text("PermaLink");
$portlet.empty();
$portlet.append($a);
}else{
$a=$portlet.find("a");
show=$a.text();
if(show){
$span=$("<span>");
$span.css({"color":"#808080"});
$span.text(show);
$span.attr({"title":support});
$portlet.empty();
$portlet.append($span);}}}}
function fresh(){
var opt=feature("purge"),say="PURGE this page from server cache",seed=null,slot="p-cactions",show="Purge cache",start="ca",got,re,swap;
switch(typeof opt){
case "boolean":
if(opt){
seed=false;
}else{
slot=false;}
break;
case "string":
seed=opt;
re=/^([a-z]+)-(.+)$/;
got=re.exec(seed);
if(got){
switch(got[1]){
case "p":
slot=seed;
seed=false;
switch(got[2]){
case "navigation":
start="n";
break;
case "tb":
start="t";
break;}
break;
case "ca":
break;
case "n":
slot="p-navigation";
break;
case "t":
slot="p-tb";
break;}}
break;}
if(slot&&seed===null){
Env.skin=mw.config.get("skin");
if(Env.skin!=="vector"){
slot=false;}}
if(slot){
Env.wgPageName=mw.config.get("wgPageName");
swap=mw.util.getUrl(Env.wgPageName,{action:"purge"});
if(seed){
seed="#"+seed;}
mw.util.addPortletLink(slot,swap,show,start+"-purge",say,null,seed);}}
function from(){
var caused,opts,show,last,legacy,showed,state,swap;
if(typeof window.history.___pushState==="function"&&typeof window.history.___replaceState==="function"){
swap=mw.util.getUrl(Env.wgRedirectedFrom,{redirect:"no"});
if(window.history.previous){
last=(window.history.previous.indexOf(swap)>=0);}
if(!last){
opts=feature("redirect");
if(opts&&typeof opts==="object"&&typeof opts.legacy==="boolean"){
legacy=opts.legacy;}
showed=window.document.title;
caused={caused:Sign};
if(legacy){
state=mw.util.getUrl(Env.wgRedirectedFrom);
}else{
state=window.___location.href;}
show="#REDIRECT "+Env.wgRedirectedFrom;
window.history.___replaceState(caused,show,swap);
window.history.___pushState(caused,showed,state);}}}
function fire(){
Env=mw.config.get(["wgAction","wgCanonicalSpecialPageName","wgRedirectedFrom"]);
if(!Env.wgCanonicalSpecialPageName){
Env.diff=mw.util.getParamValue("diff");
Env.oldid=mw.util.getParamValue("oldid");}
if(Env.diff||Env.wgCanonicalSpecialPageName==="Diff"){
flip();
freezer(true);
}else if(!Env.wgCanonicalSpecialPageName){
if(Env.wgAction==="view"){
Env.curid=mw.util.getParamValue("curid");
if(Env.curid||Env.oldid){
freeze(true);
}else{
freezer(true);}
fresh();
if(Env.wgRedirectedFrom){
from();}
}else{
freezer(true);}}}
if(mw.loader.getState(Signature)!=="ready"){
mw.loader.state(Signature,"ready");
mw.loader.using(["mediawiki.util","user"],function(){
$(fire);
});}
}(window.mediaWiki,window.jQuery));
/// EOF</nowiki>pageLinkHelper.js