User:FrenchTouch/global.js

/* Send a message to multiple users */

importArticles({   type: 'script',    articles: [        'u:dev:MediaWiki:CategoryRenameAuto-update/code.js',        'u:dev:MediaWiki:AjaxBatchDelete/code.js',        'u:dev:Message/code.js',        'u:dev:FastDelete/code.js'    ] });

/* Purge pages */

PurgeButtonText = 'Actualiser'; importScriptPage('PurgeButton/code.js', 'dev');

/* Bouton pour Message Wall Greeting */

/*jshint browser:true jquery:true laxbreak:true smarttabs:true*/ /*global mediaWiki */ // Add "Edit Greeting" button to Message Wall if (mediaWiki.config.get('wgNamespaceNumber') === 1200) { (function(window, $, mw) {	"use strict";	var messages = {		en: {			editGreeting: 'Edit Greeting',			history: 'Greeting History',			wallHistory: 'Wall History'		},		es: {			editGreeting: 'Editar Bienvenida',			history: 'Historial de la Bienvenida',			wallHistory: 'Historial del Muro'		},		hu: {			editGreeting: 'Üdvözlet szerkesztése',			history: 'Üdvözlet laptörténete',			wallHistory: 'Fal története'		},		pl: {			editGreeting: 'Edytuj powitanie',			history: 'Historia powitania',			wallHistory: 'Historia tablicy'		},               fr: {			editGreeting: 'Modifier Accueil',			history: 'Historique Accueil',			wallHistory: 'Historique du Mur'		}	};	messages = $.extend(messages.en, messages[mw.config.get('wgUserLanguage')]);	function checkSetIn(map, what) {		for (var i = 0, l = what.length ; i < l ; ++i) {			if (map[what[i]]) { return true; }		}		return false;	}	// Message Walls are always in Edit mode in Oasis. if (({view:1, edit:1})[mw.config.get('wgAction')] !== 1) { return; } // We show the button for the owning user, and for sysops. // We don't show it for anyone else since you get a permission error when trying to // access someone else's message. Why? Beats me. var user = mw.config.get('wgTitle'); // NOTE: Anons can edit their greetings as well, not going to support that though since //   I can't easily see what their IP address is to figure out if they own the wall or not. if (user !== mw.config.get('wgUserName')) { // Not self if (!checkSetIn({sysop:1, staff:1}, mw.config.get('wgUserGroups')) || // Not sysop		   user.indexOf('/') !== -1 // Archived talk page		   ) { return; }	}	function createOasis(url, wallUrl) { if ($('#EditMessageWallGreeting').length) { return; } // Double run var $button = $(window.Mustache.render( ' ' +			'' + '' + ' ' + '{' + '{editGreeting}}' + ' ' + // Whitespace is needed here for negative margin on drop to work '  ' +			'' + '{' + '{history}}' + '{' + '{wallHistory}}' + ' ', messages )).prependTo('#WikiaMainContentContainer').children; if (window.WikiaButtons && window.WikiaButtons.menuButtons) { window.WikiaButtons.add($button); }	}	function createMonobook(url) { $('#ca-edit > a').prop('href', url + '?action=edit').text(messages.editGreeting); }	mw.loader.load(['mediawiki.Title', 'wikia.mustache'], null, true); $(function {		mw.loader.using(['mediawiki.Title', 'wikia.mustache'], function { (mw.config.get('skin') === 'oasis' ? createOasis : createMonobook)(				new mw.Title(user, 1202).getUrl, // Message Wall Greeting				new mw.Title(user, 1200).getUrl // Message Wall			); });	}); })(window, jQuery, mediaWiki); } // Remove the [broken] talk page link from the Greeting page. if (mediaWiki.config.get('wgNamespaceNumber') === 1202) { jQuery(function($) { // Monobook, Oasis $('#ca-talk, .WikiaPageHeader a[data-id="comment"]').remove; }); }

/* Upload multiple files at once */ // ');           $('#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); //