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 |
||
| (4 revisi perantara oleh pengguna yang sama tidak ditampilkan) | |||
| Baris 1: | Baris 1: | ||
/** | /** | ||
* ==================================================================== | * ==================================================================== | ||
* MIPPEDIA DATA - ADVANCED STRUCTURED DATA SYSTEM (V10. | * MIPPEDIA DATA - ADVANCED STRUCTURED DATA SYSTEM (V10.3 FINAL) | ||
* ==================================================================== | * ==================================================================== | ||
*/ | */ | ||
(function($, mw) { | (function($, mw) { | ||
'use strict'; | 'use strict'; | ||
var META_SAVE_ENDPOINT = 'https://data.mippedia.org/api-meta/save.php'; | |||
function isEntityNamespacePage() { | function isEntityNamespacePage() { | ||
| Baris 37: | Baris 39: | ||
var txt = ($('#mw-content-text').text() || '').trim(); | var txt = ($('#mw-content-text').text() || '').trim(); | ||
return /^(#REDIRECT|#ALIH)\s*\[\[/i.test(txt); | return /^(#REDIRECT|#ALIH)\s*\[\[/i.test(txt); | ||
} | |||
function hideNativeEditForNonStaff() { | |||
if (!isEntityNamespacePage() || isSysopUser()) return; | |||
var selectors = [ | |||
'#ca-edit', | |||
'#ca-ve-edit', | |||
'li#ca-edit', | |||
'li#ca-ve-edit', | |||
'.page-actions-menu__list-item #ca-edit', | |||
'.page-actions-menu__list-item #ca-ve-edit', | |||
'.minerva-toolbar a[href*="action=edit"]', | |||
'.minerva-toolbar a[href*="veaction=edit"]', | |||
'.page-actions-menu a[href*="action=edit"]', | |||
'.page-actions-menu a[href*="veaction=edit"]', | |||
'#p-views a[href*="action=edit"]', | |||
'#p-views a[href*="veaction=edit"]', | |||
'#p-cactions a[href*="action=edit"]', | |||
'#p-cactions a[href*="veaction=edit"]' | |||
].join(', '); | |||
$(selectors).each(function() { | |||
var $el = $(this); | |||
if ($el.closest('#mippedia-data-app, #mip-connector, #desc-manager').length) return; | |||
if ($el.is('li')) { | |||
$el.hide(); | |||
} else { | |||
var $li = $el.closest('li'); | |||
if ($li.length && !$li.hasClass('mw-list-item-hidden')) { | |||
$li.hide(); | |||
} | |||
$el.hide(); | |||
} | |||
}); | |||
} | } | ||
| Baris 42: | Baris 79: | ||
mw.loader.using(['mediawiki.api', 'mediawiki.util']).then(function() { | mw.loader.using(['mediawiki.api', 'mediawiki.util']).then(function() { | ||
hideNativeEditForNonStaff(); | |||
setTimeout(hideNativeEditForNonStaff, 300); | |||
setTimeout(hideNativeEditForNonStaff, 1000); | |||
var pageName = mw.config.get('wgPageName'); | var pageName = mw.config.get('wgPageName'); | ||
| Baris 73: | Baris 113: | ||
} | } | ||
var SOCIAL_PLATFORMS = { | var SOCIAL_PLATFORMS = { | ||
applemusic: { name: 'Apple Music', base: 'https://music.apple.com/artist/', color: '#fc3c44', icon: '<svg width="13" height="13" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2C6.477 2 2 6.477 2 12s4.477 10 10 10 10-4.477 10-10S17.523 2 12 2zm3.32 12.383c-.328.232-.82.418-1.32.418-1.238 0-1.922-.828-1.922-2.191v-4.14l4.312-.868v1.398l-2.91.586v2.805c0 .734.336 1.148.977 1.148.336 0 .617-.094.863-.258v1.102z"/></svg>' }, | applemusic: { name: 'Apple Music', base: 'https://music.apple.com/artist/', color: '#fc3c44', icon: '<svg width="13" height="13" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2C6.477 2 2 6.477 2 12s4.477 10 10 10 10-4.477 10-10S17.523 2 12 2zm3.32 12.383c-.328.232-.82.418-1.32.418-1.238 0-1.922-.828-1.922-2.191v-4.14l4.312-.868v1.398l-2.91.586v2.805c0 .734.336 1.148.977 1.148.336 0 .617-.094.863-.258v1.102z"/></svg>' }, | ||
| Baris 117: | Baris 156: | ||
]; | ]; | ||
var svgEdit = '<svg class="md-icon" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path></svg>'; | var svgEdit = '<svg class="md-icon" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path></svg>'; | ||
var svgLock = '<svg class="md-icon" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>'; | var svgLock = '<svg class="md-icon" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>'; | ||
| Baris 130: | Baris 168: | ||
var svgExternal = '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path><polyline points="15 3 21 3 21 9"></polyline><line x1="10" y1="14" x2="21" y2="3"></line></svg>'; | var svgExternal = '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path><polyline points="15 3 21 3 21 9"></polyline><line x1="10" y1="14" x2="21" y2="3"></line></svg>'; | ||
function sanitizeHTML(str) { | function sanitizeHTML(str) { | ||
if (typeof str !== 'string') return ''; | if (typeof str !== 'string') return ''; | ||
| Baris 470: | Baris 507: | ||
"@type": "Organization", | "@type": "Organization", | ||
"name": "Mippedia Community", | "name": "Mippedia Community", | ||
"url": "https:// | "url": "https://mippediacommunity.site/" | ||
} | } | ||
}; | }; | ||
| Baris 495: | Baris 532: | ||
} | } | ||
var css = ` | var css = ` | ||
#mippedia-data-app { | #mippedia-data-app { | ||
| Baris 670: | Baris 706: | ||
$('<style>').text(css).appendTo('head'); | $('<style>').text(css).appendTo('head'); | ||
function showModal(title, text) { | function showModal(title, text) { | ||
$('.md-modal-overlay').remove(); | $('.md-modal-overlay').remove(); | ||
| Baris 702: | Baris 737: | ||
} | } | ||
function loadData() { | function loadData() { | ||
return api.get({ | return api.get({ | ||
| Baris 766: | Baris 800: | ||
if ($btnEl) $btnEl.addClass('is-loading').prop('disabled', true); | if ($btnEl) $btnEl.addClass('is-loading').prop('disabled', true); | ||
var summaryTxt = customSummary ? ('Mippedia Data: ' + customSummary) : ('Mippedia Data V10. | var summaryTxt = customSummary ? ('Mippedia Data: ' + customSummary) : ('Mippedia Data V10.3: ' + actionType); | ||
var jsonStr = JSON.stringify({ locked: isLocked, items: dataItems }); | var jsonStr = JSON.stringify({ locked: isLocked, items: dataItems }); | ||
var wt = "<!-- MIPPEDIA_DATA_START | " + jsonStr + " -->\n"; | var wt = "<!-- MIPPEDIA_DATA_START | " + jsonStr + " -->\n"; | ||
| Baris 826: | Baris 860: | ||
} | } | ||
function buildUI(rawContent) { | function buildUI(rawContent) { | ||
if (isRedirectView()) return; | if (isRedirectView()) return; | ||
| Baris 1.086: | Baris 1.119: | ||
} | } | ||
function showForm(index, rawContent) { | function showForm(index, rawContent) { | ||
if (!canEditData()) { | if (!canEditData()) { | ||
| Baris 1.361: | Baris 1.393: | ||
} | } | ||
function showJsonModal(rawContent) { | function showJsonModal(rawContent) { | ||
var $container = $('#md-form-container').empty(); | var $container = $('#md-form-container').empty(); | ||
| Baris 1.401: | Baris 1.432: | ||
} | } | ||
loadData().then(function(rawContent) { | loadData().then(function(rawContent) { | ||
if (isRedirectView()) return; | if (isRedirectView()) return; | ||
| Baris 1.411: | Baris 1.441: | ||
}); | }); | ||
}); | }); | ||
window.mipSaveProtectedMeta = function(targetType, payloadObj) { | |||
return $.ajax({ | |||
url: META_SAVE_ENDPOINT, | |||
method: 'POST', | |||
contentType: 'application/json', | |||
xhrFields: { withCredentials: true }, | |||
data: JSON.stringify({ | |||
target: targetType, | |||
pageTitle: pageName, | |||
payload: payloadObj | |||
}) | |||
}); | |||
}; | |||
}); | }); | ||
| Baris 1.658: | Baris 1.702: | ||
/* ========================================================== | /* ========================================================== | ||
🚀 MIPPEDIA DATA - CORE SYSTEM (REGISTERED USER | 🚀 MIPPEDIA DATA - CORE SYSTEM (REGISTERED USER + PRO UI) | ||
========================================================== */ | ========================================================== */ | ||
(function() { | (function() { | ||
| Baris 1.667: | Baris 1.711: | ||
var pageTitle = mw.config.get('wgPageName'); | var pageTitle = mw.config.get('wgPageName'); | ||
var cleanEntityTitle = pageTitle.replace(/_/g, ' '); | |||
var dataPage = 'MediaWiki:Sitelinks-Data.json'; | var dataPage = 'MediaWiki:Sitelinks-Data.json'; | ||
var isRegisteredUser = !!mw.config.get('wgUserName'); | var isRegisteredUser = !!mw.config.get('wgUserName'); | ||
var projects = { | var projects = { | ||
'id': { name: 'ID', url: 'https://id.mippedia.org/api.php', base: 'https://id.mippedia.org/wiki/', | 'id': { | ||
'en': { name: 'EN', url: 'https://en.mippedia.org/api.php', base: 'https://en.mippedia.org/wiki/', | name: 'ID', | ||
fullName: 'Mippedia bahasa Indonesia', | |||
host: 'id.mippedia.org', | |||
url: 'https://id.mippedia.org/api.php', | |||
base: 'https://id.mippedia.org/wiki/', | |||
accent: '#4f46e5', | |||
badgeBg: '#eef2ff', | |||
badgeText: '#3730a3' | |||
}, | |||
'en': { | |||
name: 'EN', | |||
fullName: 'Mippedia bahasa Inggris', | |||
host: 'en.mippedia.org', | |||
url: 'https://en.mippedia.org/api.php', | |||
base: 'https://en.mippedia.org/wiki/', | |||
accent: '#2563eb', | |||
badgeBg: '#eff6ff', | |||
badgeText: '#1d4ed8' | |||
} | |||
}; | }; | ||
var svgPencil = '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path></svg>'; | |||
var svgExtArrow = '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path><polyline points="15 3 21 3 21 9"></polyline><line x1="10" y1="14" x2="21" y2="3"></line></svg>'; | |||
function showBoxNotif(title, msg, type) { | function showBoxNotif(title, msg, type) { | ||
| Baris 1.707: | Baris 1.773: | ||
'</p></div>'; | '</p></div>'; | ||
var editBtn = '< | var editBtn = '<button type="button" id="mip-open-editor" title="Edit ID Situs" style="cursor:pointer; display:inline-flex; align-items:center; justify-content:center; width:34px; height:34px; border-radius:8px; background:#f8fafc; border:1px solid #cbd5e1; color:#4f46e5; transition:0.2s;">' + svgPencil + '</button>'; | ||
var connectorHtml = '<div id="mip-connector" style="background:#fff; border:1px solid #e2e8f0; border-radius:16px; padding:20px; margin-top:24px; box-shadow:0 6px 20px rgba(15,23,42,0.04); box-sizing:border-box;">' + | var connectorHtml = '<div id="mip-connector" style="background:#fff; border:1px solid #e2e8f0; border-radius:16px; padding:20px; margin-top:24px; box-shadow:0 6px 20px rgba(15,23,42,0.04); box-sizing:border-box;">' + | ||
'<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:14px;">' + | '<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:14px;">' + | ||
'<div>' + | |||
'<div id="mip-display" style="display: | '<strong style="font-size:15px; color:#0f172a; display:flex; align-items:center; gap:8px;">ID Situs</strong>' + | ||
'<div style="font-size:12px; color:#64748b; margin-top:2px;">Tautan artikel terhubung pada cabang bahasa Mippedia</div>' + | |||
'</div>' + | |||
editBtn + | |||
'</div>' + | |||
'<div id="mip-display" style="display:grid; grid-template-columns:repeat(auto-fit,minmax(220px,1fr)); gap:10px;"><small style="color:#94a3b8;">Mensinkronisasi basis data...</small></div>' + | |||
'<div id="mip-editor" style="display:none; margin-top:18px; border-top:1px dashed #cbd5e1; padding-top:18px;">' + | '<div id="mip-editor" style="display:none; margin-top:18px; border-top:1px dashed #cbd5e1; padding-top:18px;">' + | ||
Object.keys(projects).map(p => '<div style="margin-bottom:12px; display:flex; gap:10px; align-items:center;"><span style="width:68px; font-size:11px; font-weight:800; background:#eef2ff; color:#3730a3; padding:10px 6px; text-align:center; border-radius:8px; border:1px solid #c7d2fe;">' + projects[p].name + '</span><input type="text" id="in-' + p + '" placeholder="Judul artikel di | Object.keys(projects).map(p => '<div style="margin-bottom:12px; display:flex; gap:10px; align-items:center;"><span style="width:68px; font-size:11px; font-weight:800; background:#eef2ff; color:#3730a3; padding:10px 6px; text-align:center; border-radius:8px; border:1px solid #c7d2fe;">' + projects[p].name + '</span><input type="text" id="in-' + p + '" placeholder="Judul artikel di ' + projects[p].fullName + '..." style="flex:1; padding:10px 12px; font-size:13px; border:1.5px solid #cbd5e1; border-radius:10px; outline:none;"></div>').join('') + | ||
'<button id="mip-save" style="width:100%; padding:13px; background:linear-gradient(135deg,#4f46e5,#4338ca); color:white; border:none; border-radius:10px; font-size:14px; font-weight:700; cursor:pointer; box-shadow:0 4px 12px rgba(79,70,229,0.25);">Terbitkan</button>' + | '<button id="mip-save" style="width:100%; padding:13px; background:linear-gradient(135deg,#4f46e5,#4338ca); color:white; border:none; border-radius:10px; font-size:14px; font-weight:700; cursor:pointer; box-shadow:0 4px 12px rgba(79,70,229,0.25);">Terbitkan</button>' + | ||
'</div></div>'; | '</div></div>'; | ||
| Baris 1.734: | Baris 1.806: | ||
var $box = $('#mip-display').empty(); | var $box = $('#mip-display').empty(); | ||
var found = false; | var found = false; | ||
Object.keys(projects).forEach(p => { | Object.keys(projects).forEach(p => { | ||
if (data[p]) { | if (data[p]) { | ||
found = true; | found = true; | ||
$box.append('<a style="background:' + | var proj = projects[p]; | ||
var articleClean = data[p].replace(/_/g, ' '); | |||
var href = proj.base + encodeURIComponent(data[p]); | |||
$box.append( | |||
'<a href="' + href + '" target="_blank" rel="noopener noreferrer" style="display:flex; align-items:center; justify-content:space-between; gap:12px; padding:12px 14px; border-radius:12px; background:#f8fafc; border:1px solid #e2e8f0; border-left:4px solid ' + proj.accent + '; text-decoration:none; transition:0.2s;">' + | |||
'<div style="min-width:0; flex:1;">' + | |||
'<div style="display:flex; align-items:center; gap:6px; margin-bottom:4px;">' + | |||
'<span style="background:' + proj.badgeBg + '; color:' + proj.badgeText + '; border:1px solid ' + proj.accent + '30; padding:2px 8px; border-radius:999px; font-size:10px; font-weight:800; letter-spacing:0.4px;">' + proj.name + '</span>' + | |||
'<span style="font-size:11px; color:#64748b; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">' + proj.host + '</span>' + | |||
'</div>' + | |||
'<div style="font-size:13.5px; font-weight:800; color:#0f172a; line-height:1.35; word-break:break-word;">' + articleClean + '</div>' + | |||
'</div>' + | |||
'<span style="color:' + proj.accent + '; display:inline-flex; align-items:center; flex-shrink:0;">' + svgExtArrow + '</span>' + | |||
'</a>' | |||
); | |||
$('#in-' + p).val(data[p]); | $('#in-' + p).val(data[p]); | ||
} | } | ||
}); | }); | ||
if (!found) $box.html('< | |||
if (!found) { | |||
$box.css('display', 'block').html('<div style="color:#64748b; font-size:13px; background:#f8fafc; padding:14px; border-radius:12px; border:1px dashed #cbd5e1;">Entitas <strong>' + cleanEntityTitle + '</strong> belum terhubung ke cabang Mippedia ID maupun EN.</div>'); | |||
} else { | |||
$box.css('display', 'grid'); | |||
} | |||
}); | }); | ||
} | } | ||
| Baris 1.752: | Baris 1.844: | ||
var $btn = $(this).text('Sedang Memvalidasi...').prop('disabled', true); | var $btn = $(this).text('Sedang Memvalidasi...').prop('disabled', true); | ||
var newData = {}, promises = [], invalid = [], isDel = true; | var newData = {}, promises = [], invalid = [], isDel = true; | ||
| Baris 1.771: | Baris 1.862: | ||
} | } | ||
window.mipSaveProtectedMeta('sitelinks', isDel ? {} : newData) | |||
.done(function() { | |||
showBoxNotif('Suntingan Anda berhasil diterbitkan!', 'ID Situs berhasil disinkronisasi ke jaringan Mippedia.', 'success'); | |||
setTimeout(function() { location.reload(); }, 1500); | |||
}).fail(function(xhr) { | |||
var msg = (xhr.responseJSON && xhr.responseJSON.error) ? xhr.responseJSON.error : 'Gagal menyimpan via endpoint server.'; | |||
showBoxNotif('Gagal Menyimpan', msg, 'error'); | |||
$btn.text('Terbitkan').prop('disabled', false); | |||
}); | }); | ||
}); | }); | ||
| Baris 1.893: | Baris 1.980: | ||
Label Deskripsi | Label Deskripsi | ||
</span> | </span> | ||
< | <button type="button" id="desc-open-editor" style="cursor:pointer; padding:6px; border-radius:8px; background:#f8fafc; border:1px solid #e2e8f0; transition:0.2s; display:inline-flex; align-items:center; justify-content:center;" title="Edit Deskripsi"> | ||
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="#4f46e5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path></svg> | <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="#4f46e5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path></svg> | ||
</ | </button> | ||
</div> | </div> | ||
| Baris 1.953: | Baris 2.040: | ||
$(document).on('click', '#desc-save', function() { | $(document).on('click', '#desc-save', function() { | ||
if (!isRegisteredUser) { alert('Akses ditolak. Silakan login menggunakan akun terdaftar.'); return; } | if (!isRegisteredUser) { alert('Akses ditolak. Silakan login menggunakan akun terdaftar.'); return; } | ||
var $btn = $(this).text('Proses Sinkronisasi...').css('opacity', '0.7') | var $btn = $(this).text('Proses Sinkronisasi...').css('opacity', '0.7').prop('disabled', true); | ||
var newData = { id: $('#desc-in-id').val().trim(), en: $('#desc-in-en').val().trim() }; | var newData = { id: $('#desc-in-id').val().trim(), en: $('#desc-in-en').val().trim() }; | ||
window.mipSaveProtectedMeta('shortdesc', newData) | |||
var | .done(function() { location.reload(); }) | ||
.fail(function(xhr) { | |||
var msg = (xhr.responseJSON && xhr.responseJSON.error) ? xhr.responseJSON.error : 'Gagal menyimpan deskripsi.'; | |||
alert(msg); | |||
$btn.text('Terbitkan').css('opacity', '1').prop('disabled', false); | |||
}); | }); | ||
}); | }); | ||