User:Gary/link intermediate revisions.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. |
Documentation for this user script can be added at User:Gary/link intermediate revisions. |
/*
LINK INTERMEDIATE REVISIONS
Description: Link intermediate revisions when viewing a diff, to easily see which revisions are between the two diffs currently being viewed.
*/
function createDiffMultiLink()
{
if (!mw.util.getParamValue('diff') || !mw.util.getParamValue('oldid')) return false;
$.get(mw.config.get('wgScriptPath') + '/api.php', { action: 'query', prop: 'revisions', titles: mw.config.get('wgPageName'), rvprop: 'timestamp', rvstartid: mw.util.getParamValue('diff'), rvendid: mw.util.getParamValue('oldid'), rvlimit: '5000', format: 'json', indexpageids: 1 }, diffMultiCallback);
}
function twoDigitPadding(integer)
{
var string = integer.toString();
if (string.length == 1) return '0' + integer;
else return integer;
}
function diffMultiCallback(response)
{
if (!response['query'] || !response['query']['pages'] || response['query']['pageids'][0] == -1) return false;
var diffMulti = $('#bodyContent .diff-multi').eq(0);
if (!diffMulti.length) return false;
var pageId = response['query']['pageids'][0];
var page = response['query']['pages'][pageId];
var revisions = page['revisions'];
if (!revisions) return false;
var oldid = new Date(revisions[revisions.length - 1]['timestamp']);
oldid = oldid.getUTCFullYear().toString() + twoDigitPadding(oldid.getUTCMonth() + 1).toString() + oldid.getUTCDate().toString() + twoDigitPadding(oldid.getUTCHours() + 1).toString() + twoDigitPadding(oldid.getUTCMinutes() + 1).toString() + twoDigitPadding(oldid.getUTCSeconds() + 1).toString();
var diff = new Date(revisions[0]['timestamp']);
diff = diff.getUTCFullYear().toString() + twoDigitPadding(diff.getUTCMonth() + 1).toString() + diff.getUTCDate().toString() + twoDigitPadding(diff.getUTCHours() + 1).toString() + twoDigitPadding(diff.getUTCMinutes() + 1).toString() + twoDigitPadding(diff.getUTCSeconds() + 1).toString();
var a = $('<a href="' + mw.config.get('wgScript') + '?title=' + mw.config.get('wgPageName') + '&action=history&offset=' + diff + '&limit=' + revisions.length + '"></a>').append(diffMulti.contents().eq(0));
diffMulti.prepend(a);
}
$(createDiffMultiLink);