User:Bawolff/campaignAsJson.js

Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
$( function($) {
	if ( wgNamespaceNumber === 460 && ( wgAction === 'view' || wgAction === 'submit' ) ) {
		 mw.loader.load( ['ext.eventLogging.jsonSchema', 'mediawiki.content.json']);

		var makeTable = function ( json ) {
			var api2 = new mw.Api();
			api2.get({
				action: 'parse',
				prop: 'text',
				text: json,
				contentformat: 'application/json',
				contentmodel: 'json',
				title: mw.config.get('wgPageName'),
			}).done( function (html) {
				var div = wgAction === 'view' ? '#mw-content-text' : '#wikiPreview';
				$(div).html( html.parse.text['*'] );
			});
		}
		if ( wgAction === 'view' ) {
			var api = new mw.Api();
			api.get( {
   			 	action: 'query',
    			prop: 'revisions',
		    	revids: mw.util.getParamValue('oldid') ? mw.util.getParamValue('oldid') : mw.config.get('wgCurRevisionId' ),
			    rvprop: 'content',
				indexpageids: true,
			} ).done ( function ( data ) {
				var json = data.query.pages[data.query.pageids[0]].revisions[0]['*'];
				makeTable( json );
			});
		} else {
			makeTable( $( '#wpTextbox1' )[0].value );
		}
	}
});