$( function () {
$( "a" ).each( function ( index ) {
var oldUrl = decodeURI( $( this ).attr( "href" ) );
var serverName = mw.config.get( "wgServerName" );
var newUrl = oldUrl.replace( /\[\[.+?\|/g, "[[:m:" +
( serverName === "meta.wikimedia.org" ? "" :
mw.config.get( "wgServerName" ).split( "." ) + ":" +
mw.config.get( "wgServerName" ).split( "." ) + ":" ) +
"Special:Permalink/" + mw.config.get( "wgRevisionId" ) + "|" );
$( this ).attr( "href", encodeURI( newUrl ) );
} );
} );