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 - | 🚀 MIPPEDIA DATA - CORE SYSTEM (ULTIMATE BUNDLE) | ||
Status: | Status: FINAL & REVISED (Visual Fix + Permission Logic) | ||
========================================================== */ | ========================================================== */ | ||
(function() { | (function() { | ||
$(document).ready(function() { | $(document).ready(function() { | ||
// --- 1. FILTER GLOBAL --- | // --- 1. FILTER GLOBAL (Namespace 0 & Bukan Halaman Utama) --- | ||
if (mw.config.get('wgNamespaceNumber') !== 0 || | if (mw.config.get('wgNamespaceNumber') !== 0 || | ||
mw.config.get('wgIsMainPage') || | mw.config.get('wgIsMainPage') || | ||
| Baris 169: | Baris 168: | ||
var userGroups = mw.config.get('wgUserGroups'); | var userGroups = mw.config.get('wgUserGroups'); | ||
var isAdmin = userGroups.includes('sysop') || userGroups.includes('interface-admin'); | var isAdmin = userGroups.includes('sysop') || userGroups.includes('interface-admin'); | ||
var projects = { | var projects = { | ||
| Baris 179: | Baris 175: | ||
}; | }; | ||
// --- 2. NOTIFIKASI | // --- 2. KOTAK NOTIFIKASI INFORMASI MODERN --- | ||
function showBoxNotif(title, msg, type) { | function showBoxNotif(title, msg, type) { | ||
$('.mip-box-notif').remove(); | $('.mip-box-notif').remove(); | ||
| Baris 185: | Baris 181: | ||
{bg:'#fff5f5', border:'#f56565', text:'#742a2a', icon:'🚫'}; | {bg:'#fff5f5', border:'#f56565', text:'#742a2a', icon:'🚫'}; | ||
var $notif = $('<div class="mip-box-notif" style="position:fixed; top:25px; right:25px; width:350px; background:'+theme.bg+'; border-left:6px solid '+theme.border+'; padding:18px; z-index:10001; border-radius:12px; box-shadow:0 15px 35px rgba(0,0,0,0.2); font-family:sans-serif; animation:mipSlideIn 0.4s ease-out;">' + | |||
'<div style="display:flex; align-items:center; gap:12px; margin-bottom:8px;">' + | |||
'<span style="font-size:20px;">'+theme.icon+'</span>' + | |||
'<strong style="color:'+theme.text+'; font-size:15px; letter-spacing:-0.3px;">'+title+'</strong>' + | |||
var $notif = $('<div class="mip-box-notif" style="position:fixed; | |||
'<div style="display:flex; align-items:center; gap:12px; margin-bottom: | |||
'<span style="font-size: | |||
'<strong style="color:'+theme.text+'; font-size: | |||
'</div>' + | '</div>' + | ||
'<p style="margin:0; font-size: | '<p style="margin:0; font-size:13px; color:'+theme.text+'; line-height:1.6; opacity:0.9;">'+msg+'</p>' + | ||
'</div>').appendTo('body'); | '</div>').appendTo('body'); | ||
setTimeout(function() { $notif.fadeOut(function(){ $(this).remove(); }); }, | setTimeout(function() { $notif.fadeOut(function(){ $(this).remove(); }); }, 5500); | ||
} | } | ||
// --- 3. UI GENERATOR --- | // --- 3. UI GENERATOR (DIPERTEBAL) --- | ||
// A. Header | // A. Header Pro | ||
var headerHtml = '<div id="mip-header" style="background:#f8f9fa; border:1px solid #ddd; border-left: | var headerHtml = '<div id="mip-header" style="background:#f8f9fa; border:1px solid #ddd; border-left:6px solid #6a5acd; padding:18px; margin-bottom:25px; border-radius:6px; box-shadow:inset 0 0 10px rgba(0,0,0,0.02);">' + | ||
'<div style="display:flex; align-items:center; gap: | '<div style="display:flex; align-items:center; gap:10px; margin-bottom:8px;">' + | ||
'<span style="background:#6a5acd; color:white; padding: | '<span style="background:#6a5acd; color:white; padding:3px 10px; border-radius:4px; font-size:11px; font-weight:bold; text-transform:uppercase; letter-spacing:0.5px;">Basis Data Terstruktur</span>' + | ||
'<strong style="font-size: | '<strong style="color:#111; font-size:16px;">Mippedia Data Project</strong></div>' + | ||
'<p style="margin:0; font-size: | '<p style="margin:0; font-size:13px; color:#444; line-height:1.6;">' + | ||
'Selamat datang di repositori pusat <strong>Mippedia Data</strong>. Halaman ini menyimpan metadata entitas yang disinkronisasi secara otomatis lintas ekosistem. ' + | |||
'Informasi di bawah ini bersifat teknis dan digunakan sebagai referensi data terbuka bagi pengembang dan komunitas Mippedia di seluruh dunia.' + | |||
'</p></div>'; | |||
// B. Connector | // B. Connector Box | ||
var editBtn = '<span id="mip-open-editor" style="cursor:pointer; font-size:20px; color:#6a5acd; opacity:0.8; transition:0.3s;" onmouseover="this.style.opacity=1" onmouseout="this.style.opacity=0.8">✎</span>'; | |||
var editBtn = | var connectorHtml = '<div id="mip-connector" style="background:#fff; border:1px solid #e2e8f0; border-radius:16px; padding:22px; margin-top:30px; box-shadow:0 10px 25px rgba(0,0,0,0.04);">' + | ||
'<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:20px;">' + | |||
var connectorHtml = '<div id="mip-connector" style="background:#fff; border:1px solid # | '<strong style="font-size:15px; color:#1a202c; display:flex; align-items:center; gap:8px;">🔗 Koneksi Ekosistem Mippedia</strong>'+editBtn+'</div>' + | ||
'<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom: | '<div id="mip-display" style="display:flex; gap:12px; flex-wrap:wrap;"><small style="color:#a0aec0;">Mensinkronisasi basis data...</small></div>' + | ||
'<div id="mip-display" style="display:flex; gap: | '<div id="mip-editor" style="display:none; margin-top:20px; border-top:2px solid #f7fafc; padding-top:20px;">' + | ||
'<div id="mip-editor" style="display:none; margin-top: | Object.keys(projects).map(p => '<div style="margin-bottom:12px; display:flex; gap:10px;"><span style="width:75px; font-size:11px; font-weight:bold; background:#edf2f7; display:flex; align-items:center; justify-content:center; border-radius:8px; color:#4a5568;">'+projects[p].name+'</span><input type="text" id="in-'+p+'" placeholder="Judul artikel di '+projects[p].name+'..." style="flex:1; padding:10px; font-size:13px; border:1.5px solid #e2e8f0; border-radius:10px; outline:none; transition:0.2s;" onfocus="this.style.borderColor=\'#6a5acd\'"></div>').join('') + | ||
Object.keys(projects).map(p => '<div style="margin-bottom: | '<button id="mip-save" style="width:100%; padding:14px; background:#6a5acd; color:white; border:none; border-radius:12px; font-size:14px; font-weight:bold; cursor:pointer; box-shadow:0 4px 12px rgba(106,90,205,0.3); transition:0.3s;">Simpan & Sinkronkan Data</button>' + | ||
'<button id="mip-save" style="width:100%; padding: | |||
'</div></div>'; | '</div></div>'; | ||
// C. Footer | // C. Footer Lisensi Lengkap | ||
var footerHtml = '<div id="mip-footer" style="background:# | var footerHtml = '<div id="mip-footer" style="background:#fafafa; border:1px solid #eee; border-radius:10px; padding:20px; margin-top:30px; text-align:center;">' + | ||
'<div style="font-size: | '<div style="font-size:11px; color:#718096; font-weight:800; text-transform:uppercase; letter-spacing:1px; margin-bottom:10px;">Lisensi, Atribusi & Penggunaan Data</div>' + | ||
'<p style="margin:0; font-size: | '<p style="margin:0 0 10px; font-size:13px; color:#4a5568; line-height:1.6;">' + | ||
'Seluruh data terstruktur yang tersaji dalam repositori ini merupakan milik publik dan tersedia di bawah lisensi resmi ' + | |||
'<a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" style="color:#6a5acd; text-decoration:none; font-weight:700;">Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)</a>.' + | |||
'</p>' + | |||
'<p style="margin:0; font-size:12px; color:#a0aec0;">Akses API dan penggunaan data secara massal wajib mencantumkan atribusi kepada <strong>Mippedia Community</strong> selaku pengelola proyek.</p></div>'; | |||
// Injeksi | // Injeksi | ||
| Baris 230: | Baris 228: | ||
$('#mw-content-text').append(connectorHtml).append(footerHtml); | $('#mw-content-text').append(connectorHtml).append(footerHtml); | ||
// --- 4. LOGIC | // --- 4. LOGIC ENGINE --- | ||
function loadLinks() { | function loadLinks() { | ||
new mw.Api().get({ action: 'query', prop: 'revisions', titles: dataPage, rvprop: 'content', formatversion: 2 }).done(function(d) { | new mw.Api().get({ action: 'query', prop: 'revisions', titles: dataPage, rvprop: 'content', formatversion: 2 }).done(function(d) { | ||
| Baris 240: | Baris 238: | ||
if (data[p]) { | if (data[p]) { | ||
found = true; | found = true; | ||
$box.append('<a style="background:'+projects[p].color+'; color:white | $box.append('<a style="background:'+projects[p].color+'; color:white; padding:8px 16px; border-radius:10px; font-size:12px; font-weight:bold; text-decoration:none; border-bottom:3px solid rgba(0,0,0,0.15);" href="'+projects[p].base+encodeURIComponent(data[p])+'" target="_blank">Mippedia '+projects[p].name+': '+data[p]+'</a>'); | ||
$('#in-' + p).val(data[p]); | $('#in-' + p).val(data[p]); | ||
} | } | ||
}); | }); | ||
if (!found) $box.html('<em style="color:# | if (!found) $box.html('<em style="color:#cbd5e0; font-size:13px;">Entitas ini belum terhubung ke cabang Mippedia manapun.</em>'); | ||
}); | }); | ||
} | } | ||
$(document).on('click', '#mip-save', function() { | $(document).on('click', '#mip-save', function() { | ||
// CEK IZIN: Tolak user biasa | |||
if (!isAdmin) { | if (!isAdmin) { | ||
showBoxNotif(' | showBoxNotif('Izin Ditolak', 'Halaman ini dilindungi. Hanya <b>Pengurus (Sysop)</b> atau <b>Admin Antarmuka</b> yang memiliki otoritas untuk memodifikasi metadata ekosistem secara langsung.', 'error'); | ||
return; | return; | ||
} | } | ||
var $btn = $(this).text(' | var $btn = $(this).text('Sedang Memvalidasi...').prop('disabled', true); | ||
var api = new mw.Api(); | var api = new mw.Api(); | ||
var newData = {}, promises = [], invalid = [], isDel = true; | var newData = {}, promises = [], invalid = [], isDel = true; | ||
| Baris 270: | Baris 269: | ||
$.when.apply($, promises).then(function() { | $.when.apply($, promises).then(function() { | ||
if (invalid.length > 0) { | if (invalid.length > 0) { | ||
showBoxNotif(' | showBoxNotif('Verifikasi Gagal', 'Artikel dengan judul tersebut tidak ditemukan di basis data Mippedia cabang: ' + invalid.join(', ') + '. Periksa kembali ejaan dan kapitalisasi.', 'error'); | ||
$btn.text('Sinkronkan Data').prop('disabled', false); return; | $btn.text('Simpan & Sinkronkan Data').prop('disabled', false); return; | ||
} | } | ||
api.get({ action: 'query', prop: 'revisions', titles: dataPage, rvprop: 'content', formatversion: 2 }).done(function(r) { | api.get({ action: 'query', prop: 'revisions', titles: dataPage, rvprop: 'content', formatversion: 2 }).done(function(r) { | ||
var full = r.query.pages[0].revisions ? JSON.parse(r.query.pages[0].revisions[0].content) : {}; | var full = r.query.pages[0].revisions ? JSON.parse(r.query.pages[0].revisions[0].content) : {}; | ||
if (isDel) delete full[pageTitle]; else full[pageTitle] = newData; | if (isDel) delete full[pageTitle]; else full[pageTitle] = newData; | ||
api.postWithEditToken({ action: 'edit', title: dataPage, text: JSON.stringify(full, null, 2), summary: 'Sync: ' + pageTitle }).done(function() { | |||
showBoxNotif(' | api.postWithEditToken({ action: 'edit', title: dataPage, text: JSON.stringify(full, null, 2), summary: 'Sync Metadata: ' + pageTitle }) | ||
.done(function() { | |||
showBoxNotif('Data Tersimpan!', 'Metadata entitas berhasil disinkronisasi ke seluruh jaringan ekosistem Mippedia.', 'success'); | |||
setTimeout(function(){ location.reload(); }, 1500); | setTimeout(function(){ location.reload(); }, 1500); | ||
}).fail(function(c) { | |||
showBoxNotif('Gagal Menyimpan', 'Terjadi kesalahan pada token API atau koneksi server. Kode: ' + c, 'error'); | |||
$btn.text('Simpan & Sinkronkan Data').prop('disabled', false); | |||
}); | }); | ||
}); | }); | ||