User:Tgr/common.js

From Wikipedia, the free encyclopedia
Template:Script doc autoNote: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: hold down the Ctrl key and click the Refresh or Reload button. Firefox: hold down the Shift key while clicking Reload (or press Ctrl-Shift-R). Google Chrome and Safari users can just click the Reload button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
$.when( mw.loader.using( [ 'mediawiki.util', 'mediawiki.Uri' ] ), $.ready ).then( function () {
	// CommonsMetadata convenience link
	if ( mw.config.get( 'wgNamespaceNumber' ) === mw.config.get( 'wgNamespaceIds' ).file ) {
		var CMDLink = new mw.Uri( mw.util.wikiScript( 'api' ) ).extend( {
			action: 'query',
			titles: mw.config.get( 'wgPageName' ),
			prop: 'imageinfo',
			iiprop: 'extmetadata',
			iiextmetadatamultilang: 0,
			format: 'jsonfm'
		} ).toString();
		mw.util.addPortletLink( 'p-tb', CMDLink, 'CMD metadata', 't-cmd', 'Extended metadata via CommonsMetadata', null, null );
	}

	// trigger bugs on demand
	mw.util.addPortletLink( 'p-tb', '#makeError', 'make JS error', 't-makeError', 'Generate a JS error', null, null );
	$( '#t-makeError' ).click( function ( e ) {
		throw 'Error';
	} );
} );