User:WhoSaidThat/RevisionsUI.js

mw.loader.load( 'jquery.ui' );

function loadCompleted{

window.setInterval(checkNew,1000);

//alert(this+ ' ' + this.page +' RevisionsData object listing load complete');  // expected output = '[object] Some Page object...'

window.revisionsData=this;

var launch=$('Launch revisions UI'); launch.click(function{		$('#launchRevs').hide;		launchRevUI;		return false;	});

var l=$('#ca-talk').offset.left+$('#ca-talk').contents.width+5; var t=$('#ca-talk').offset.top+2;

//alert(t+' '+l); //expected output label coords launch.css({'position':'absolute','top':t+'px','left':l+'px','z-index':10});

$('body').append(launch);

/* //launch.insertAfter('#top'); //launch.insertAfter('#siteNotice'); //launch.insertAfter('#mw-js-message');

if($('#siteSub').length>0){ $('#siteSub').append( ' ' ); $('#siteSub').append( launch ); }else{ launch.insertAfter('#top'); }*/

}

function checkNew{

var parseWikiText=function(str){ str=str.replace(/\[\[([^\|\]]+)\|([^\]]+)\]\]/g,'$2' ); str=str.replace(/\[\[([^\]]+)\]\]/g,'$1' ); return str; }

revisionsData.checkForNewRevisions;

if(revisionsData.newerVersion){ var contrib=revisionsData.newerVersion.size-revisionsData.revisions[0].size; mw.util.jsMessage('A new version of this page is available Click here to refresh User name : '+			revisionsData.newerVersion.user		+' Size : '+revisionsData.newerVersion.size+ ' ('+ contrib +') Comment : '+		parseWikiText(revisionsData.newerVersion.comment)); }else{ //mw.util.jsMessage('Nothing to see here'); } }

function launchRevUI{

//alert('load complete '+window.revisionsData.revisions.length); //if(revisionsData.revisions.length==0) return false;

var rds=new RDSet(window.revisionsData,['last-90-days','ip','outliers']); window.revisionsObject=rds;

var g=rds.newGraph('#revHistoryGraph',$('#content').width,50); g.graphObject.plot(['contrib','size']); g.graphObject.attachMoveEvent(function(canvas, coords, time, nearest, click){

var c=canvas.getContext('2d'); c.fillStyle='#ffffff'; c.fillRect(0,0,canvas.width,canvas.height);

g.graphObject.cursorIndex=nearest.index;

g.graphObject.plot(['contrib','size']); refreshGraphInfo(nearest); });

var result=''; //rds.data.page; result += '  '; result += ' '; result += ' between' result += '  '; result += ' and  apply filter';

result += ' light medium  heavy  '; result += ' ';

$(result).insertAfter( "#firstHeading" ); $("#revInterface").append(g);

//alert('graph displayed');

$('#timeA').datepicker({'dateFormat':'dd M yy' }); $('#timeB').datepicker({'dateFormat':'dd M yy' });

var buttons='&lt; previous'; buttons += '     next &gt;</a>';

$("#revInterface").append($(' '));

$("#revInterface").append($(' '));

///// LIST

$("#revInterface").append($(' ')); $('#revListBox').dialog({'title':'Selected Revision History','autoOpen':false,	'minWidth':800,	'minHeight':350,	'maxHeight':550});

/*<h2 id="revListTitle">Selected Revision History

var closeButton=$('<a href="#"><img src="http://upload.wikimedia.org/wikipedia/en/1/18/Test-x-icon.png"/></a>'); $(closeButton).click(function{ $('#revListBox').hide; return false; }); closeButton.css({'float':'right','background-color':'blue'}); closeButton.hover(function{ $(this).css({'background-color':'red'}); },function{ $(this).css({'background-color':'blue'});} );

var miniButton=$('<a href="#">*</a>') miniButton.css({'float':'right'}); miniButton.click(function{ $('#revListBox div:last-child').toggle; return false; });

//$('#revListBox').append(' '); //$('#revListBox').append(miniButton); //$('#revListBox').append(closeButton);

//$("#revListBox").draggable({'handle':$('#revListTitle')});

if($('#siteSub').offset){ var t=$('#siteSub').offset.top+$('#siteSub').height+3; var l=$('#siteSub').offset.left+10; }else{ var t=100; var l=100; }			//$('#revListBox').css({'background-color':'white','border':'1px double black','position':'absolute','top':t+'px','left':l+'px','z-index':10});

var hideButton=$('<a href="#">Hide filtered revisions</a>'); $(hideButton).click( function{ $('#revListBox').find('tr.filtered').toggle; return false; }	); $('#revListBox').append(hideButton); $('#revListBox').append($(' '));

$('#revButtonR').click(function{				var rList=rds.newRevisionsList;				$('#revListBox div:last-child').html('');				$('#revListBox div:last-child').append(rList);				$('#revListBox').dialog('open');

});			$('#revButtonC').click(function{ $('#pieChartBox').html(''); var pc=rds.newUserPieChart($('#content').width/2); $(pc).click(function{ $(this).fadeOut; }); $(pc).hide;

if($('#siteSub').offset){ var t=$('#siteSub').offset.top+$('#siteSub').height; var l=$('#siteSub').offset.left+$('#siteSub').width; }else{ var t=100; var l=100; }				$(pc).css({'position':'absolute','top':t+'px','left':l+'px','z-index':10}); $('#pieChartBox').append(pc); $(pc).fadeIn;

});			$('#filter').change(function{ refreshGraph;

});			$('#filterType').change(function{ refreshGraph;

});			$('#timeA').change(function{ refreshGraph;

});			$('#timeB').change(function{ refreshGraph;

});

rds.loadWordAuthors;//rds.load; // load before refresh so as to preserve initial filters and reduce load burden

refreshGraph;

window.setTimeout(refreshLoading,500);

var paras = $('#bodyContent').find('p,li'); paras.each(function(i,o){		var alt=[];		$(o).contents.each(function(j,p){ if(p.nodeType==3){ var words=p.nodeValue.replace(/\u00a0/g, " ").split(' '); for(var i=0; i<words.length; i++){ var wn=words[i]; if(i>0) wn=words[i-1]+' '+wn; if(i<words.length-1) wn+=' '+words[i+1]; var s=$(' '+words[i]+' ')

s.get(0).neighbours=wn; $(s).click( clickWord );

s.hover(hoverWord, function{	$(this).css({'text-decoration':'none','cursor':null}); }); alt.push(s); } 			}else{ alt.push($(p).clone); }		});		$(o).html('');		for(var i=0; i<alt.length; i++) $(o).append(alt[i]);	});

function hoverWord{

var r=revisionsObject.findFirstOccurence(this.neighbours);

if( r.timestamp ==  revisionsObject.data.revisions[0].timestamp ) var c= 'wait'; else var c= 'help'; $(this).css({'text-decoration':'underline','cursor':c}); }

function clickWord(e){ var r=revisionsObject.findFirstOccurence(this.neighbours);

if( r.timestamp ==  revisionsObject.data.revisions[revisionsObject.data.revisions.length-1].timestamp ){ var note="Note: This is the earliest revision that has been loaded and probably doesn't represent the author of the quoted words." ;		}else{ var note="Note: The revision containing the quoted words may occur earlier than the revisions provided above if the author made consecutive edits."; }

var diffUrl = 'http://en.wikipedia.org/w/index.php?title='; diffUrl += revisionsObject.data.page.replace(/ /g,'_') + '&diff=prev&oldid=' + r.revid;

var h=' '; h += ' <a class="button" href="#" onclick="$(this.parentNode).fadeOut; return false;">&times</a> ' ; h += ' <a href="http://en.wikipedia.org/wiki/Special:Contributions/' +r.user.replace(/ /g,'_')+ '" target="_blank">'; h += r.user +' '; h += ' "&hellip; ' +this.neighbours+' &hellip;" '; h += ' <a href="' +diffUrl+ '" target="_blank">' +r.revid+ '</a> '; h += ' '+ $.datepicker.formatDate('D d MM yy',new Date(r.timestamp)) +' '; h += ' '+revisionsObject.parseWikiText(r.comment)+' '; h += ' ' +note+ ' '; h += ' ';

var info=$(h); info.draggable; info.css({'position':'absolute',			'top':e.pageY,			'left':e.pageX ,			'background-color':'white',			'padding':'0.5em',			'border':'1px solid black'});

$('body').append(info);

}

}

function refreshGraph{

var timeA=new Date($('#timeA').val);

var endTime=new Date($('#timeB').val); endTime.setHours(23); endTime.setMinutes(59); var timeB=new Date( endTime);

var rds=revisionsObject;

rds.filter(['reset','time'],timeA,timeB);

if($('#filter').prop("checked")){

switch($('#filterType').val){ case 'light': rds.filter('outliers-b',4,50); break; case 'medium': rds.filter(['outliers','mentioned']); rds.filter('outliers-b',4,50); break; case 'heavy': rds.filter(['outliers','mentioned','ip']); rds.filter('outliers-b',4,50); rds.filter(['minor','small','reverts']); break; }	}

var people=rds.countUsersInRange; var revisions=rds.countRevisions;

$('#pieChartBox').html(''); $('#revListBox').hide('');

$('#revButtonR').html( revisions +' revisions'); $('#revButtonC').html( 'contributed by ' + people + ' people');

var tRange=rds.getTimeRange;

$('#timeA').datepicker( "setDate" ,tRange.min).blur; $('#timeB').datepicker( "setDate" ,tRange.max).blur;

rds.graphs[0].plot(['contrib','size']); refreshGraphInfo;

}

function refreshGraphInfo(nearest){

var rds=revisionsObject;

if(!nearest) nearest=rds.graphs[0].data[rds.graphs[0].cursorIndex];

var contribUrl = 'http://en.wikipedia.org/wiki/Special:Contributions/'; contribUrl += nearest.user.replace(/ /g,'_') ;

var diffUrl = 'http://en.wikipedia.org/w/index.php?title='; diffUrl += revisionsObject.data.page.replace(/ /g,'_') + '&diff=prev&oldid=' + nearest.revid;

$('#graphInfoUser').html( '<a href="' +contribUrl+ '" target="_blank">' +nearest.user+ '</a>'); $('#graphInfoId').html( '<a href="' +diffUrl+ '" target="_blank">' +nearest.revid+ '</a>' ); $('#graphInfoDate').html( $.datepicker.formatDate('D d MM yy',new Date(nearest.timestamp)) ); $('#graphInfoSize').html( nearest.size+ '(' +nearest.contrib+ ')' ); $('#graphInfoComment').html(revisionsObject.parseWikiText(nearest.comment?nearest.comment:' ') );

}

function refreshLoading{

var pc=Math.round(100*revisionsObject.loading/revisionsObject.loadingTarget); $('#siteSub').html('loading '+pc+ ' %'+revisionsObject.loading+' '+revisionsObject.loadingTarget); if(pc<100) window.setTimeout(refreshLoading,500); }

/* function findWords(t){ var r=revisionsObject.findFirstOccurence(t.neighbours); alert(r.timestamp+' '+r.user); }*/