MediaWiki:RecentRelated.js

var recentRelated = { init : function { if ( mw.config.get('wgAction') != 'view' ) return ; var self = this ; var portletLink = mw.util.addPortletLink( 'p-navigation', '#', 'recentRelated','t-trcent-related'); $(portletLink).click ( function {			self.run ;			return false ;		} ) ; } ,	run : function { $('#firstHeading').text ( 'Recent changes related to edits by ' + mw.user.getName ) ; $('#bodyContent') .html ( Checking edits... ) .css ( 'background-color', '#EEEEEE' ) ; var self = this ; var url = mw.util.wikiScript('api'); $.getJSON ( url, {			action : 'query' ,			list : 'usercontribs' ,			ucuser : mw.user.getName ,			uclimit : 100 ,			ucshow : '!minor' ,			format : 'json'		} , function ( d ) {			var cont = {} ;			self.left = 0 ;			$.each ( d.query.usercontribs , function ( k , v ) { if ( undefined === cont[v.title] ) { cont[v.title] = v ; self.left++ ; } else { if ( cont[v.title].timestamp < v.timestamp ) cont[v.title] = v ; }			} ) ;			self.list = {} ;			$.each ( cont, function ( k , v ) { self.processMyEdits ( v ) ; } ) ;		} ) ;	} ,	processMyEdits : function ( o ) { var self = this ; var user = mw.user.getName ; var url = mw.util.wikiScript('api') ; $.getJSON ( url, {			action : 'query' ,			prop : 'revisions' ,			rvendid : o.revid ,			titles : o.title ,			rvprop : 'ids|timestamp|flags|comment|user' ,			rvlimit : 50 ,			format : 'json'		} , function ( d ) {			if ( undefined !== d.query.pages ) {				$.each ( d.query.pages , function ( k1 , v1 ) { if ( undefined === self.list[v1.title] ) self.list[v1.title] = [] ; $.each ( v1.revisions, function ( k2, v2 ) {						self.list[v1.title].push ( v2 ) ;						if ( v2.user == user ) return false ;					} ) ; } ) ;			self.left-- ;			if ( self.left == 0 ) self.showResults ;			}		} ) ; } ,	showResults : function { var self = this ; var user = mw.user.getName ; var parts = {} ; var keys = [] ; $.each ( self.list, function ( page , pd ) {			if ( pd.length == 1 && pd[0].user == user ) return ; // Only the user's own edits, skip			pd.sort(function(a,b){return b.timestamp.localeCompare(a.timestamp);});			var ts ;			var h = '' ;			h += " " + page + "" ;			h += " [&Delta;]" ;			h += " " ;			var k = ts ;			while ( undefined !== parts[k] ) k += 'b' ;			parts[k] = h ;			keys.push ( k ) ;		} ) ; keys.sort ( function ( a, b ) { return b.localeCompare(a); } ) ; var h = '' ; $.each ( keys, function ( dummy , key ) {			h += parts[key] ;		} ) ; $('#bodyContent').html ( h ) ; } } ;

$(recentRelated.init);