MediaWiki:Synchronizer.js

var Centralizer = {

init: function { Centralizer.makeTable; Centralizer.makeRows; },

makeTable: function { var table = $( ' ' ); var row = $( ' ' ); var headerWiki = $( ' ' ).text( 'Wiki' ); var headerLink = $( ' ' ).text( 'Link' ); var headerStatus = $( ' ' ).text( 'Status' ); row.append( headerWiki, headerLink, headerStatus ); table.append( row ); $( '#centralizer' ).html( table ); },

makeRows: function { var id = mw.config.get( 'wgWikibaseItemId' ); $.get( '//www.wikidata.org/wiki/Special:EntityData/' + id + '.json' ).done( function ( data ) {			//console.log( data );			var entities = data.entities;			var entity = entities[ id ];			var sitelinks = entity.sitelinks;

var siteData, siteName, siteURL, siteTitle, siteAPI; var link; var row, cellWiki, cellLink, cellStatus; for ( var siteID in sitelinks ) { siteData = sitelinks[ siteID ]; siteName = siteData.site; siteLink = siteData.url; siteTitle = siteData.title;

link = $( '' ).text( siteTitle ).attr( 'href', siteLink );

cellWiki = $( ' ' ).html( siteID ); cellLink = $( ' ' ).html( link ); cellStatus = $( ' ' ); row = $( ' ' ).append( cellWiki, cellLink, cellStatus ); $( '#centralizer table' ).append( row );

Centralizer.getStatus( siteData, cellStatus ); }		} );	},

getStatus: function ( siteData, cellStatus ) { var siteLink = siteData.url; var siteTitle = siteData.title; var siteAPI = siteLink.replace( /\/wiki\/.+/, '/w/api.php' ); // Hacky but efficient new mw.ForeignApi( siteAPI ).get( {			formatversion: 2,			action: 'query',			prop: 'revisions',			rvprop: 'content|timestamp',			rvslots: 'main',			titles: siteTitle		} ).done( function ( data ) {			console.log( data );			var revision = data.query.pages[0].revisions[0];			//content = revision.slots.main.content;			var timestamp = revision.timestamp;			cellStatus.html( timestamp );		} ); } };

$( Centralizer.init );