User:NintendoSoul/global.js

// ');           $('#go').html(i18n.uploadfiles);        },        handleFileSelect: function  {            input = document.getElementById('fileinput');            if (!input.files) {                alert(i18n.browsersupport);                $('#fileinput').attr("disabled", false);            } else if (!input.files[0]) {                alert(i18n.problem);                $('#fileinput').attr("disabled", false);            } else {                $('fieldset').attr('disabled', 'disabled');                $('#go').attr('disabled', 'disabled');                var numberfiles = $('fieldset').length - 1;                if (numberfiles > 0) {                    for (i = 0; i < numberfiles; i++) {                        file = input.files[i];                        filename = $('.imagename').eq(i).val || input.files[i].name;                        console.log(filename);                        if ($('#WikiaArticle').find('select:eq(' + i + ')').find('option:selected').val !== "none") { licence = '' + '\n' + $('#UploadDescription').val; } else { licence = $('#UploadDescription').val; }                       console.log(licence); $('#loading' + (i + 1)).css('display', 'initial'); MultiUpload.uploadfiles(file, filename, licence); }                   alert(i18n.success); $('#go').html(i18n.reset); $('#go').removeAttr('disabled'); $('#go').click(function (event) {                       if ($('#go').html == i18n.reset) {                        event.stopPropagation;                        $('#WikiaArticle').find('*').attr("disabled", false);                        $('#editor').html();                        $('#editor').css('display', 'none');                        $('#go').html(i18n.update);                        $('#fileinput').val();                        }                    }); }           }        },        uploadfiles: function (fileToUpload, fileName, licence) { var lFileName = fileName; formdata = new FormData; //see https://developer.mozilla.org/en-US/docs/Web/Guide/Using_FormData_Objects?redirectlocale=en-US&redirectslug=Web%2FAPI%2FFormData%2FUsing_FormData_Objects formdata.append('action', 'upload'); formdata.append('filename', lFileName); formdata.append('token', mw.user.tokens.get('editToken')); formdata.append('file', fileToUpload); formdata.append('text', licence); formdata.append('format', 'json'); //as we now have created the data to send, we send it... $.ajax({ //http://stackoverflow.com/questions/6974684/how-to-send-formdata-objects-with-ajax-requests-in-jquery               url: mw.util.wikiScript('api'), //url to api.php                 contentType: false,                processData: false,                type: 'POST',                data: formdata, //the formdata object we created above                dataType: 'json',                async: false,                success: function (data) {                    //        console.log(data);                    if (data.upload.result == 'Warning') {                        if (data.upload.warnings.hasOwnProperty('duplicate')) {                            //if file is a duplicate, we use the name of the first existing file                            lFileName = data.upload.warnings.duplicate[0];                            alert(i18n.duplicate + lFileName);                            MultiUpload.uploadfinished(false); } else if (data.upload.warnings.hasOwnProperty('exists')) { lFileName = prompt(i18n.alreadyname, lFileName); if (lFileName != null) { lFileName = MultiUpload.uploadfiles(fileToUpload, lFileName, licence); } else { MultiUpload.uploadfinished(false); }                       }                    } else { MultiUpload.uploadfinished(true); }               },                error: function (xhr, status, error) { alert(error); MultiUpload.uploadfinished(false); }           });        },        uploadfinished: function (result) {            if (result) {                $('#loading' + (i + 1) + ' > img').attr('src', 'http://vignette4.wikia.nocookie.net/guigui/images/e/ef/Success.png/revision/latest?cb=20141230103851&path-prefix=fr');            } else {                $('#loading' + (i + 1) + ' > img').attr('src', 'http://vignette1.wikia.nocookie.net/guigui/images/8/8a/Problem.png/revision/latest?cb=20141230110222&path-prefix=fr');            }        }    };    $('#WikiaArticle').on("click", "#go", function  { MultiUpload.update; });   MultiUpload.init; // Start script })(jQuery); //