Content deleted Content added
-1.91 |
-1.92 |
||
Line 1:
/// Gadget-pageLinkHelper.js
// Some minor link helpers
/// 2015-01-03 PerfektesChaos@de.wikipedia
// ResourceLoader: compatible;
// dependencies: user, user.options, mediawiki.user, mediawiki.util
/// Fingerprint: #0#0#
// Documentation: [[w:en:User:PerfektesChaos/js/pageLinkHelper]]
/// <nowiki>
/*jshint bitwise:true, curly:true, eqeqeq:true, latedef:true,
Line 12 ⟶ 13:
( function ( mw, $ ) {
"use strict";
var Version = -1.
Sign = "pageLinkHelper",
Signature = "ext.gadget." + Sign,
Shop = "w:en:User:PerfektesChaos/js/",
OPTS = { },
Config, Env, PLH;
Line 58 ⟶ 60:
"vmf" : "de" }
}; // 2014-12-22 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 90 ⟶ 137:
function $float( $apply, anchor ) {
// Insert/exchange upper right corner element
// Precondition:
// $apply -- jQuery element to insert
// false to check availability
// anchor -- string, with user defined selector, or undefined
// Postcondition:
// Returns true, if insertion possible
Line 100 ⟶ 148:
// > Sign
// >< Env
//
var r, // = undefined
sequence, suitable, $anchor, $clear;
Line 107 ⟶ 155:
Env.$corner.attr( { "class": Sign,
"id": Sign + "Corner" } );
if (
if ( $anchor.length > 1 ) {
$anchor = $anchor.eq( 0 );
}
} else {
if ( ! Env.skin ) {
Env.skin = mw.config.get( "skin" );
}
switch ( Env.skin ) {
case "cologneblue" :
suitable = "firstHeading";
sequence = "after";
break;
case "modern" :
suitable = "contentSub";
sequence = "before";
break;
case "monobook" :
case "vector" :
suitable = "bodyContent";
sequence = "prepend";
break;
} // switch Env.skin
$anchor = $( "#" + suitable );
}
if ( ! $anchor.length ) {
$anchor = $( "#firstHeading" );
Line 140 ⟶ 195:
}
if ( Env.$corner ) {
Env.$corner.
Env.$corner.prepend( $apply );
}
r = true;
}
return r;
} // $float()
Line 250 ⟶ 262:
// > Config
// >< Env
// OPTS.face()
// facility()
// mw.config.get()
Line 260 ⟶ 272:
r = access;
}
OPTS.face();
if ( PLH &&
typeof PLH.config === "object" &&
Line 321 ⟶ 333:
// Uses:
// >< Env
// OPTS.facet()
// mw.config.get()
// fair()
Line 327 ⟶ 339:
// (apply.fun)
// 2014-12-19 PerfektesChaos@de.wikipedia
var opt = OPTS.facet( apply.signature ),
seed = null,
slot = "p-cactions",
Line 419 ⟶ 431:
return r;
} // favorite()
function feed( about, alter, assign ) {
// Execute URL replacement after some delay
// Precondition:
// about -- object, with reason
// alter -- string, with title
// assign -- string, with new URL
// Uses:
// history.___replaceState()
// 2015-01-03 PerfektesChaos@de.wikipedia
window.history.___replaceState( about, alter, assign );
} // feed()
Line 518 ⟶ 544:
// > document
// >< Env
//
// $float()
// $factory()
// fiat()
// mw.config.get()
// mw.util.wikiUrlencode()
// setTimeout()
// history.___replaceState()
// freezer()
//
// 2015-01-03 PerfektesChaos@de.wikipedia
var
msec = 200,
sign = Sign + "Difflink",
caused, got, i, id1, id2, j,
re, selector, shift, show, story, swap,
$a, $div, $span, $spanB, $spanE;
switch ( typeof opt ) {
case "boolean" :
break;
case "object" :
if ( opt ) {
if ( typeof opt.link === "boolean" ) {
link = opt.link;
}
if ( typeof opt.msec === "number" ) {
msec = opt.msec;
}
if ( typeof opt.selector === "string" ) {
selector = opt.selector;
}
} else {
opt = true;
}
break;
default :
opt = true;
} // switch typeof opt
if ( opt ) {
$div = $( "#" + sign );
if ( ! $div.length ) {
opt = $float( false, selector );
}
}
if ( opt ) {
if ( Env.wgCanonicalSpecialPageName ) {
// 2014 redirected to &diff=
Line 571 ⟶ 631:
if ( id1 ) {
Env.spcNS = mw.config.get( "wgFormattedNamespaces" )[ "-1" ];
Env.wgPageName = mw.config.get( "wgPageName" );
}
story = ":Diff/" + id1
+ ( id2 ? "/" + id2 : "" );
+ mw.util.wikiUrlencode( Env.wgPageName );
story = Env.spcNS + story;
$span = $( "<span>" );
if ( link ) {
$spanB = $( "<span>" );
$spanB.text( "[[" );
$a = $( "<a>" );
$a.attr( { "href": shift } );
$a.text( story );
$spanE = $( "<span>" );
$spanE.text( "]]" );
$span.append( $spanB );
$span.append( $a );
$span.append( $spanE );
} else {
$span.text( "[[" + story + "]]" );
}
$div = $factory( sign );
$div.append( $span );
Line 586 ⟶ 666:
fiat( false, "n" );
}
if ( ! link &&
typeof window.history.___replaceState === "function" ) { caused = { caused: Sign };
show = window.
if ( msec > 0 )
if ( id2 )
swap = shift + "&diff=" + id2 + "&oldid=" + id1;
} else {
swap = shift + "&diff=" + id1;
}
window.history.___replaceState( caused, show, swap );
window.setTimeout( feed, msec, caused, show, shift );
} else {
window.history.___replaceState( caused, show, shift );
}
}
}
Line 603 ⟶ 686:
freezer( true );
} // flip()
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-03 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" );
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()
Line 844 ⟶ 976:
// >< Env
// mw.util.getUrl()
// OPTS.facet()
// history.___pushState()
// history.___replaceState()
Line 858 ⟶ 990:
}
if ( ! last ) {
opts = OPTS.facet( "redirect" );
if ( opts &&
typeof opts === "object" &&
Line 880 ⟶ 1,012:
function further(
//
// Precondition:
//
// Uses:
// mw.
//
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
forward( n,
}
}
} // further()
Line 932 ⟶ 1,057:
// mw.config.get()
// mw.util.getParamValue()
//
// flip()
// further()
// freeze()
// freezer()
// fresh()
// from()
// OPTS.facet()
// fresher()
// freshest()
// flat()
//
var linkUpdate;
Env = { skin: false,
Line 952 ⟶ 1,078:
switch ( Env.wgCanonicalSpecialPageName ) {
case "Contributions" :
break;
case "Diff" :
Line 959 ⟶ 1,085:
case "Recentchanges" :
case "Watchlist" :
break;
case "Gadgets" :
Line 975 ⟶ 1,101:
switch ( Env.wgAction ) {
case "history" :
further(
break;
case "view" :
Line 1,002 ⟶ 1,128:
} // switch wgAction
if ( linkUpdate ) {
if ( OPTS.facet( "forcelinkupdate" ) ) {
fresher( true );
}
if ( OPTS.facet( "forcerecursivelinkupdate" ) ) {
freshest( true );
}
Line 1,011 ⟶ 1,137:
}
}
if ( OPTS.facet( "slangQQX" ) ) {
flat( true );
}
Line 1,020 ⟶ 1,146:
if ( mw.loader.getState( Signature ) !== "ready" ) {
mw.loader.state( Signature, "ready" );
mw.
mw.loader.using(
"mediawiki.util",
"user",
"user.options" ],
function () {
$( fire ); // don't hurry
|