MediaWiki
Gadget-Upload local file.js
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
$( function() {
mw.loader.using( [ 'mediawiki.api', 'oojs-ui' ], function() {
var button = new OO.ui.ButtonWidget( {
label: 'Upload to Commons',
flags: 'progressive|primary'
} );
$( '.fullMedia' ).after( button.$element );
button.on( 'click', function() {
button.setDisabled( true );
new mw.Api().postWithToken( 'csrf', {
'action': 'upload-to-commons',
'format': 'json',
'localfilename': mw.config.get( 'wgTitle' ),
'comment': 'oauth upload with gadget',
'ignorewarnings': true,
'logtags': 'manual-remote-upload',
} ).then( function( data ) {
var imageInfo = data['upload-to-commons'].oauth.upload.imageinfo;
var a = $( '<a>' );
$(a).text( imageInfo.canonicaltitle );
$(a).attr( 'href', imageInfo.descriptionurl );
mw.notify( $(a), { title:'Upload succeeded' } );
} ).fail( function( error ) {
mw.notify( 'An error has occured, please see browser\'s log.' , { title:'Upload failed', type:'error' } );
console.log( error );
} );
} );
} );
} );