|
|
Línea 1: |
Línea 1: |
| mw.loader.using('mediawiki.util', function () { | | mw.loader.using('mediawiki.util', function () { |
| document.addEventListener('DOMContentLoaded', function () {
| | console.log("Hello, world!") |
| const button = document.getElementById('crear-noticia-boton');
| |
| if (!button) return;
| |
| | |
| button.addEventListener('click', function () {
| |
| const titleInput = document.getElementById('crear-noticia-titulo');
| |
| const dateInput = document.getElementById('crear-noticia-fecha');
| |
| | |
| const rawTitle = titleInput?.value.trim();
| |
| const date = dateInput?.value || new Date().toISOString().slice(0, 10);
| |
| | |
| if (!rawTitle) {
| |
| alert('Por favor escribe un título para la noticia.');
| |
| return;
| |
| }
| |
| | |
| const cleanTitle = rawTitle.replace(/ /g, '_').replace(/[^\wáéíóúÁÉÍÓÚñÑ0-9_-]/g, '');
| |
| const pageName = 'Noticia:' + cleanTitle;
| |
| | |
| // Build preload page URL
| |
| const preloadPage = 'Plantilla:NoticiaPreload';
| |
| | |
| // Build URL with preload page and placeholder values passed via query
| |
| const url = mw.util.getUrl(pageName) +
| |
| '?action=edit' +
| |
| '&preload=' + encodeURIComponent(preloadPage) +
| |
| '&veaction=edit' +
| |
| '&titulo=' + encodeURIComponent(rawTitle) +
| |
| '&fecha=' + encodeURIComponent(date);
| |
| | |
| window.location.href = url;
| |
| });
| |
| }); | | }); |
| });
| |
mw.loader.using('mediawiki.util', function () {
console.log("Hello, world!")
});