Content deleted Content added
-1.4 |
-1.5 |
||
Line 2:
// Some minor link helpers
// ResourceLoader: compatible; dependencies: user, mediawiki.util
/// 2014-12-
/// Fingerprint: #0#0#
/// <nowiki>
Line 11:
( function ( mw, $ ) {
"use strict";
var Version = -1.
Sign = "pageLinkHelper",
Signature = "ext.gadget." + Sign,
Line 74:
return r;
} // $float()
function fiat( apply, at ) {
// Equip diffpage revision with wikilink for permalink c&p
// Precondition:
// apply -- revision ID
// at -- revision column; "n" or "o"
// DOM.ready
// Diffpage
// Uses:
// > Sign
// > Env.spcNS
// mw.util.getParamValue()
// 2014-12-14 PerfektesChaos@de.wikipedia
var $div = $( "#mw-diff-" + at + "title1" ),
id, s, $a, $span;
if ( $div.length ) {
if ( apply ) {
id = apply;
} else {
$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 );
}
}
} // fiat()
Line 112 ⟶ 148:
// Uses:
// > Sign
// > ___location
// >< Env
// mw.config.get()
// $float()
// $factory()
//
// freezer()
// 2014-12-14 PerfektesChaos@de.wikipedia
var sign = Sign + "Difflink",
$div = $( "#" + sign ),
Line 137 ⟶ 175:
i = parseInt( id1, 10 );
if ( id2 ) {
j = parseInt( id2, 10 );
if ( isNaN( i ) ) {
id2 = id1;
id1 = j;
}
} else {
if ( ! isNaN( j ) && i > j ) {
}
}
Line 155 ⟶ 195:
} else if ( isNaN( i ) ) {
id1 = false;
} else {
id1 = i;
}
}
if ( id1 ) {
show = "[[" +
+ ( id2 ? "
$span =
$span.text( show );
$div = $factory( sign );
$div.append( $span );
$float( $div );
if ( id2 ) {
fiat( id1, "o" );
fiat( id2, "n" );
} else {
fiat( false, "o" );
fiat( false, "n" );
}
}
}
freezer( true );
} // flip()
Line 187 ⟶ 236:
// mw.util.wikiUrlencode()
// mw.util.getUrl()
// freezer()
// 2014-12- var sign = Sign + "Permalink",
$div = $( "#" + sign ),
Line 205 ⟶ 255:
$div = $factory( sign );
special = mw.config.get( "wgFormattedNamespaces" )[ "-1" ]
+ ":
swift = "?title="
+ mw.util.wikiUrlencode( Env.wgPageName );
Line 215 ⟶ 265:
if ( Env.oldid ) {
$div.append( $spanBeg.clone() );
show = special + "
$a.attr( { "href": mw.util.getUrl( show ) + swift } );
$a.text( show );
Line 225 ⟶ 275:
}
$div.append( $spanBeg );
show = special + "Redirect/page/" + Env.curid;
$a.attr( { "href": mw.util.getUrl( show ) + swift } );
$a.text( show );
Line 402 ⟶ 452:
}
} // from()
function further( amount ) {
// Convert links on page into Special: format
// Precondition:
// amount -- number of links per item to inspect
// DOM.ready
// mediawiki.util loaded
// Uses:
// mw.util.getParamValue()
// 2014-12-14 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 {
shift = "PermanentLink/" + start;
}
shift = special + shift + "$1";
strip = strip.replace( /^.+(\?title=.+)$/,
shift );
$a.attr( "href", strip );
}
} // for j
} // for i
}
} // further()
Line 414 ⟶ 508:
// mw.util.getParamValue()
// flip()
// further()
// freeze()
// freezer()
// fresh()
// from()
// 2014-12-
Env =
if ( Env.wgCanonicalSpecialPageName ) {
case "Diff" :
flip();
break;
case "Contributions" :
further( 2 );
break;
case "Watchlist" :
further( 1 );
break;
} // switch wgCanonicalSpecialPageName
} else {
Env.diff = mw.util.getParamValue( "diff" );
Env.oldid = mw.util.getParamValue( "oldid" );
} else {
switch ( Env.wgAction ) {
case "history" :
further( 3 );
break;
case "view" :
Env.curid = mw.util.getParamValue( "curid" );
if ( Env.curid || Env.oldid ) {
freeze( true );
} else {
freezer( true );
}
fresh();
Env.wgRedirectedFrom
= mw.config.get( "wgRedirectedFrom" );
if ( Env.wgRedirectedFrom ) {
from();
}
break;
default:
freezer( true );
} // switch wgAction
}
}
|