User:Mercury~enwiki/AzaToth/twinklediff.js

//Status.debugLevel = 1;

/**
 * Last diff tab, show difference between last revision and the one before

/** TwinkleConfig.toolboxButtons (string) If id defined in this array, the button of the action is located in the toolbox instead of in the actions bar. if( typeof( TwinkleConfig.toolboxButtons ) == 'undefined' ) { TwinkleConfig.toolboxButtons = []; } function lastdiff {	if( wgNamespaceNumber >= 0 ) { var query = { 'title': wgPageName, 'diff': 'cur', 'oldid': 'prev' };		mw.util.addPortletLink(chooseBox( 'tw-lastdiff', TwinkleConfig.toolboxButtons ), mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( query ), 'last', 'tw-lastdiff', 'Show most recent diff' ); } } addOnloadHook(lastdiff);

var dataXML; var ntitle; var me;

function diffSincePrevUserButton { if( wgNamespaceNumber < 0 ) { return; }

if( !QueryString.exists( 'diff' ) ) { // Not diff page return; }

ntitle = getElementsByClassName( document.getElementById('bodyContent'), 'td', 'diff-ntitle' )[0];

if( !ntitle ) { // Nothing to see here, move along... return; }

var l = mw.util.addPortletLink(chooseBox( 'tw-since', TwinkleConfig.toolboxButtons ), "javascript:diffSincePrevUserInit(false);", 'since', 'tw-since', 'Show difference between last diff and the revision made by previous user' );

var l = mw.util.addPortletLink(chooseBox( 'tw-sincemine', TwinkleConfig.toolboxButtons ), "javascript:diffSincePrevUserInit(true);", 'since mine', 'tw-sincemine', 'Show difference between last diff and my last revision' ); } addOnloadHook(diffSincePrevUserButton);

function diffSincePrevUserInit(me) { try { Status.init( document.getElementById('bodyContent') ); var rev = wgCurRevisionId; var user; if( me ) { Status.debug( '"me" is choosen' ); user = wgUserName; } else if( vandal ) { Status.debug( 'vandal ' + vandal + ' already defined' ); // twinklefluff or simlar have already parsed this thingi user = vandal; } else { Status.debug( 'testing 3:rd element' ); user = ntitle.getElementsByTagName('a')[3].firstChild.nodeValue; Status.debug( '3:rd element: ' + user ); if( user == 'Current revision' ) { Status.debug( 'testing 6:th element' ); user = ntitle.getElementsByTagName('a')[6].firstChild.nodeValue; Status.debug( '6:th element: ' + user ); }		}

diffSincePrevUser( user, rev, me ); } catch(e) { if(e.what){ alert(e.what) } else { alert(e); }	} }

function diffSincePrevUser( user, rev, pMe ) {

me = pMe; dataXML = sajax_init_object;

dataXML.overrideMimeType('text/xml');

var query = { 'prop': 'revisions', 'format': 'xml', 'action': 'query', 'titles': wgPageName, 'rvlimit': 50, 'rvprop': [ 'ids', 'user' ], 'rvendid': wgCurRevisionId };

Status.debug( "Query string:" + QueryString.create( query ), 1 ); Status.status( 'Querying revisions...' );

dataXML.open( 'GET', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/api.php?" + QueryString.create( query ), true );

dataXML.onload = function {

var doc = this.responseXML.documentElement; var revisions = doc.getElementsByTagName('rev');

var curNode = revisions[0];

var last = null;

Status.status( 'Finding last revision made by user...' );

while( curNode != null ) { Status.debug( 'curNode: ' + curNode.getAttribute( 'revid' ), 1 );

if( me ) { if( curNode.getAttribute( 'revid' ) < rev && curNode.getAttribute( 'user' ) == user ) { Status.debug( "found rev and user", 1 ); last = curNode.getAttribute( 'revid' ); break; } 			} else { if( curNode.getAttribute( 'revid' ) < rev && curNode.getAttribute( 'user' ) != user ) { Status.debug( "found rev and user", 1 ); last = curNode.getAttribute( 'revid' ); break; } 			}			curNode = curNode.nextSibling; }

if( last == null ) { Status.error( [ 'No previous revision found, or ', user, ' is only contributor ' ] ); return; }

var query = { 'title': wgPageName, 'oldid': last, 'diff': rev };

window.location = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( query );

};	dataXML.send( null );

}