User:Enterprisey/link-deleted-revs.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:Enterprisey/link-deleted-revs. |
$( function () {
function getTimestamps( revids, getPrev ) {
return new mw.Api().get( {
action: "query",
prop: "deletedrevisions",
revids: revids,
drvprop: "ids|timestamp",
formatversion: "2",
} ).then( function ( data ) {
var timestamps = {};
data.query.pages[0].deletedrevisions.forEach( function ( rev ) {
timestamps[rev.revid] = rev.timestamp;
} );
if( getPrev ) {
var parents = data.query.pages[0].deletedrevisions.map( function ( rev ) {
return rev.parentid;
} ).join( "|" );
return getTimestamps( parents, false ).then( function ( data ) {
for( var revid in data.timestamps ) {
timestamps[revid] = data.timestamps[revid];
}
return {
title: data.title,
timestamps: timestamps,
};
} );
} else {
return $.when( {
title: data.query.pages[0].title,
timestamps: timestamps,
} );
}
} ).catch( function ( e ) { console.error( e ); } );
}
if( window.location.search.indexOf( "diff=" ) >= 0 &&
!document.querySelector( "table.diff" ) ) {
var status = $( "<p>" )
.text( "Loading diff link..." )
.appendTo( "#mw-content-text" );
mw.loader.using( [ "mediawiki.api", "mediawiki.util" ], function () {
var diff = window.location.search.match( /diff=(\d+|\w+)?/ )[1];
var oldid = window.location.search.match( /oldid=(\d+|\w+)?/ )[1];
var revids = "";
if( Number( oldid ) ) {
revids += oldid;
}
if( Number( diff ) ) {
if( revids ) {
revids += "|";
}
revids += diff;
}
var getPrev = !oldid;
getTimestamps( revids, getPrev ).then( function ( data ) {
var oldidTimestamp = oldid && data.timestamps[oldid];
if( !oldid ) {
for( var revid in data.timestamps ) {
if( revid !== diff ) {
oldidTimestamp = data.timestamps[revid];
}
}
}
status.empty().append( $( "<p>" )
.append( $( "<strong>" )
.append( $( "<a>" )
.attr( "href", mw.util.getUrl( "Special:Undelete", {
target: data.title,
timestamp: oldidTimestamp,
diff: data.timestamps[diff] || diff,
} ) )
.text( "You can view it here" ) )
.append( "." ) ) );
} );
} );
} else if( window.location.search.indexOf( "oldid=" ) >= 0 &&
document.getElementsByClassName( "mw-revision" ).length === 0 &&
!document.querySelector( "table.diff" ) ) {
var status = $( "<p>" )
.text( "Loading diff link..." )
.appendTo( "#mw-content-text" );
mw.loader.using( [ "mediawiki.api", "mediawiki.util" ], function () {
var oldid = window.location.search.match( /oldid=(\d+)/ )[1];
getTimestamps( oldid ).then( function ( data ) {
status.empty().append( $( "<p>" )
.append( $( "<strong>" )
.append( $( "<a>" )
.attr( "href", mw.util.getUrl( "Special:Undelete", {
target: data.title,
timestamp: data.timestamps[oldid],
} ) )
.text( "You can view it here" ) )
.append( "." ) ) );
} )
} );
}
} );