MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. */	'use strict'; var config = mw.config.get([		'wgCanonicalSpecialPageName',		'UMFBypassLicenseCheck',		'wgScriptPath',		'wgContentLanguage'	]); var msg;
 * (function($, mw) {

if (config.wgCanonicalSpecialPageName !== 'Upload') return; function init { $('#wpUploadFile').parent.parent.addClass('regularFileSelect'); $('tr.regularFileSelect').before(			' ' +				'' + msg('multiupload').escape + ' ' +				'' +					' ' +						' ' + msg('yes').escape +					'  ' +					' ' +						' ' + msg('no').escape +					' ' +				' ' +			' '		); $('tr.regularFileSelect').after(			'' +				'' + msg('sourcefiles').escape + ' ' +				' ' +			' '		); $('input[name="wpUpload"]').addClass('regularFileSelect'); $('#wpDestFile').parent.parent.addClass('regularFileSelect'); $('#wpIgnoreWarning').parent.parent.addClass('regularFileSelect'); $('input[name="wpUpload"]').after(''); $('input[name="multipleFiles"]').change(function{			if (this.value === msg('yes').plain) {				$('.regularFileSelect').hide;				$('.multipleFileSelect').show;			} else {				$('.regularFileSelect').show;				$('.multipleFileSelect').hide;			}		}); $('#multiFileSubmit').click(function {			var files = $('#multiupload')[0].files;			if (files.length === 0) {				alert(msg('nofiles').plain);				return false;			}			if ($('#wpLicense option:selected').val ===  && !config.UMFBypassLicenseCheck) {				alert(msg('nolicense').plain);				return false;			}			var comment = $('#wpUploadDescription').val;			var license = ($('#wpLicense option:selected').val === ) ?  : '\n== ' + mw.msg('license-header') + ' ==\n' + $('#wpLicense option:selected').prop('title');			var text = (comment !==  ? '== ' + mw.msg('filedesc') + ' ==\n' + comment : '') + license;			var watch = 'preferences';			if ($('#wpWatchthis').is(':checked')) watch = 'watch';			else watch = 'nochange';			var curFile = 0;			$('#firstHeading').text(msg('uploading').plain);			$('#mw-content-text').html(' ' + msg('uploaded').escape + '  ' + msg('failed').escape + '  ');			function gNF {				if(curFile>files.length) {					$('#mw-content-text').append(' ' + msg('done').escape + ' ');					return;				}				if(files[curFile] === undefined) {					curFile++;					gNF;					return;				}				var fd = new FormData;				fd.append("action","upload");				fd.append("token",mw.user.tokens.get('csrfToken'));				fd.append("filename",files[curFile].name);				fd.append("file",files[curFile]);				fd.append("comment",comment);				fd.append("text",text);				fd.append("watchlist",watch);				fd.append("ignorewarnings",1); fd.append("format","json"); $.ajax({					url: config.wgScriptPath + '/api.php',					method: 'POST',					data: fd,					cache: false,					contentType: false,					processData: false,					type: 'POST'				}).done(function(d){					if (d.error == undefined) {						$('#mw-content-text > ul').append(''+d.upload.filename+'</li>');					}					else {						$('#multiUploadFailed ul').append('<li>' + files[curFile].name + '</li>');						$('#multiUploadFailed').show;					}					curFile++;					gNF;				}).fail(function(d) {					$('#multiUploadFailed ul').append('<li>' + files[curFile].name + '</li>');					$('#multiUploadFailed').show;					curFile++;					gNF;				}); }			gNF; });	}	mw.loader.using(['mediawiki.api', 'jquery']).then(function { return new mw.Api.loadMessagesIfMissing([			'filedesc',			'license-header'		], {amlang: config.wgContentLanguage}); }).then(function { mw.hook('dev.i18n').add(function (i18n) {			i18n.loadMessages('UploadMultipleFiles').done(function (i18no) { msg = i18no.msg; init; });		});		importArticles({			type: 'script',			articles: 'u:dev:MediaWiki:I18n-js/code.js'		}); }); })(window.jQuery, window.mediaWiki);