|
|
(No se muestran 5 ediciones intermedias del mismo usuario) |
Línea 1: |
Línea 1: |
| mw.loader.using('mediawiki.util', function () {
| |
| document.addEventListener('DOMContentLoaded', function () {
| |
| 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 wikitext safely
| |
| const preloadWikitext = [
| |
| `{{NoticiaMeta|fecha=${date}}}`,
| |
| '',
| |
| `== ${rawTitle} ==`,
| |
| '',
| |
| 'Escribe aquí el contenido de la noticia.'
| |
| ].join('\n');
| |
|
| |
| // Build final URL
| |
| const editUrl = mw.util.getUrl(pageName) +
| |
| '?action=edit' +
| |
| '&preloadtext=' + encodeURIComponent(preloadWikitext) +
| |
| '&veaction=edit';
| |
|
| |
| window.location.href = editUrl;
| |
| });
| |
| });
| |
| });
| |