Fix Training materials upload: run on ready + api.upload
Clearer large-upload errors; 120 MB client check
Line 3,332: Line 3,332:
if (!DOC_EXT.test(file.name)) {
if (!DOC_EXT.test(file.name)) {
setStatus('File type not allowed (PDF, Office docs, images, TIFF).', true);
setStatus('File type not allowed (PDF, Office docs, images, TIFF).', true);
return;
}
var maxBytes = 120 * 1024 * 1024;
if (file.size > maxBytes) {
setStatus('File is too large (max about 120 MB). Split the PDF or compress it, then try again.', true);
return;
return;
}
}
Line 3,337: Line 3,342:
var note = $.trim($form.find('.camp-manual-note').val() || '');
var note = $.trim($form.find('.camp-manual-note').val() || '');
$submit.prop('disabled', true);
$submit.prop('disabled', true);
setStatus('Uploading…');
setStatus('Uploading… (large files can take a few minutes)');


var api = new mw.Api();
var api = new mw.Api();
var fileText = 'Camp Ritchie / MITC training material.\n\n[[Category:Training materials]]';
var fileText = 'Camp Ritchie / MITC training material.';
var uploadParams = {
var uploadParams = {
filename: file.name,
filename: file.name,
Line 3,350: Line 3,355:
? api.upload(file, uploadParams)
? api.upload(file, uploadParams)
: api.postWithToken('csrf', $.extend({ action: 'upload', file: file, format: 'json' }, uploadParams), {
: api.postWithToken('csrf', $.extend({ action: 'upload', file: file, format: 'json' }, uploadParams), {
contentType: 'multipart/form-data'
contentType: 'multipart/form-data',
timeout: 0
});
});
uploadPromise.then(function (data) {
uploadPromise.then(function (data) {
Line 3,363: Line 3,369:
window.location.reload();
window.location.reload();
}).fail(function (code, data) {
}).fail(function (code, data) {
var err = (data && data.error && data.error.info) || code || 'Upload failed';
var err = (data && data.error && data.error.info) ||
(data && data.exception && data.exception.message) ||
'';
if (!err || err === 'http' || err === 'error' || err === 'timeout') {
err = 'Upload failed (connection dropped or timed out). For large PDFs, wait and retry; if it keeps failing, try a smaller file or Special:Upload.';
}
setStatus(String(err), true);
setStatus(String(err), true);
$submit.prop('disabled', false);
$submit.prop('disabled', false);