User:PerfektesChaos/js/pageTeaserHint/core/d.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. User:PerfektesChaos/js/pageTeaserHint/core/d. |
/// User:PerfektesChaos/js/pageTeaserHint/core/d.js
/// 2020-12-27 [email protected]
// Enrich links to pages with teaser presentation now
// ResourceLoader: compatible
// dependencies: mediawiki.api,
// mediawiki.storage,
// mediawiki.util
/// Fingerprint: #0#0#
/// License: CC-by-sa/4.0
/// <nowiki>
/* global window: false */
/* jshint forin: false,
bitwise:true, curly:true, eqeqeq:true, latedef:true,
laxbreak:true,
nocomma:true, strict:true, undef:true, unused:true */
( function ( mw, $ ) {
"use strict";
var Version = -1.5,
Signature = "pageTeaserHint",
Sub = "core",
PTHC = { trigger: { large: true,
src: "OOjs UI icon "
+ "camera-invert.svg",
sub: "c2"
}
},
API = { Api: false,
badges: [ 17437796,
17437798,
17506997,
17580674,
70893996,
70894304 ],
errors: false,
max: 10,
msec: 100,
more: 3,
scream: false,
server: "api/rest_v1/",
site: false,
solver: false,
summary: "page/summary",
$ajax: false },
BABEL = { dict: false,
dictionary: false,
lower: false,
maxDays: 30,
translate: false },
HTML = { badge: { src: "OOjs UI icon ribbonPrize.svg",
sub: "d3" },
codepages: { "css": "CSS",
"javascript": "JavaScript",
"json": "JSON",
"scribunto": "Lua" },
columns: { allpages: ".mw-allpages-body",
category: ".mw-category",
prefixindex: ".mw-prefixindex-body" },
css: { box: { "border": "2px "
+ "solid "
+ "#808080",
"padding-left": "0.5em",
"padding-right": "0.5em",
"padding-bottom": "3px" },
extr: { "display": "block",
"max-height": "15em",
"overflow": "auto" },
prvw: { "border": "1px "
+ "solid "
+ "#808080",
"border-radius": "0.5em",
"display": "table",
"margin-top": "3px",
"margin-bottom": "3px",
"padding-left": "0.5em",
"padding-right": "0.5em" } },
d: [ "redir",
"shorty",
"wikidata",
"extract",
"var" ],
disambig: { "ltr": { src: "Disambig-dark.svg",
sub: "ea" },
"rtl": { src: "Disambig arabic.svg",
sub: "17" }
},
e: [ "item",
"story",
"info",
"stamp",
"size",
"disambig",
"merits",
"protected",
"watching" ],
info: { src: "OOjs UI icon "
+ "info-progressive.svg",
sub: "5f" },
less: false,
list: false,
mag: 22,
protect: { src: "OOjs UI icon unLock-ltr.svg",
sub: "ab" },
redir: { "ltr": { src: "OOjs UI icon "
+ "newline-rtl.svg",
sub: "5d" },
"rtl": { src: "OOjs UI icon "
+ "newline-ltr.svg",
sub: "3c" }
},
sysop: { src: "OOjs UI icon lock-ltr-"
+ "destructive.svg",
sub: "e6" },
wikidata: { src: "Wikidata.svg",
sub: "71" }
},
QUEUE = { lonely: true,
mode: 0 },
REPOS;
function fired ( apply ) {
// Application requested execution, initialize now and run
// Precondition:
// apply -- application object
// Uses:
// > Signature
// >< PTHC
// < REPOS
// mw.hook()
// mw.config.get()
// BABEL.fire()
// QUEUE.fire()
// (BABEL.flat)
// 2020-12-27 [email protected]
var heritage = [ "doc",
"$file",
"furnish",
"got",
"page",
"re",
"scope",
"selector",
"$widget" ],
cnf, i, s, sign;
if ( typeof apply === "object"
&& apply &&
typeof apply.scope === "string"
&& apply.scope ) {
mw.hook( Signature + ".init" ).remove( fired );
for ( i = 0; i < heritage.length; i++ ) {
sign = heritage[ i ];
cnf = apply[ sign ];
if ( cnf ) {
s = typeof cnf;
if ( s !== "function" ) {
if ( s !== ( sign.substr( 0, 1 ) === "s"
? "string"
: "object" ) ) {
s = false;
}
}
if ( s ) {
PTHC[ sign ] = cnf;
}
}
} // for i
if ( typeof apply.$file === "function" ) {
PTHC.$file = apply.$file;
} else {
PTHC.$file = function () { };
}
if ( typeof apply.pub === "object"
&& apply.pub ) {
heritage = apply.pub;
if ( typeof heritage.type === "string" ) {
PTHC.pub.typeParent = heritage.type;
}
if ( typeof heritage.vsn === "number" ) {
PTHC.pub.vsnParent = heritage.vsn;
}
if ( typeof heritage.doc === "string" ) {
PTHC.doc = heritage.doc;
}
}
if ( typeof apply.REPOS === "object"
&& apply.REPOS ) {
REPOS = apply.REPOS;
}
if ( typeof apply.ltr === "boolean" ) {
PTHC.ltr = apply.ltr;
} else {
PTHC.ltr = true;
}
cnf = mw.config.get( [ "wgUserLanguage",
"wgUserName" ] );
PTHC.slang = cnf.wgUserLanguage.toLowerCase();
PTHC.listen = cnf.wgUserName;
BABEL.fire();
mw.hook( Signature + ".clear" ).add( BABEL.flat );
QUEUE.fire();
}
} // fired()
function first () {
// Autorun on loading
// Uses:
// > Signature
// > Sub
// > Version
// < PTHC.signature
// < PTHC.pub
// mw.loader.getState()
// mw.loader.state()
// mw.hook()
// (fired)
// 2020-12-27 [email protected]
var signature = Signature + "/" + Sub,
rls;
PTHC.signature = "ext.gadget." + signature;
if ( mw.loader.getState( PTHC.signature ) !== "ready" ) {
rls = { };
rls[ PTHC.signature ] = "ready";
mw.loader.state( rls );
PTHC.pub = { type: signature,
vsn: Version };
mw.hook( signature + ".ready" ).fire( PTHC.pub );
mw.hook( Signature + ".init" ).add( fired );
}
} // first()
API.fault = function ( jqXHR, textStatus, errorThrown ) {
// API failure
// Precondition:
// Common failure call
// Uses:
// > Signature
// >< API.more
// < API.scream
// < API.errors
// API.fetch()
// (API.finish)
// 2020-12-27 [email protected]
API.more = API.more - 1;
if ( textStatus ) {
switch ( typeof textStatus ) {
case "object":
if ( typeof textStatus.textStatus === "string" ) {
API.scream = textStatus.textStatus;
} else {
API.scream = "";
}
if ( typeof textStatus.exception === "string"
&& textStatus.exception ) {
API.scream = API.scream + " ("
+ textStatus.exception + ")";
}
break;
case "string":
API.scream = textStatus;
break;
} // switch typeof textStatus
}
if ( errorThrown ) {
if ( API.scream ) {
API.scream = API.scream + " -- Error: ";
}
API.scream = API.scream + errorThrown;
}
if ( ! API.scream ) {
API.scream = "???";
}
if ( typeof window.console === "object" &&
typeof window.console.log === "function" ) {
window.console.log( Signature + " * " + API.scream );
if ( typeof textStatus === "object"
&& textStatus &&
typeof window.console.dir === "function" ) {
window.console.dir( textStatus );
}
}
API.errors = false;
if ( API.multi > 0 ) {
API.finish();
} else {
API.fetch();
}
}; // API.fault()
API.fetch = function () {
// Receive page metadata by REST API
// Uses:
// > PTHC.re.usc
// > API.solver
// > API.page
// >< API.n
// API.fetch()
// (API.finish)
// (API.found)
// (API.fault)
// (API.finish)
// 2020-12-27 [email protected]
var got, s;
if ( API.n > 0 ) {
API.n--;
s = API.requests[ API.n ];
got = PTHC.got[ s ];
if ( s.indexOf( " " ) > 0 ) {
s = s.replace( PTHC.re.usc, "_" );
}
API.page.url = API.solver + encodeURIComponent( s );
$.ajax( API.page ).done( API.found )
.fail( API.fault );
} else {
API.page = false;
API.requests = false;
API.finish();
}
}; // API.fetch()
API.find = function ( ask, another ) {
// Receive page metadata by API
// Precondition:
// ask -- Array of page names
// another -- continue, or not
// Uses:
// > API.query
// > API.Api
// (API.found)
// (API.fault)
// 2020-12-27 [email protected]
if ( another ) {
API.query[ "continue" ] = another;
}
API.query.titles = ask;
API.Api.get( API.query ).done( API.found )
.fail( API.fault );
}; // API.find()
API.fire = function ( all, action, after ) {
// Start API retrieval
// Precondition:
// all -- Array with page names
// action -- mode
// after -- function to be called finally
// Uses:
// > API.max
// > API.server
// > API.summary
// >< API.Api
// >< API.badges
// >< API.site
// < API.requests
// < API.finish
// < API.n
// < API.i
// < API.scope
// < API.multi
// < API.query
// < API.solver
// < API.page
// API.fetch()
// API.follower()
// 2020-12-27 [email protected]
var i;
API.requests = all;
API.finish = after;
API.n = API.requests.length;
if ( API.n > 0 ) {
if ( ! API.Api ) {
API.Api = new mw.Api();
}
API.scope = action;
API.i = 0;
switch ( API.scope ) {
case "info":
API.multi = API.max;
API.query = { action: "query",
"continue": "",
prop: "info",
inprop: "protection|watched"
};
break;
case "pageprops":
for ( i = 0; i < API.badges.length; i++ ) {
API.badges[ i ] = "wikibase-badge-Q" + API.badges[ i ];
} // for i
API.multi = API.max;
API.query = { action: "query",
"continue": "",
prop: "pageprops",
redirects: "",
ppprop: "disambiguation"
+ "|displaytitle"
// + "|page_image"
+ "|wikibase_item"
+ "|wikibase-shortdesc"
};
for ( i = 0; i < API.badges.length; i++ ) {
API.query.ppprop = API.query.ppprop + "|"
+ API.badges[ i ];
} // for i
break;
case "summary":
API.multi = -1;
if ( typeof API.solver !== "string" ) {
if ( typeof API.site !== "string" ) {
API.site = window.location.protocol + "//" +
window.location.hostname + "/";
}
API.solver = API.site + API.server + API.summary + "/";
API.page = { /* beforeSend: f, */
dataType: "json"
// No "Intelligent Guess"
};
}
break;
} // switch action
if ( API.multi < 0 ) {
API.fetch();
} else {
API.follower();
}
} else {
API.finish();
}
}; // API.fire()
API.follower = function ( another ) {
// Request block of page metadata by API
// Precondition:
// another -- continue, or not
// Uses:
// > API.multi
// > API.finish
// >< API.n
// >< API.requests
// (API.finish)
// 2020-12-27 [email protected]
var i, k, n, requests;
if ( API.n > 0 ) {
n = API.n - API.multi;
k = ( n < 0 ? 0 : n );
requests = [ ];
for ( i = k; i < API.n; i++ ) {
requests.push( API.requests[ i ] );
} // for i
API.n = n;
API.find( requests, another );
} else {
API.requests = false;
API.finish();
}
}; // API.follower()
API.foreign = function ( array, after ) {
// Update message set for current language
// Precondition:
// array -- array of message ID
// after -- function to be executed after completion
// Uses:
// >< API.Api
// (API.fault)
// 2020-12-27 [email protected]
if ( ! API.Api ) {
API.Api = new mw.Api();
}
API.Api.getMessages( array ).done( after )
.fail( API.fault );
}; // API.foreign()
API.found = function ( arrived ) {
// Answer arrived
// Precondition:
// arrived -- JSON result
// Uses:
// > API.multi
// > PTHC.got
// > API.scope
// >< API.n
// >< API.requests
// < QUEUE.lonely
// < API.scream
// HTML.follow()
// API.follower()
// 2020-12-27 [email protected]
var got, i, id, page, query, redir, s, sign;
if ( typeof arrived === "object"
&& arrived ) {
if ( API.multi < 0 ) {
if ( typeof arrived.title === "string" &&
typeof PTHC.got[ arrived.title ] === "object" ) {
got = PTHC.got[ arrived.title ];
if ( typeof arrived.description === "string" ) {
s = "story";
if ( typeof arrived.description_source === "string"
&& arrived.description_source
!== "central" ) {
s = "shorty"; // "local"
}
got[ s ] = arrived.description;
}
if ( typeof arrived.displaytitle === "string" ) {
got.show = arrived.displaytitle;
}
if ( typeof arrived.extract_html === "string"
&& arrived.extract_html ) {
got.extract = { ltr: null,
summary: arrived.extract_html };
if ( typeof arrived.lang === "string"
&& arrived.lang ) {
got.extract.slang = arrived.lang;
if ( typeof arrived.dir === "string"
&& arrived.dir ) {
got.extract.ltr = ( arrived.dir !== "rtl" );
}
}
}
if ( typeof arrived.thumbnail === "object" ) {
got.thumb = arrived.thumbnail;
QUEUE.lonely = false;
}
if ( typeof arrived.timestamp === "string" ) {
got.stamp = arrived.timestamp;
}
}
window.setTimeout( API.fetch, API.msec );
} else {
if ( typeof arrived.query === "object" ) {
query = arrived.query;
if ( typeof query.pages === "object" ) {
for ( id in query.pages ) {
page = query.pages[ id ];
sign = page.title;
if ( API.scope === "pageprops" &&
typeof page[ API.scope ] === "object" ) {
page = page[ API.scope ];
}
if ( typeof PTHC.got[ sign ] === "object" ) {
got = PTHC.got[ sign ];
if ( typeof page.displaytitle === "string" ) {
got.show = page.displaytitle;
}
if ( typeof page.contentmodel === "string"
&& page.contentmodel !== "wikitext"
) {
got.stuff = page.contentmodel;
}
if ( typeof page.disambiguation
=== "string" ) {
got.linked = true;
}
if ( typeof page.length === "number" ) {
got.kBytes = Math.ceil( page.length * 0.001 );
}
if ( typeof page.pagelanguage === "string" ) {
got.slang = page.pagelanguage;
if ( typeof page.pagelanguagedir
=== "string"
&& page.pagelanguagedir === "rtl" )
{
got.ltr = false;
}
}
if ( typeof page.protection === "object" &&
typeof page.protection.length === "number"
&& page.protection.length ) {
got.protection = page.protection;
}
if ( PTHC.listen && API.scope === "info" ) {
got.listen =
( typeof page.watched === "string" );
}
if ( typeof page.wikibase_item === "string" ) {
s = page.wikibase_item.substr( 1 );
got.item = parseInt( s, 10 );
}
if ( typeof page[ "wikibase-shortdesc" ]
=== "string" ) {
got.shorty = page[ "wikibase-shortdesc" ];
}
if ( API.scope === "pageprops" ) {
for ( i = 0; i < API.badges.length; i++ ) {
s = API.badges[ i ];
if ( typeof page[ s ] === "string" ) {
got.merits = true;
break;
/*
got.merits = got.merits
+ parseInt( page[ s ],
10 );
*/
}
} // for i
}
HTML.follow( sign, got, API.scope );
}
} // for id in query.pages
if ( typeof query.redirects === "object" ) {
for ( i = 0; i < query.redirects.length; i++ ) {
redir = query.redirects[ i ];
sign = redir.from;
if ( typeof PTHC.got[ sign ] === "object" ) {
got = PTHC.got[ sign ];
got.shift = redir.to;
HTML.follow( sign, got, API.scope );
}
} // for i
}
}
}
API.follower();
}
}
API.scream = false;
}; // API.found()
BABEL.def = {
"author": "protect-level-author",
"autoconfirmed": "protect-level-autoconfirmed",
"badge": "Wikibase-pageswithbadges-badge",
"banner-protect": "protect-level-banner-protect",
"centralnotice-admin": "protect-level-centralnotice-admin",
"create": "restriction-create",
"disambig": "Visualeditor-dialog-"
+ "meta-settings-disambiguation-label",
"edit": "restriction-edit",
"editautopatrolprotected": "protect-level-"
+ "editautopatrolprotected",
"editeditorprotected": "protect-level-editeditorprotected",
"editor": "protect-level-editor",
"editextendedsemiprotected":"protect-level-"
+ "editextendedsemiprotected",
"extendedconfirmed": "protect-level-extendedconfirmed",
"images": "coll-images-title",
// Mobile-frontend-enable-images-prefix
"infinity": "infiniteblock",
"kilobyte": "Kilobytes",
"megabyte": "Megabytes",
"move": "restriction-move",
"pageinfo": "pageinfo",
"redirect": "redirectpagesub",
"sysop": "protect-level-sysop",
"templateeditor": "protect-level-templateeditor",
"unwatch": "unwatch",
"watch": "watch",
"wikidata": "project-localized-name-wikidatawiki"
}; // BABEL.translate
BABEL.fair = function ( at ) {
// Convert ISO UTC timestamp into browser local date
// Precondition:
// at -- ISO UTC timestamp
// 2020-12-27_21:09:34 +00:00
// Postcondition:
// Returns string, with browser local date and time
// 2020-12-27 [email protected]
var iY = at.substr( 0, 4 ),
iM = at.substr( 5, 2 ),
iD = at.substr( 8, 2 ),
ih = at.substr( 11, 2 ),
im = at.substr( 14, 2 ),
is = at.substr( 17, 2 ),
date = new Date( iY, iM - 1, iD, ih, im, is );
date.setMinutes( date.getMinutes()
- date.getTimezoneOffset() );
return date.toLocaleString();
}; // BABEL.fair()
BABEL.fire = function () {
// Initialize messages storage
// Uses:
// > PTHC.slang
// > BABEL.def
// > BABEL.lower
// >< BABEL.translate
// >< BABEL.dict
// >< BABEL.lower
// < BABEL.slang
// 2020-12-27 [email protected]
var date, less, load, repo, s, stored;
if ( typeof mw.storage === "object"
&& mw.storage &&
typeof mw.storage.get === "function" &&
typeof mw.storage.remove === "function" &&
typeof mw.storage.set === "function" ) {
if ( ! BABEL.translate ) {
BABEL.slang = PTHC.slang.toLowerCase();
BABEL.translate = { };
for ( s in BABEL.def ) {
stored = BABEL.def[ s ];
BABEL.translate[ s ] = stored;
} // for s in BABEL.def
}
if ( typeof BABEL.dict !== "object" ) {
stored = mw.storage.get( Signature );
if ( stored ) {
try {
repo = JSON.parse( stored );
if ( typeof repo === "object"
&& repo ) {
BABEL.dictionary = repo;
if ( typeof repo.next === "number" ) {
date = new Date();
if ( repo.next < date.getTime() ) {
load = true;
}
}
if ( typeof BABEL.dictionary[ BABEL.slang ]
=== "object" ) {
BABEL.dict = BABEL.dictionary[ BABEL.slang ];
} else {
load = true;
}
} else {
less = true;
}
} catch( ex ) {
less = true;
}
} else {
load = true;
}
}
if ( less || BABEL.lower ) {
mw.storage.remove( Signature );
BABEL.lower = false;
load = true;
}
if ( load ) {
BABEL.fresh();
}
}
}; // BABEL.fire()
BABEL.flat = function () {
// Clear messages storage
// Uses:
// < BABEL.lower
// BABEL.fire()
// 2020-12-27 [email protected]
BABEL.lower = true;
BABEL.fire();
}; // BABEL.flat()
BABEL.fresh = function () {
// Update messages storage
// Uses:
// >< BABEL.translate
// API.foreign()
// 2020-12-27 [email protected]
var q = [ ],
s;
for ( s in BABEL.translate ) {
q.push( BABEL.translate[ s ] );
} // for s in BABEL.translate
API.foreign( q, BABEL.freshed );
}; // BABEL.fresh()
BABEL.freshed = function ( arrived ) {
// Messages arrived
// Precondition:
// arrived -- JSON result
// Uses:
// > BABEL.maxDays
// > BABEL.slang
// > Signature
// < BABEL.dict
// mw.storage.set()
// 2020-12-27 [email protected]
var date = new Date(),
s;
if ( typeof BABEL.dictionary !== "object" ) {
BABEL.dictionary = { };
}
BABEL.dictionary.next = date.getTime()
+ BABEL.maxDays * 86400000;
if ( typeof BABEL.dictionary[ BABEL.slang ] !== "object" ) {
BABEL.dictionary[ BABEL.slang ] = { };
}
BABEL.dict = BABEL.dictionary[ BABEL.slang ];
for ( s in arrived ) {
if ( arrived[ s ] ) {
BABEL.dict[ s ] = arrived[ s ];
}
} // for s in arrived
BABEL.dictionary[ BABEL.slang ] = BABEL.dict;
mw.storage.set( Signature, JSON.stringify( BABEL.dictionary ) );
}; // BABEL.freshed()
BABEL.from = function ( alien ) {
// Translate a message
// Precondition:
// alien -- ID
// Postcondition:
// Returns string, which ever
// Uses:
// > BABEL.translate
// > BABEL.dict
// BABEL.fetch()
// 2020-12-27 [email protected]
var r, s;
if ( BABEL.translate &&
typeof BABEL.translate[ alien ] === "string" ) {
s = BABEL.translate[ alien ];
if ( s &&
BABEL.dict &&
typeof BABEL.dict[ s ] === "string" ) {
r = BABEL.dict[ s ];
}
}
return r || s || alien;
}; // BABEL.from()
HTML.face = function ( $area, add ) {
// Ensure text properties
// Precondition:
// $area -- jquery object to be populated
// add -- generating data
// Uses:
// > PTHC.ltr
// 2020-12-27 [email protected]
if ( add.slang ) {
$area.attr( "lang", add.slang );
if ( add.ltr !== PTHC.ltr ) {
$area.attr( "dir", ( add.ltr ? "ltr" : "rtl" ) );
}
}
}; // HTML.face()
HTML.$factory = function ( $area, at, add ) {
// Create single element
// Precondition:
// $area -- jquery object to be populated
// at -- element name
// add -- generating data
// Uses:
// > PTHC.ltr
// > HTML.redir
// > HTML.mag
// > HTML.wikidata
// > PTHC.selector
// > PTHC.scope
// > HTML.css.prvw
// > HTML.info
// > HTML.disambig
// > HTML.badge
// > HTML.sysop
// > HTML.protect
// >< PTHC.re.eol
// mw.util.getUrl()
// PTHC.$file()
// HTML.face()
// BABEL.from()
// BABEL.fair()
// 2020-12-27 [email protected]
var e, i, s, s2, $e, $img;
switch ( at ) {
case "redir":
s = ( PTHC.ltr ? "margin-right" : "margin-left" );
$img = PTHC.$file( HTML.redir, HTML.mag );
$img.attr( { "title": BABEL.from( "redirect" ) } )
.css( s, "0.5em" );
$area.prepend( $img );
$e = $( "<a>" );
$e.attr( { "href": mw.util.getUrl( add,
{ action: "view" } ) } )
.text( add );
$area.append( $e );
break;
case "shorty":
$area.text( add.shorty );
HTML.face( $area, add );
break;
case "item":
s = ( PTHC.ltr ? "margin-right" : "margin-left" );
$img = PTHC.$file( HTML.wikidata, HTML.mag );
$e = $( "<a>" );
$e.append( $img )
.attr( { "href": "https://www.wikidata.org/wiki/Q"
+ add,
"title": BABEL.from( "wikidata" )
+ " Q" + add } );
$area.prepend( $e );
break;
case "story":
s = ( PTHC.ltr ? "margin-left" : "margin-right" );
$e = $( "<span>" );
$e.css( s, "2em" )
.text( add.story );
HTML.face( $e, add );
$area.append( $e );
break;
case "extract":
s = add.summary;
if ( s.indexOf( "\n" ) > 0 ) {
if ( typeof PTHC.re.eol ) {
PTHC.re.eol = new RegExp( "\n(</?u?li?>)", "g" );
}
s = s.replace( PTHC.re.eol, "$1" );
}
$e = $( "<div>" );
$e.addClass( PTHC.selector + "extracted" )
.html( s );
if ( PTHC.scope !== "search" ) {
}
HTML.face( $e, add );
$area.css( HTML.css.prvw )
.append( $e );
break;
case "info":
s = ( PTHC.ltr ? "margin-right" : "margin-left" );
$e = $( "<a>" );
$e.attr( { "href": mw.util.getUrl( add,
{ action: "info" } ),
"title": BABEL.from( "pageinfo" ) } )
.css( s, "1em" );
$img = PTHC.$file( HTML.info, HTML.mag );
$e.append( $img );
$area.prepend( $e );
break;
case "stamp":
$e = $( "<span>" );
$e.attr( { "title": BABEL.fair( add ) } )
.css( { "margin-left": "1em",
"margin-right": "1em",
"white-space": "nowrap" } )
.text( add.substr( 0, 10 ) + " "
+ add.substr( 11, 5 ) );
$area.append( $e );
break;
case "size":
if ( add > 1077 ) {
i = Math.floor( add * 0.00097 );
s = "MB";
s2 = "megabyte";
} else {
i = add;
s = "kB";
s2 = "kilobyte";
}
$e = $( "<span>" );
$e.attr( { "title": BABEL.from( s2 ) } )
.css( { "margin-left": "1em",
"margin-right": "1em",
"white-space": "nowrap" } )
.text( i + " " + s );
$area.append( $e );
break;
case "disambig":
$img = PTHC.$file( HTML.disambig, HTML.mag );
$img.attr( { "title": BABEL.from( "disambig" ) } )
.css( { "margin-left": "1em",
"margin-right": "1em" } );
$area.append( $img );
break;
case "model":
$e = $( "<span>" );
s = add.toLowerCase();
if ( typeof HTML.codepages[ s ] === "string" ) {
s = HTML.codepages[ s ];
}
$e.text( s )
.css( { "margin-left": "1em",
"margin-right": "1em" } );
$area.append( $e );
break;
case "merits":
$e = $( "<span>" );
$img = PTHC.$file( HTML.badge, HTML.mag );
$e.append( $img )
.css( { "margin-left": "1em",
"margin-right": "1em" } );
$area.append( $e );
break;
case "protected":
if ( add.length > 1 &&
add[ 0 ].type === "edit" &&
add[ 0 ].level === "sysop" &&
add[ 1 ].type === "move" &&
add[ 1 ].level === "sysop" ) {
s = "sysop";
} else {
s = "protect";
}
$img = PTHC.$file( HTML[ s ], HTML.mag );
s = "";
for ( i = 0; i < add.length; i++ ) {
e = add[ i ];
if ( typeof e.type === "string" &&
typeof e.level === "string" ) {
if ( s ) {
s = s
+ String.fromCharCode( 0xA0, 0x7C, 0x20, 0x0A );
}
s = s + BABEL.from( e.type )
+ String.fromCharCode( 0xA0, 0x2013, 0x20 )
+ BABEL.from( e.level );
if ( typeof e.expiry === "string"
&& e.expiry === "infinity" ) {
s = s + String.fromCharCode( 0xA0, 0x2F, 0x20 )
+ BABEL.from( e.expiry );
}
}
} // for i
if ( s ) {
$img.attr( { "title": s } );
}
$img.css( { "margin-left": "1em",
"margin-right": "1em" } );
$area.append( $img );
break;
case "watching":
s = ( add.listen ? "un" : "" ) + "watch";
i = ( add.listen ? 0x2605 : 0x2606 );
$e = $( "<a>" );
$e.attr( { href: mw.util.getUrl( add.slot,
{ action: s } ),
title: BABEL.from( s ) } )
.css( "padding-" + ( PTHC.ltr ? "left" : "right" ),
"1em" )
.text( String.fromCharCode( i ) );
$area.append( $e );
break;
} // switch at
}; // HTML.$factory()
HTML.fiat = function ( about, $area, at, append, add ) {
// Create element content
// Precondition:
// about -- entry object
// $area -- jquery object to be populated
// at -- section name
// append -- sub-section name
// add -- generating data
// Uses:
// HTML.$factory()
// 2020-12-27 [email protected]
switch ( at ) {
case "redir":
$area.append( HTML.$factory( $area, "redir", add ) );
break;
case "shorty":
$area.append( HTML.$factory( $area, "shorty", add ) );
break;
case "wikidata":
if ( append ) {
$area.append( HTML.$factory( $area, "story", add ) );
} else {
$area.prepend( HTML.$factory( $area, "item", add ) );
}
break;
case "extract":
$area.append( HTML.$factory( $area, "extract", add ) );
break;
case "var":
$area.append( HTML.$factory( $area, append, add ) );
break;
} // switch at
}; // HTML.fiat()
HTML.fill = function ( about, at, append, add ) {
// Create list entry segment
// Precondition:
// about -- entry object
// at -- section name
// append -- sub-section name
// add -- generating data
// Uses:
// > HTML.d
// > PTHC.selector
// HTML.fiat()
// 2020-12-27 [email protected]
var i, live, s, $d, $previous;
if ( about[ at ] ) {
$d = about[ at ];
live = true;
} else {
for ( i = 0; i < HTML.d.length; i++ ) {
s = HTML.d[ i ];
if ( s === at ) {
break; // for i
}
if ( about[ s ] ) {
$previous = about[ s ];
}
} // for i
s = ( HTML.list ? "<dd>" : "<div>" );
$d = $( s );
$d.addClass( PTHC.selector + at );
if ( $previous ) {
$previous.after( $d );
} else if ( ! HTML.list ) {
about.$box.append( $d );
}
about[ at ] = $d;
}
if ( append && ! about[ append ] ) {
live = false;
}
if ( ! live ) {
HTML.fiat( about, $d, at, append, add );
about[ append ] = true;
}
}; // HTML.fill()
HTML.finesse = function () {
// Equip &action=info page
// Uses:
// > PTHC.got
// > PTHC.$widget
// HTML.$factory()
// 2020-12-27 [email protected]
var got, s, $div;
for ( s in PTHC.got ) {
got = PTHC.got[ s ];
break; // for s
} // for s in PTHC.got
if ( got && got.extract ) {
$div = $( "<div>" );
HTML.$factory( $div, "extract", got.extract );
PTHC.$widget.before( $div );
}
}; // HTML.finesse()
HTML.first = function ( at, assigned, $a ) {
// Initialize page metadata for entry
// Precondition:
// at -- page name
// assigned -- entry object
// $a -- jquery <a> of entry
// Postcondition:
// Returns entry object
// Uses:
// > HTML.d
// > HTML.e
// > HTML.list
// > PTHC.selector
// > HTML.css.box
// mw.util.getUrl()
// HTML.full()
// 2020-12-27 [email protected]
var r = { $a: $a },
i, s, $parent;
for ( i = 0; i < HTML.d.length; i++ ) {
r[ HTML.d[ i ] ] = false;
} // for i
for ( i = 0; i < HTML.e.length; i++ ) {
r[ HTML.e[ i ] ] = false;
} // for i
if ( HTML.list ) {
r.dt = $a.parents( "dt" );
if ( assigned.shift ) {
s = mw.util.getUrl( at, { redirect: "no" } );
} else {
s = mw.util.getUrl( at, { action: "view" } );
}
$a.attr( { "href": s } )
.css( { "font-weight": "bold" } );
} else {
r.$box = $( "<div>" );
r.$box.addClass( PTHC.selector + "box" )
.css( HTML.css.box );
$parent = $a.parents( "li.mw-search-result" );
$parent.append( r.$box )
.css( { "clear": "both" } );
s = mw.util.getUrl( at, { action: "view" } );
$a.attr( { "href": s } );
}
HTML.full( assigned, r, at );
return r;
}; // HTML.first()
HTML.flat = function ( $area ) {
// Remove multiplicity of columns
// Precondition:
// $area -- jquery object
// 2020-12-27 [email protected]
$area.css( { "columns": "1",
"-khtml-columns": "1",
"-moz-columns": "1",
"-ms-columns": "1",
"-webkit-columns": "1" } );
}; // HTML.flat()
HTML.flip = function () {
// Conversion of <ul> elements into <dl>
// Uses:
// > PTHC.page.$container
// > PTHC.scope
// >< HTML.d
// < HTML.less
// < HTML.list
// HTML.flat()
// 2020-12-27 [email protected]
var i, k, $cont, $dl, $dt, $exclude, $li, $lis, $ul, $uls, $up;
if ( PTHC.scope !== "user" ) {
$exclude = PTHC.page.$container.find( ".mw-parser-output ul" );
}
HTML.d.unshift( "dt" );
HTML.less = ( PTHC.scope === "contributions" );
HTML.list = true;
HTML.flat( PTHC.page.$container );
if ( typeof HTML.columns[ PTHC.scope ] === "string" ) {
$cont = PTHC.page.$container.find( HTML.columns[ PTHC.scope ] );
HTML.flat( $cont );
}
$uls = PTHC.page.$container.find( "ul > li > ul" );
if ( $uls.length ) {
if ( $exclude ) {
$uls = $uls.not( $exclude );
}
for ( i = 0; i < $uls.length; i++ ) {
$ul = $uls.eq( i );
$up = $ul.parent();
$lis = $ul.children( "li" );
for ( k = 0; k < $lis.length; k++ ) {
$li = $lis.eq( k );
$li.detach();
$up.before( $li );
} // for k
$up.remove();
} // for i
}
$uls = PTHC.page.$container.find( "ul" );
if ( $uls.length ) {
if ( $exclude ) {
$uls = $uls.not( $exclude );
}
for ( i = 0; i < $uls.length; i++ ) {
$ul = $uls.eq( i );
$lis = $ul.children( "li" );
if ( $lis.length ) {
$dl = $( "<dl>" );
for ( k = 0; k < $lis.length; k++ ) {
$li = $lis.eq( k );
$dt = $( "<dt>" );
$cont = $li.contents();
$cont.detach();
$dt.append( $cont )
.css( { "font-weight": "normal" } );
$dl.append( $dt );
$li.remove();
} // for k
$ul.before( $dl );
}
$ul.remove();
} // for i
}
}; // HTML.flip()
HTML.floats = function () {
// Equip all entries with images if known
// Uses:
// > PTHC.got
// > PTHC.ltr
// > HTML.list
// 2020-12-27 [email protected]
var got, i, s, $div, $dt, $img;
for ( s in PTHC.got ) {
got = PTHC.got[ s ];
if ( got.thumb ) {
$div = $( "<div>" );
if ( PTHC.ltr ) {
$div.css( { "float": "right",
"margin-left": "1em" } );
} else {
$div.css( { "float": "left",
"margin-right": "1em" } );
}
$div.css( { "margin-bottom": "0.5em",
"margin-top": "0.5em" } );
$img = $( "<img>" );
$img.attr( { src: got.thumb.source,
height: got.thumb.height,
width: got.thumb.width } )
.css( { "display": "inline" } );
$div.append( $img );
if ( HTML.list ) {
for ( i = 0; i < got.dl.length; i++ ) {
$dt = got.dl[ i ].dt;
$dt.css( { "clear": "both" } )
.append( $div );
} // for i
} else {
got.div.$box.prepend( $div );
}
}
} // for s in PTHC.got
}; // HTML.floats()
HTML.flop = function () {
// Ensure list styles on search results
// Uses:
// > PTHC.selector
// > HTML.css.extr
// < HTML.less
// mw.util.addCSS()
// 2020-12-27 [email protected]
var css = { ol: "decimal",
ul: "disc" },
sel = "." + PTHC.selector + "extracted",
set = sel + "{",
s;
for ( s in HTML.css.extr ) {
set = set + s + ":" + HTML.css.extr[ s ] + ";";
} // for s in HTML.css.extr
set = set + "}";
for ( s in css ) {
set = set + sel + " " + s + " li{"
+ "list-style:" + css[ s ] + " none outside;"
+ "padding-bottom:0;}";
} // for s in css
mw.util.addCSS( set );
HTML.less = true;
}; // HTML.flop()
HTML.follow = function ( at, assigned, about ) {
// Process API return
// Precondition:
// at -- page name
// assigned -- page object
// about -- kind of API request
// Postcondition:
// Page has been modified
// Uses:
// > PTHC.scope
// HTML.first()
// 2020-12-27 [email protected]
var i;
switch ( about ) {
case "pageprops":
if ( typeof assigned.ul === "object" &&
typeof assigned.ul.length === "number" ) {
if ( PTHC.scope === "search" ) {
assigned.div = HTML.first( at,
assigned,
assigned.ul[ 0 ] );
} else {
assigned.dl = [ ];
for ( i = 0; i < assigned.ul.length; i++ ) {
assigned.dl[ i ] = HTML.first( at,
assigned,
assigned.ul[ i ] );
} // for i
}
delete assigned.ul;
}
break;
case "summary":
switch ( PTHC.scope ) {
case "info":
break;
case "search":
HTML.full( assigned, assigned.div, at );
break;
default:
if ( typeof assigned.dl === "object" ) {
for ( i = 0; i < assigned.dl.length; i++ ) {
HTML.full( assigned, assigned.dl[ i ], at );
} // for i
}
} // switch PTHC.scope
break;
case "info":
if ( PTHC.scope === "search" ) {
HTML.full( assigned, assigned.div, at );
} else if ( typeof assigned.dl === "object" ) {
for ( i = 0; i < assigned.dl.length; i++ ) {
HTML.full( assigned, assigned.dl[ i ], at );
} // for i
}
break;
} // switch about
}; // HTML.follow()
HTML.follower = function () {
// Finalize presentation for anonymous users
// Uses:
// > PTHC.got
// HTML.follow()
// 2020-12-27 [email protected]
var s;
for ( s in PTHC.got ) {
HTML.follow( s, PTHC.got[ s ], "info" );
} // for s in PTHC.got
}; // HTML.follower()
HTML.full = function ( assigned, about, at ) {
// Complete page metadata for list entry
// Precondition:
// assigned -- page object
// about -- entry object
// at -- page name
// Uses:
// > PTHC.listen
// > HTML.less
// HTML.fill()
// 2020-12-27 [email protected]
about.$a.html( assigned.show );
if ( assigned.linked ) {
about.$a.addClass( "mw-disambig" );
}
if ( assigned.shift ) {
HTML.fill( about, "redir", false, assigned.shift );
}
if ( assigned.shorty ) {
HTML.fill( about, "shorty", false, assigned );
}
if ( assigned.item ) {
HTML.fill( about, "wikidata", false, assigned.item );
}
if ( assigned.story ) {
HTML.fill( about, "wikidata", "story", assigned );
}
if ( assigned.extract ) {
HTML.fill( about, "extract", false, assigned.extract );
}
HTML.fill( about, "var", "info", at );
if ( ! HTML.less ) {
if ( assigned.stamp ) {
HTML.fill( about, "var", "stamp", assigned.stamp );
}
if ( assigned.kBytes > 0 ) {
HTML.fill( about, "var", "size", assigned.kBytes );
}
}
if ( assigned.linked ) {
HTML.fill( about, "var", "disambig" );
}
if ( assigned.stuff && API.scope === "info" ) {
HTML.fill( about, "var", "model", assigned.stuff );
}
if ( assigned.merits && API.scope === "info" ) {
HTML.fill( about, "var", "merits", assigned.merits );
}
if ( assigned.protection ) {
HTML.fill( about, "var", "protected", assigned.protection );
}
if ( PTHC.listen &&
typeof assigned.listen === "boolean" ) {
HTML.fill( about,
"var",
"watching",
{ listen: assigned.listen,
slot: at } );
}
}; // HTML.full()
QUEUE.fire = function () {
// Start execution loop
// Uses:
// > PTHC.scope
// > PTHC.got
// > PTHC.ltr
// > PTHC.listen
// > PTHC.$widget
// > QUEUE.lonely
// >< QUEUE.mode
// >< QUEUE.got
// HTML.flop()
// HTML.flip()
// API.fire()
// HTML.finesse()
// HTML.follower()
// QUEUE.floats()
// 2020-12-27 [email protected]
var s, got;
if ( ! QUEUE.mode ) {
switch ( PTHC.scope ) {
case "info":
QUEUE.mode = 2;
break;
case "search":
QUEUE.mode = 1;
HTML.flop();
break;
default:
QUEUE.mode = 1;
HTML.flip();
} // switch PTHC.scope
QUEUE.got = [ ];
for ( s in PTHC.got ) {
got = PTHC.got[ s ];
QUEUE.got.push( s );
got.extract = false;
got.item = 0;
got.kBytes = -1;
got.merits = 0;
got.linked = false;
got.listen = null;
got.ltr = PTHC.ltr;
got.shift = false;
got.shorty = false;
got.slang = false;
got.source = false;
got.stamp = false;
got.story = false;
got.stuff = false;
got.thumb = false;
} // for s in PTHC.got
}
switch ( QUEUE.mode ) {
case 1:
API.fire( QUEUE.got, "pageprops", QUEUE.fire );
break;
case 2:
API.fire( QUEUE.got, "summary", QUEUE.fire );
break;
case 3:
if ( PTHC.scope === "info" ) {
QUEUE.mode++;
HTML.finesse();
} else if ( PTHC.listen ) {
API.fire( QUEUE.got, "info", QUEUE.fire );
break; // switch QUEUE.mode
} else {
HTML.follower();
}
default: // fall through
PTHC.$widget.empty();
if ( ! QUEUE.lonely && PTHC.scope !== "info" ) {
QUEUE.lonely = true;
QUEUE.floats();
}
} // switch QUEUE.mode
QUEUE.mode++;
}; // QUEUE.fire()
QUEUE.floats = function ( ask ) {
// Handle image request
// Precondition:
// ask -- object: click event
// Uses:
// >< PTHC.trigger
// >< QUEUE.lonely
// BABEL.from()
// PTHC.furnish()
// QUEUE.fire()
// HTML.floats()
// (QUEUE.floats)
// 2020-12-27 [email protected]
if ( ask ) {
QUEUE.fire();
HTML.floats();
} else {
PTHC.trigger.fiat = QUEUE.floats;
PTHC.trigger.fetch = BABEL.from;
PTHC.trigger.support = BABEL.from( "images" );
PTHC.furnish( PTHC.trigger );
}
}; // QUEUE.floats()
first();
}( window.mediaWiki, window.jQuery ) );
// Emacs
// Local Variables:
// coding: utf-8-dos
// fill-column: 80
// End:
/// EOF </nowiki> pageTeaserHint/core/d.js