|
|
Línea 1: |
Línea 1: |
| /* ===== MEDIAWIKI COMMON.JS - PANEL CON EXTENSIÓN CHART ===== */ | | /* ===== MEDIAWIKI COMMON.JS - PANEL ===== */ |
| $(function() {
| | // Cargar estadísticas del sitio |
| // 1. Sistema básico de avatares
| | function loadAdminStats() { |
| if (mw.config.exists('wgUserAvatar')) {
| | // Estadísticas básicas |
| var avatarUrl = mw.util.getUrl('File:' + mw.config.get('wgUserAvatar'), {
| |
| width: 24
| |
| });
| |
| $('#pt-userpage, .mw-userlink').prepend(
| |
| $('<img>').addClass('user-avatar').attr('src', avatarUrl)
| |
| );
| |
| }
| |
| | |
| // 2. Panel de administración (solo para admins)
| |
| if (mw.config.get('wgUserGroups').includes('sysop')) {
| |
| initAdminPanel();
| |
| }
| |
| | |
| // 3. Cargar recursos necesarios
| |
| loadRequiredResources();
| |
| });
| |
| | |
| /* ===== FUNCIONES PRINCIPALES ===== */
| |
| function initAdminPanel() {
| |
| // Añadir enlace al panel
| |
| mw.util.addPortletLink(
| |
| 'p-tb',
| |
| mw.util.getUrl('Special:Analytics'),
| |
| '<i class="fas fa-chart-pie"></i> Panel',
| |
| 't-adminpanel',
| |
| 'Panel de administración'
| |
| );
| |
| | |
| // Mejorar dashboard de Analytics
| |
| if (mw.config.get('wgCanonicalSpecialPageName') === 'Analytics') {
| |
| enhanceAnalyticsDashboard();
| |
| }
| |
| | |
| // Cargar estadísticas
| |
| loadChartStats();
| |
| }
| |
| | |
| /* ===== IMPLEMENTACIÓN CON EXTENSIÓN CHART ===== */
| |
| function enhanceAnalyticsDashboard() { | |
| // 1. Crear contenedores para gráficos | |
| $('#mw-content-text').prepend(
| |
| '<div class="chart-grid">' +
| |
| '<div class="chart-container" id="edits-chart"></div>' +
| |
| '<div class="chart-container" id="users-chart"></div>' +
| |
| '<div class="chart-container" id="pages-chart"></div>' +
| |
| '</div>'
| |
| );
| |
| | |
| // 2. Cargar gráficos
| |
| loadChart('edits-chart', 'Data:EditsChart.json');
| |
| loadChart('users-chart', 'Data:UsersChart.json');
| |
| loadChart('pages-chart', 'Data:PagesChart.json');
| |
| | |
| // 3. Añadir controles
| |
| addChartControls();
| |
| }
| |
| | |
| function loadChart(containerId, chartDefinition) {
| |
| $.get(mw.util.wikiScript('api'), { | | $.get(mw.util.wikiScript('api'), { |
| action: 'parse', | | action: 'query', |
| text: '{{#chart:' + chartDefinition + '}}', | | meta: 'siteinfo', |
| prop: 'text', | | siprop: 'statistics', |
| format: 'json' | | format: 'json' |
| }).done(function(data) { | | }).done(function(data) { |
| $('#' + containerId).html(data.parse.text['*']); | | $('#stat-pages').text(data.query.statistics.pages.toLocaleString()); |
| });
| | $('#stat-users').text(data.query.statistics.users.toLocaleString()); |
| }
| | $('#stat-edits').text(data.query.statistics.edits.toLocaleString()); |
| | |
| function addChartControls() {
| |
| var controls = [
| |
| { id: 'day', text: 'Últimas 24h' }, | |
| { id: 'week', text: 'Última semana' },
| |
| { id: 'month', text: 'Último mes' }
| |
| ];
| |
| | |
| var $controls = $('<div class="chart-time-controls"></div>');
| |
|
| |
| controls.forEach(function(control) {
| |
| $controls.append( | |
| '<button class="time-period-btn" data-period="' + control.id + '">' +
| |
| control.text + '</button>'
| |
| );
| |
| }); | | }); |
|
| |
|
| $('.chart-grid').before($controls); | | // Cambios recientes |
| | | $.get(mw.util.wikiScript('api'), { |
| $('.time-period-btn').on('click', function() {
| | action: 'query', |
| var period = $(this).data('period'); | | list: 'recentchanges', |
| updateAllCharts(period);
| | rclimit: 1, |
| | format: 'json' |
| | }).done(function(data) { |
| | $('#stat-recent-changes').text(data.query.recentchanges.length); |
| }); | | }); |
| } | | } |
|
| |
|
| function updateAllCharts(period) {
| | // Tooltips para iconos |
| // Actualizar cada gráfico con el nuevo período
| | $(document).on('mouseenter', '.admin-links-item i', function() { |
| $('.chart-container').each(function() {
| | $(this).parent().attr('title', $(this).parent().text().trim()); |
| var $container = $(this);
| | }); |
| var chartDef = $container.data('chart-def') + '?period=' + period;
| |
| loadChart($container.attr('id'), chartDef);
| |
| });
| |
| }
| |
| | |
| /* ===== FUNCIONES AUXILIARES ===== */
| |
| function loadRequiredResources() {
| |
| // Cargar FontAwesome si no está presente
| |
| if (!$('link[href*="font-awesome"]').length) {
| |
| $('head').append(
| |
| '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">'
| |
| );
| |
| }
| |
|
| |
|
| // Estilos para los gráficos
| | // Cargar FontAwesome si no está presente |
| | if (!$('link[href*="font-awesome"]').length) { |
| $('head').append( | | $('head').append( |
| '<style>' + | | '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">' |
| '.chart-grid {' +
| |
| ' display: grid;' +
| |
| ' grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));' +
| |
| ' gap: 20px;' +
| |
| ' margin: 20px 0;' +
| |
| '}' +
| |
| '.chart-container {' +
| |
| ' background: white;' +
| |
| ' border-radius: 8px;' +
| |
| ' padding: 15px;' +
| |
| ' box-shadow: 0 2px 5px rgba(0,0,0,0.1);' +
| |
| '}' +
| |
| '.chart-time-controls {' +
| |
| ' text-align: center;' +
| |
| ' margin: 15px 0;' +
| |
| '}' +
| |
| '.time-period-btn {' +
| |
| ' background: #f8f9fa;' +
| |
| ' border: 1px solid #a2a9b1;' +
| |
| ' padding: 5px 10px;' +
| |
| ' margin: 0 5px;' +
| |
| ' border-radius: 4px;' +
| |
| ' cursor: pointer;' +
| |
| '}' +
| |
| '.time-period-btn:hover {' +
| |
| ' background: #eaecf0;' +
| |
| '}' +
| |
| '</style>'
| |
| ); | | ); |
| } | | } |
|
| |
| /* ===== EJEMPLOS DE DEFINICIÓN DE GRÁFICOS ===== */
| |
| // Estos serían guardados en páginas de datos como Data:EditsChart.json
| |
| /*
| |
| {
| |
| "license": "CC0-1.0",
| |
| "version": 1,
| |
| "source": "Data:EditStats.tab",
| |
| "type": "line",
| |
| "title": {
| |
| "en": "Ediciones por hora",
| |
| "es": "Ediciones por hora"
| |
| },
| |
| "xAxis": {
| |
| "title": {"en": "Hora", "es": "Hora"},
| |
| "format": "time"
| |
| },
| |
| "yAxis": {
| |
| "title": {"en": "Ediciones", "es": "Ediciones"},
| |
| "format": "number"
| |
| }
| |
| }
| |
| */
| |
|
| |
| /*
| |
| {
| |
| "license": "CC0-1.0",
| |
| "version": 1,
| |
| "source": "Data:UserStats.tab",
| |
| "type": "bar",
| |
| "title": {
| |
| "en": "Usuarios activos",
| |
| "es": "Usuarios activos"
| |
| },
| |
| "xAxis": {
| |
| "title": {"en": "Día", "es": "Día"},
| |
| "format": "date"
| |
| },
| |
| "yAxis": {
| |
| "title": {"en": "Usuarios", "es": "Usuarios"},
| |
| "format": "number"
| |
| }
| |
| }
| |
| */
| |
/* ===== MEDIAWIKI COMMON.JS - PANEL ===== */
// Cargar estadísticas del sitio
function loadAdminStats() {
// Estadísticas básicas
$.get(mw.util.wikiScript('api'), {
action: 'query',
meta: 'siteinfo',
siprop: 'statistics',
format: 'json'
}).done(function(data) {
$('#stat-pages').text(data.query.statistics.pages.toLocaleString());
$('#stat-users').text(data.query.statistics.users.toLocaleString());
$('#stat-edits').text(data.query.statistics.edits.toLocaleString());
});
// Cambios recientes
$.get(mw.util.wikiScript('api'), {
action: 'query',
list: 'recentchanges',
rclimit: 1,
format: 'json'
}).done(function(data) {
$('#stat-recent-changes').text(data.query.recentchanges.length);
});
}
// Tooltips para iconos
$(document).on('mouseenter', '.admin-links-item i', function() {
$(this).parent().attr('title', $(this).parent().text().trim());
});
// Cargar FontAwesome si no está presente
if (!$('link[href*="font-awesome"]').length) {
$('head').append(
'<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">'
);
}