MediaWiki:Common.js: Perbedaan antara revisi
Tidak ada ringkasan suntingan Tanda: Suntingan perangkat seluler Suntingan peramban seluler |
Tidak ada ringkasan suntingan Tanda: Suntingan perangkat seluler Suntingan peramban seluler |
||
| Baris 153: | Baris 153: | ||
/* ========================================================== | /* ========================================================== | ||
🚀 MIPPEDIA DATA - CORE INTERFACE (FINAL BUNDLE) | |||
Includes: Header, Sitelink V4 (Smart API), and Footer | |||
Rules: Only Namespace 0 & NOT Main Page | |||
========================================================== */ | ========================================================== */ | ||
(function() { | (function() { | ||
$(document).ready(function() { | $(document).ready(function() { | ||
// PROTEKSI | // --- PROTEKSI GLOBAL --- | ||
if (mw.config.get('wgNamespaceNumber') !== 0 || mw.config.get('wgAction') !== 'view') return; | // 1. Harus Namespace Utama (0) | ||
// 2. Bukan Halaman Utama (Main Page) | |||
// 3. Hanya mode View (bukan edit/history) | |||
if (mw.config.get('wgNamespaceNumber') !== 0 || | |||
mw.config.get('wgIsMainPage') || | |||
mw.config.get('wgAction') !== 'view') return; | |||
var pageTitle = mw.config.get('wgPageName'); | |||
var dataPage = 'MediaWiki:Sitelinks-Data.json'; | |||
var projects = { | |||
'id': { name: 'ID', url: 'https://id.mippedia.org/api.php', base: 'https://id.mippedia.org/wiki/', color: '#6a5acd' }, | |||
'en': { name: 'EN', url: 'https://en.mippedia.org/api.php', base: 'https://en.mippedia.org/wiki/', color: '#4169e1' }, | |||
'concise': { name: 'Concise', url: 'https://concise.mippedia.org/api.php', base: 'https://concise.mippedia.org/wiki/', color: '#20b2aa' } | |||
}; | |||
// --- 1. HEADER (ATAS) --- | |||
var headerHtml = | var headerHtml = | ||
'<div id="mip-data-header" style="background: #f8f9fa; border-left: 5px solid #6a5acd; border-right: 1px solid #ddd; border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; padding: 12px; margin-bottom: 15px; border-radius: 0 4px 4px 0; font-family: sans-serif;">' + | '<div id="mip-data-header" style="background: #f8f9fa; border-left: 5px solid #6a5acd; border-right: 1px solid #ddd; border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; padding: 12px; margin-bottom: 15px; border-radius: 0 4px 4px 0; font-family: sans-serif;">' + | ||
| Baris 172: | Baris 188: | ||
'</p>' + | '</p>' + | ||
'</div>'; | '</div>'; | ||
$('#mw-content-text').prepend(headerHtml); | |||
// --- 2. SITELINK V4 (SMART CONNECTOR) --- | |||
function showFancyNotif(msg, type) { | |||
$('.mip-notif').remove(); | |||
var color = type === 'success' ? '#00ffa3' : '#ff4d4d'; | |||
var icon = type === 'success' ? '✓' : '✕'; | |||
var $notif = $('<div class="mip-notif" style="position:fixed; top:40px; left:50%; transform:translateX(-50%); background:rgba(15,15,15,0.92); backdrop-filter:blur(12px); color:white; padding:14px 28px; border-radius:12px; font-size:13px; font-weight:600; z-index:10000; display:flex; align-items:center; gap:12px; box-shadow:0 15px 35px rgba(0,0,0,0.5); border:1px solid rgba(255,255,255,0.1); border-bottom:3px solid '+color+'; animation:mipSlideDown 0.5s cubic-bezier(0.19, 1, 0.22, 1);">'+ | |||
'<span style="background:'+color+'; color:#000; width:22px; height:22px; display:flex; align-items:center; justify-content:center; border-radius:50%; font-size:12px; font-weight:900;">'+icon+'</span>'+ | |||
'<span>'+msg+'</span></div>').appendTo('body'); | |||
setTimeout(function() { $notif.fadeOut(); }, 3800); | |||
} | |||
var editIcon = mw.config.get('wgUserGroups').includes('sysop') || !mw.config.get('wgRestrictionEdit').includes('sysop') ? '<span id="mip-edit-links" style="cursor:pointer; color:#6a5acd; font-size:18px; opacity:0.7;">✎</span>' : ''; | |||
var sitelinkHtml = '<div id="mip-sitelink-box" style="background:#fff; border:1px solid #e0e0e0; border-radius:14px; padding:20px; margin-top:25px; box-shadow:0 8px 24px rgba(0,0,0,0.04);">' + | |||
} | '<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:18px;"><strong style="font-size:14px; color:#1a1a1a;">🔗 Koneksi Ekosistem Mippedia</strong>' + editIcon + '</div>' + | ||
'<div id="mip-link-display" style="display:flex; gap:10px; flex-wrap:wrap;"><small style="color:#888;">Memuat koneksi...</small></div>' + | |||
'<div id="mip-link-editor" style="display:none; margin-top:18px; border-top:1px solid #f0f0f0; padding-top:18px;">' + | |||
Object.keys(projects).map(p => '<div style="margin-bottom:10px; display:flex; gap:10px;"><span style="width:65px; font-size:10px; font-weight:800; background:#f5f5f5; display:flex; align-items:center; justify-content:center; border-radius:8px;">'+projects[p].name+'</span><input type="text" id="input-'+p+'" placeholder="Ketik judul..." style="flex:1; padding:9px; font-size:13px; border:1.5px solid #eee; border-radius:8px; outline:none;"></div>').join('') + | |||
'<button id="mip-save-links" style="width:100%; margin-top:12px; padding:12px; background:#6a5acd; color:white; border:none; border-radius:10px; font-size:13px; font-weight:700; cursor:pointer;">Sinkronkan Data</button></div></div>' + | |||
'<style>@keyframes mipSlideDown{from{top:0; opacity:0;} to{top:40px; opacity:1;}} .mip-pill{color:white !important; padding:7px 15px; border-radius:8px; font-size:11px; font-weight:700; text-decoration:none !important; border-bottom:2px solid rgba(0,0,0,0.15); transition:0.2s;} .mip-pill:hover{transform:translateY(-2px); opacity:0.9;}</style>'; | |||
$('#mw-content-text').append(sitelinkHtml); // Sitelink muncul setelah konten | |||
// --- 3. FOOTER (LISENSI) --- | |||
var footerHtml = | var footerHtml = | ||
'<div id="mip-data-footer" style="background: #fff; border: 1px dashed #ccc; padding: 10px; margin-top: 20px; text-align: center; border-radius: 6px;">' + | '<div id="mip-data-footer" style="background: #fff; border: 1px dashed #ccc; padding: 10px; margin-top: 20px; text-align: center; border-radius: 6px;">' + | ||
| Baris 195: | Baris 222: | ||
'</p>' + | '</p>' + | ||
'</div>'; | '</div>'; | ||
$('#mw-content-text').append(footerHtml); | $('#mw-content-text').append(footerHtml); | ||
// --- LOGIC: LOAD, VERIFY, & SAVE --- | |||
function loadData() { | |||
function | |||
new mw.Api().get({ action: 'query', prop: 'revisions', titles: dataPage, rvprop: 'content', formatversion: 2 }).done(function(data) { | new mw.Api().get({ action: 'query', prop: 'revisions', titles: dataPage, rvprop: 'content', formatversion: 2 }).done(function(data) { | ||
var content = data.query.pages[0].revisions ? JSON.parse(data.query.pages[0].revisions[0].content) : {}; | var content = data.query.pages[0].revisions ? JSON.parse(data.query.pages[0].revisions[0].content) : {}; | ||
var links = content[pageTitle] || {}; | |||
var $display = $('#mip-link-display').empty(); | |||
var hasAny = false; | |||
Object.keys(projects).forEach(p => { | |||
if (links[p]) { | |||
hasAny = true; | |||
$display.append('<a class="mip-pill" style="background:'+projects[p].color+'" href="'+projects[p].base+encodeURIComponent(links[p])+'" target="_blank">Mippedia '+projects[p].name+': '+links[p]+'</a>'); | |||
$('#input-' + p).val(links[p]); | |||
} | |||
}); | |||
if (!hasAny) $display.html('<em style="color:#888; font-size:12px;">Belum terkoneksi.</em>'); | |||
}); | }); | ||
} | } | ||
$(document).on('click', '#mip-save-links', function() { | $(document).on('click', '#mip-save-links', function() { | ||
var $btn = $(this); | var $btn = $(this).text('Memverifikasi...').prop('disabled', true); | ||
var api = new mw.Api(); | var api = new mw.Api(); | ||
var newData = {} | var newData = {}, checkPromises = [], invalid = [], isDel = true; | ||
Object.keys(projects).forEach(p => { | Object.keys(projects).forEach(p => { | ||
var v = $('#input-' + p).val().trim(); | var v = $('#input-' + p).val().trim(); | ||
if (v) { | if (v) { | ||
isDel = false; | |||
checkPromises.push($.ajax({ url: projects[p].url, data: { action: 'query', titles: v, format: 'json', origin: '*' }, dataType: 'json' }).done(function(d){ | |||
if (d.query.pages["-1"]) invalid.push(projects[p].name); else newData[p] = v; | |||
})); | |||
if ( | |||
}) | |||
} | } | ||
}); | }); | ||
$.when.apply($, checkPromises).then(function() { | $.when.apply($, checkPromises).then(function() { | ||
if ( | if (invalid.length > 0) { | ||
showFancyNotif('Judul | showFancyNotif('Judul tidak ada di: ' + invalid.join(', '), 'error'); | ||
$btn.text('Sinkronkan Data').prop('disabled', false); | $btn.text('Sinkronkan Data').prop('disabled', false); return; | ||
} | } | ||
api.get({ action: 'query', prop: 'revisions', titles: dataPage, rvprop: 'content', formatversion: 2 }).done(function(res) { | api.get({ action: 'query', prop: 'revisions', titles: dataPage, rvprop: 'content', formatversion: 2 }).done(function(res) { | ||
var fullData = res.query.pages[0].revisions ? JSON.parse(res.query.pages[0].revisions[0].content) : {}; | var fullData = res.query.pages[0].revisions ? JSON.parse(res.query.pages[0].revisions[0].content) : {}; | ||
if (isDel) delete fullData[pageTitle]; else fullData[pageTitle] = newData; | |||
if ( | api.postWithEditToken({ action: 'edit', title: dataPage, text: JSON.stringify(fullData, null, 2), summary: 'Update Sitelink: ' + pageTitle }).done(function() { | ||
showFancyNotif(isDel ? 'Koneksi Dihapus' : 'Data Terkoneksi!', 'success'); | |||
api.postWithEditToken({ | |||
showFancyNotif( | |||
setTimeout(function(){ location.reload(); }, 1200); | setTimeout(function(){ location.reload(); }, 1200); | ||
}); | }); | ||
}); | }); | ||
| Baris 331: | Baris 274: | ||
$(document).on('click', '#mip-edit-links', function() { $('#mip-link-editor').slideToggle(); }); | $(document).on('click', '#mip-edit-links', function() { $('#mip-link-editor').slideToggle(); }); | ||
loadData(); | |||
}); | }); | ||
})(); | })(); | ||