User:Gracenotes/vandinfo.js

var revContinue;

getData = function(revid) {

var revInfo = new Object; revInfo.page; //page name revInfo.rev; //revision number revInfo.namespace; //namespace number revInfo.user; //user name revInfo.anon; //if an anon? revInfo.minor; //is minor? revInfo.editsum; //edit summary revInfo.minor; //minor? revInfo.pageLength; //length of page revInfo.cats; //number of cats on page revInfo.pageHistory = []; //array with page history revInfo.pageHistoryIndex; //array with page history revInfo.pageHistoryLeng; //array with page history revInfo.tenBefore; revInfo.date; //date revInfo.tenAfter; revInfo.revsBefore;

var resdiv = document.getElementById('resultsDiv'); while (resdiv.hasChildNodes) { resdiv.removeChild(resdiv.firstChild); } revContinue = true;

function getPageTitle(revid) { var revInfoJSON = new XMLHttpRequest; revInfoJSON.open('GET', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/query.php?what=revisions&format=json&revids=' + revid, true) revInfoJSON.onload = function { if (revInfoJSON.status != 200) { alert('Can\'t download history! Oh noes!'); return; }     revInfoJSON = eval('(' + revInfoJSON.responseText + ')'); for (var i in revInfoJSON.pages) var page = revInfoJSON.pages[i].title; addResultToDiv('Page', page); addResultToDiv('Revision id', revid);

getPageInfo(page, revid, i); }   revInfoJSON.send(null); }

getPageTitle(revid);

function getPageInfo(page, revid, pageID) { var revInfoJSON = new XMLHttpRequest; revInfoJSON.open('GET', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&prop=revisions&rvlimit=1&rvprop=timestamp|user|comment|content&titles=' + page + '&rvstartid=' + revid + '&format=json', true); revInfoJSON.onload = function { if (revInfoJSON.status != 200) { alert('Can\'t download history! Oh noes!'); return; }     revInfoJSON = eval('(' + revInfoJSON.responseText + ')').query.pages[pageID]; //assign all data revInfo.page = page; revInfo.rev = revid; revInfo.namespace = revInfoJSON.ns; addResultToDiv('Namespace number', revInfo.namespace); revInfoJSON = revInfoJSON.revisions[0]; revInfo.user = revInfoJSON.user; addResultToDiv('User', revInfo.user); revInfo.editsum = revInfoJSON.comment || ''; addResultToDiv('Summary', revInfo.editsum); revInfo.timestamp = revInfoJSON.timestamp; revInfo.anon = (revInfoJSON.anon == '' ? true : false); addResultToDiv('Anon edit', revInfo.anon); revInfo.minor = (revInfoJSON.minor == '' ? true : false); addResultToDiv('Minor edit', revInfo.minor); var wikitext = revInfoJSON.*; revInfo.pageLength = wikitext.length; addResultToDiv('Page length', revInfo.pageLength);

addResultToDiv('Status', 'loading'); pageHistory(page, revid, pageID) }   revInfoJSON.send(null); }

function pageHistory (page, revid, pageID, startFrom) { if (!revContinue) return false; var revInfoJSON = new XMLHttpRequest; revInfoJSON.open('GET', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&rawcontinue=&prop=revisions&rvlimit=50&rvprop=timestamp|user|comment|ids&format=json&' + 'titles=' + page + (startFrom ? '&rvstartid=' + startFrom : ''), true); revInfoJSON.onload = function { if (revInfoJSON.status != 200) { alert('Can\'t download history! Oh noes!'); return; } k = 0; revInfoJSON = eval('(' + revInfoJSON.responseText + ')'); var cont = revInfoJSON["query-continue"] && revInfoJSON["query-continue"].revisions.rvstartid; revInfoJSON = revInfoJSON.query.pages[pageID].revisions; var temp; for (var i in revInfoJSON) { temp = revInfo.pageHistory.length; revInfo.pageHistory[temp] = [revInfoJSON[i].timestamp, revInfoJSON[i].user, revInfoJSON[i].comment]; if (revInfoJSON[i].revid == revid) revInfo.pageHistoryIndex = temp; }     document.getElementById('resultsDiv').lastChild.previousSibling.nodeValue += '.'; if (cont) { //       if (revInfo.pageHistory.length % 250 != 0 || confirm(revInfo.pageHistory.length + " edits from page history so far. Continue looking?")) pageHistory (page, revid, pageID, cont); }     else { pageHistoryParse(page, revid, pageID); }   }    revInfoJSON.send(null); }

function pageHistoryParse(page, revid, pageID) { var leng = revInfo.pageHistory.length; revInfo.pageHistoryLeng = leng; var pos = revInfo.pageHistoryIndex //most recent = lower, less recent = higher; revInfo.tenBefore = pos + 10 <= leng && revInfo.pageHistory[pos + 10][0]; revInfo.tenAfter = pos - 10 >= 0 && revInfo.pageHistory[pos - 10][0]; var k = ''; addResultToDiv('Timestamp ten before', revInfo.tenBefore); addResultToDiv('Timestamp of edit', revInfo.timestamp); addResultToDiv('Timestamp ten after', revInfo.tenAfter); addResultToDiv('Page history length', leng); addResultToDiv('Page history index', pos); } }

function addResultToDiv(name, result) { var div = document.getElementById('resultsDiv'); var aa = document.createTextNode(name + ': ' + result); var bb = document.createElement('br'); div.appendChild(aa); div.appendChild(bb); }

$ (function { var inputBox = document.getElementById('revInput');  if (!inputBox) return;  inputBox.innerHTML = " &#160; &#160; "

document.getElementById('revInputInfo').onclick = function { getData(document.getElementById('revInputText').value); } document.getElementById('revInputDiff').onclick = function { alert('Insert (diff) here'); }; document.getElementById('revHistoryStop').onclick = function { revContinue = false; };

});