User:Gracenotes/changesSince.js

// if (wgNamespaceNumber >= 0) { $( function {  var liRev = document.getElementById('t-whatlinkshere').cloneNode(true);   aRev = liRev.firstChild;   liRev.setAttribute('id', 't-checkchange')   aRev.setAttribute('href', 'javascript:checkChanges')   aRev.setAttribute('title', 'Check changes of a page since it was loaded')   aRev.setAttribute('accesskey', '');   aRev.firstChild.nodeValue = 'Check changes';   getElementsByClassName(document.getElementById('p-tb'), 'div', "pBody")[0].getElementsByTagName('ul')[0].appendChild(liRev); }); }

var revInfoType = 'initial'; var revInfoXML; var revPromptText = "Page has been edited since it was loaded. What do you want to see?\ni=general information about what changed\nc=go to the current revision of this page\nd=view the differences that have since been made\nh=go to the page history\nCancel=exit";

function checkChanges { //this is standard ajax stuff; the try/catch format, however, is from twinklefluff try { var revAlso = (revInfoType == 'more') ? '|comment&rvstartid='+wgCurRevisionId+'&rvdir=newer' : ''; revinfoXML = sajax_init_object; revinfoXML.overrideMimeType('text/xml'); revinfoXML.onreadystatechange = checkChangesFromXML; revinfoXML.open( 'GET', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&titles=' + encodeURI(wgPageName) + '&prop=revisions&format=xml&rvprop=user' + revAlso, true ); revinfoXML.send(null); } catch(omgTehError) {} }

function checkChangesFromXML {

if ( revinfoXML.readyState != 4 ){ return; }

if( revinfoXML.status != 200 ){ alert ('There was an error.'); return; }

var XMLdoc = revinfoXML.responseXML.documentElement;

if(!XMLdoc) { return; }

if ( revInfoType == 'initial') { var revStuff = XMLdoc.getElementsByTagName('rev')[0]; var trueCurRevId = revStuff.getAttribute('revid'); if (wgCurRevisionId == trueCurRevId) { alert('Page has not been edited since loaded. This most recent revision was made by ' + revStuff.getAttribute('user')) }   else { var revPrompt = prompt(revPromptText); revDecide(revPrompt); } }  else { var revStuff = XMLdoc.getElementsByTagName('rev'); var rvsTotal = revStuff.length - 1; var revSummary = 'There ' + (rvsTotal == 1 ? 'has been 1 revision' : 'have been ' + rvsTotal + ' revisions') + ' committed since this page loaded.\n\n' for (i = 0; i <= rvsTotal; i++) { var tempC = revStuff[i].getAttribute('comment'); var revComment = (tempC != undefined ? '(' + tempC.replace(/\[\[(?:[^\]|]*\|)?([^\]|]+)\]\]/g, '$1') + ')': 'no comment'); revSummary += revStuff[i].getAttribute('user') + ': ' + (revStuff[i].getAttribute('minor') != undefined ? 'm ' : '') + revComment + '\n' if (rvsTotal > 5 && i == 1) { revSummary += "... " + (rvsTotal - 4) + " revisions here ..."; i = rvsTotal - 2; }   }    var revPrompt = prompt(revSummary + revPromptText); revDecide(revPrompt); } }

function revDecide(revPrompt) { switch (revPrompt) { case 'i': revInfoType = 'more'; checkChanges; break; case 'c': document.location = wgServer + wgArticlePath.replace('$1', wgPageName); break; case 'd': document.location = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=' + wgPageName + '&diff='+0+'&oldid='+wgCurRevisionId; break; case 'h': document.location = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=' + wgPageName + '&action=history'; break; default: revInfoType = 'initial'; }     return false; }

//used in order to determine if viewing a previous revision, and what its revisionid is; since it makes sense that viewing a past revision with MediaWiki should compare that revision //regex written by Lupin; capturing parentheses capture parameter name of query function query_get(paramName) { var cmdRe=RegExp('[&?]'+paramName+'=([^&]*)'); var h=document.location; var m; if (m=cmdRe.exec(h)) { try { return unescape(m[1]); } catch (someError) {} } return null; } // end