Content deleted Content added
-1.93 |
-2.6 |
||
(6 intermediate revisions by the same user not shown) | |||
Line 1:
/// Gadget-pageLinkHelper.js
// Some minor link helpers
///
// ResourceLoader: compatible;
// dependencies: user, user.options,
// mediawiki.api, mediawiki.user, mediawiki.util /// Fingerprint: #0#0#
// Documentation: [[w:en:User:PerfektesChaos/js/pageLinkHelper]]
/// <nowiki>
/* global window: false */
/* jshint
laxbreak:true,
( function ( mw, $ ) {
"use strict";
var Version = -
Sign = "pageLinkHelper",
Signature = "ext.gadget." + Sign,
Shop = "w:en:User:PerfektesChaos/js/",
Diff = { },
Hist = { },
OPTS = { },
Perm = { },
Purge = { },
QQmsg = { },
Redir = { },
URL2i = { },
Config, Env, PLH;
Line 35 ⟶ 43:
purgeLURtitle: { en: "PURGE/recursive",
de: "PURGE/rekursiv" },
purgeLURGtip: { en: "PURGE related pages"
+ " and force recursive link update",
de: "PURGE bezogener Seiten"
+ " mit rekursivem Linkupdate" },
purgeLURGtitle:{ en: "PURGE/recursive related pages",
de: "PURGE/rekursiv bezogene Seiten" },
purgeTip: { en: "PURGE this page from server cache",
de: "PURGE:"
Line 42 ⟶ 56:
de: "Seite purgen" },
qqxTip: { en: "Reload"
+ " and show interface element IDs"
de: "Neu laden"
+ " und MediaWiki-IDs zeigen" },
qqxTitle: { en: "lang=qqx" },
translate: { "als" : "de",
Line 59 ⟶ 75:
"stq" : "de",
"vmf" : "de" }
}; //
Line 113 ⟶ 84:
// access -- distinguishing selector ID
// Uses:
// > Env.ltr
// > Sign
//
var space = "4px",
style = "#B0C4DE 1px solid",
Line 121 ⟶ 93:
"id": access } );
$r.css( { "border-bottom": style,
"background-color": "#FFFFFF",
"background": "rgba(255, 255, 255, 0.5)",
"font-family": "monospace",
"margin-bottom": "1em",
"margin-top": space,
"padding-bottom": space,
"padding-right": space,
"padding-left": space } );
if ( Env.ltr ) {
$r.css( { "border-left": style,
"float": "right",
"margin-left": "1em" } );
} else {
$r.css( { "border-right": style,
"float": "left",
"margin-right": "1em" } );
}
return $r;
} // $factory()
Line 148 ⟶ 126:
// > Sign
// >< Env
//
var r, // = undefined
sequence, suitable, $anchor, $clear;
if ( typeof Env.$corner === "undefined" ) {
Env.ltr = ( ! $( "body.sitedir-rtl" ).length );
Env.$corner = $( "<div>" );
Env.$corner.attr( { "class": Sign,
Line 166 ⟶ 145:
switch ( Env.skin ) {
case "cologneblue" :
suitable = "#firstHeading";
sequence = "after";
break;
case "modern" :
suitable = "#contentSub";
sequence = "before";
break;
case "monobook" :
case "vector" :
suitable = "
sequence = "prepend";
break;
} // switch Env.skin
$anchor = $(
}
if ( ! $anchor.length ) {
Line 188 ⟶ 167:
$anchor[ sequence ]( Env.$corner );
$clear = $( "<div>" );
$clear.css( { "clear": ( Env.ltr ? "left" : "right" ) } );
Env.$corner.after( $clear );
} else {
Line 262 ⟶ 241:
// > Config
// >< Env
// facility()
// mw.config.get()
//
var el, r, say;
if ( alter ) {
Line 272 ⟶ 250:
r = access;
}
if ( typeof PLH.config === "object" &&
PLH.config &&
typeof PLH.config[ access ] === "object" ) {
Line 322 ⟶ 298:
// true; or "|vector|" etc.
// .fun -- callback for link generation
// .forward -- callback for click
// .show -- link title keyword
// .support -- tooltip keyword
Line 338 ⟶ 315:
// mw.util.addPortletLink()
// (apply.fun)
//
var opt = OPTS.facet( apply.signature ),
seed = null,
Line 412 ⟶ 389:
}
if ( slot ) {
swap = apply.fun();
} else {
swap = "#";
}
if ( typeof apply.suffix === "string" ) {
suffix = apply.suffix;
Line 428 ⟶ 409:
null,
seed );
if ( typeof apply.forward === "function" ) {
$( r ).find( "a" ).click( apply.forward );
}
}
return r;
Line 448 ⟶ 432:
function
// Autorun on load
// Uses:
// > Signature
// mw.loader.getState()
// mw.loader.state()
// mw.loader.using()
// (OPTS.fire)
// 2018-08-24 PerfektesChaos@de.wikipedia
var rls;
if ( mw.loader.getState( Signature ) !== "ready" ) {
rls = { };
rls[ Signature ] = "ready";
mw.loader.state( rls );
mw.loader.using( [ "mediawiki.api",
"mediawiki.user",
"mediawiki.util",
"user",
"user.options" ],
OPTS.fire );
}
} // fire()
function first() {
// Initialize
// Precondition:
// mediawiki.user mediawiki.util loaded
// Uses:
// > Sign
// >
// < Env
// mw.config.get()
// mw.util.getParamValue()
//
//
//
//
//
//
// Redir.from()
// OPTS.facet()
//
// Purge.freshest()
// QQmsg.flat()
// mw.hook()
// 2020-01-05 PerfektesChaos@de.wikipedia
var embed, i, linkUpdate, s;
Env = { skin: false,
wgCanonicalSpecialPageName:
mw.config.get( "wgCanonicalSpecialPageName" ),
wgFormattedNamespaces: false,
wgNamespaceNumber: false,
wgPageName: false
};
if ( Env.wgCanonicalSpecialPageName ) {
switch ( Env.wgCanonicalSpecialPageName ) {
case "Contributions" :
URL2i.forward( 2 );
break;
case "Diff" :
Diff.flip();
break;
case "Mobile" :
break;
case "Whatlinkshere" :
Env.wgNamespaceNumber = -1;
if ( OPTS.facet( "forcerecursivelinkupdate" ) ) {
Env.wgFormattedNamespaces =
mw.config.get( "wgFormattedNamespaces" );
Env.wgRelevantPageName =
mw.config.get( "wgRelevantPageName" );
embed = [ 10, 828 ];
for ( i = 0; i < embed.length; i++ ) {
s = embed[ i ] + "";
s = Env.wgFormattedNamespaces[ s ] + ":";
if ( Env.wgRelevantPageName
.substr( 0, s.length ) === s ) {
Purge.freshissimo();
break; // for i
}
} // for i
}
break;
case "Recentchanges" :
case "Watchlist" :
if ( !
mw.user.options.get( "gadget-navigation-popups" ) ) {
URL2i.forward( 1 );
}
break;
case "Gadgets" :
// form();
break;
} // switch wgCanonicalSpecialPageName
} else {
Env.diff = mw.util.getParamValue( "diff" );
Env.oldid = mw.util.getParamValue( "oldid" );
if ( Env.diff ) {
Diff.flip();
} else {
linkUpdate = true;
Env.wgAction = mw.config.get( "wgAction" );
switch ( Env.wgAction ) {
case "history" :
Hist.further();
break;
case "view" :
Env.curid = mw.util.getParamValue( "curid" );
if ( Env.curid || Env.oldid ) {
Perm.furnish( true );
} else {
Perm.flip( true );
}
Purge.fresh( true );
Env.wgRedirectedFrom
= mw.config.get( "wgRedirectedFrom" );
if ( Env.wgRedirectedFrom ) {
Redir.from();
}
Env.wgNamespaceNumber
= mw.config.get( "wgNamespaceNumber" );
if ( Env.wgNamespaceNumber === 14 &&
OPTS.facet( "forcerecursivelinkupdate" ) ) {
Purge.freshissimo();
}
break;
case "info" :
Purge.fresh( true );
break;
case "edit" :
case "submit" :
linkUpdate = false;
// fall through
default:
Perm.flip( true );
} // switch wgAction
if ( linkUpdate ) {
if ( OPTS.facet( "forcelinkupdate" ) ) {
Purge.fresher( true );
}
if ( OPTS.facet( "forcerecursivelinkupdate" ) ) {
Purge.freshest( true );
}
}
}
}
QQmsg.flat( true );
}
mw.hook( Sign + ".ready" ).fire( PLH );
} // first()
OPTS.facet = function
//
// Precondition:
//
//
// Postcondition:
// Returns
// Uses:
// >
//
// 2017-01-20
var r; // = undefined
if ( typeof PLH[ applied ] !== "undefined" ) {
}
if ( OPTS.user
typeof OPTS.user[ applied ] !== "undefined" )
r
PLH[ applied ] =
}
return r;
}; //
OPTS.features = function ( apply ) {
// Receive user options
// Precondition:
// apply -- options object
// module 'user' loaded
// 2017-01-20 PerfektesChaos@de.wikipedia
if ( typeof OPTS.user === "undefined" ) {
if ( typeof apply === "object"
&& apply ) {
OPTS.user = apply;
} else {
OPTS.user = false;
}
}
}; // OPTS.features()
OPTS.fire = function () {
// Consider user options by mw.libs, and run
// Precondition:
// user user.options loaded
// Uses:
// > Sign
// > Version
// > mw.libs
// > Shop
// < PLH
// mw.user.options.set()
// mw.hook()
// (OPTS.features)
// (Purge.foreign)
// (first)
// 2017-01-21 PerfektesChaos@de.wikipedia
mw.user.options.set( "gadget-" + Sign, Version );
if ( typeof mw.libs[ Sign ] === "object" &&
mw.libs[ Sign ] ) {
PLH = mw.libs[ Sign ];
} else {
PLH = { };
}
PLH.type = Sign;
PLH.vsn = Version;
PLH.doc = "[[" + Shop + Sign + "]]";
mw.hook( Sign + ".before" ).add( OPTS.features );
PLH.fresh = Purge.foreign;
$( first ); // don't hurry
}; // OPTS.fire()
Diff.flip = function
// Equip diffpage with wikilink for c&p
// Precondition:
Line 547 ⟶ 680:
// $float()
// $factory()
// Perm.fiat()
// mw.config.get()
// mw.util.wikiUrlencode()
// setTimeout()
// history.___replaceState()
//
// (feed)
// 2015-01-
var link = false,
msec =
opt = OPTS.facet( "diff" ),
sign = Sign + "Difflink",
Line 660 ⟶ 793:
$float( $div );
if ( id2 ) {
Perm.fiat( id1, "o" );
Perm.fiat( id2, "n" );
} else {
Perm.fiat( false, "o" );
Perm.fiat( false, "n" );
}
if ( ! link &&
Line 684 ⟶ 817:
}
}
}; // Diff.flip()
Hist.further = function
//
// Precondition:
//
// Uses:
//
// mw.user.options.get()
// 2015-01-03 PerfektesChaos@de.wikipedia
var
switch ( typeof opt ) {
case "boolean" :
if ( opt === false ) {
n = 0;
}
break;
case "string" :
if ( opt === "diff" ) {
scan = "diff";
}
break;
} // switch opt
if ( n ) {
n = 2;
}
if ( n
}
}
}; //
Perm.fiat = function
// Equip diffpage revision with wikilink for permalink c&p
// Precondition:
// apply -- revision ID, or some keyword
// at -- revision column; "n" or "o"
// DOM.ready
// Diffpage
// Uses:
// > Sign
// > Env.spcNS
// mw.config.get()
// mw.util.getParamValue()
// 2014-12-16 PerfektesChaos@de.wikipedia
var $div = $( "#mw-diff-" + at + "title1" ),
id, s, $a, $span;
if ( $div.length ) {
if ( apply ) {
id = apply;
if ( apply === "cur" ) {
id = mw.config.get( "wgCurRevisionId" );
} else if ( typeof apply === "string" &&
! /^\d+$/.test( apply ) ) { // "next"
id = false;
}
}
if ( ! id ) {
$a = $div.find( "a" ).eq( 0 );
s = $a.attr( "href" );
id = mw.util.getParamValue( "oldid", s );
}
if ( id ) {
s = "[[" + Env.spcNS + ":PermanentLink/" + id + "]]";
$span = $( "<span>" );
$span.attr( { "class": Sign + " " + Sign + "DiffRev" } );
$span.css( { "font-family": "monospace",
"margin-left": "1em" } );
$span.text( s );
$div.append( $span );
}
}
}; // Perm.fiat()
Perm.flip = function ( assign ) {
// Change portlet for permalink
// Precondition:
// assign -- true if link to be diverted, false to gray out
// DOM.ready
// Uses:
// > Sign
// > Version
// fair()
// (Perm.furnish)
// 2014-12-19 PerfektesChaos@de.wikipedia
var $portlet = $( "#t-permalink" ),
show, support, $a, $span;
if ( $portlet.length ) {
support = Sign + " " + Version;
if ( assign ) {
$a = $( "<a>" );
$a.attr( { "title": support } );
$a.click( Perm.furnish );
$a.text( fair( "permTitle", false, "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 );
}
}
}
}; // Perm.flip()
Perm.furnish = function () {
// Equip page with wikilink to perma for c&p
// Precondition:
Line 752 ⟶ 957:
// mw.util.getUrl()
// fair()
//
//
var sign = Sign + "Permalink",
$div = $( "#" + sign ),
Line 771 ⟶ 976:
Env.oldid = mw.config.get( "wgCurRevisionId" );
}
$div
= mw.config.get( "wgFormattedNamespaces" );
}
special = Env.wgFormattedNamespaces[ "-1" ] + ":";
swift = "?title="
+ mw.util.wikiUrlencode( Env.wgPageName );
Line 803 ⟶ 1,011:
$div.append( $spanEnd );
$float( $div );
}
}; //
Purge.fail = function
//
// Precondition:
//
//
// Uses:
//
// 2016-08-30
if ( typeof window.console === "object" &&
if ( typeof window.console.log === "function" ) {
}
if ( typeof add === "object" && add &&
typeof window.console.dir === "function" ) {
window.console.dir( add );
}
}
}; // Purge.fail()
Purge.feed = function () {
// Launch API generator query
// Uses:
// > Purge.Api
// > Purge.request
// (Purge.further)
// (Purge.fail)
// 2016-08-30 PerfektesChaos@de.wikipedia
Purge.Api.post( Purge.request )
.done( Purge.further )
.fail( Purge.fail );
}; // Purge.feed()
Purge.fiat = function ( additional, already ) {
// Start API purging of a single page
// Precondition:
// additional -- some keyword, or not
// already -- request parameters, or not
// Uses:
// mw.Api() .post()
// 2017-01-20 PerfektesChaos@de.wikipedia
var o = new mw.Api( { parameters: { action: "purge" } } ),
p;
if ( already ) {
p = already;
} else {
p = { pageids: Env.curid };
}
if ( additional ) {
p[ additional ] = true;
}
o.post( p )
.done( function () { window.___location.reload( true ); } );
}; // Purge.fiat()
Purge.first = function () {
// Ensure curid=pageid and purgeable revision
// Postcondition:
// Returns curid=pageid, or undefined
// Uses:
// >< Env.curid
// mw.config.get()
// 2016-08-18 PerfektesChaos@de.wikipedia
if ( typeof Env.curid !== "number" ) {
Env.curid = mw.config.get( "wgArticleId" );
}
return Env.curid;
}; // Purge.first()
Purge.foreign = function ( additional, array, allow ) {
// External access to purge function
// Precondition:
// additional -- string, number, or false
// array -- Attay of page titles, or page IDs, or not
// allow -- number of permitted array elements, or not
// Uses:
// Purge.fiat()
// Purge.full()
// 2017-01-21 PerfektesChaos@de.wikipedia
var many = 50,
e, i, m, p, q, s, stage;
switch ( additional ) {
case 1 :
stage = "forcelinkupdate";
break;
case 2 :
stage = "forcerecursivelinkupdate";
break;
case "forcelinkupdate" :
case "forcerecursivelinkupdate" :
stage = additional;
break;
default:
stage = "";
} // switch additional
if ( typeof allow === "number"
&& allow > many ) {
many = allow;
}
if ( typeof array === "object"
&& array &&
typeof array.length === "number"
&& array.length ) {
e = array[ 0 ];
s = typeof e;
switch ( s ) {
case "number" :
p = { pageids: e };
q = p.pageids;
break;
case "" :
p = { titles: e };
q = p.titles;
break;
} // typeof array[ 0 ]
if ( p ) {
m = many - 1;
for ( i = 1; i < array.length; i++ ) {
if ( m ) {
e = array[ i ];
if ( typeof e === s ) {
if ( s === "number" && e < 0 ) {
e = 0;
}
if ( e ) {
q = q + "|" + e;
m--;
}
}
} else {
break; // for i
}
} // for i
}
}
if ( ! p ) {
switch ( Env.wgNamespaceNumber ) {
case -1 :
switch ( Env.wgCanonicalSpecialPageName ) {
case "Whatlinkshere" :
p = false;
break;
} // switch wgCanonicalSpecialPageName
break;
case 14 :
p = false;
break;
} // switch wgNamespaceNumber
}
if ( p === false ) {
Purge.full( stage );
} else {
Purge.fiat( stage, p );
}
}; //
Purge.fresh = function
// Provide purge link
// Precondition:
// ahead -- true if initializing, false to link
// DOM.ready
// user resources loaded
// Uses:
//
// favorite()
//
//
// 2016-08-18
if ( ahead === true ) {
} else {
}
};
Purge.fresher = function
// Provide forcelinkupdate purge link
// Precondition:
// ahead -- true if initializing, false to link
// DOM.ready
// user resources loaded
// Postcondition:
// Returns link, or undefined
// Uses:
//
// favorite()
//
//
// 2016-08-18
if ( ahead === true ) {
favorite( { signature: "forcelinkupdate",
skins: false,
show: "purgeLUtitle",
support: "purgeLUtip",
Line 916 ⟶ 1,237:
}
} else {
}
};
Purge.freshest = function
// Provide forcerecursivelinkupdate purge link
// Precondition:
// ahead -- true if initializing, false to link
// DOM.ready
// user resources loaded
// Uses:
//
// favorite()
//
//
// 2016-08-18
if ( ahead === true ) {
favorite( { signature: "forcerecursivelinkupdate",
skins: false,
show: "purgeLURtitle",
support: "purgeLURtip",
Line 956 ⟶ 1,266:
}
} else {
}
}; // Purge.freshest()
Purge.freshissimo = function () {
// Provide generator forcerecursivelinkupdate purge link
// Precondition:
// DOM.ready
// user resources loaded
// Uses:
// < Purge.portlet
// favorite()
// (Purge.full)
// 2016-08-30 PerfektesChaos@de.wikipedia
Purge.portlet = favorite( { signature: "forcerecursivelinkupdate",
skins: false,
forward: Purge.full,
show: "purgeLURGtitle",
support: "purgeLURGtip",
suffix: "purgeGenLinkUpdRec"
} );
}; // Purge.freshissimo()
Purge.full = function ( additional ) {
// Start API purging of a generator
// Precondition:
// additional -- some keyword, or not
// Uses:
// > Env
// < Purge.Api
// < Purge.request
// mw.Api() .post()
// Purge.feed()
// 2017-01-21 PerfektesChaos@de.wikipedia
var many = 20,
p;
switch ( Env.wgNamespaceNumber ) {
case -1 :
switch ( Env.wgCanonicalSpecialPageName ) {
case "Whatlinkshere" :
p = { generator: "embeddedin",
geititle: Env.wgRelevantPageName,
geilimit: many };
break;
} // switch wgCanonicalSpecialPageName
break;
case 14 :
p = { generator: "categorymembers",
gcmpageid: Env.curid,
gcmtype: "page|file",
gcmlimit: many };
break;
} // switch wgNamespaceNumber
if ( p ) {
if ( typeof additional === "string" ) {
if ( additional ) {
p[ additional ] = true;
}
} else {
p.forcerecursivelinkupdate = true;
}
Purge.Api = new mw.Api( { parameters: { action: "purge" } } );
Purge.request = p;
Purge.feed();
}
}; // Purge.full()
Purge.further = function ( arrived ) {
// Start API purging of a generator
// Precondition:
// arrived -- object with answers
// Uses:
// >< Purge.portlet
// >< Purge.request
// (Purge.feed)
// 2016-08-30 PerfektesChaos@de.wikipedia
var msec = 61000;
if ( typeof Purge.portlet === "object" ) {
$( Purge.portlet ).remove();
Purge.portlet = false;
}
if ( typeof arrived[ "continue" ] === "object" &&
typeof arrived.warnings !== "object" ) {
$.extend( Purge.request, arrived[ "continue" ] );
window.setTimeout( Purge.feed, msec );
}
}; // Purge.further()
QQmsg.flat = function ( ahead ) {
// Provide "uselang=qqx" link
// Precondition:
// ahead -- true if initializing, false to link
// DOM.ready
// mediawiki.util loaded
// user resources loaded
// Postcondition:
// Returns link, or undefined
// Uses:
// > ___location
// favorite()
// (QQmsg.flat)
// 2014-12-19 PerfektesChaos@de.wikipedia
var r;
if ( ahead ) {
favorite( { signature: "slangQQX",
skins: false,
fun: QQmsg.flat,
show: "qqxTitle",
support: "qqxTip",
suffix: "langQQX"
} );
} else {
r = window.___location.href;
r = r.replace( /^(.+)#.+$/, "$1" )
.replace( /([?&])uselang=[^&]*(&.*)?$/, "$1$2" );
if ( ! /[?&]$/.test( r ) ) {
if ( r.indexOf( "?" ) > 0 ) {
r = r + "&";
} else {
r = r + "?";
}
}
r = r + "uselang=qqx";
}
return r;
}; //
Redir.from = function
// Redirected from somewhere
// Precondition:
Line 980 ⟶ 1,418:
// history.___replaceState()
// 2014-12-07 PerfektesChaos@de.wikipedia
var caused,
if ( typeof window.history.___pushState === "function" &&
typeof window.history.___replaceState === "function" ) {
Line 990 ⟶ 1,428:
}
if ( ! last ) {
if (
typeof
typeof
legacy =
}
showed = window.document.title;
Line 1,008 ⟶ 1,446:
}
}
}; // Redir.from()
URL2i.forward = function
//
// Precondition:
// amount
// alike -- if string "diff", required to occur
// DOM.ready
// mediawiki.util loaded
// Uses:
// mw.
// 2015-01-
var
if ( n ) {
+ mw.config.get( "wgFormattedNamespaces" )[ "-1" ]
for ( j = 0; j < amount; j++ ) {
strip.substr( 0, 3 ) === "/w/" ) { // wikidata
start = mw.util.getParamValue( "oldid", strip );
if ( start ) {
strip = strip.replace( /&oldid=\d+\b/, "" )
.replace( /&curid=\d+\b/, "" );
shift = mw.util.getParamValue( "diff", strip );
if ( shift ) {
strip = strip.replace( /&diff=\d+\b/, "" );
shift = "Diff/" + start + "/" + shift;
} else if ( alike ) {
shift = special + shift + "$1";
strip = strip.replace( /^.+(\?title=.+)$/,
shift );
}
}
}
} // for
}
};
fire();
}( window.mediaWiki, window.jQuery ) );
/// EOF </nowiki> pageLinkHelper/d.js
|