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

Content deleted Content added
-2.2
-2.3
Line 1:
/// Gadget-pageLinkHelper.js
// Some minor link helpers
/// 20162017-0801-3021 PerfektesChaos@de.wikipedia
// ResourceLoader: compatible;
// dependencies: user, user.options,
Line 14:
( function ( mw, $ ) {
"use strict";
var Version = -2.23,
Sign = "pageLinkHelper",
Signature = "ext.gadget." + Sign,
Line 76:
"vmf" : "de" }
}; // 2015-01-06 PerfektesChaos@de.wikipedia
 
 
 
OPTS.face = function () {
// Initialize environment and application object, if user defined
// Precondition:
// module 'user' loaded
// Postcondition:
//
// Uses:
// > mw.libs
// > Sign
// > Version
// > Shop
// >< PLH
// 2014-12-22 PerfektesChaos@de.wikipedia
if ( typeof mw.libs[ Sign ] === "object" &&
mw.libs[ Sign ] &&
! PLH ) {
PLH = mw.libs[ Sign ];
PLH.vsn = Version;
PLH.doc = "[[" + Shop + Sign + "]]";
}
}; // OPTS.face()
 
 
 
OPTS.facet = function ( applied ) {
// Check for user option
// Precondition:
// applied -- option keyword
// module 'user' loaded
// Postcondition:
// Returns value, or undefined
// Uses:
// > PLH
// OPTS.face()
// 2014-12-19 PerfektesChaos@de.wikipedia
var r; // = undefined
OPTS.face();
if ( PLH && typeof PLH[ applied ] !== "undefined" ) {
r = PLH[ applied ];
}
return r;
}; // OPTS.facet()
 
 
Line 286 ⟶ 241:
// > Config
// >< Env
// OPTS.face()
// facility()
// mw.config.get()
// 20142017-1201-20 PerfektesChaos@de.wikipedia
var el, r, say;
if ( alter ) {
Line 296 ⟶ 250:
r = access;
}
if ( typeof PLH.config === "object" &&
OPTS.face();
if ( PLH &&
typeof PLH.config === "object" &&
PLH.config &&
typeof PLH.config[ access ] === "object" ) {
Line 482 ⟶ 434:
function fire() {
// Autorun on load
// Uses:
// > Signature
// mw.loader.getState()
// mw.loader.state()
// mw.loader.using()
// (OPTS.fire)
// 2017-01-20 PerfektesChaos@de.wikipedia
if ( mw.loader.getState( Signature ) !== "ready" ) {
mw.loader.state( Signature, "ready" );
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
// > VersionPLH
// < Env
// mw.user.options.set()
// mw.config.get()
// mw.util.getParamValue()
Line 504 ⟶ 477:
// Purge.freshest()
// QQmsg.flat()
// 2016-08-30 PerfektesChaos@de mw.wikipediahook()
// 2017-01-20 PerfektesChaos@de.wikipedia
var linkUpdate, s;
mw.user.options.set(var "gadget-"embed, + Signi, VersionlinkUpdate, )s;
Env = { skin: false,
wgCanonicalSpecialPageName:
Line 523 ⟶ 496:
break;
case "Whatlinkshere" :
Env.wgFormattedNamespaceswgNamespaceNumber = -1;
if ( OPTS.facet( "forcerecursivelinkupdate" ) ) {
Env.wgFormattedNamespaces =
mw.config.get( "wgFormattedNamespaces" );
Env.wgRelevantPageName =
mw.config.get( "wgRelevantPageName" );
s embed = Env.wgFormattedNamespaces[ "10", ]828 + ":"];
if ( Env.wgRelevantPageName.substr for ( i = 0,; s i < embed.length; ) i++ === ) s{
&& s = OPTS.facet(embed[ "forcerecursivelinkupdate"i )] )+ {"";
s = Env.wgNamespaceNumberwgFormattedNamespaces[ =s ] + -1":";
Purge.freshissimo 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 );
}
Line 599 ⟶ 580:
QQmsg.flat( true );
}
} //mw.hook( Sign + ".ready" ).fire( PLH );
} // first()
 
 
 
OPTS.facet = function ( applied ) {
// Check for user option
// Precondition:
// applied -- option keyword
// module 'user' loaded
// Postcondition:
// Returns value, or undefined
// Uses:
// > PLH
// > OPTS.user
// 2017-01-20 PerfektesChaos@de.wikipedia
var r; // = undefined
if ( typeof PLH[ applied ] !== "undefined" ) {
r = PLH[ applied ];
}
if ( OPTS.user &&
typeof OPTS.user[ applied ] !== "undefined" ) {
r = OPTS.user[ applied ];
PLH[ applied ] = r;
}
return r;
}; // OPTS.facet()
 
 
 
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()
 
 
Line 988 ⟶ 1,046:
.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()
 
 
Line 1,007 ⟶ 1,089:
 
 
Purge.fiatforeign = function ( additional, array, allow ) {
// StartExternal APIaccess purgingto ofpurge a single pagefunction
// Precondition:
// additional -- somestring, keywordnumber, or notfalse
// array -- Attay of page titles, or page IDs, or not
// allow -- number of permitted array elements, or not
// Uses:
// mwPurge.Api() .postfiat()
// 2016-08-18 PerfektesChaos@de Purge.wikipediafull()
// 2017-01-21 PerfektesChaos@de.wikipedia
var o = new mw.Api( { parameters: { action: "purge" } } ),
var pmany = { pageids: Env.curid };50,
if ( additional ) {e, i, m, p, q, s, stage;
switch p[( additional ] =) true;{
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;
}
o.postif ( ptypeof array === )"object"
.done( function () { window.___location.reload(&& true ); } ); array &&
typeof array.length === "number"
}; // Purge.fiat()
&& 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.foreign()
 
 
Line 1,135 ⟶ 1,288:
 
 
Purge.full = function ( additional ) {
// Start API purging of a generator
// Precondition:
Line 1,145 ⟶ 1,298:
// mw.Api() .post()
// Purge.feed()
// 20162017-0801-3021 PerfektesChaos@de.wikipedia
var many = 20,
p;
Line 1,166 ⟶ 1,319:
} // 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.request[ additional ] = true;
Purge.feed();
}
Line 1,338 ⟶ 1,497:
 
 
fire();
if ( mw.loader.getState( Signature ) !== "ready" ) {
mw.loader.state( Signature, "ready" );
mw.loader.using( [ "mediawiki.api",
"mediawiki.user",
"mediawiki.util",
"user",
"user.options" ],
function () {
$( fire ); // don't hurry
} );
}
}( window.mediaWiki, window.jQuery ) );
/// EOF </nowiki> pageLinkHelper.js