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 203: | Baris 203: | ||
/* ========================================================== | /* ========================================================== | ||
🔗 MIPPEDIA DATA - | 🔗 MIPPEDIA DATA - ULTIMATE SITELINK CONNECTOR (PRO VERSION) | ||
Status: | Status: INDUSTRIAL GRADE (Anti-Crash & Protection Aware) | ||
========================================================== */ | ========================================================== */ | ||
(function() { | (function() { | ||
$(document).ready(function() { | $(document).ready(function() { | ||
// Hanya jalan di halaman artikel utama | |||
if (mw.config.get('wgAction') !== 'view' || mw.config.get('wgNamespaceNumber') !== 0) return; | if (mw.config.get('wgAction') !== 'view' || mw.config.get('wgNamespaceNumber') !== 0) return; | ||
var pageTitle = mw.config.get('wgPageName'); | var pageTitle = mw.config.get('wgPageName'); | ||
var dataPage = 'MediaWiki:Sitelinks-Data.json'; | var dataPage = 'MediaWiki:Sitelinks-Data.json'; | ||
var isProtected = mw.config.get('wgRestrictionEdit') && mw.config.get('wgRestrictionEdit').includes('sysop'); | |||
var userGroups = mw.config.get('wgUserGroups'); | |||
var isAdmin = userGroups.includes('sysop') || userGroups.includes('interface-admin'); | |||
var projects = { | var projects = { | ||
'id': { name: 'ID', url: 'https://id.mippedia.org/api.php', base: 'https://id.mippedia.org/wiki/', color: '#6a5acd' }, | 'id': { name: 'ID', url: 'https://id.mippedia.org/api.php', base: 'https://id.mippedia.org/wiki/', color: '#6a5acd' }, | ||
| Baris 219: | Baris 223: | ||
}; | }; | ||
// 1. Tampilkan Box Utama | |||
var editIcon = (isProtected && !isAdmin) ? '' : '<span id="mip-edit-links" style="cursor: pointer; color: #6a5acd; font-size: 18px; transition: 0.3s;" title="Edit Koneksi">✎</span>'; | |||
var containerHtml = | var containerHtml = | ||
'<div id="mip-sitelink-box" style="background: #fff; border: 1px solid #ddd; border-radius: | '<div id="mip-sitelink-box" style="background: #fff; border: 1px solid #ddd; border-radius: 12px; padding: 18px; margin-top: 25px; font-family: sans-serif; box-shadow: 0 4px 15px rgba(0,0,0,0.05);">' + | ||
'<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: | '<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px;">' + | ||
'<strong style="font-size: | '<strong style="font-size: 14px; color: #333; letter-spacing: 0.3px;">🔗 Koneksi Ekosistem Mippedia</strong>' + | ||
editIcon + | |||
'</div>' + | '</div>' + | ||
'<div id="mip-link-display" style="display: flex; gap: | '<div id="mip-link-display" style="display: flex; gap: 10px; flex-wrap: wrap;"><div class="mip-loader"></div></div>' + | ||
'<div id="mip-link-editor" style="display: none; margin-top: | '<div id="mip-link-editor" style="display: none; margin-top: 15px; border-top: 1px solid #eee; padding-top: 15px; animation: fadeIn 0.4s;">' + | ||
Object.keys(projects).map(p => | Object.keys(projects).map(p => | ||
'<div style="margin-bottom: | '<div style="margin-bottom: 10px; display: flex; gap: 8px;">' + | ||
'<span style="width: | '<span style="width: 60px; font-size: 10px; font-weight: 800; background: #f0f0f0; display: flex; align-items: center; justify-content: center; border-radius: 6px; color: #555;">' + projects[p].name + '</span>' + | ||
'<input type="text" id="input-' + p + '" placeholder="Judul artikel..." style="flex: 1; padding: | '<input type="text" id="input-' + p + '" placeholder="Judul artikel..." style="flex: 1; padding: 7px 12px; font-size: 13px; border: 1px solid #ddd; border-radius: 6px; outline: none; transition: 0.2s;">' + | ||
'</div>' | '</div>' | ||
).join('') + | ).join('') + | ||
'<button id="mip-save-links" style="width: 100%; margin-top: | '<button id="mip-save-links" style="width: 100%; margin-top: 10px; padding: 10px; background: #6a5acd; color: white; border: none; border-radius: 8px; font-size: 13px; cursor: pointer; font-weight: bold; transition: 0.3s;">Sinkronkan Data</button>' + | ||
'</div>' + | '</div>' + | ||
'</div>'; | '</div>' + | ||
'<style>' + | |||
'.mip-loader { border: 2px solid #f3f3f3; border-top: 2px solid #6a5acd; border-radius: 50%; width: 15px; height: 15px; animation: spin 1s linear infinite; }' + | |||
'@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }' + | |||
'@keyframes fadeIn { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }' + | |||
'#mip-save-links:hover { background: #5a4db8; transform: translateY(-1px); box-shadow: 0 4px 8px rgba(106, 90, 205, 0.3); }' + | |||
'#mip-edit-links:hover { transform: scale(1.2) rotate(15deg); }' + | |||
'.mip-pill { text-decoration: none !important; color: white !important; padding: 6px 14px; border-radius: 20px; font-size: 11px; font-weight: bold; transition: 0.3s; display: flex; align-items: center; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }' + | |||
'.mip-pill:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.15); opacity: 0.9; }' + | |||
'</style>'; | |||
$('#mip-data-footer').before(containerHtml); | $('#mip-data-footer').before(containerHtml); | ||
// | // 2. Fungsi Load Data (Global & Public) | ||
function | function loadData() { | ||
$.getJSON(mw.util.wikiScript('api'), { | |||
var | action: 'query', prop: 'revisions', titles: dataPage, rvprop: 'content', formatversion: 2, origin: location.origin | ||
renderLinks( | }).done(function(data) { | ||
var raw = data.query.pages[0].revisions ? data.query.pages[0].revisions[0].content : "{}"; | |||
var fullData = JSON.parse(raw); | |||
renderLinks(fullData[pageTitle] || {}); | |||
}).fail(function() { | |||
$('#mip-link-display').html('<small style="color:red;">Gagal memuat data server.</small>'); | |||
}); | }); | ||
} | } | ||
function renderLinks( | function renderLinks(links) { | ||
var $display = $('#mip-link-display') | var $display = $('#mip-link-display').empty(); | ||
var count = 0; | |||
var | for (var p in projects) { | ||
if (links[p]) { | |||
for (var p in | $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>'); | ||
if ( | $('#input-' + p).val(links[p]); | ||
count++; | |||
$display.append('<a href="' + projects[p].base + encodeURIComponent( | |||
$('#input-' + p).val( | |||
} | } | ||
} | } | ||
if ( | if (count === 0) $display.html('<em style="color: #bbb; font-size: 12px;">Entitas ini belum terhubung ke artikel manapun.</em>'); | ||
} | } | ||
// --- | // 3. Fungsi Animasi Sukses (Pop-up Profesional) | ||
function showNotif(msg, type) { | |||
var color = type === 'success' ? '#2ecc71' : '#e74c3c'; | |||
var $notif = $('<div style="position:fixed; top:20px; left:50%; transform:translateX(-50%); background:'+color+'; color:white; padding:12px 25px; border-radius:50px; font-size:14px; font-weight:bold; z-index:10000; box-shadow:0 10px 20px rgba(0,0,0,0.2); animation: fadeIn 0.3s;">'+msg+'</div>').appendTo('body'); | |||
setTimeout(function() { $notif.fadeOut(function() { $(this).remove(); }); }, 3000); | |||
} | |||
// 4. Sinkronisasi (Save/Delete) | |||
$(document).on('click', '#mip-save-links', function() { | $(document).on('click', '#mip-save-links', function() { | ||
var btn = $(this) | var btn = $(this).text('Proses Mendata...').prop('disabled', true); | ||
var api = new mw.Api(); | var api = new mw.Api(); | ||
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) : {}; | ||
var currentEntry = {}; | var currentEntry = {}; | ||
var isDeleting = true; | |||
Object.keys(projects).forEach(p => { | Object.keys(projects).forEach(p => { | ||
var val = $('#input-' + p).val().trim(); | var val = $('#input-' + p).val().trim(); | ||
if (val) currentEntry[p] = val; | if (val) { | ||
currentEntry[p] = val; | |||
isDeleting = false; | |||
} | |||
}); | }); | ||
fullData[pageTitle] = currentEntry; | if (isDeleting) delete fullData[pageTitle]; | ||
else fullData[pageTitle] = currentEntry; | |||
api.postWithEditToken({ | api.postWithEditToken({ | ||
action: 'edit', | action: 'edit', title: dataPage, text: JSON.stringify(fullData, null, 2), | ||
summary: 'Update Sitelink: ' + pageTitle + ' [Automated System]', format: 'json' | |||
summary: ' | |||
}).done(function() { | }).done(function() { | ||
showNotif(isDeleting ? '✅ Koneksi berhasil dihapus!' : '🚀 Berhasil menghubungkan data!', 'success'); | |||
location.reload(); | setTimeout(function() { location.reload(); }, 1000); | ||
}).fail(function(code) { | |||
showNotif('❌ Gagal: ' + code + '. Pastikan Anda login atau memiliki izin.', 'error'); | |||
btn.text('Sinkronkan Data').prop('disabled', false); | |||
}); | }); | ||
}); | }); | ||
| Baris 294: | Baris 324: | ||
$(document).on('click', '#mip-edit-links', function() { $('#mip-link-editor').slideToggle(); }); | $(document).on('click', '#mip-edit-links', function() { $('#mip-link-editor').slideToggle(); }); | ||
loadData(); | |||
}); | }); | ||
})(); | })(); | ||