Content deleted Content added
-1.94 |
-2.1 |
||
Line 1:
/// Gadget-pageLinkHelper.js
// Some minor link helpers
///
// ResourceLoader: compatible;
// dependencies: user, user.options, mediawiki.user, mediawiki.util
Line 7:
// 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/",
OPTS = { },
Perm = { },
Purge = { },
Config, Env, PLH;
Line 332 ⟶ 334:
// true; or "|vector|" etc.
// .fun -- callback for link generation
// .forward -- callback for click
// .show -- link title keyword
// .support -- tooltip keyword
Line 348 ⟶ 351:
// mw.util.addPortletLink()
// (apply.fun)
//
var opt = OPTS.facet( apply.signature ),
seed = null,
Line 422 ⟶ 425:
}
if ( slot ) {
swap = apply.fun();
} else {
swap = "#";
}
if ( typeof apply.suffix === "string" ) {
suffix = apply.suffix;
Line 438 ⟶ 445:
null,
seed );
if ( typeof apply.forward === "function" ) {
$( r ).find( "a" ).click( apply.forward );
}
}
return r;
Line 455 ⟶ 465:
window.history.___replaceState( about, alter, assign );
} // feed()
Line 557 ⟶ 523:
// $float()
// $factory()
// Perm.fiat()
// mw.config.get()
// mw.util.wikiUrlencode()
// setTimeout()
// history.___replaceState()
//
// (feed)
// 2015-01-07 PerfektesChaos@de.wikipedia
Line 670 ⟶ 636:
$float( $div );
if ( id2 ) {
Perm.fiat( id1, "o" );
Perm.fiat( id2, "n" );
} else {
Perm.fiat( false, "o" );
Perm.fiat( false, "n" );
}
if ( ! link &&
Line 694 ⟶ 660:
}
}
} // flip()
Line 748 ⟶ 714:
}
} // forward()
Line 1,077 ⟶ 816:
// mw.user.options.get()
// further()
//
//
// Purge.fresh()
// from()
// OPTS.facet()
// Purge.fresher()
// Purge.freshest()
// flat()
//
var linkUpdate;
mw.user.options.set( "gadget-" + Sign, Version );
Line 1,126 ⟶ 865:
Env.curid = mw.util.getParamValue( "curid" );
if ( Env.curid || Env.oldid ) {
} else {
}
Purge.fresh( true );
Env.wgRedirectedFrom
= mw.config.get( "wgRedirectedFrom" );
Line 1,138 ⟶ 877:
break;
case "info" :
Purge.fresh( true );
break;
case "edit" :
Line 1,145 ⟶ 884:
// fall through
default:
} // switch wgAction
if ( linkUpdate ) {
if ( OPTS.facet( "forcelinkupdate" ) ) {
Purge.fresher( true );
}
if ( OPTS.facet( "forcerecursivelinkupdate" ) ) {
Purge.freshest( true );
}
}
Line 1,161 ⟶ 900:
}
} // fire()
Perm.fiat = function ( apply, at ) {
// 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:
// DOM.ready
// mediawiki.util loaded
// Uses:
// > Sign
// >< Env
// mw.config.get()
// $float()
// $factory()
// mw.util.wikiUrlencode()
// mw.util.getUrl()
// fair()
// Perm.flip()
// 2014-12-29 PerfektesChaos@de.wikipedia
var sign = Sign + "Permalink",
$div = $( "#" + sign ),
show, special, swift, $a, $br, $spanBeg, $spanEnd;
if ( ! $div.length && $float() ) {
if ( ! Env.wgPageName ) {
Env.wgPageName = mw.config.get( "wgPageName" );
}
if ( Env.curid ) {
Env.curid = parseInt( Env.curid, 10 );
} else {
Env.curid = mw.config.get( "wgArticleId" );
}
if ( Env.oldid ) {
Env.oldid = parseInt( Env.oldid, 10 );
} else {
Env.oldid = mw.config.get( "wgCurRevisionId" );
}
$div = $factory( sign );
special = mw.config.get( "wgFormattedNamespaces" )[ "-1" ]
+ ":";
swift = "?title="
+ mw.util.wikiUrlencode( Env.wgPageName );
$spanBeg = $( "<span>" );
$spanBeg.text( "[[" );
$spanEnd = $( "<span>" );
$spanEnd.text( "]]" );
$a = $( "<a>" );
if ( Env.oldid ) {
$div.append( $spanBeg.clone() );
show = special
+ fair( "PermanentLink", false, "PermaLink" )
+ "/" + Env.oldid;
$a.attr( { "href": mw.util.getUrl( show ) + swift } );
$a.text( show );
$div.append( $a );
$div.append( $spanEnd.clone() );
$br = $( "<br />" );
$div.append( $br );
$a = $( "<a>" );
}
$div.append( $spanBeg );
show = special
+ fair( "Redirect", false )
+ "/page/" + Env.curid;
$a.attr( { "href": mw.util.getUrl( show ) + swift } );
$a.text( show );
$div.append( $a );
$div.append( $spanEnd );
$float( $div );
Perm.flip( false );
}
}; // Perm.furnish()
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.fiat = function ( additional ) {
// Equip diffpage revision with wikilink for permalink c&p
// Precondition:
// additional -- some keyword, or not
// Uses:
// mw.Api() .post()
// 2016-08-18 PerfektesChaos@de.wikipedia
var o = new mw.Api( { parameters: { action: "purge" } } ),
p = { pageids: Env.curid };
if ( additional ) {
p[ additional ] = true;
}
o.post( p )
.done( function () { window.___location.reload( true ); } );
}; // Purge.fiat()
Purge.fresh = function ( ahead ) {
// Provide purge link
// Precondition:
// ahead -- true if initializing, false to link
// DOM.ready
// user resources loaded
// Uses:
// Purge.first()
// favorite()
// Purge.fiat()
// (Purge.fresh)
// 2016-08-18 PerfektesChaos@de.wikipedia
if ( ahead === true ) {
if ( Purge.first() ) {
favorite( { signature: "purge",
skins: true,
forward: Purge.fresh,
show: "purgeTitle",
support: "purgeTip",
suffix: "purge"
} );
}
} else {
Purge.fiat();
}
}; // Purge.fresh()
Purge.fresher = function ( ahead ) {
// Provide forcelinkupdate purge link
// Precondition:
// ahead -- true if initializing, false to link
// DOM.ready
// user resources loaded
// Postcondition:
// Returns link, or undefined
// Uses:
// Purge.first()
// favorite()
// Purge.fiat()
// (Purge.fresher)
// 2016-08-18 PerfektesChaos@de.wikipedia
if ( ahead === true ) {
if ( Purge.first() ) {
favorite( { signature: "forcelinkupdate",
skins: false,
forward: Purge.fresher,
show: "purgeLUtitle",
support: "purgeLUtip",
suffix: "purgeLinkUpd"
} );
}
} else {
Purge.fiat( "forcelinkupdate" );
}
}; // Purge.fresher()
Purge.freshest = function ( ahead ) {
// Provide forcerecursivelinkupdate purge link
// Precondition:
// ahead -- true if initializing, false to link
// DOM.ready
// user resources loaded
// Uses:
// Purge.first()
// favorite()
// Purge.fiat()
// (Purge.fresher)
// 2016-08-18 PerfektesChaos@de.wikipedia
if ( ahead === true ) {
if ( Purge.first() ) {
favorite( { signature: "forcerecursivelinkupdate",
skins: false,
forward: Purge.freshest,
show: "purgeLURtitle",
support: "purgeLURtip",
suffix: "purgeLinkUpdRec"
} );
}
} else {
Purge.fiat( "forcerecursivelinkupdate" );
}
}; // Purge.freshest()
Line 1,166 ⟶ 1,182:
if ( mw.loader.getState( Signature ) !== "ready" ) {
mw.loader.state( Signature, "ready" );
mw.loader.using( [ "mediawiki.
"mediawiki.user",
"mediawiki.util",
"user",
|