User:Dorumin/global.js

/* Wiki-wide profile config */ var qtUserPageTemplate = ''; var qtEnableUserPageOverwrite = true;

/* AjaxRC */ window.ajaxPages = ["Blog:Recent_posts","Special:Chat","Special:WikiActivity","Special:RecentChanges","Special:Watchlist","Special:Log","Special:Log/upload","Special:Contributions"]; window.ajaxIndicator = 'http://vignette2.wikia.nocookie.net/dev/images/8/82/Facebook_throbber.gif'; window.ajaxRefresh = 30000; window.AjaxRCRefreshText = 'Auto-refresh'; window.AjaxRCRefreshHoverText = 'Automatically refresh the page';

/* Ajax BatchDelete settings */ massCategorizationDelay = 1000;

/* Modifications to the QuickDelete script */ var fdButtons = []; fdButtons[fdButtons.length] = { 'summary': 'Housekeeping', 'label': 'HK'}; $(window).load(function {   switch( wgCanonicalNamespace ) {        case 'User':        case 'User_talk':        $('.UserProfileActionButton .wikia-menu-button').css('margin-left','24px').appendTo('.UserProfileActionButton');        break;    }    $('.UserProfileActionButton .wikia-button').show; }); /* OverPowered MultiUpload script (original at w:c:dev:MultiUpload) */ (function ($) {   var i18n = {        en: {            logout: "You have to be log in and autoconfirmed to upload files",            update: "Update the form",            nofile: "You have to choose a file to upload it",            imagename: 'Image n°',            filename: 'File name : ',            licensetext: 'File license : ',            uploadfiles: 'Upload all images',            browsersupport: 'This browser doesn\'t seem to support the `files` property of file inputs.',            nolicence: 'None selected',            problem: 'A problem occured, upload cancelled',            success: 'Image uploaded successfully.',            duplicate: 'This image is a doublon of : ',            alreadyname: 'A image has already this name, please choose an other one below :',            reset: 'Reset the form',            description: 'Summary :',            filedescription: 'File description' },	es: { logout: "Debes haber iniciado sesión y estar autoconfirmado para subir archivos", update: "Actualizar el formulario", nofile: "Tienes que elegir un archivo para subirlo", imagename: 'Imagen n°', filename: 'Nombre del archivo : ', licensetext: 'Licencia del archivo : ', uploadfiles: 'Subir todas las imágenes', browsersupport: 'Este navegador no parece soportar la propiedad `files` de las entradas de archivo.', nolicence: 'Ninguna seleccionada', problem: 'Ha ocurrido un problema, subida cancelada', success: 'Imagen subida satisfactoriamente.', duplicate: 'Esta imagen es un duplicado de : ', alreadyname: 'Una imagen ya tiene este nombre, por favor escoge otro nombre debajo:', reset: 'Reiniciar el formulario', description: 'Sumario:', filedescription: 'Descripción del archivo' }   };    // UserLanguage > ContentLanguage > ENGLISH i18n = $.extend(i18n.en, i18n[mw.config.get('wgContentLanguage')], i18n[mw.config.get('wgUserLanguage')]); var MultiUpload = { init: function { $('#my-tools-menu').prepend(' Multi Upload'); 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.logout); return false; }               var MultiUploadoption = MultiUploadoption || {}; $.extend(MultiUpload, MultiUploadoption); $('#mw-content-text').remove; $('#WikiaArticle').append('\n Ici \n ' + i18n.update + ' '); $('#editor').css('display', 'none'); var token = mw.user.tokens.get('editToken'); $('.AdminDashboardArticleHeader > h1').html('Multi Upload'); var filename; }       },        updatelicensebutton: function (licencestext) { if (licencestext !== null) { var licences = licencestext.split('\n'); if (licences[licences.length - 1] === '') { licences.splice(-1, 1); //Remove last line as it is empty }               $('.licence').replaceWith('  '); $('.licence').prepend(' ' + i18n.nolicence + ' '); 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.errorapi + ' : ' + 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.nofile); return false; }           if (!MultiUpload.max || typeof MultiUpload.max != "number" || MultiUpload.max < 0 || MultiUpload.max > 101) { if ($.inArray('staff', wgUserGroups) + $.inArray('helper', wgUserGroups) + $.inArray('util', wgUserGroups) + $.inArray('bot-global', wgUserGroups) > -4) { MultiUpload.max = 200; } else if ($.inArray('bureaucrat', wgUserGroups) + $.inArray('bot', wgUserGroups) > -2) { MultiUpload.max = 70; } else if ($.inArray('sysop', wgUserGroups) > -1) { MultiUpload.max = 50; } else if ($.inArray('rollback', wgUserGroups) > -1) { MultiUpload.max = 1000; } else { MultiUpload.max = 1000; }           }            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.imagename + (i + 1) + ' ' + i18n.filename + '  ' + i18n.licensetext + ' '); }           MultiUpload.getlicence; $('#editor').append(' ' + i18n.filedescription + '  '); $('#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); //

/****************** Import scripts ******************/ importArticles({   type: 'script',    articles: [        'w:dev:MediaWiki:QuickCreateUserPage/code.js',        'u:dev:AjaxBatchDelete/code.js',        'u:dev:DupImageList/code.js',        'u:dev:ListFiles/code.js',        'u:dev:AjaxUndo/code.js',        'u:dev:AjaxRC/code.js',        'u:dev:FastDelete/code.js',        'u:dev:FindAndReplace/code.js'    ] }); /* Modification on the edit summary for QuickCreateUserPage (original at w:c:dev:QuickCreateUserPage) */ ( function( $, mw, window ) {	'use strict';	var QuickCreateUserPage = {		init: function {			var $qcLink = $( ' ' ).attr( 'id', 'quick-cup' ).html( $( '' ).attr( 'title', QuickCreateUserPage.langMsg( 'button-tooltip', true ) ) .attr( 'style', 'cursor: pointer' ).text( QuickCreateUserPage.langMsg( 'button-link-text', true ) ) .click( QuickCreateUserPage.createUserPage ) );			if ( mw.config.get( 'skin' ) === 'oasis' ) {				$( '#AccountNavigation' ).find( 'li > ul.subnav' ).prepend( $qcLink );			} else {				$( '#column-one' ).find( '#p-personal > .pBody > ul' ).prepend( $qcLink );			}		},		langConfig: {			//English			en: {				'button-link-text': 'Create user page',				'button-tooltip': 'Create your user page on this wiki automagically',				'buttontalk-link-text': 'Create user talk page',				'buttontalk-tooltip': 'Create your user talk page on this wiki automagically',				'cup-reason': 'Creating user page (bot edit)',				'cup-success-text': 'Successfully created page!',				'cup-error-exists': 'Page already exists!',				'cup-error-failed': 'Creating page failed!'			},			// Spanish			es: {					'button-link-text': 'Crear página de usuario',					'button-tooltip': 'Crea tu página de usuario en este wiki',					'buttontalk-link-text': 'Crear página de discusión', 'buttontalk-tooltip': 'Crea tu página de discusión en este wiki', 'cup-reason': 'Creando página de usuario (edicion de bot)', 'cup-success-text': '¡Página creada exitosamente!', 'cup-error-exists': '¡Ya existe la página!', 'cup-error-failed': '¡Error al crear la página!' }		},		langMsg: function ( name, userLang ) { if ( userLang && mw.config.get( 'wgUserLanguage' ) in QuickCreateUserPage.langConfig && name in QuickCreateUserPage.langConfig[mw.config.get( 'wgUserLanguage' )] ) { return QuickCreateUserPage.langConfig[mw.config.get( 'wgUserLanguage' )][name]; }			if ( !userLang && mw.config.get( 'wgContentLanguage' ) in QuickCreateUserPage.langConfig && name in QuickCreateUserPage.langConfig[mw.config.get( 'wgContentLanguage' )] ) { return QuickCreateUserPage.langConfig[mw.config.get( 'wgContentLanguage' )][name]; }			return QuickCreateUserPage.langConfig.en[name]; },		createUserPage: function { var	userPageContent = window.qtUserPageTemplate || '', pageName = 'User:' + mw.config.get( 'wgUserName' ), overwriteUserPage = window.qtEnableUserPageOverwrite || false; if ( overwriteUserPage === true ) { QuickCreateUserPage.makeEdit( pageName, userPageContent ); return; }			$.getJSON( mw.util.wikiScript( 'api' ), {				action: 'query',				prop: 'revisions',				titles: pageName,				format: 'json'			} ).done( function ( data ) {				var	pageIds = Object.keys( data.query.pages ),					pageId = pageIds[0];				if ( pageId !== '-1' ) {					QuickCreateUserPage.showResult( 'error', 'cup-error-exists' );				} else {					QuickCreateUserPage.makeEdit( pageName, userPageContent );				}			} ); },		makeEdit: function( pageName, pageContent ) { $.ajax( {				type: 'POST',				url: mw.util.wikiScript( 'api' ),				dataType: 'json',				data: {					action: 'edit',					title: pageName,					summary: QuickCreateUserPage.langMsg( 'cup-reason', false ),					text: pageContent,					format: 'json',					token: mw.user.tokens.get( 'editToken' )				}			} ).done( function ( data ) {				if ( data.edit.result === 'Success' ) {					QuickCreateUserPage.showResult( 'ok', 'cup-success-text' );				} else {					QuickCreateUserPage.showResult( 'error', 'cup-error-failed' );				}			} ).fail( function ( data ) {				QuickCreateUserPage.showResult( 'error', 'cup-error-failed' );			} ); },		showResult: function( result, message ) { var resultClass = ( result === 'error' ? 'error' : 'confirm' ); new BannerNotification( QuickCreateUserPage.langMsg( message, true ), resultClass ).show; }	};	$( QuickCreateUserPage.init ); }( jQuery, mediaWiki, this ) );