User:Gilben/global.js

(function($) {   // Don't load twice..    if (window.MultiUploadLoaded) {        return;    }    window.MultiUploadLoaded = true;    function init(i18n) {        var MultiUpload = {            init: function {                $('#my-tools-menu').prepend( $('', {                       class: 'custom'                    }).append(                        $('', { href: mw.util.getUrl('Special:BlankPage', {                               blankspecial: 'MultiUpload'                            }), text: i18n.msg('title').plain })                   )                );                if (mw.config.get('wgCanonicalSpecialPageName') === 'Blankpage' && $.getUrlVar('blankspecial') === 'MultiUpload') {                    if (wgUserName === null || !$.inArray('autoconfirmed', wgUserGroups)) { /* If the user don't have multiple upload rights (if it's not autoconfirmed) */                        $('#mw-content-text').html(i18n.msg('logout').plain);                        return false;                    }                    var MultiUploadoption = window.MultiUploadoption || {};                    $.extend(MultiUpload, MultiUploadoption);                    $('#mw-content-text').remove;                    $('#WikiaArticle').append('\n Ici \n ' + i18n.msg('update').plain + ' ');                    $('#editor').css('display', 'none'); var token = mw.user.tokens.get('editToken'); $('.page-header__title').text(i18n.msg('title').plain); document.title = i18n.msg('title').plain; var filename; }           },            updatelicensebutton: function(licencestext) { if (licencestext !== null) { var licences = licencestext.trim.split('\n'); $('.licence').replaceWith(' '); $('.licence').prepend(' ' + i18n.msg('nolicence').plain + ' '); for (i = 0; i < licences.length; i++) { if (licences[i].indexOf('** ') === 0) { licences[i] = licences[i].replace("** ", ""); if (licences[i].split('|')[0] == MultiUpload.defaultlicence) { $('.licence').find('optgroup:last-child').append('' + licences[i].split('|')[1] + ' '); } else { $('.licence').find('optgroup:last-child').append('' + licences[i].split('|')[1] + ' '); }                       } else { licences[i] = licences[i].replace('* ', ''); $('.licence').append('</optgroup'); }                   }                }            },            getlicence: function { $.ajax({                   type: "GET",                    url: wgServer + '/api.php?action=query&meta=allmessages&ammessages=Licenses&format=json',                    success: function(data) {                        var content = data.query.allmessages[0]['*'];                        MultiUpload.updatelicensebutton(content);                    },                    error: function(data) {                        alert(i18n.msg('errorapi').plain + ' : ' + data.error.info);                    }                }); },           update: function { if ($('fieldset').length > 0) { MultiUpload.handleFileSelect; return false; }               $('#editor').css('display', 'block'); $('#fileinput').attr("disabled", true); input = document.getElementById('fileinput'); $('#editor').html(''); if (input.files.length === 0) { alert(i18n.msg('nofile').plain); return false; }               if (!MultiUpload.max || typeof MultiUpload.max != "number" || MultiUpload.max < 0 || MultiUpload.max > 1001) { if ($.inArray('staff', wgUserGroups) + $.inArray('helper', wgUserGroups) + $.inArray('util', wgUserGroups) + $.inArray('bot-global', wgUserGroups) > -4) { MultiUpload.max = 2000; } else if ($.inArray('bureaucrat', wgUserGroups) + $.inArray('bot', wgUserGroups) > -2) { MultiUpload.max = 4000; } else if ($.inArray('sysop', wgUserGroups) > -1) { MultiUpload.max = 4000; } else if ($.inArray('rollback', wgUserGroups) > -1) { MultiUpload.max = 3000; } else { MultiUpload.max = 2000; }               }                if (!MultiUpload.max) { alert(lng.problem); return false; }               var limit; if (MultiUpload.max < input.files.length) { limit = MultiUpload.max; } else { limit = input.files.length; }               for (i = 0; i < limit; i++) { $('#editor').append(' ' + i18n.msg('imagename').plain + (i + 1) + ' ' + i18n.msg('filename').plain + '  ' + i18n.msg('licensetext').plain + ' '); }               MultiUpload.getlicence; $('#editor').append(' ' + i18n.msg('filedescription').plain + '  '); $('#go').html(i18n.msg('uploadfiles').plain); $(' ' + i18n.msg('ignorewarnings').plain + ' ').insertAfter('#go'); },           handleFileSelect: function { input = document.getElementById('fileinput'); if (!input.files) { alert(i18n.msg('browsersupport').plain); $('#fileinput').attr("disabled", false); } else if (!input.files[0]) { alert(i18n.msg('problem').plain); $('#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 = '{' + '{' + $('#WikiaArticle').find('select:eq(' + i + ')').find('option:selected').val + '}}' + '\n' + $('#UploadDescription').val; } else { licence = $('#UploadDescription').val; }                           console.log(licence); $('#loading' + (i + 1)).css('display', 'initial'); MultiUpload.uploadfiles(file, filename, licence); }                       alert(i18n.msg('success').plain); $('#go').html(i18n.msg('reset').plain); $('#go').removeAttr('disabled'); $('#go').click(function(event) {                           if ($('#go').html == i18n.msg('reset').plain) {                                event.stopPropagation;                                $('#WikiaArticle').find('*').attr("disabled", false);                                $('#editor').html();                                $('#editor').css('display', 'none');                                $('#go').html(i18n.msg('update').plain);                                $('#fileinput').val();                            }                        }); }               }            },            uploadfiles: function(fileToUpload, fileName, licence) { var lFileName = fileName; formdata = new FormData; // see https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_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'); if ($('#ignorewarnings').prop('checked')) { formdata.append('ignorewarnings', '1'); }               // as we now have created the data to send, we send it... $.ajax({ // https://stackoverflow.com/a/8244082                   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.msg('duplicate').plain + lFileName);                                MultiUpload.uploadfinished(false); } else if (data.upload.warnings.hasOwnProperty('exists')) { lFileName = prompt(i18n.msg('alreadyname').plain, 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', 'https://vignette.wikia.nocookie.net/guigui/images/e/ef/Success.png/revision/latest?path-prefix=fr');                } else {                    $('#loading' + (i + 1) + ' > img').attr('src', 'https://vignette.wikia.nocookie.net/guigui/images/8/8a/Problem.png/revision/latest?path-prefix=fr');                }            }        };        $('#WikiaArticle').on("click", "#go", function { MultiUpload.update; });       MultiUpload.init; // Start script    }    mw.hook('dev.i18n').add(function(i18n) { i18n.loadMessages('MultiUpload').then(init); });   importArticle({ type: 'script', article: 'u:dev:MediaWiki:I18n-js/code.js' }); })(jQuery);

importArticles({   type: 'script',    articles: [        'u:dev:MediaWiki:FindAndReplace/code.js',        'u:dev:MediaWiki:MultiUpload/code.js',        'u:dev:MediaWiki:MultipleFileDelete/code.js',        'u:dev:MediaWiki:MultiUpload/code.js',        'u:dev:MediaWiki:QuickIW/code.js',        'u:dev:MediaWiki:RevertOldGlobalNav/code.js',        'u:dev:MediaWiki:UnsafeScripts/code.js',        'u:dev:MediaWiki:ViewRemoved/code.js',    ] }); /* Autplay video removal */ $(function { $('.featured-video-wrapper').remove; });