MediaWiki:SimpleBatchUploadUpgrade.js: Unterschied zwischen den Versionen
Aus FürthWiki
(Die Seite wurde neu angelegt: „if (mw.config.get('wgCanonicalSpecialPageName') === 'BatchUpload') { $(function () { const $uploadForm = $('#fileupload'); const $uploadTable = $('<table id="file-preview"><thead><tr><th>Datei</th><th>Neuer Name</th><th>Status</th></tr></thead><tbody></tbody></table>'); const $uploadButton = $('<button id="start-upload" disabled>📤 Hochladen</button>'); let fileEntries = []; // Upload-Button und Tabelle einf…“) |
Keine Bearbeitungszusammenfassung Markierung: Zurückgesetzt |
||
| Zeile 1: | Zeile 1: | ||
if (mw.config.get('wgCanonicalSpecialPageName') === 'BatchUpload') { | if (mw.config.get('wgCanonicalSpecialPageName') === 'BatchUpload') { | ||
$(function () { | $(function () { | ||
const $ | const $form = $('#fileupload'); | ||
const $ | const $preview = $('<div id="file-preview-area"><h3>📄 Dateivorschau</h3><table><thead><tr><th>Original</th><th>Neuer Name</th><th>Status</th></tr></thead><tbody></tbody></table></div>'); | ||
const $ | const $uploadBtn = $('<button>📤 Hochladen</button>').prop('disabled', true); | ||
const uploadQueue = []; | |||
$form.before($preview); | |||
$ | $preview.after($uploadBtn); | ||
$ | |||
// | // ⛔️ Verhindert automatischen Upload | ||
$ | $form.fileupload('option', 'autoUpload', false); | ||
function checkFileExists(name, callback) { | |||
function checkFileExists( | |||
$.get(mw.util.wikiScript('api'), { | $.get(mw.util.wikiScript('api'), { | ||
action: 'query', | action: 'query', | ||
format: 'json', | format: 'json', | ||
titles: 'File:' + | titles: 'File:' + name | ||
}).done(function ( | }).done(function (res) { | ||
const exists = | const exists = res.query.pages && !res.query.pages['-1']; | ||
callback(exists); | callback(exists); | ||
}); | }); | ||
} | } | ||
function updateUploadButtonState() { | |||
function | const allClear = uploadQueue.every(entry => entry.status.text() === '✅ OK'); | ||
$uploadBtn.prop('disabled', !allClear); | |||
} | } | ||
$form.on('fileuploadadd', function (e, data) { | |||
$ | data.files.forEach(file => { | ||
data.files.forEach | |||
const row = $('<tr></tr>'); | const row = $('<tr></tr>'); | ||
const input = $('<input type="text">').val( | const originalName = file.name; | ||
const status = $('<td> | const input = $('<input type="text">').val(originalName); | ||
const status = $('<td>🔍 Prüfe …</td>'); | |||
row.append($('<td>').text(originalName)); | |||
row.append($('< | row.append($('<td>').append(input)); | ||
row.append(status); | row.append(status); | ||
$ | $preview.find('tbody').append(row); | ||
const entry = { file, data, input, status, row }; | |||
uploadQueue.push(entry); | |||
// Erste Prüfung | // Erste Prüfung | ||
checkFileExists( | checkFileExists(input.val(), function (exists) { | ||
if (exists) { | if (exists) { | ||
status.text('⚠️ Existiert'); | status.text('⚠️ Existiert'); | ||
row.css('background | row.css('background', '#ffe0e0'); | ||
} else { | } else { | ||
status.text('✅ OK'); | status.text('✅ OK'); | ||
row.css('background | row.css('background', '#e0ffe0'); | ||
} | } | ||
updateUploadButtonState(); | |||
}); | }); | ||
// | // Bei Namensänderung neu prüfen | ||
input.on('input', function () { | input.on('input', function () { | ||
const newName = input.val().trim(); | |||
checkFileExists(newName, function (exists) { | |||
if (exists) { | |||
status.text('⚠️ Existiert'); | |||
row.css('background', '#ffe0e0'); | |||
} else { | |||
status.text('✅ OK'); | |||
row.css('background', '#e0ffe0'); | |||
} | |||
updateUploadButtonState(); | |||
}); | |||
}); | }); | ||
}); | }); | ||
}); | }); | ||
// Upload starten | // Upload starten | ||
$ | $uploadBtn.on('click', function (e) { | ||
e.preventDefault(); | e.preventDefault(); | ||
uploadQueue.forEach(entry => { | |||
const formData = new FormData(); | const formData = new FormData(); | ||
formData.append('file', entry.file); | formData.append('file', entry.file); | ||
formData.append('filename', entry.input.val().trim()); | formData.append('filename', entry.input.val().trim()); | ||
formData.append('token', mw.user.tokens.get('csrfToken')); | formData.append('token', mw.user.tokens.get('csrfToken')); | ||
formData.append('action', 'upload'); | formData.append('action', 'upload'); | ||
formData.append('format', 'json'); | formData.append('format', 'json'); | ||
formData.append('ignorewarnings', '1'); | formData.append('ignorewarnings', '1'); | ||
$.ajax({ | $.ajax({ | ||
| Zeile 116: | Zeile 90: | ||
processData: false, | processData: false, | ||
contentType: false, | contentType: false, | ||
success: function ( | success: function () { | ||
entry.status.text('✅ Hochgeladen'); | entry.status.text('✅ Hochgeladen'); | ||
entry.row.css('background | entry.row.css('background', '#d0f0d0'); | ||
}, | }, | ||
error: function () { | error: function () { | ||
entry.status.text('❌ Fehler'); | entry.status.text('❌ Fehler'); | ||
entry.row.css('background | entry.row.css('background', '#fdd'); | ||
} | } | ||
}); | }); | ||
Version vom 13. Juni 2025, 10:55 Uhr
if (mw.config.get('wgCanonicalSpecialPageName') === 'BatchUpload') {
$(function () {
const $form = $('#fileupload');
const $preview = $('<div id="file-preview-area"><h3>📄 Dateivorschau</h3><table><thead><tr><th>Original</th><th>Neuer Name</th><th>Status</th></tr></thead><tbody></tbody></table></div>');
const $uploadBtn = $('<button>📤 Hochladen</button>').prop('disabled', true);
const uploadQueue = [];
$form.before($preview);
$preview.after($uploadBtn);
// ⛔️ Verhindert automatischen Upload
$form.fileupload('option', 'autoUpload', false);
function checkFileExists(name, callback) {
$.get(mw.util.wikiScript('api'), {
action: 'query',
format: 'json',
titles: 'File:' + name
}).done(function (res) {
const exists = res.query.pages && !res.query.pages['-1'];
callback(exists);
});
}
function updateUploadButtonState() {
const allClear = uploadQueue.every(entry => entry.status.text() === '✅ OK');
$uploadBtn.prop('disabled', !allClear);
}
$form.on('fileuploadadd', function (e, data) {
data.files.forEach(file => {
const row = $('<tr></tr>');
const originalName = file.name;
const input = $('<input type="text">').val(originalName);
const status = $('<td>🔍 Prüfe …</td>');
row.append($('<td>').text(originalName));
row.append($('<td>').append(input));
row.append(status);
$preview.find('tbody').append(row);
const entry = { file, data, input, status, row };
uploadQueue.push(entry);
// Erste Prüfung
checkFileExists(input.val(), function (exists) {
if (exists) {
status.text('⚠️ Existiert');
row.css('background', '#ffe0e0');
} else {
status.text('✅ OK');
row.css('background', '#e0ffe0');
}
updateUploadButtonState();
});
// Bei Namensänderung neu prüfen
input.on('input', function () {
const newName = input.val().trim();
checkFileExists(newName, function (exists) {
if (exists) {
status.text('⚠️ Existiert');
row.css('background', '#ffe0e0');
} else {
status.text('✅ OK');
row.css('background', '#e0ffe0');
}
updateUploadButtonState();
});
});
});
});
// Upload starten
$uploadBtn.on('click', function (e) {
e.preventDefault();
uploadQueue.forEach(entry => {
const formData = new FormData();
formData.append('file', entry.file);
formData.append('filename', entry.input.val().trim());
formData.append('token', mw.user.tokens.get('csrfToken'));
formData.append('action', 'upload');
formData.append('format', 'json');
formData.append('ignorewarnings', '1');
$.ajax({
url: mw.util.wikiScript('api'),
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function () {
entry.status.text('✅ Hochgeladen');
entry.row.css('background', '#d0f0d0');
},
error: function () {
entry.status.text('❌ Fehler');
entry.row.css('background', '#fdd');
}
});
});
});
});
}