Extension:MultimediaViewer/Extension:Metadata

This is an extension-extension meant to be run as javascript on any given MediaWiki page. I put mine in User:MarkTraceur/common.js, for example.

It will add a metadata API call link to the media viewer tool. Useful for development, mostly.

NOTE: This is a Bad Idea™, do not do this if you want your code to run in the long-term. We will be coming out with an extension framework later on.

function messWithInternalClasses() {
	var oldLinks = mw.mmv.ui.MetadataPanel.prototype.initializeImageLinks,
		oldSet = mw.mmv.ui.MetadataPanel.prototype.setImageInfo,
		oldEmpty = mw.mmv.ui.MetadataPanel.prototype.empty;

	mw.mmv.ui.MetadataPanel.prototype.initializeImageLinks = function () {
		oldLinks.call( this );

		this.$metadataLi = $( '<li>' )
			.addClass( 'mw-mmv-extension-metadata-li empty' )
			.appendTo( this.$imageLinks );

		this.$metadata = $( '<a>' )
			.addClass( 'mw-mmv-extension-metadata' )
			.text( 'Metadata API call' )
			.appendTo( this.$metadataLi );
	};

	mw.mmv.ui.MetadataPanel.prototype.setImageInfo = function ( image, imageData, repoData, localUsage, globalUsage, user ) {
		var metadataHref;

		oldSet.call( this, image, imageData, repoData, localUsage, globalUsage, user );

		metadataHref = mw.util.wikiScript( 'api' ) + '?action=query&format=json&prop=imageinfo&iiprop=timestamp|user|url|size|mime|mediatype|extmetadata&iiextmetadatafilter=DateTime|DateTimeOriginal|ImageDescription|License|LicenseShortName|UsageTerms|LicenseUrl|Credit|Artist|GPSLatitude|GPSLongitude|Categories|Permission&iiextmetadatalanguage=en&titles=' + encodeURIComponent( image.filePageTitle.getPrefixedDb() );

		this.$metadata.prop( 'href', metadataHref );

		this.$metadataLi.removeClass( 'empty' );
	};

	mw.mmv.ui.MetadataPanel.prototype.empty = function () {
		oldEmpty.call( this );

		this.$metadata.prop( 'href', null );
		this.$metadata.addClass( 'empty' );
	};
}

if ( mw.mmv ) {
	mw.loader.using( 'mmv.ui.metadataPanel', function () {
		messWithInternalClasses();
	} );
}