Also listen for keyup on Find a soldier suggestions
Fix OCR/photo upload: use postWithToken multipart (MW 1.43 has no postWithFormData)
Line 975: Line 975:
var api = new mw.Api();
var api = new mw.Api();
var fileText = (isDoc ? 'Document' : 'Portrait') + ' for [[' + pageTitle + ']].';
var fileText = (isDoc ? 'Document' : 'Portrait') + ' for [[' + pageTitle + ']].';
api.postWithFormData('csrf', {
api.postWithToken('csrf', {
action: 'upload',
action: 'upload',
filename: file.name,
filename: file.name,
Line 981: Line 981:
comment: 'Uploaded from soldier page',
comment: 'Uploaded from soldier page',
text: fileText,
text: fileText,
format: 'json'
format: 'json',
ignorewarnings: true
}, {
contentType: 'multipart/form-data'
}).then(function (data) {
}).then(function (data) {
var uploaded = data.upload && data.upload.filename;
var uploaded = data.upload && data.upload.filename;
Line 1,312: Line 1,315:
function ocrPost(params, formData) {
function ocrPost(params, formData) {
if (formData) {
if (formData) {
return api().postWithFormData('csrf', formData).then(function (data) {
return api().postWithToken('csrf', formData, {
contentType: 'multipart/form-data'
}).then(function (data) {
return data.ritchieocr || data;
return data.ritchieocr || data;
});
});
Line 1,529: Line 1,534:
ocrPost(null, fd).then(function (resp) {
ocrPost(null, fd).then(function (resp) {
var job = (resp.job || resp);
var job = (resp.job || resp);
if (!job || !job.id) {
$host.empty().append($('<p>').text('OCR upload failed: no job id returned.'));
return;
}
pollJob($host, job.id, cfg);
pollJob($host, job.id, cfg);
}).catch(function (err) {
}).catch(function (err) {
$host.empty().append($('<p>').text(String(err && err.error && err.error.info || err)));
var msg = err;
if (err && err.error && err.error.info) {
msg = err.error.info;
} else if (typeof err === 'string') {
msg = err;
} else if (err && err.message) {
msg = err.message;
} else {
try {
msg = JSON.stringify(err);
} catch (e) {
msg = String(err);
}
}
$host.empty().append($('<p>').text('OCR upload failed: ' + msg));
});
});
}
}