MediaWiki

Difference between revisions of "Gadget-Upload local file.js"

(Page créée avec « $( function() { mw.loader.using( [ 'mediawiki.api', 'oojs-ui' ], function() { var button = new OO.ui.ButtonWidget( { label: 'Upload to Commons', flags: '... »)
 
(Empty description)
 
Line 1: Line 1:
 +
/* ************************************************************************** */
 +
/* TITLE ******************************************************************** */
 +
// Description:
 +
// Usage:
 +
// See also: [[Help:If any]]
 +
 
$( function() {
 
$( function() {
 
   mw.loader.using( [ 'mediawiki.api', 'oojs-ui' ], function() {
 
   mw.loader.using( [ 'mediawiki.api', 'oojs-ui' ], function() {

Latest revision as of 22:06, 6 January 2022

/* ************************************************************************** */
/* TITLE ******************************************************************** */
// Description: 
// Usage: 
// See also: [[Help:If any]]

$( 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 );
      } );
    } );
  } );
} );