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 528: | Baris 528: | ||
} | } | ||
}); | }); | ||
}); | |||
/* MIPPEDIA DATA CENTER - ENGINE */ | |||
$(document).ready(function() { | |||
var ns = mw.config.get('wgNamespaceNumber'); | |||
var pageName = mw.config.get('wgPageName'); | |||
if (ns === 0 && !mw.config.get('wgIsMainPage')) { | |||
// Render Kotak Input di atas Infobox | |||
var html = ` | |||
<div id="mippedia-manager" style="border: 2px solid #36c; padding: 15px; background: #fff; margin-bottom: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);"> | |||
<div style="font-weight: bold; color: #36c; margin-bottom: 10px; display: flex; justify-content: space-between;"> | |||
<span>🌐 Mippedia Central Description</span> | |||
<button id="btn-edit-mip" style="padding: 2px 8px; cursor: pointer;">Edit Data</button> | |||
</div> | |||
<div id="mip-display" style="font-style: italic; color: #555; font-size: 0.9em;">Memuat data dari database...</div> | |||
<div id="mip-form" style="display:none; margin-top: 10px; border-top: 1px solid #eee; pt: 10px;"> | |||
<label style="display:block; font-size:12px;">ID (Bahasa Indonesia):</label> | |||
<input type="text" id="mip-id" style="width:100%; margin-bottom:8px; padding:4px;"> | |||
<label style="display:block; font-size:12px;">EN (English):</label> | |||
<input type="text" id="mip-en" style="width:100%; margin-bottom:8px; padding:4px;"> | |||
<label style="display:block; font-size:12px;">Concise (Ringkas):</label> | |||
<input type="text" id="mip-concise" style="width:100%; margin-bottom:12px; padding:4px;"> | |||
<button id="mip-save" style="background: #36c; color: #fff; border: none; padding: 6px 12px; border-radius: 4px; cursor: pointer;">Simpan Permanen</button> | |||
</div> | |||
</div>`; | |||
$('.mw-parser-output').prepend(html); | |||
// Load Data Existing dari API | |||
$.getJSON(mw.util.wikiScript('api'), { | |||
action: 'query', | |||
prop: 'revisions', | |||
titles: pageName, | |||
rvprop: 'content', | |||
format: 'json' | |||
}, function(data) { | |||
var page = Object.values(data.query.pages)[0]; | |||
if (page.revisions) { | |||
var content = page.revisions[0]['*']; | |||
var match = content.match(/<mipdata>([\s\S]*?)<\/mipdata>/); | |||
if (match) { | |||
var json = JSON.parse(match[1]); | |||
$('#mip-id').val(json.id); | |||
$('#mip-en').val(json.en); | |||
$('#mip-concise').val(json.concise); | |||
$('#mip-display').html(`<b>ID:</b> ${json.id || '-'} | <b>EN:</b> ${json.en || '-'} | <b>Concise:</b> ${json.concise || '-'}`); | |||
} | |||
} | |||
}); | |||
$('#btn-edit-mip').click(function() { $('#mip-form').slideToggle(); }); | |||
// Simpan Data | |||
$('#mip-save').click(function() { | |||
var newData = { | |||
id: $('#mip-id').val(), | |||
en: $('#mip-en').val(), | |||
concise: $('#mip-concise').val() | |||
}; | |||
var tag = "\n<mipdata>" + JSON.stringify(newData) + "</mipdata>"; | |||
new mw.Api().postWithToken('csrf', { | |||
action: 'edit', | |||
title: pageName, | |||
summary: 'Update Mippedia Central Metadata', | |||
appendtext: tag, // Menyimpan secara permanen di akhir halaman | |||
nocreate: true | |||
}).done(function() { | |||
alert('Data berhasil disimpan permanen!'); | |||
location.reload(); | |||
}); | |||
}); | |||
} | |||
}); | }); | ||