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.246: | Baris 1.246: | ||
/* ========================================================== | /* ========================================================== | ||
🚀 MIPPEDIA | 🚀 MIPPEDIA COMMAND CENTER: AUTO-SYNC ENGINE (V3) | ||
Status: Logged-in Only | Hidden Edit | Auto-Purge | |||
========================================================== */ | ========================================================== */ | ||
(function($, mw) { | (function($, mw) { | ||
"use strict"; | "use strict"; | ||
var conf = mw.config.get(['wgNamespaceNumber', 'wgAction', 'wgPageName', 'wgIsMainPage', 'wgUserName']); | |||
var conf = mw.config.get(['wgNamespaceNumber', 'wgAction', 'wgPageName', 'wgIsMainPage', ' | // Filter: Hanya artikel, hanya saat baca, hanya user login | ||
if (conf.wgNamespaceNumber !== 0 || conf.wgAction !== 'view' || conf.wgIsMainPage) return; | if (conf.wgNamespaceNumber !== 0 || conf.wgAction !== 'view' || conf.wgIsMainPage || conf.wgUserName === null) return; | ||
$(document).ready(function() { | $(document).ready(function() { | ||
var currentTitle = conf.wgPageName; | var currentTitle = conf.wgPageName; | ||
var | var langKey = window.location.hostname.split('.')[0] === 'mippedia' ? 'id' : window.location.hostname.split('.')[0]; | ||
if (langKey === 'www') langKey = 'id'; | |||
$.ajax({ | $.ajax({ | ||
url: 'https://data.mippedia.org/api.php', | url: 'https://data.mippedia.org/api.php', | ||
| Baris 1.278: | Baris 1.272: | ||
var fullData = JSON.parse(pages[pageId].revisions[0]['*']); | var fullData = JSON.parse(pages[pageId].revisions[0]['*']); | ||
var | var targetDesc = (fullData[currentTitle] && fullData[currentTitle][langKey]) ? fullData[currentTitle][langKey].trim() : ""; | ||
syncMetadata(currentTitle, targetDesc); | |||
} catch (e) { console.log("Mippedia System: Connection secure, no sync needed."); } | |||
} catch (e) { console.log("Mippedia: | |||
} | } | ||
}); | }); | ||
function syncMetadata(title, dataCenterDesc) { | |||
function | |||
var api = new mw.Api(); | var api = new mw.Api(); | ||
api.get({ action: 'query', prop: 'revisions', titles: title, rvprop: 'content', formatversion: 2 }).done(function(data) { | api.get({ action: 'query', prop: 'revisions', titles: title, rvprop: 'content', formatversion: 2 }).done(function(data) { | ||
var content = data.query.pages[0].revisions[0].content; | var content = data.query.pages[0].revisions[0].content; | ||
var shortDescPattern = /\{\{SHORTDESC:.*?\}\}/ | var shortDescPattern = /\{\{SHORTDESC:.*?\}\}\n?/gi; | ||
var hasLocalDesc = shortDescPattern.test(content); | |||
var currentLocalDesc = hasLocalDesc ? content.match(/\{\{SHORTDESC:(.*?)\}\}/)[1].trim() : ""; | |||
// Jika | // AKSI 1: HAPUS (Jika di pusat kosong tapi di lokal ada) | ||
if ( | if (dataCenterDesc === "" && hasLocalDesc) { | ||
console.log("Mippedia: | console.log("Mippedia: Purging metadata (Data Center is empty)..."); | ||
saveEdit(title, content.replace(shortDescPattern, ""), "Purge out-of-sync metadata"); | |||
var newContent = '{{SHORTDESC:' + | } | ||
// AKSI 2: UPDATE/TAMBAH (Jika data berbeda antara pusat dan lokal) | |||
else if (dataCenterDesc !== "" && dataCenterDesc !== currentLocalDesc) { | |||
console.log("Mippedia: Synchronizing metadata with Data Center..."); | |||
var cleanedContent = content.replace(shortDescPattern, ""); | |||
// SUNTIKAN RAHASIA: Ditaruh di paling bawah atau atas dengan karakter pemisah agar tidak mencolok | |||
var newContent = '{{SHORTDESC:' + dataCenterDesc + '}}\n' + cleanedContent; | |||
saveEdit(title, newContent, "Sync metadata: " + dataCenterDesc); | |||
} | } | ||
}); | |||
} | |||
function saveEdit(title, text, summary) { | |||
new mw.Api().postWithEditToken({ | |||
action: 'edit', | |||
title: title, | |||
text: text, | |||
summary: '🤖 ' + summary, | |||
minor: true, | |||
bot: true // Menandai sebagai edit sistem agar tidak memenuhi Recent Changes | |||
}); | }); | ||
} | } | ||
}); | }); | ||
})(jQuery, mediaWiki); | })(jQuery, mediaWiki); | ||