Diferencia entre revisiones de «MediaWiki:Common.js»
Ir a la navegación
Ir a la búsqueda
Portada: contador temático y resumen de la última publicación mediante consultas públicas locales; sin cambios de permisos. |
Ajustar enlace de lectura del bloque de última publicación. |
||
| Línea 35: | Línea 35: | ||
titleNode.replaceChildren(link); | titleNode.replaceChildren(link); | ||
document.getElementById('h-latest-summary').textContent = summary; | document.getElementById('h-latest-summary').textContent = summary; | ||
document. | document.querySelector('#h-latest-link a').href = mw.util.getUrl(page.title); | ||
document.getElementById('h-latest-date').textContent = 'Publicado el ' + new Intl.DateTimeFormat('es-ES',{timeZone:'Europe/Madrid',day:'numeric',month:'long',year:'numeric'}).format(new Date(latest.timestamp)); | document.getElementById('h-latest-date').textContent = 'Publicado el ' + new Intl.DateTimeFormat('es-ES',{timeZone:'Europe/Madrid',day:'numeric',month:'long',year:'numeric'}).format(new Date(latest.timestamp)); | ||
}); | }); | ||
Revisión actual - 02:36 7 nov 2026
/* Cualquier código JavaScript escrito aquí se cargará para todos los usuarios en cada carga de página */
/* Humanitas: portada dinámica. Solo lecturas de la API local. */
(function () {
'use strict';
if (mw.config.get('wgPageName') !== 'Portada' || mw.config.get('wgAction') !== 'view') return;
mw.loader.using(['mediawiki.api', 'mediawiki.util']).then(function () {
jQuery(function () {
var countNode = document.getElementById('h-article-count');
if (!countNode) return;
var api = new mw.Api();
var excluded = ['Portada','Portada/pt','Página principal','Categorías','La Bulería','Perfiles verificados'];
var pages = [], changes = [];
function eligible(p) { return excluded.indexOf(p.title) === -1; }
function load(next) {
var params = {action:'query',formatversion:2,list:'allpages|recentchanges',apnamespace:0,apfilterredir:'nonredirects',aplimit:500,rcnamespace:0,rctype:'new',rcprop:'title|timestamp|ids',rclimit:50};
if (next) { params.apcontinue = next; }
return api.get(params).then(function(data) {
if (!data.query || !data.query.allpages) throw new Error('Sin inventario');
pages = pages.concat(data.query.allpages.filter(eligible));
if (!changes.length) changes = data.query.recentchanges || [];
if (data.continue && data.continue.apcontinue) return load(data.continue.apcontinue);
countNode.textContent = pages.length.toLocaleString('es-ES');
document.getElementById('h-count-note').textContent = 'Artículos temáticos · recuento automático';
var latest = changes.find(function(c) { return pages.some(function(p) { return p.pageid === c.pageid; }); });
if (!latest) return;
return api.get({action:'query',formatversion:2,prop:'extracts',pageids:latest.pageid,exintro:1,explaintext:1}).then(function(result) {
var page = result.query && result.query.pages && result.query.pages[0];
if (!page || page.missing) return;
var paragraphs = (page.extract || '').split(/\n+/).map(function(p){return p.trim();}).filter(function(p){return p.length > 75 && !/Actualización:|Preparación asistida|Revisión humana|Comprobación documental|Sin firma personal/.test(p);});
var summary = paragraphs[0] || 'Consulta la introducción, las fuentes y el estado editorial en el artículo.';
if (summary.length > 650) summary = summary.slice(0,647).replace(/\s+\S*$/, '') + '…';
var titleNode = document.getElementById('h-latest-title');
var link = document.createElement('a'); link.href = mw.util.getUrl(page.title); link.textContent = page.title;
titleNode.replaceChildren(link);
document.getElementById('h-latest-summary').textContent = summary;
document.querySelector('#h-latest-link a').href = mw.util.getUrl(page.title);
document.getElementById('h-latest-date').textContent = 'Publicado el ' + new Intl.DateTimeFormat('es-ES',{timeZone:'Europe/Madrid',day:'numeric',month:'long',year:'numeric'}).format(new Date(latest.timestamp));
});
});
}
load().catch(function () {
document.getElementById('h-count-note').textContent = 'Recuento de referencia: 7 de noviembre de 2026. Consulta el índice actualizado.';
});
});
});
}());