Diferencia entre revisiones de «MediaWiki:Common.js»
De WikiCAAD
Línea 19: | Línea 19: | ||
const pageName = 'Noticia:' + cleanTitle; | const pageName = 'Noticia:' + cleanTitle; | ||
const | // Build preload wikitext safely | ||
`{{NoticiaMeta|fecha=${date}}} | const preloadWikitext = [ | ||
); | `{{NoticiaMeta|fecha=${date}}}`, | ||
'', | |||
`== ${rawTitle} ==`, | |||
'', | |||
'Escribe aquí el contenido de la noticia.' | |||
].join('\n'); | |||
const | // Build final URL | ||
action | const editUrl = mw.util.getUrl(pageName) + | ||
preloadtext | '?action=edit' + | ||
veaction | '&preloadtext=' + encodeURIComponent(preloadWikitext) + | ||
'&veaction=edit'; | |||
window.location.href = | window.location.href = editUrl; | ||
}); | }); | ||
}); | }); | ||
}); | }); |
Revisión del 13:49 6 jul 2025
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;
});
});
});