MediaWiki:Vector.js
Note: After publishing, 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)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* All JavaScript here will be loaded for users of the Vector skin */
function addGalleryRow() {
const container = document.getElementById('gallery-builder');
const row = container.firstElementChild.cloneNode(true);
row.querySelectorAll('input').forEach(i => i.value = '');
container.appendChild(row);
}
mw.hook('pf.formSubmit').add(function () {
let gallery = '<gallery>\n';
document.querySelectorAll('.gallery-row').forEach(row => {
const image = row.querySelector('[name="gallery_image[]"]').value;
const caption = row.querySelector('[name="gallery_caption[]"]').value;
if (image) {
gallery += 'File:' + image.replace(/^File:/, '') +
(caption ? '|' + caption : '') + '\n';
}
});
gallery += '</gallery>';
document.querySelector('[name="gallery"]').value = gallery;
});