User:Equazcion/link intermediate revisions.js
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Modified from [[User:Gary King/link intermediate revisions.js]]
if (typeof(unsafeWindow) != 'undefined')
{
var console = unsafeWindow.console;
importScriptURI = unsafeWindow.importScriptURI;
mw = unsafeWindow.mw;
}
mw.loader.using( ['mediawiki.util'], function () {
$(createDiffMultiLink);
});
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 diffMultis = $('#bodyContent .diff-multi');
if (!diffMultis.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 diffMulti = diffMultis.eq(0);
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.append(a);
}