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

Content deleted Content added
-2.1
-2.2
Line 1:
/// Gadget-pageLinkHelper.js
// Some minor link helpers
/// 2016-08-1830 PerfektesChaos@de.wikipedia
// ResourceLoader: compatible;
// dependencies: user, user.options,
// mediawiki.api, mediawiki.user, mediawiki.util
/// Fingerprint: #0#0#
// Documentation: [[w:en:User:PerfektesChaos/js/pageLinkHelper]]
Line 13 ⟶ 14:
( function ( mw, $ ) {
"use strict";
var Version = -2.12,
Sign = "pageLinkHelper",
Signature = "ext.gadget." + Sign,
Shop = "w:en:User:PerfektesChaos/js/",
Diff = { },
Hist = { },
OPTS = { },
Perm = { },
Purge = { },
QQmsg = { },
Redir = { },
URL2i = { },
Config, Env, PLH;
 
Line 37 ⟶ 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 468 ⟶ 480:
 
 
function flatfire( ahead ) {
// ProvideAutorun "uselang=qqx"on linkload
// Precondition:
// mediawiki.user mediawiki.util loaded
// ahead -- true if initializing, false to link
// DOM.ready
// mediawiki.util loaded
// user resources loaded
// Postcondition:
// Returns link, or undefined
// Uses:
// > ___locationSign
// favorite()> Version
// (flat) < Env
// 2014-12-19 PerfektesChaos@de mw.user.options.wikipediaset()
var// r; mw.config.get()
if// ( ahead ) {mw.util.getParamValue()
// URL2i.forward()
favorite( { signature: "slangQQX",
// skins: false,Diff.flip()
// fun: flat,mw.user.options.get()
// show: "qqxTitle",Purge.freshissimo()
// support: "qqxTip",Hist.further()
// suffix: "langQQX"Perm.furnish()
// } Perm.flip();
// Purge.fresh()
// Redir.from()
// OPTS.facet()
// Purge.fresher()
// Purge.freshest()
// QQmsg.flat()
// 2016-08-30 PerfektesChaos@de.wikipedia
var linkUpdate, s;
mw.user.options.set( "gadget-" + Sign, Version );
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 "Whatlinkshere" :
Env.wgFormattedNamespaces =
mw.config.get( "wgFormattedNamespaces" );
Env.wgRelevantPageName =
mw.config.get( "wgRelevantPageName" );
s = Env.wgFormattedNamespaces[ "10" ] + ":";
if ( Env.wgRelevantPageName.substr( 0, s.length ) === s
&& OPTS.facet( "forcerecursivelinkupdate" ) ) {
Env.wgNamespaceNumber = -1;
Purge.freshissimo();
}
break;
case "Recentchanges" :
case "Watchlist" :
if ( ! mw.user.options.get( "gadget-navigation-popups" ) ) {
URL2i.forward( 1 );
}
break;
case "Gadgets" :
// form();
break;
} // switch wgCanonicalSpecialPageName
} else {
rEnv.diff = windowmw.___locationutil.hrefgetParamValue( "diff" );
rEnv.oldid = rmw.replaceutil.getParamValue( /^(.+)#.+$/, "$1oldid" );
if ( Env.replace(diff /([?&])uselang=[^&]*(&.*)?$/, "$1$2" );{
if ( ! /[?&]$/Diff.testflip( r ) ) {;
} if ( r.indexOf( "?" ) > 0 )else {
linkUpdate r = r + "&"true;
}Env.wgAction else= {mw.config.get( "wgAction" );
switch ( Env.wgAction r) = r + "?";{
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 );
}
}
}
r = r + "uselang=qqx";
}
if ( OPTS.facet( "slangQQX" ) ) {
return r;
} // QQmsg.flat( true );
}
} // fire()
 
 
 
Diff.flip = function flip() {
// Equip diffpage with wikilink for c&p
// Precondition:
Line 661 ⟶ 755:
}
Perm.flip( true );
}; // Diff.flip()
 
 
 
Hist.further = function forward( amount, alike ) {
// Convert links on page into Special: format
// Precondition:
// amount -- number of links per item to inspect
// alike -- if string "diff", required to occur
// DOM.ready
// mediawiki.util loaded
// Uses:
// mw.util.getParamValue()
// 2015-01-11 PerfektesChaos@de.wikipedia
var $results = $( "#mw-content-text li" ),
n = $results.length,
i, j, shift, special, start, strip, $a, $li;
if ( n ) {
special = "/wiki/"
+ mw.config.get( "wgFormattedNamespaces" )[ "-1" ]
+ ":";
for ( i = 0; i < n; i++ ) {
$li = $results.eq( i ).find( "a" );
for ( j = 0; j < amount; j++ ) {
$a = $li.eq( j );
strip = $a.attr( "href" );
if ( strip &&
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 = false;
} else {
shift = "PermaLink/" + start;
}
if ( shift ) {
shift = special + shift + "$1";
strip = strip.replace( /^.+(\?title=.+)$/,
shift );
$a.attr( "href", strip );
}
}
}
} // for j
} // for i
}
} // forward()
 
 
 
function from() {
// Redirected from somewhere
// Precondition:
// mediawiki.util loaded
// Uses:
// > history
// > ___location
// > document
// > Sign
// >< Env
// mw.util.getUrl()
// OPTS.facet()
// history.___pushState()
// history.___replaceState()
// 2014-12-07 PerfektesChaos@de.wikipedia
var caused, opts, last, legacy, show, 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 ) {
// should actually not cause wgRedirectedFrom, but avoid
last = ( window.history.previous.indexOf( swap ) >= 0 );
}
if ( ! last ) {
opts = OPTS.facet( "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 );
}
}
} // from()
 
 
 
function further() {
// Deal with history page
// Precondition:
// loaded user.options mediawiki.user
// Uses:
// OPTS.facet()
// mw.user.options.get()
// 2015-01-03 PerfektesChaos@de.wikipedia
Line 794 ⟶ 790:
}
if ( n >= 1 ) {
URL2i.forward( n, scan );
}
}
}; // Hist.further()
 
 
 
function fire() {
// Autorun on load
// Precondition:
// mediawiki.user mediawiki.util loaded
// Uses:
// > Sign
// > Version
// < Env
// mw.user.options.set()
// mw.config.get()
// mw.util.getParamValue()
// forward()
// flip()
// mw.user.options.get()
// further()
// Perm.furnish()
// Perm.flip()
// Purge.fresh()
// from()
// OPTS.facet()
// Purge.fresher()
// Purge.freshest()
// flat()
// 2016-08-18 PerfektesChaos@de.wikipedia
var linkUpdate;
mw.user.options.set( "gadget-" + Sign, Version );
Env = { skin: false,
wgCanonicalSpecialPageName:
mw.config.get( "wgCanonicalSpecialPageName" ),
wgPageName: false
};
if ( Env.wgCanonicalSpecialPageName ) {
switch ( Env.wgCanonicalSpecialPageName ) {
case "Contributions" :
forward( 2 );
break;
case "Diff" :
flip();
break;
case "Recentchanges" :
case "Watchlist" :
if ( ! mw.user.options.get( "gadget-navigation-popups" ) ) {
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 ) {
flip();
} else {
linkUpdate = true;
Env.wgAction = mw.config.get( "wgAction" );
switch ( Env.wgAction ) {
case "history" :
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 ) {
from();
}
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 );
}
}
}
}
if ( OPTS.facet( "slangQQX" ) ) {
flat( true );
}
} // fire()
 
 
Line 1,001 ⟶ 895:
// fair()
// Perm.flip()
// 20142016-1208-2930 PerfektesChaos@de.wikipedia
var sign = Sign + "Permalink",
$div = $( "#" + sign ),
Line 1,019 ⟶ 913:
Env.oldid = mw.config.get( "wgCurRevisionId" );
}
$div = $factory( sign );
specialif ( =! mwEnv.config.get( "wgFormattedNamespaces" )[ "-1" ]{
+ ":";Env.wgFormattedNamespaces
= mw.config.get( "wgFormattedNamespaces" );
}
special = Env.wgFormattedNamespaces[ "-1" ] + ":";
swift = "?title="
+ mw.util.wikiUrlencode( Env.wgPageName );
Line 1,054 ⟶ 951:
}
}; // Perm.furnish()
 
 
 
Purge.fail = function ( arrived, add ) {
// API purging failed
// Precondition:
// arrived -- string with basic message
// add -- object with additional information
// Uses:
// window.console
// 2016-08-30 PerfektesChaos@de.wikipedia
if ( typeof window.console === "object" &&
typeof arrived === "string" ) {
if ( typeof window.console.log === "function" ) {
window.console.log( arrived );
}
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()
 
 
Line 1,074 ⟶ 1,008:
 
Purge.fiat = function ( additional ) {
// EquipStart diffpageAPI revisionpurging withof wikilinka forsingle permalink c&ppage
// Precondition:
// additional -- some keyword, or not
Line 1,177 ⟶ 1,111:
}
}; // 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 () {
// Start API purging of a generator
// Precondition:
// additional -- some keyword, or not
// Uses:
// > Env
// < Purge.Api
// < Purge.request
// mw.Api() .post()
// Purge.feed()
// 2016-08-30 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 ) {
Purge.Api = new mw.Api( { parameters: { action: "purge" } } );
Purge.request = p;
// Purge.request[ additional ] = true;
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;
}; // QQmsg.flat()
 
 
 
Redir.from = function () {
// Redirected from somewhere
// Precondition:
// mediawiki.util loaded
// Uses:
// > history
// > ___location
// > document
// > Sign
// >< Env
// mw.util.getUrl()
// OPTS.facet()
// history.___pushState()
// history.___replaceState()
// 2014-12-07 PerfektesChaos@de.wikipedia
var caused, opt, last, legacy, show, 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 ) {
// should actually not cause wgRedirectedFrom, but avoid
last = ( window.history.previous.indexOf( swap ) >= 0 );
}
if ( ! last ) {
opt = OPTS.facet( "redirect" );
if ( opt &&
typeof opt === "object" &&
typeof opt.legacy === "boolean" ) {
legacy = opt.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 );
}
}
}; // Redir.from()
 
 
 
URL2i.forward = function ( amount, alike ) {
// Convert links on page into Special: format
// Precondition:
// amount -- number of links per item to inspect
// alike -- if string "diff", required to occur
// DOM.ready
// mediawiki.util loaded
// Uses:
// mw.util.getParamValue()
// 2015-01-11 PerfektesChaos@de.wikipedia
var $results = $( "#mw-content-text li" ),
n = $results.length,
i, j, shift, special, start, strip, $a, $li;
if ( n ) {
special = "/wiki/"
+ mw.config.get( "wgFormattedNamespaces" )[ "-1" ]
+ ":";
for ( i = 0; i < n; i++ ) {
$li = $results.eq( i ).find( "a" );
for ( j = 0; j < amount; j++ ) {
$a = $li.eq( j );
strip = $a.attr( "href" );
if ( strip &&
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 = false;
} else {
shift = "PermaLink/" + start;
}
if ( shift ) {
shift = special + shift + "$1";
strip = strip.replace( /^.+(\?title=.+)$/,
shift );
$a.attr( "href", strip );
}
}
}
} // for j
} // for i
}
}; // URL2i.forward()