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 1: | Baris 1: | ||
/** | /** | ||
* ==================================================================== | * ==================================================================== | ||
* MIPPEDIA DATA - ADVANCED STRUCTURED DATA SYSTEM (V9. | * MIPPEDIA DATA - ADVANCED STRUCTURED DATA SYSTEM (V9.1 SECURE ULTIMATE) | ||
* ==================================================================== | * ==================================================================== | ||
*/ | */ | ||
| Baris 21: | Baris 21: | ||
} | } | ||
var pathName = window.location.pathname || ''; | |||
var searchStr = window.location.search || ''; | var searchStr = window.location.search || ''; | ||
if (/[?&](action|diff|oldid|veaction|redlink)=/i.test(searchStr)) return false; | if (/[?&](action|diff|oldid|veaction|redlink|printable)=/i.test(searchStr)) return false; | ||
if (/[?&]title=(Istimewa|Special|MediaWiki):/i.test(searchStr)) return false; | if (/[?&]title=(Istimewa|Special|MediaWiki|Berkas|File|Kategori|Category|Templat|Template|Modul|Module):/i.test(searchStr)) return false; | ||
// Jika diakses via /index.php, pastikan benar-benar tampilan judul entitas biasa tanpa parameter khusus | |||
if (/\/index\.php$/i.test(pathName) && searchStr !== '' && !/^\?title=[^&]+$/i.test(searchStr)) { | |||
return false; | |||
} | |||
return true; | return true; | ||
} | |||
function isCurrentPageRedirect() { | |||
if (typeof mw !== 'undefined' && mw.config && mw.config.get('wgIsRedirect')) return true; | |||
if ($('.redirectMsg, .mw-redirect-link').length > 0) return true; | |||
var txt = ($('#mw-content-text').text() || '').trim(); | |||
return /^(#REDIRECT|#ALIH)\s*\[\[/i.test(txt); | |||
} | } | ||
| Baris 259: | Baris 272: | ||
} | } | ||
function fetchFirstDataCreator() { | function fetchFirstDataCreator() { | ||
return api.get({ | return api.get({ | ||
| Baris 279: | Baris 291: | ||
} | } | ||
function fetchAutoDescriptionForSchema() { | function fetchAutoDescriptionForSchema() { | ||
var cleanIdExtract = function(txt) { | var cleanIdExtract = function(txt) { | ||
var s = (txt || '').replace(/\[\d+\]/g, '').replace(/\{\{[^}]+\}\}/g, '').replace(/\s+/g, ' ').trim(); | |||
if (s.length > 300) { | |||
s = s.substring(0, 297).replace(/\s+\S*$/, '') + '...'; | |||
} | |||
return s; | |||
}; | }; | ||
| Baris 309: | Baris 324: | ||
} | } | ||
var enTarget = cleanPageTitle; | var enTarget = cleanPageTitle; | ||
return $.ajax({ | return $.ajax({ | ||
| Baris 356: | Baris 370: | ||
} | } | ||
// | // Pastikan hanya ada SATU Dataset JSON-LD di halaman & isPartOf valid | ||
function updateJsonLdForSearchEngines() { | function updateJsonLdForSearchEngines() { | ||
if (!isStrictEntityDataPage() | if (!isStrictEntityDataPage() || isCurrentPageRedirect()) return; | ||
var sameAsList = []; | var sameAsList = []; | ||
| Baris 402: | Baris 415: | ||
var finalDesc = schemaMeta.description; | var finalDesc = schemaMeta.description; | ||
if (!finalDesc) { | if (!finalDesc) { | ||
var domDesc = $('#mip-auto-description').text().replace(/Baca selengkapnya/gi, '').trim(); | var domDesc = ($('#mip-auto-description').text() || '').replace(/Baca selengkapnya/gi, '').trim(); | ||
if (domDesc) finalDesc = domDesc; | if (domDesc) finalDesc = domDesc; | ||
} | } | ||
if (!finalDesc) { | if (!finalDesc) { | ||
finalDesc = " | finalDesc = "Kumpulan data terstruktur entitas " + cleanPageTitle + " pada repositori Mippedia Data."; | ||
} | |||
if (finalDesc.length > 300) { | |||
finalDesc = finalDesc.substring(0, 297).replace(/\s+\S*$/, '') + '...'; | |||
} | } | ||
var pageUrl = window.location.href.split('#')[0]; | |||
var ldJson = { | var ldJson = { | ||
"@context": "https://schema.org", | "@context": "https://schema.org", | ||
"@type": "Dataset", | "@type": "Dataset", | ||
"identifier": | "identifier": pageUrl, | ||
"url": | "url": pageUrl, | ||
"name": cleanPageTitle, | "name": cleanPageTitle, | ||
"headline": "Data Terstruktur: " + cleanPageTitle, | "headline": "Data Terstruktur: " + cleanPageTitle, | ||
"description": finalDesc, | "description": finalDesc, | ||
"isPartOf | "isPartOf": "https://data.mippedia.org/", | ||
"license": "https://creativecommons.org/publicdomain/zero/1.0/", | "license": "https://creativecommons.org/publicdomain/zero/1.0/", | ||
"creator": { | "creator": { | ||
| Baris 438: | Baris 452: | ||
if (citations.length > 0) ldJson.citation = citations; | if (citations.length > 0) ldJson.citation = citations; | ||
// Hapus atau perbarui skrip JSON-LD lain yang menghasilkan Dataset duplikat | |||
$('script[type="application/ld+json"]').each(function() { | |||
if (this.id === 'mip-jsonld-schema') return; | |||
try { | |||
var parsed = JSON.parse($(this).text()); | |||
var types = Array.isArray(parsed['@type']) ? parsed['@type'] : [parsed['@type']]; | |||
if (types.indexOf('Dataset') !== -1) { | |||
$(this).remove(); | |||
} | |||
} catch (e) {} | |||
}); | |||
$('#mip-jsonld-schema').remove(); | |||
var $script = $('<script type="application/ld+json" id="mip-jsonld-schema"></script>'); | var $script = $('<script type="application/ld+json" id="mip-jsonld-schema"></script>'); | ||
$script.text(JSON.stringify(ldJson, null, 2)); | $script.text(JSON.stringify(ldJson, null, 2)); | ||
| Baris 706: | Baris 733: | ||
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 V9. | var summaryTxt = customSummary ? ('Mippedia Data: ' + customSummary) : ('Mippedia Data V9.1: ' + 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 767: | Baris 794: | ||
// 7. BUILDER UI UTAMA | // 7. BUILDER UI UTAMA | ||
function buildUI(rawContent) { | function buildUI(rawContent) { | ||
if (isCurrentPageRedirect()) return; | |||
updateJsonLdForSearchEngines(); | updateJsonLdForSearchEngines(); | ||
| Baris 1.313: | Baris 1.341: | ||
// 10. EXECUTE | // 10. EXECUTE | ||
loadData().then(function(rawContent) { | loadData().then(function(rawContent) { | ||
if (isCurrentPageRedirect()) return; | |||
var candidates = collectCandidateTitlesForLinks(); | var candidates = collectCandidateTitlesForLinks(); | ||
checkPagesExistBatch(candidates).always(function() { | checkPagesExistBatch(candidates).always(function() { | ||
| Baris 1.363: | Baris 1.392: | ||
/* ========================================================== | /* ========================================================== | ||
🧠 MIPPEDIA DATA - SMART CONTEXT + | 🧠 MIPPEDIA DATA - SMART CONTEXT + REDIRECT & HIDE ENGINE (V10.5) | ||
========================================================== */ | ========================================================== */ | ||
(function() { | (function() { | ||
| Baris 1.381: | Baris 1.409: | ||
} | } | ||
var pathName = window.location.pathname || ''; | |||
var searchStr = window.location.search || ''; | var searchStr = window.location.search || ''; | ||
if (/[?&](action|diff|oldid|veaction|redlink)=/i.test(searchStr)) return false; | if (/[?&](action|diff|oldid|veaction|redlink|printable)=/i.test(searchStr)) return false; | ||
if (/[?&]title=(Istimewa|Special|MediaWiki):/i.test(searchStr)) return false; | if (/[?&]title=(Istimewa|Special|MediaWiki|Berkas|File|Kategori|Category|Templat|Template|Modul|Module):/i.test(searchStr)) return false; | ||
if (/\/index\.php$/i.test(pathName) && searchStr !== '' && !/^\?title=[^&]+$/i.test(searchStr)) { | |||
return false; | |||
} | |||
return true; | return true; | ||
| Baris 1.427: | Baris 1.460: | ||
var pageTitle = mw.config.get('wgPageName').replace(/_/g, ' '), | var pageTitle = mw.config.get('wgPageName').replace(/_/g, ' '), | ||
cacheKey = ' | cacheKey = 'mip_smart_context_thumb_v105_' + pageTitle, | ||
currentYear = new Date().getFullYear(); | currentYear = new Date().getFullYear(); | ||
| Baris 1.455: | Baris 1.488: | ||
'.mip-is-noindex #desc-manager,' + | '.mip-is-noindex #desc-manager,' + | ||
'.mip-is-noindex .wikitable,' + | '.mip-is-noindex .wikitable,' + | ||
'.mip-is-noindex .infobox {' + | '.mip-is-noindex .infobox,' + | ||
'.mip-redirect-hidden #mippedia-data-app,' + | |||
'.mip-redirect-hidden #mip-desc-section,' + | |||
'.mip-redirect-hidden #mip-header,' + | |||
'.mip-redirect-hidden #mip-connector,' + | |||
'.mip-redirect-hidden #mip-footer,' + | |||
'.mip-redirect-hidden #desc-manager,' + | |||
'.mip-redirect-hidden .wikitable,' + | |||
'.mip-redirect-hidden .infobox {' + | |||
'display: none !important;' + | 'display: none !important;' + | ||
'}' + | '}' + | ||
| Baris 1.544: | Baris 1.585: | ||
function syncDescriptionIntoJsonLd(descText) { | function syncDescriptionIntoJsonLd(descText) { | ||
if (!descText) return; | if (!descText) return; | ||
var cleaned = descText.replace(/\[\d+\]/g, '').replace(/\s+/g, ' ').trim(); | |||
if (cleaned.length > 300) cleaned = cleaned.substring(0, 297).replace(/\s+\S*$/, '') + '...'; | |||
var $ld = $('#mip-jsonld-schema'); | var $ld = $('#mip-jsonld-schema'); | ||
if ($ld.length) { | if ($ld.length) { | ||
try { | try { | ||
var parsed = JSON.parse($ld.text()); | var parsed = JSON.parse($ld.text()); | ||
parsed.description = | parsed.description = cleaned; | ||
$ld.text(JSON.stringify(parsed, null, 2)); | $ld.text(JSON.stringify(parsed, null, 2)); | ||
} catch (e) {} | } catch (e) {} | ||
| Baris 1.554: | Baris 1.597: | ||
} | } | ||
function | // Khusus halaman pengalihan: sembunyikan data (bukan noindex) & pindahkan/hapus metadata ke target pengalihan | ||
function handleRedirectPageHideAndMigrate(targetTitle) { | |||
$('body').addClass('mip-redirect-hidden').removeClass('mip-is-noindex'); | |||
$('#mip-empty-state-notice').remove(); | |||
$('#mippedia-data-app, #mip-desc-section, #mip-header, #mip-connector, #mip-footer, #desc-manager').hide(); | |||
var userGroups = mw.config.get('wgUserGroups') || []; | var userGroups = mw.config.get('wgUserGroups') || []; | ||
var | var isAdmin = userGroups.indexOf('sysop') !== -1 || userGroups.indexOf('interface-admin') !== -1; | ||
if (!isAdmin || !targetTitle) return; | |||
var | var api = new mw.Api(); | ||
var oldKey = pageTitle; | |||
var newKey = targetTitle.replace(/_/g, ' '); | |||
if (!newKey || oldKey.toLowerCase() === newKey.toLowerCase()) return; | |||
if (isEmpty) { | var storePages = ['MediaWiki:Sitelinks-Data.json', 'MediaWiki:ShortDesc-Data.json']; | ||
storePages.forEach(function(stPage) { | |||
api.get({ | |||
action: 'query', | |||
prop: 'revisions', | |||
titles: stPage, | |||
rvprop: 'content', | |||
formatversion: 2 | |||
}).done(function(res) { | |||
var pg = res && res.query && res.query.pages && res.query.pages[0]; | |||
if (!pg || pg.missing || !pg.revisions || !pg.revisions[0]) return; | |||
var jsonObj = {}; | |||
try { jsonObj = JSON.parse(pg.revisions[0].content || '{}'); } catch (e) { return; } | |||
var matchedKey = null; | |||
Object.keys(jsonObj).forEach(function(k) { | |||
if (k.replace(/_/g, ' ').toLowerCase() === oldKey.toLowerCase()) matchedKey = k; | |||
}); | |||
if (matchedKey) { | |||
var oldVal = jsonObj[matchedKey]; | |||
if (!jsonObj[newKey]) { | |||
jsonObj[newKey] = oldVal; | |||
} else if (typeof oldVal === 'object' && typeof jsonObj[newKey] === 'object') { | |||
jsonObj[newKey] = $.extend({}, oldVal, jsonObj[newKey]); | |||
} | |||
delete jsonObj[matchedKey]; | |||
api.postWithEditToken({ | |||
action: 'edit', | |||
title: stPage, | |||
text: JSON.stringify(jsonObj, null, 2), | |||
summary: 'Pindahkan data pengalihan: ' + matchedKey + ' -> ' + newKey | |||
}); | |||
} | |||
}); | |||
}); | |||
} | |||
function checkRedirectAndHide() { | |||
var api = new mw.Api(); | |||
return api.get({ | |||
action: 'query', | |||
prop: 'revisions|info', | |||
titles: pageName, | |||
rvprop: 'content', | |||
inprop: 'redirect', | |||
formatversion: 2 | |||
}).then(function(res) { | |||
var pg = res && res.query && res.query.pages && res.query.pages[0]; | |||
if (!pg || pg.missing) return false; | |||
var raw = (pg.revisions && pg.revisions[0] && pg.revisions[0].content) || ''; | |||
var redMatch = raw.match(/^(?:#REDIRECT|#ALIH)\s*\[\[([^\]|#]+)/i); | |||
if (pg.redirect || redMatch) { | |||
var target = redMatch ? redMatch[1].trim() : ''; | |||
handleRedirectPageHideAndMigrate(target); | |||
return true; | |||
} | |||
return false; | |||
}, function() { | |||
return false; | |||
}); | |||
} | |||
function toggleMippediaLayout(isEmpty) { | |||
if (!isValidDataEntityPage()) return; | |||
var $existingNotice = $('#mip-empty-state-notice'); | |||
var userGroups = mw.config.get('wgUserGroups') || []; | |||
var isSysop = userGroups.indexOf('sysop') !== -1; | |||
var $wikiDataElements = $mainContent.children().not('#mip-empty-state-notice, #mip-desc-section, script, style, .printfooter'); | |||
var $editElements = $('#ca-edit, .mw-editsection, .wb-editsection, .mip-edit-trigger, [id*="edit"], [class*="edit-pencil"]'); | |||
if (isEmpty) { | |||
$('body').addClass('mip-is-noindex').attr('data-mip-noindex', '1'); | $('body').addClass('mip-is-noindex').attr('data-mip-noindex', '1'); | ||
enforceRobotsMeta(true); | enforceRobotsMeta(true); | ||
| Baris 1.626: | Baris 1.748: | ||
function init() { | function init() { | ||
checkRedirectAndHide().done(function(isRed) { | |||
if (isRed) return; | |||
if (id != "-1" && pg[id].langlinks && pg[id].langlinks[0]) { | var pPrimary = projects[0]; | ||
$.ajax({ | |||
url: pPrimary.url, | |||
data: { action: 'query', prop: 'revisions|pageimages|langlinks', lllang: 'en', rvprop: 'timestamp', piprop: 'thumbnail', pithumbsize: 150, titles: pageTitle, format: 'json', origin: '*' }, | |||
dataType: 'json', | |||
success: function(res) { | |||
var pg = res.query.pages, id = Object.keys(pg)[0]; | |||
var latestTS = (id != "-1" && pg[id].revisions && pg[id].revisions[0]) ? pg[id].revisions[0].timestamp : "0"; | |||
var thumbUrl = (id != "-1" && pg[id].thumbnail) ? pg[id].thumbnail.source : ""; | |||
if (id != "-1" && pg[id].langlinks && pg[id].langlinks[0]) { | |||
globalEnTitle = pg[id].langlinks[0]['*']; | |||
} | |||
if (cached.content && cached.ts === latestTS && latestTS !== "0" && !cached.isEmpty) { | |||
toggleMippediaLayout(false); | |||
renderAll(cached.p, cached.content, cached.isTrans, cached.orig, cached.img, cached.customUrl, cached.enTitle); | |||
} else { | |||
fetchPriorityData(0, latestTS, thumbUrl); | |||
} | |||
}, | |||
error: function() { | |||
if (cached.content && !cached.isEmpty) { | |||
toggleMippediaLayout(false); | |||
renderAll(cached.p, cached.content, cached.isTrans, cached.orig, cached.img, cached.customUrl, cached.enTitle); | |||
} else { | |||
fetchPriorityData(0, "0", ""); | |||
} | |||
} | } | ||
} | }); | ||
}); | }); | ||
} | } | ||