MediaWiki:Gadget-multiupload.js

mw.loader.using(['site']).then(function {	if (mw.config.get("wgPageName")!=="Special:Upload") return;		$("#mw-htmlform-source tr:first-child").addClass("regularFileSelect");	$("tr.regularFileSelect").before(' Upload multiple files:   Yes   No  ');	$("tr.regularFileSelect").after('Source files:   ');	$("input[name='wpUpload']").addClass("regularFileSelect");	$("#wpDestFile").parent.parent.addClass("regularFileSelect");	$("#bodyContent fieldset:last-child").addClass("regularFileSelect");	$("span.mw-htmlform-submit-buttons").append(''); $("input[name='multipleFiles']").change(function{		if (this.value==="Yes") {			$(".regularFileSelect").hide;			$(".multipleFileSelect").show;		}		else {			$(".regularFileSelect").show;			$(".multipleFileSelect").hide;		}	}); $("#multiFileSubmit").click(function {		files = $("#multiupload")[0].files;		if (files.length === 0) {			alert("Please select some files first.");			return false;		}		if ($("#wpLicense option:selected").val === "") {			alert("Please select a valid license first.");			return false;		}		summary = $("#wpUploadDescription").val;		if (summary !== "") summary = "== Summary ==\n"+summary;		license = "== License ==\n"+$("#wpLicense option:selected").prop("title");		text = summary + "\n" + license;		curFile = 0;		$("#firstHeading").text("Uploading files...");		$("#mw-content-text").html(" Uploaded:  Failed:  ");		function gNF {			if(curFile>files.length) {				$("#mw-content-text").append(" Done. ");				return;			}	       if(files[curFile] === undefined) {                curFile++;                gNF;                return;	        }			$.ajax({url:'/api.php',data:{action:'query',meta:'tokens',format:'json'},dataType:'json'}).done(function(data) { fd = new FormData; fd.append("action","upload"); fd.append("token",data.query.tokens.csrftoken); fd.append("filename",files[curFile].name); fd.append("file",files[curFile]); fd.append("text",text); fd.append("ignorewarnings",1); fd.append("format","json"); $.ajax({					url:'/api.php',					method:'POST',					data:fd,					cache:false,					contentType:false,					processData:false,					type:'POST'		     	}).done(function(d){		      		$("#mw-content-text > ul").append(''+d.upload.filename+'</li>');					curFile++;					gNF;		        }).fail(function(d) {		        	$("#multiUploadFailed ul").append('<li>'+files[curFile].name+'</li>');		        	$("#multiUploadFailed").show;		        	curFile++;		        	gNF;		        }); });		}		gNF;	}); });