User:Ahecht/Scripts/FileExporter.js

Source: Wikipedia, the free encyclopedia.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*
 * 
 * This gadget adds a link from Wikipedia images to the FileImporter tool on
 * Wikimedia Commons.
 *
 * Based on: https://commons.wikimedia.org/wiki/MediaWiki:Gadget-CropTool.js
 *
 * Installation:
 * 
 * Add the following line to [[Special:MyPage/common.js]] or [[:meta:Special:MyPage/global.js]] to install:
 *    mw.loader.load( "//en.wikipedia.org/w/index.php?title=User:Ahecht/Scripts/FileExporter.js&action=raw&ctype=text/javascript" ); // Linkback: [[:en:User:Ahecht/Scripts/FileExporter.js]]
 * 
 */

(function (mw, $) {
"use strict";

if ( mw.config.get('wgNamespaceNumber') !== 6 || mw.config.get('wgAction') !== 'view' )
	return;

$(function () {

	var currentUri = new mw.Uri(),
		exportUri = new mw.Uri('//commons.wikimedia.org/wiki/Special:ImportFile');

	exportUri.extend({
		clientUrl: currentUri,
		importSource: 'FileExporter',
	});

	mw.util.addPortletLink(
		'p-views',
		exportUri.toString(),
		'Export to Commons',
		'f-export',
		'Export file to Wikimedia Commons');
});

})(mediaWiki, jQuery);