User:MarkTraceur/editPageUploadTool.js

( function ( mw ) {	if ( mw.config.get( 'wgAction' ) !== 'edit' ) {		return; // This is an edit page only gadget.	}

mw.loader.using( [ 'ext.wikiEditor' ], function {		window.setTimeout( function  { var dialogReady = $.Deferred, ready = $.when( dialogReady, mw.loader.using( [ 'oojs', 'oojs-ui' ] ) ), $link = $( 'a[rel=file]' ) .clone .detach .attr( {					title: 'Upload file',					href: '#'				} ) .appendTo( '.group-insert' ), working = false, script = importScript( 'User:MarkTraceur/commonsUploadForEditDialog.js' ); script.addEventListener( 'load', function {			dialogReady.resolve;		} ); $link.click( function {			if ( working ) {				return false;			}			ready.done( function  { var dialog = new mw.CommonsUploadForEditDialog( {} ), windowManager = new OO.ui.WindowManager; $( 'body' ).append( windowManager.$element ); windowManager.addWindows( [ dialog ] ); windowManager.openWindow( dialog ); dialog.on( 'upload-complete', function ( upload ) {					var selection = $( '#wpTextbox1' ).textSelection( 'encapsulateSelection', { replace: true, pre: '' } );				} ); } );			return false;		} ); }, 1000 );	} ); }( mediaWiki ) );