User:PerfektesChaos/js/pageLinkHelper/d.js: Difference between revisions

Content deleted Content added
-1.6
-1.7
Line 11:
( function ( mw, $ ) {
"use strict";
var Version = -1.67,
Sign = "pageLinkHelper",
Signature = "ext.gadget." + Sign,
Config, Env, PLH;
 
 
Config = { PermanentLink: { de: "PermaLink" },
Redirect: { de: "Weiterleitung" },
purgeTip: { en: "PURGE this page from server cache",
de: "PURGE:"
+ " Diese Seite"
+ " im Server-Cache aktualisieren" },
purgeTitle: { en: "Purge cache",
de: "Seite purgen" },
translate: { "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" }
}; // 2014-12-16 PerfektesChaos@de.wikipedia
 
 
Line 74 ⟶ 100:
return r;
} // $float()
 
 
 
function face() {
// Initialize environment and application object
// Precondition:
// module 'user' loaded
// Postcondition:
//
// Uses:
// > mw.libs
// > Sign
// > Version
// >< PLH
// 2014-12-16 PerfektesChaos@de.wikipedia
if ( typeof mw.libs[ Sign ] !== "object" ||
! mw.libs[ Sign ] ) {
mw.libs[ Sign ] = { };
}
if ( ! PLH ) {
PLH = mw.libs[ Sign ];
PLH.vsn = Version;
}
} // face()
 
 
 
function facility( available ) {
// Localize in user language, GUI only
// Precondition:
// available -- translation object
// Postcondition:
// Returns string, or undefined
// Uses:
// > Config
// >< Env
// mw.config.get()
// 2014-12-16 PerfektesChaos@de.wikipedia
var i, r, slang;
if ( ! Env.userLang ) {
Env.userLang = mw.config.get( "wgUserLanguage" ).toLowerCase();
}
slang = Env.userLang;
if ( typeof available[ slang ] === "string" ) {
r = available[ slang ];
} else {
i = slang.indexOf( "-", 2 );
if ( i > 0 ) {
slang = slang.substr( 0, i );
if ( typeof available[ slang ] === "string" ) {
r = available[ slang ];
}
}
}
if ( ! r ) {
if ( typeof Config.translate[ slang ] === "string" ) {
slang = Config.translate[ slang ];
if ( typeof available[ slang ] === "string" ) {
r = available[ slang ];
}
}
if ( ! r ) {
r = available.en;
}
}
return r;
} // facility()
 
 
 
function fair( access, adapt ) {
// Localization
// Precondition:
// access -- configuration keyword
// adapt -- default string (en), if user language dependant
// else project (language) dependant
// Postcondition:
// Returns value, or keyword 'access'
// Uses:
// > PLH
// > Config
// >< Env
// face()
// facility()
// mw.config.get()
// 2014-12-16 PerfektesChaos@de.wikipedia
var r = access,
el, say;
face();
if ( typeof PLH.config === "object" &&
PLH.config &&
typeof PLH.config[ access ] === "object" ) {
el = PLH.config[ access ];
}
if ( ! el ) {
el = Config[ access ];
}
if ( el ) {
if ( adapt ) {
say = facility( el );
if ( say ) {
r = say;
} else if ( typeof adapt === "string" ) {
r = adapt;
} else {
r = "???" + access + "???";
}
} else {
if ( ! Env.wgDBname ) {
Env.wgDBname = mw.config.get( "wgDBname" );
}
if ( typeof el[ Env.wgDBname ] === "string" ) {
r = el[ Env.wgDBname ];
} else {
if ( ! Env.wgContentLanguage ) {
Env.wgContentLanguage
= mw.config.get( "wgContentLanguage" );
}
if ( typeof el[ Env.wgContentLanguage ] === "string" ) {
r = el[ Env.wgContentLanguage ];
}
}
}
} else if ( adapt ) {
r = "???" + access + "???";
}
return r;
} // fair()
 
 
 
function feature( applied ) {
// Check for user option
// Precondition:
// applied -- option keyword
// module 'user' loaded
// Postcondition:
// Returns value, or undefined
// Uses:
// > PLH
// 2014-12-16 PerfektesChaos@de.wikipedia
var r; // = undefined
face();
if ( typeof PLH[ applied ] !== "undefined" ) {
r = PLH[ applied ];
}
return r;
} // feature()
 
 
Line 80 ⟶ 254:
// Equip diffpage revision with wikilink for permalink c&p
// Precondition:
// apply -- revision ID, or some keyword
// at -- revision column; "n" or "o"
// DOM.ready
Line 97 ⟶ 271:
if ( apply === "cur" ) {
id = mw.config.get( "wgCurRevisionId" );
} else if ( typeof apply === "string" &&
! /^\d+$/.test( apply ) ) { // "next"
id = false;
}
} else {
if ( ! id ) {
$a = $div.find( "a" ).eq( 0 );
s = $a.attr( "href" );
Line 114 ⟶ 292:
}
} // fiat()
 
 
 
function feature( applied ) {
// Check for user option
// Precondition:
// applied -- option keyword
// module 'user' loaded
// Postcondition:
// Returns value, or undefined
// Uses:
// > mw.libs
// > Sign
// > Version
// >< PLH
// 2014-12-11 PerfektesChaos@de.wikipedia
var r; // = undefined
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;
} // feature()
 
 
Line 240 ⟶ 390:
// mw.util.wikiUrlencode()
// mw.util.getUrl()
// fair()
// freezer()
// 2014-12-1416 PerfektesChaos@de.wikipedia
var sign = Sign + "Permalink",
$div = $( "#" + sign ),
Line 269 ⟶ 420:
if ( Env.oldid ) {
$div.append( $spanBeg.clone() );
show = special + "PermanentLink/" + Env.oldid;
+ fair( "PermanentLink" )
+ "/" + Env.oldid;
$a.attr( { "href": mw.util.getUrl( show ) + swift } );
$a.text( show );
Line 279 ⟶ 432:
}
$div.append( $spanBeg );
show = special + "Redirect/page/" + Env.curid;
+ fair( "Redirect" )
+ "/page/" + Env.curid;
$a.attr( { "href": mw.util.getUrl( show ) + swift } );
$a.text( show );
Line 340 ⟶ 495:
// mw.config.get()
// mw.util.getUrl()
// fair()
// mw.util.addPortletLink()
// 2014-12-0716 PerfektesChaos@de.wikipedia
var opt = feature( "purge" ),
say = "PURGE this page from server cache",
seed = null,
slot = "p-cactions",
show = "Purge cache",
start = "ca",
got, re, swap;
Line 402 ⟶ 556:
mw.util.addPortletLink( slot,
swap,
showfair( "purgeTitle", true ),
start + "-purge",
sayfair( "purgeTip", true ),
null,
seed );
Line 532 ⟶ 686:
break;
case "Gadgets" :
// form();
break;
} // switch wgCanonicalSpecialPageName