Jump to content

User:Abkhalias/scripts.js

From Wikipedia, the free encyclopedia
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.
function createDiffMultiLink()
{
	if (!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.config.get('wgRevisionId'), 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 pageId = response['query']['pageids'][0];
	var page = response['query']['pages'][pageId];
	var revisions = page['revisions'];
	if (!revisions) return false;

	var diff = new Date(revisions[0]['timestamp']);
	diff = diff.getUTCFullYear().toString() + twoDigitPadding(diff.getUTCMonth() + 1).toString() + twoDigitPadding(diff.getUTCDate()).toString() + twoDigitPadding(diff.getUTCHours()).toString() + twoDigitPadding(diff.getUTCMinutes() + 1).toString() + twoDigitPadding(diff.getUTCSeconds()).toString();
    mw.util.addPortletLink('p-navigation', mw.config.get('wgScript') + '?title=' + mw.config.get('wgPageName') + '&action=history&offset=' + diff, "(Diff History)");
}

$(createDiffMultiLink);