MediaWiki:Common.js

De WikiCAAD

Nota: Después de publicar, quizás necesite actualizar la caché de su navegador para ver los cambios.

  • Firefox/Safari: Mantenga presionada la tecla Shift mientras pulsa el botón Actualizar, o presiona Ctrl+F5 o Ctrl+R (⌘+R en Mac)
  • Google Chrome: presione Ctrl+Shift+R (⌘+Shift+R en Mac)
  • Edge: mantenga presionada Ctrl mientras pulsa Actualizar, o presione Ctrl+F5
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;

      const preloadContent = encodeURIComponent(
        `{{NoticiaMeta|fecha=${date}}}\n\n== ${rawTitle} ==\n\nEscribe aquí el contenido de la noticia.`
      );

      const url = mw.util.getUrl(pageName, {
        action: 'edit',
        preloadtext: preloadContent,
        veaction: 'edit'
      });

      window.location.href = url;
    });
  });
});