User:SD0001/deleted-metadata-link.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:SD0001/deleted-metadata-link. |
// Link to deletedrevisions API output for deleted pages
// And a link to snippet of deleted text for AFD/PROD/G13 deleted content
$.ready.then(function() {
if (mw.config.get('wgArticleId') === 0 && !!$('.mw-warning-with-logexcerpt:has(".mw-logline-delete")').length) {
var apiParams = {
action: 'query',
prop:'deletedrevisions',
titles: mw.config.get('wgPageName').replace(/_/g, ' '),
drvprop: 'user|timestamp|tags|size',
drvlimit: 'max',
formatversion: 2
};
var link = '/w/api.php?' + $.param(apiParams);
$('.mw-warning-with-logexcerpt:first').before(
$('<div>').addClass('deleted-metadata-link').append(
'See ',
$('<a>').attr('href', link).text('deleted revisions')
)
);
mw.loader.using(['mediawiki.api', 'ext.gadget.morebits']).then(function() {
new mw.Api().get(apiParams).then(function(data) {
var user = data.query.pages[0].deletedrevisions[0].user;
var ts = new Morebits.date(data.query.pages[0].deletedrevisions[0].timestamp);
$('.deleted-metadata-link').append(
': last edited by ',
$('<a>').attr('href', '/wiki/User:' + encodeURIComponent(user)).text(user),
' at ' + ts.format('HH:mm, D MMMM YYYY') + ' (' + getTimeZoneString() + ')'
);
var $latestLogLine = $('.mw-logline-delete').first();
if ($latestLogLine.length) {
var $firstLinkInComment = $latestLogLine.find('.comment a').first();
var date = parseLocalDate($latestLogLine.find('a').first().text());
if (date.isValid()) {
if ($firstLinkInComment.is('[href^="/wiki/Wikipedia:Articles_for_deletion"]')) {
getRevidLinkFromDate('User:SDZeroBot/AfD grid', date).then(function(link) {
$('.deleted-metadata-link').append(' <a href="' + link + '">Look up snippet in AfD grid</a>');
});
} else if ($firstLinkInComment.is('[href^="/wiki/Wikipedia:PROD"]')) {
getRevidLinkFromDate('User:SDZeroBot/PROD grid', date).then(function(link) {
$('.deleted-metadata-link').append(' <a href="' + link + '">Look up snippet in PROD grid</a>');
});
} else if ($firstLinkInComment.is('[href^="/wiki/Wikipedia:Criteria_for_speedy_deletion#G13"]') ||
$firstLinkInComment.is('[href^="/wiki/Wikipedia:CSD#G13"]')) {
getRevidLinkFromDate('User:SDZeroBot/G13 Watch', date, true).then(function(link) {
$('.deleted-metadata-link').append(' <a href="' + link + '">Look up snippet in G13 Watch</a>');
});
}
}
}
});
});
}
});
function parseLocalDate(dateText) {
var date = new Morebits.date(dateText + ' (UTC)');
var userTimeZoneOffset = parseInt(mw.user.options.get('timecorrection').split('|')[1]);
return date.subtract(userTimeZoneOffset, 'minutes');
}
function getTimeZoneString() {
var timecorrection = -new Date().getTimezoneOffset();
var negative = false;
if (timecorrection < 0) {
timecorrection = -timecorrection;
negative = true;
}
return 'UTC' + (negative ? '–' : '+') + (timecorrection / 60);
}
function getRevidLinkFromDate(page, date, postLog) {
return new mw.Api().get({
titles: page,
prop: 'revisions',
rvstart: postLog ? date.add(1, 'day').toISOString() : date.toISOString(),
rvlimit: 1,
formatversion: 2
}).then(function(data) {
return data.query.pages[0].revisions[0].revid;
}).then(function(revid) {
return '/w/index.php?title=' + encodeURIComponent(page) + '&oldid=' + revid +
'#:~:text=' + encodeURIComponent(Morebits.pageNameNorm); // jump to text in Chrome
});
}