MediaWiki:Gadget-InformationToCOA.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.
/* global  mw, $, importScript*/
// <nowiki>
( function () {
	'use strict';
	if ( mw.config.get( 'wgNamespaceNumber' ) === 6 ) {
		$.when( mw.loader.using( [ 'mediawiki.util', 'mediawiki.Title' ] ), $.ready ).done( function () {
			$( mw.util.addPortletLink(
				'p-tb',
				'#',
				'InformationToCOA',
				't-toCoA',
				'Replace template Information with COAInformation'
			) ).on( 'click', function ( e ) {
				e.preventDefault();
				var url = 'MediaWiki:InformationToCOA.js';
				if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) === -1 ) {
					url = 'https://commons.wikimedia.org/w/index.php?title=' +
					encodeURIComponent( new mw.Title( mw.config.get( 'wgTitle' ), 6 ).toString() ) +
					'&action=edit&withJS=' + url;
					window.location = url;
				} else if ( !/\{\{COAInformation/.test( $( '#wpTextbox1' ).val() ) ) {
					importScript( url );
				}
			} ).find( 'a' ).css( 'color', '#862' );
		} );
	}
}() );
// </nowiki>