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 |
||
| (6 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 24: | Baris 26: | ||
if (typeof mw === 'undefined' || !mw.config) return false; | if (typeof mw === 'undefined' || !mw.config) return false; | ||
return !!mw.config.get('wgUserName'); | return !!mw.config.get('wgUserName'); | ||
} | |||
function isSysopUser() { | |||
if (typeof mw === 'undefined' || !mw.config || !mw.config.get('wgUserName')) return false; | |||
var groups = mw.config.get('wgUserGroups') || []; | |||
return Array.isArray(groups) && (groups.indexOf('sysop') !== -1 || groups.indexOf('bureaucrat') !== -1); | |||
} | } | ||
| Baris 31: | 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 36: | 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'); | ||
var cleanPageTitle = pageName.replace(/_/g, ' '); | var cleanPageTitle = pageName.replace(/_/g, ' '); | ||
var isLoggedIn = isLoggedInUser(); | var isLoggedIn = isLoggedInUser(); | ||
var isSysop = isSysopUser(); | |||
var dataItems = []; | var dataItems = []; | ||
var isLocked = false; | var isLocked = false; | ||
| Baris 53: | Baris 100: | ||
function normalizeTitleKey(t) { | function normalizeTitleKey(t) { | ||
return (t || '').toString().replace(/_/g, ' ').replace(/\s+/g, ' ').trim().toLowerCase(); | return (t || '').toString().replace(/\[\[([^|\]]+\|)?([^\]]+)\]\]/g, '$2').replace(/_/g, ' ').replace(/\s+/g, ' ').trim().toLowerCase(); | ||
} | } | ||
function cleanTitleText(t) { | function cleanTitleText(t) { | ||
return (t || '').toString().replace(/_/g, ' ').replace(/\s+/g, ' ').trim(); | return (t || '').toString().replace(/\[\[([^|\]]+\|)?([^\]]+)\]\]/g, '$2').replace(/[\[\]]/g, '').replace(/_/g, ' ').replace(/\s+/g, ' ').trim(); | ||
} | |||
function canEditData() { | |||
if (!isLoggedIn) return false; | |||
if (isSysop) return true; | |||
return !isLocked; | |||
} | } | ||
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 104: | 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 svgUnlock = '<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 9.9-1"></path></svg>'; | |||
var svgRef = '<svg class="md-icon" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>'; | var svgRef = '<svg class="md-icon" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>'; | ||
var svgCopy = '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>'; | var svgCopy = '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>'; | ||
| Baris 115: | 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 167: | Baris 219: | ||
return (str || '') | return (str || '') | ||
.replace(/\[\[([^|\]]+\|)?([^\]]+)\]\]/g, '$2') | .replace(/\[\[([^|\]]+\|)?([^\]]+)\]\]/g, '$2') | ||
.replace(/[\[\]]/g, '') | |||
.replace(/\[https?:\/\/[^\s\]]+\s*([^\]]*)\]/g, '$1') | .replace(/\[https?:\/\/[^\s\]]+\s*([^\]]*)\]/g, '$1') | ||
.replace(/\{\{[^}]+\}\}/g, '') | .replace(/\{\{[^}]+\}\}/g, '') | ||
| Baris 244: | Baris 297: | ||
function renderSmartEntityElement(targetTitle, displayLabel, isSmallBtn) { | function renderSmartEntityElement(targetTitle, displayLabel, isSmallBtn) { | ||
var cleanTitle = cleanTitleText(targetTitle); | var cleanTitle = cleanTitleText(targetTitle); | ||
var labelText = displayLabel || cleanTitle; | var labelText = cleanTitleText(displayLabel) || cleanTitle; | ||
var key = normalizeTitleKey(cleanTitle); | var key = normalizeTitleKey(cleanTitle); | ||
var entry = pageExistsMap[key]; | var entry = pageExistsMap[key]; | ||
| Baris 454: | Baris 507: | ||
"@type": "Organization", | "@type": "Organization", | ||
"name": "Mippedia Community", | "name": "Mippedia Community", | ||
"url": "https:// | "url": "https://mippediacommunity.site/" | ||
} | } | ||
}; | }; | ||
| Baris 479: | Baris 532: | ||
} | } | ||
var css = ` | var css = ` | ||
#mippedia-data-app { | #mippedia-data-app { | ||
| Baris 497: | Baris 549: | ||
} | } | ||
.md-btn-icon:hover:not(:disabled) { background: #f1f5f9; border-color: #94a3b8; transform: translateY(-1px); } | .md-btn-icon:hover:not(:disabled) { background: #f1f5f9; border-color: #94a3b8; transform: translateY(-1px); } | ||
.md-btn-locked-state { background: #fef2f2; border-color: #fecaca; color: #dc2626; cursor: not-allowed; } | |||
.md-search-box { position: relative; margin-bottom: 16px; width: 100%; box-sizing: border-box; } | .md-search-box { position: relative; margin-bottom: 16px; width: 100%; box-sizing: border-box; } | ||
| Baris 653: | 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 685: | Baris 737: | ||
} | } | ||
function loadData() { | function loadData() { | ||
return api.get({ | return api.get({ | ||
| Baris 696: | Baris 747: | ||
var parsed = JSON.parse(match[1]); | var parsed = JSON.parse(match[1]); | ||
dataItems = parsed.items || []; | dataItems = parsed.items || []; | ||
isLocked = parsed.locked | isLocked = !!parsed.locked; | ||
} catch (e) { console.error("JSON Error", e); } | } catch (e) { console.error("JSON Error", e); } | ||
} | } | ||
| Baris 704: | Baris 755: | ||
function buildWikitextVal(item) { | function buildWikitextVal(item) { | ||
var val = item.val; | var val = cleanTitleText(item.val); | ||
if (item.linkTarget && item.linkTarget | if (item.linkTarget && cleanTitleText(item.linkTarget) !== '') { | ||
return "[[" + item.linkTarget | return "[[" + cleanTitleText(item.linkTarget) + "|" + val + "]]"; | ||
} | } | ||
if (item.linkSplit) { | if (item.linkSplit) { | ||
| Baris 741: | Baris 792: | ||
if (!isLoggedIn) { | if (!isLoggedIn) { | ||
showModal('Perlu Login Akun Terdaftar', 'Hanya pengguna terdaftar yang sudah login yang dapat menambah atau mengubah data terstruktur. Silakan masuk (login) terlebih dahulu.'); | showModal('Perlu Login Akun Terdaftar', 'Hanya pengguna terdaftar yang sudah login yang dapat menambah atau mengubah data terstruktur. Silakan masuk (login) terlebih dahulu.'); | ||
return; | |||
} | |||
if (isLocked && !isSysop) { | |||
showModal('Data Terkunci', 'Data terstruktur ini sedang dikunci oleh Pengurus dan hanya dapat diubah oleh Pengurus.'); | |||
return; | return; | ||
} | } | ||
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 751: | Baris 806: | ||
dataItems.forEach(function(item) { | dataItems.forEach(function(item) { | ||
var cleanProp = cleanTitleText(item.prop); | |||
var valTxt = buildWikitextVal(item); | var valTxt = buildWikitextVal(item); | ||
var refTxt = buildWikitextRef(item.ref); | var refTxt = buildWikitextRef(item.ref); | ||
wt += "|-\n| " + | wt += "|-\n| " + cleanProp + " || " + valTxt + " || " + refTxt + "\n"; | ||
}); | }); | ||
wt += "|}\n</div>\n<!-- MIPPEDIA_DATA_END -->"; | wt += "|}\n</div>\n<!-- MIPPEDIA_DATA_END -->"; | ||
| Baris 804: | Baris 860: | ||
} | } | ||
function buildUI(rawContent) { | function buildUI(rawContent) { | ||
if (isRedirectView()) return; | if (isRedirectView()) return; | ||
| Baris 819: | Baris 874: | ||
$actions.append($jsonBtn); | $actions.append($jsonBtn); | ||
if (!isLocked || | if (!isLocked || isSysop) { | ||
var $addBtn = $('<button class="md-btn-icon" title="Tambah Data Baru">' + svgEdit + ' Tambah</button>'); | var $addBtn = $('<button class="md-btn-icon" title="Tambah Data Baru">' + svgEdit + ' Tambah</button>'); | ||
$addBtn.on('click', function() { | $addBtn.on('click', function() { | ||
| Baris 829: | Baris 884: | ||
}); | }); | ||
$actions.append($addBtn); | $actions.append($addBtn); | ||
} else { | |||
var $lockedAddBtn = $('<button class="md-btn-icon md-btn-locked-state" title="Terkunci oleh Pengurus">' + svgLock + ' Terkunci</button>'); | |||
$lockedAddBtn.on('click', function() { | |||
showModal('Data Terkunci', 'Penambahan data sedang dikunci oleh Pengurus.'); | |||
}); | |||
$actions.append($lockedAddBtn); | |||
} | |||
if (isSysop) { | |||
var lockLabel = isLocked ? 'Buka Kunci' : 'Kunci'; | |||
var lockIcon = isLocked ? svgUnlock : svgLock; | |||
var $lockBtn = $('<button class="md-btn-icon" title="' + lockLabel + ' Data Terstruktur">' + lockIcon + ' ' + lockLabel + '</button>'); | |||
$lockBtn.on('click', function() { | |||
isLocked = !isLocked; | |||
saveData(isLocked ? 'Mengunci data' : 'Membuka kunci data', $(this), rawContent, isLocked ? 'Kunci data terstruktur' : 'Buka kunci data terstruktur', true); | |||
}); | |||
$actions.append($lockBtn); | |||
} | } | ||
| Baris 880: | Baris 952: | ||
var propTitle = cleanTitleText(item.prop || ''); | var propTitle = cleanTitleText(item.prop || ''); | ||
var labelHtml = '<div class="md-label-row">' + renderSmartEntityElement(propTitle, | var labelHtml = '<div class="md-label-row">' + renderSmartEntityElement(propTitle, propTitle, true) + '</div>'; | ||
$info.append('<span class="md-data-label">' + labelHtml + '</span>'); | $info.append('<span class="md-data-label">' + labelHtml + '</span>'); | ||
var displayValHtml = ''; | var displayValHtml = ''; | ||
var rawVal = item.val || ''; | var rawVal = cleanTitleText(item.val || ''); | ||
if (rawVal.match(/^https?:\/\//i)) { | if (rawVal.match(/^https?:\/\//i)) { | ||
displayValHtml = '<a href="' + sanitizeHTML(rawVal) + '" target="_blank" rel="noopener noreferrer" class="md-smart-wikilink">' + sanitizeHTML(extractDomain(rawVal)) + '</a>'; | displayValHtml = '<a href="' + sanitizeHTML(rawVal) + '" target="_blank" rel="noopener noreferrer" class="md-smart-wikilink">' + sanitizeHTML(extractDomain(rawVal)) + '</a>'; | ||
} else if (item.linkTarget && cleanTitleText(item.linkTarget) !== '') { | } else if (item.linkTarget && cleanTitleText(item.linkTarget) !== '') { | ||
displayValHtml = renderSmartEntityElement(item.linkTarget, rawVal, false); | displayValHtml = renderSmartEntityElement(cleanTitleText(item.linkTarget), rawVal, false); | ||
} else if (item.linkSplit) { | } else if (item.linkSplit) { | ||
var parts = rawVal.split(/([,/\s]+dan\s+|[,/\s]+atau\s+|[,/]+)/gi); | var parts = rawVal.split(/([,/\s]+dan\s+|[,/\s]+atau\s+|[,/]+)/gi); | ||
| Baris 983: | Baris 1.055: | ||
}); | }); | ||
$row.append($loginEditBtn); | $row.append($loginEditBtn); | ||
} else if (isLocked && !isSysop) { | |||
var $lockedRowBtn = $('<button class="md-btn-icon edit-btn md-btn-locked-state">' + svgLock + ' Terkunci</button>'); | |||
$lockedRowBtn.on('click', function() { | |||
showModal('Data Terkunci', 'Data ini dikunci oleh Pengurus dan hanya dapat diedit oleh Pengurus.'); | |||
}); | |||
$row.append($lockedRowBtn); | |||
} else { | } else { | ||
var $editIcon = $('<button class="md-btn-icon edit-btn">' + svgEdit + ' Edit</button>'); | var $editIcon = $('<button class="md-btn-icon edit-btn">' + svgEdit + ' Edit</button>'); | ||
| Baris 1.041: | Baris 1.119: | ||
} | } | ||
function showForm(index, rawContent) { | function showForm(index, rawContent) { | ||
if (! | if (!canEditData()) { | ||
showModal(' | showModal('Akses Dibatasi', isLocked ? 'Data sedang dikunci oleh Pengurus.' : 'Silakan login menggunakan akun terdaftar untuk menambah atau mengedit data.'); | ||
return; | return; | ||
} | } | ||
| Baris 1.069: | Baris 1.146: | ||
var $propAutoWrap = $('<div class="md-autocomplete-wrapper"></div>'); | var $propAutoWrap = $('<div class="md-autocomplete-wrapper"></div>'); | ||
var $propInput = $('<input type="text" id="md-inp-prop" class="md-input" autocomplete="off" value="' + sanitizeHTML(currentData.prop || '') + '">'); | var $propInput = $('<input type="text" id="md-inp-prop" class="md-input" autocomplete="off" value="' + sanitizeHTML(cleanTitleText(currentData.prop || '')) + '">'); | ||
var $propAutoList = $('<div class="md-autocomplete-list"></div>'); | var $propAutoList = $('<div class="md-autocomplete-list"></div>'); | ||
$propAutoWrap.append($propInput).append($propAutoList); | $propAutoWrap.append($propInput).append($propAutoList); | ||
| Baris 1.088: | Baris 1.165: | ||
var $autoWrap = $('<div class="md-autocomplete-wrapper"></div>'); | var $autoWrap = $('<div class="md-autocomplete-wrapper"></div>'); | ||
var $valInput = $('<input type="text" id="md-inp-val" class="md-input" autocomplete="off" value="' + sanitizeHTML(currentData.val || '') + '">'); | var $valInput = $('<input type="text" id="md-inp-val" class="md-input" autocomplete="off" value="' + sanitizeHTML(cleanTitleText(currentData.val || '')) + '">'); | ||
var $autoList = $('<div class="md-autocomplete-list"></div>'); | var $autoList = $('<div class="md-autocomplete-list"></div>'); | ||
$autoWrap.append($valInput).append($autoList); | $autoWrap.append($valInput).append($autoList); | ||
| Baris 1.120: | Baris 1.197: | ||
$wikilinkOpts.append($lblLinkCheck); | $wikilinkOpts.append($lblLinkCheck); | ||
$wikilinkOpts.append('<label style="display:flex; align-items:center; gap:8px; font-size:0.82rem; font-weight:700; cursor:pointer;"><input type="checkbox" id="md-inp-split" ' + chkSplit + '> Smart Split Wikilink</label>'); | $wikilinkOpts.append('<label style="display:flex; align-items:center; gap:8px; font-size:0.82rem; font-weight:700; cursor:pointer;"><input type="checkbox" id="md-inp-split" ' + chkSplit + '> Smart Split Wikilink</label>'); | ||
var $pipedGroup = $('<div style="margin-top:4px;"><label style="font-size:0.78rem; color:#475569; margin-bottom:4px;">Target Halaman Khusus (Opsional):</label><input type="text" id="md-inp-target" class="md-input" style="padding:6px 10px; font-size:0.85rem;" placeholder="Contoh: Diskografi Rumi Haitami" value="' + sanitizeHTML(currentData.linkTarget || '') + '"></div>'); | var $pipedGroup = $('<div style="margin-top:4px;"><label style="font-size:0.78rem; color:#475569; margin-bottom:4px;">Target Halaman Khusus (Opsional):</label><input type="text" id="md-inp-target" class="md-input" style="padding:6px 10px; font-size:0.85rem;" placeholder="Contoh: Diskografi Rumi Haitami" value="' + sanitizeHTML(cleanTitleText(currentData.linkTarget || '')) + '"></div>'); | ||
$wikilinkOpts.append($pipedGroup); | $wikilinkOpts.append($pipedGroup); | ||
$valBox.append($wikilinkOpts); | $valBox.append($wikilinkOpts); | ||
| Baris 1.250: | Baris 1.327: | ||
} | } | ||
var draftObj = { | var draftObj = { | ||
prop: $('#md-inp-prop').val() | prop: cleanTitleText($('#md-inp-prop').val()), | ||
val: $('#md-inp-val').val() | val: cleanTitleText($('#md-inp-val').val()), | ||
link: $('#md-inp-link').is(':checked'), | link: $('#md-inp-link').is(':checked'), | ||
linkSplit: $('#md-inp-split').is(':checked'), | linkSplit: $('#md-inp-split').is(':checked'), | ||
linkTarget: $('#md-inp-target').val() | linkTarget: cleanTitleText($('#md-inp-target').val()), | ||
isPersonOrg: $('#md-chk-person').is(':checked'), | isPersonOrg: $('#md-chk-person').is(':checked'), | ||
socials: socObj, | socials: socObj, | ||
| Baris 1.269: | Baris 1.346: | ||
$btnSave.on('click', function() { | $btnSave.on('click', function() { | ||
var newProp = $('#md-inp-prop').val() | var newProp = cleanTitleText($('#md-inp-prop').val()); | ||
var newVal = $('#md-inp-val').val() | var newVal = cleanTitleText($('#md-inp-val').val()); | ||
if (!newProp || !newVal) { | if (!newProp || !newVal) { | ||
| Baris 1.303: | Baris 1.380: | ||
link: $('#md-inp-link').is(':checked'), | link: $('#md-inp-link').is(':checked'), | ||
linkSplit: $('#md-inp-split').is(':checked'), | linkSplit: $('#md-inp-split').is(':checked'), | ||
linkTarget: $('#md-inp-target').val() | linkTarget: cleanTitleText($('#md-inp-target').val()), | ||
isPersonOrg: isPerson, | isPersonOrg: isPerson, | ||
socials: socObj, | socials: socObj, | ||
| Baris 1.316: | Baris 1.393: | ||
} | } | ||
function showJsonModal(rawContent) { | function showJsonModal(rawContent) { | ||
var $container = $('#md-form-container').empty(); | var $container = $('#md-form-container').empty(); | ||
| Baris 1.338: | Baris 1.414: | ||
$btnCancel.on('click', function() { $container.empty(); }); | $btnCancel.on('click', function() { $container.empty(); }); | ||
$btnImport.on('click', function() { | $btnImport.on('click', function() { | ||
if (! | if (!canEditData()) { | ||
showModal(' | showModal('Akses Dibatasi', isLocked ? 'Data sedang dikunci oleh Pengurus.' : 'Silakan login menggunakan akun terdaftar untuk mengimpor dan menyimpan JSON.'); | ||
return; | return; | ||
} | } | ||
| Baris 1.356: | Baris 1.432: | ||
} | } | ||
loadData().then(function(rawContent) { | loadData().then(function(rawContent) { | ||
if (isRedirectView()) return; | if (isRedirectView()) return; | ||
| Baris 1.366: | 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.613: | Baris 1.702: | ||
/* ========================================================== | /* ========================================================== | ||
🚀 MIPPEDIA DATA - CORE SYSTEM (REGISTERED USER | 🚀 MIPPEDIA DATA - CORE SYSTEM (REGISTERED USER + PRO UI) | ||
========================================================== */ | ========================================================== */ | ||
(function() { | (function() { | ||
| Baris 1.622: | 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.662: | 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.689: | 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.707: | 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.726: | 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.783: | Baris 1.915: | ||
/* ========================================================== | /* ========================================================== | ||
🚀 MIPPEDIA DATA - CONTENT GUARD | 🚀 MIPPEDIA DATA - CONTENT GUARD | ||
========================================================== */ | ========================================================== */ | ||
(function() { | (function() { | ||
| Baris 1.800: | Baris 1.932: | ||
if ($textbox.length) { | if ($textbox.length) { | ||
var content = $textbox.val() || ""; | var content = $textbox.val() || ""; | ||
var hasInfobox = content.includes('{{Infobox'); | var hasInfobox = content.includes('{{Infobox'); | ||
if (!hasInfobox | if (!hasInfobox) { | ||
e.preventDefault(); | e.preventDefault(); | ||
e.stopPropagation(); | e.stopPropagation(); | ||
| Baris 1.828: | Baris 1.958: | ||
/* ========================================================== | /* ========================================================== | ||
🌐 MIPPEDIA SHORTDESC - DATA CENTER (REGISTERED USER ACCESS) | |||
========================================================== */ | ========================================================== */ | ||
mw | (function($, mw) { | ||
"use strict"; | |||
$(document).ready(function() { | |||
if (mw.config.get('wgNamespaceNumber') !== 0 || mw.config.get('wgIsMainPage')) return; | |||
var pageTitle = mw.config.get('wgPageName'); | |||
var storagePage = 'MediaWiki:ShortDesc-Data.json'; | |||
var isRegisteredUser = !!mw.config.get('wgUserName'); | |||
var langs = { | |||
id: { label: 'Mippedia bahasa Indonesia', short: 'ID', color: '#4f46e5' }, | |||
en: { label: 'Mippedia bahasa Inggris', short: 'EN', color: '#2563eb' } | |||
}; | |||
var html = ` | |||
<div id="desc-manager" style="background:#ffffff; border:1px solid #e2e8f0; border-left:4px solid #4f46e5; border-radius:14px; padding:20px; margin: 20px 0 24px 0; box-shadow:0 4px 14px rgba(15,23,42,0.03); font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;"> | |||
var html = ` | |||
<div id="desc-manager" style="background:#ffffff; border:1px solid #e2e8f0; border-left:4px solid #4f46e5; border-radius:14px; padding:20px; margin: 20px 0 24px 0; box-shadow:0 4px 14px rgba(15,23,42,0.03); font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;"> | |||
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:12px;"> | <div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:12px;"> | ||
<span style="font-size:12px; font-weight:800; color:#334155; text-transform:uppercase; letter-spacing:0.6px; display:flex; align-items:center; gap:6px;"> | <span style="font-size:12px; font-weight:800; color:#334155; text-transform:uppercase; letter-spacing:0.6px; display:flex; align-items:center; gap:6px;"> | ||
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 2.042: | 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); | |||
}); | }); | ||
}); | }); | ||