MediaWiki:Gadget-BulkUpload/Runtime.js
From Nookipedia, the Animal Crossing wiki
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
(function() {
"use strict";
document.title = "Bulk upload form - Animal Crossing Wiki - Nookipedia";
$('#firstHeading').html('Bulk upload form');
$('#bodyContent').empty();
$('#bodyContent').append('<p>Use this form to upload multiple files at once. Filenames are kept as-is and all files will have the same information. To cancel an upload that is in progress, simply navigate away from this page.</p>');
var htmlUploadForm = `<fieldset>
<legend>Files and info</legend>
<label for="bulkUploadFiles">Select files:</label><br>
<input type="file" id="bulkUploadFiles" multiple/><br><br>
<label for="bulkUploadInfo">File description</legend><br>
<textarea id="bulkUploadInfo" cols="80" rows="12">
== Summary ==
{{File Info
|description = Describe the file (THIS IS NOT OPTIONAL)
|source = Where you found the file (THIS IS NOT OPTIONAL)
|edits = Describe any edits made (if applicable)
|other-versions = Link to similar version(s) (if applicable)
|source-file-name = Name of the original source file (if applicable)
}}
== Licensing ==
{{Fair use}}
</textarea><br><br>
<input type="checkbox" id="bulkUploadIgnoreWarnings"><label for="bulkUploadIgnoreWarnings">Ignore warnings (check to override existing files)</label><br><br>
<button id="bulkUploadButton" type="button">Upload files</button>
</fieldset>
<br>
<fieldset>
<legend>Upload status</legend>
<span id="bulkUploadStatus">Waiting for user to start upload.</span>
</fieldset>
`;
$('#bodyContent').append(htmlUploadForm);
document.getElementById('bulkUploadButton').addEventListener("click", function () {
const api = new mw.Api();
var completed = 0;
document.getElementById('bulkUploadButton').disabled = true;
$('#bulkUploadStatus').empty();
var files = $('#bulkUploadFiles')[0].files;
for (var i = 0; i < files.length; i++) {
var file = files[i];
var uploadParams = {};
if($('#bulkUploadIgnoreWarnings').is(':checked')) {
uploadParams = {
filename: file.name,
text: $('#bulkUploadInfo').val(),
ignorewarnings: "yes",
format: "json"
};
} else {
uploadParams = {
filename: file.name,
text: $('#bulkUploadInfo').val(),
format: "json"
};
}
api.upload(file, Object.freeze(uploadParams)).always( (response) => {
JSON.stringify(response);
console.log(response);
completed++;
if (response.hasOwnProperty('upload')) {
$('#bulkUploadStatus').append('Upload succeeded for ' + file.name + ' (' + completed + ' out of ' + files.length + ')<br>');
} else {
$('#bulkUploadStatus').append('Upload failed for ' + file.name + ' (' + completed + ' out of ' + files.length + ')<br>');
}
if (completed == files.length) {
$('#bulkUploadStatus').append('<span style="color: green;">Done!</span>');
document.getElementById('bulkUploadButton').disabled = false;
}
});
}
});
})();