Content deleted Content added
-1.2 |
-1.3 |
||
Line 1:
/// Gadget-pageLinkHelper.js
//
// ResourceLoader: compatible; dependencies: user, mediawiki.util
/// 2014-12-
/// Fingerprint: #0#0#
/// <nowiki>
/*jshint bitwise:true, curly:true, eqeqeq:true,
/*global window:false */
( function ( mw, $ ) {
"use strict";
var
Sign = "pageLinkHelper",
Signature = "ext.gadget." + Sign,
Env, PLH;
function $factory( access ) {
// Create <div> for upper right corner
// Precondition:
// access -- distinguishing selector ID
// Uses:
// > Sign
// 2014-12-11 PerfektesChaos@de.wikipedia
var space = "4px",
style = "#808080 1px solid",
$r = $( "<div>" );
$r.attr( { "class": Sign,
"id": access } );
style = "#808080 1px solid";
$r.css( { "border-bottom": style,
"border-left": style,
"float": "right",
"font-family": "monospace",
"margin-bottom": "1em",
"margin-left": "1em",
"margin-top": space,
"padding-bottom": space,
"padding-left": space } );
return $r;
} // $factory()
function $float( $apply ) {
// Insert upper right corner element
// Precondition:
// $apply -- jQuery element to insert
// false to vheck availability
// Postcondition:
// Returns true, if insertion possible
// Uses:
// > Sign
// >< Env
// 2014-12-11 PerfektesChaos@de.wikipedia
var r, // = undefined
$div;
if ( typeof Env.$anchor === "undefined" ) {
Env.$anchor = $( "#firstHeading" );
}
if ( Env.$anchor.length ) {
r = true;
if ( $apply ) {
$div = $( "." + Sign );
$div.remove();
$div = $( "<div>" );
$div.css( { "clear": "left" } );
Env.$anchor.after( $div );
Env.$anchor.after( $apply );
}
}
return r;
} // $float()
Line 24 ⟶ 85:
// Returns value, or undefined
// Uses:
// >
// > Sign
// > Version
// >< PLH
// 2014-12-
var r; // = undefined
if ( typeof mw.libs
PLH = mw.libs
if ( PLH ) {
PLH.vsn =
if ( typeof PLH[ applied ] !== "undefined" ) {
r = PLH[ applied ];
Line 48 ⟶ 111:
// mediawiki.util loaded
// Uses:
// > Sign
// > Env
// > ___location
// mw.config.get()
//
// 2014-12-11 PerfektesChaos@de.wikipedia
var sign = Sign + "Difflink",
$div = $( "#" + sign ),
got, i, id1, id2, j, re, show
if ( ! $div.length && $float() ) {
re = /\/wiki\/[^:]+:[^\/]+\/(\d+)(?:\/(\.+))?$/;
got = re.exec(
if ( got
}
}
}
if ( i = parseInt( id1, 10
if ( id2 )
if ( isNaN( i ) )
id2 =
}
j =
if ( ! isNaN( j ) )
if ( i
id2 = i;
id1 = j;
}
}
}
if ( id2 === "prev" ) {
id2 = false;
}
} else if ( isNaN( i ) ) {
id1 = false;
}
}
if ( id1 ) { $span.text( show );
$div = $factory( sign );
$div.append( $span );
$float( $div );
}
}
} // flip()
function freeze() {
// 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()
// 2014-12-11 PerfektesChaos@de.wikipedia
var sign = Sign + "Permalink",
$div = $( "#" + sign ),
show, special, swift, $a, $br, $spanBeg, $spanEnd;
if ( ! $div.length && $float() ) {
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" ]
+ ":Redirect/";
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 + "revision/" + 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 + "page/" + Env.curid;
$a.attr( { "href": mw.util.getUrl( show ) + swift } );
$a.text( show );
$div.append( $a );
$div.append( $spanEnd );
$float( $div );
freezer( false );
}
} // freeze()
function freezer( assign ) {
// Change portlet for permalink
// Precondition:
// assign -- true if link to be diverted, false to gray out
// DOM.ready
// Uses:
// > Sign
// > Version
// (freeze)
// 2014-12-11 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( freeze );
$a.text( "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 );
$
$
$
}
}
}
} //
Line 206 ⟶ 366:
// > ___location
// > document
// > Sign
// >< Env
// mw.util.getUrl()
Line 228 ⟶ 389:
legacy = opts.legacy;
}
showed = window.document.title;
caused = { caused: Sign };
if ( legacy ) {
state = mw.util.getUrl( Env.wgRedirectedFrom );
Line 253 ⟶ 414:
// mw.util.getParamValue()
// flip()
// freeze()
// freezer()
// fresh()
// from()
// 2014-12-
Env = mw.config.get( [ "wgAction",
"wgCanonicalSpecialPageName",
"wgRedirectedFrom" ] );
Env.oldid = mw.util.getParamValue( "oldid" );
if ( Env.diff ||
Env.wgCanonicalSpecialPageName === "Diff" ) {
flip();
freezer( true );
} else {
if if ( Env.
} else {
freezer( true );
}
fresh();
if ( Env.wgRedirectedFrom ) {
from();
}
} else {
freezer( true );
}
}
Line 273 ⟶ 448:
if ( mw.loader.
mw.loader.state(
mw.loader.using( [ "mediawiki.util",
"user" ],
|