User:NQ/custom-scripts/diffhistoryoffset.js

//Copied entirely from User:Gary/link intermediate revisions.js with minor tweaks

function createDiffHistoryLink {	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 }, DiffHistoryCallback); }

function twoDigitPadding(integer) {	var string = integer.toString; if (string.length == 1) return '0' + integer; else return integer; }

function DiffHistoryCallback(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 offset = new Date(revisions[0]['timestamp']); offset = offset.getUTCFullYear.toString + twoDigitPadding(offset.getUTCMonth + 1).toString + twoDigitPadding(offset.getUTCDate).toString + twoDigitPadding(offset.getUTCHours).toString + twoDigitPadding(offset.getUTCMinutes + 1).toString + twoDigitPadding(offset.getUTCSeconds).toString;

/* var diffHist = document.createElement("a"); diffHist.href = mw.config.get('wgScript') + '?title=' + mw.config.get('wgPageName') + '&action=history&offset=' + offset; diffHist.innerHTML = " (diff history offset) "; document.getElementById("mw-diff-ntitle5").appendChild(diffHist); */ mw.util.addPortletLink('p-tb', mw.config.get('wgScript') + '?title=' + mw.config.get('wgPageName') + '&action=history&offset=' + offset, "(Diff History)"); }

$(createDiffHistoryLink);