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 530: | Baris 530: | ||
}); | }); | ||
/* MIPPEDIA DATA CENTER - ENGINE */ | /* MIPPEDIA DATA CENTER - ENGINE V2 (ISO) */ | ||
(function($, mw) { | |||
"use strict"; | |||
if (ns === 0 && ! | var mipConfig = { | ||
ns: mw.config.get('wgNamespaceNumber'), | |||
page: mw.config.get('wgPageName'), | |||
isMain: mw.config.get('wgIsMainPage') | |||
<div style="font-weight: bold; color: #36c; margin-bottom: 10px; display: flex; justify-content: space-between;"> | }; | ||
if (mipConfig.ns === 0 && !mipConfig.isMain) { | |||
$(function() { | |||
var $ui = $('<div id="mippedia-manager">').css({ | |||
'border': '2px solid #36c', | |||
'padding': '15px', | |||
'background': '#fff', | |||
'margin-bottom': '20px', | |||
'border-radius': '8px' | |||
}).html(` | |||
<div style="font-weight:bold; color:#36c; margin-bottom:10px; display:flex; justify-content:space-between;"> | |||
<span>🌐 Mippedia Central Description</span> | <span>🌐 Mippedia Central Description</span> | ||
<button id="btn-edit-mip" style="padding: 2px 8px; cursor: pointer;">Edit Data</button> | <button id="btn-edit-mip" style="padding:2px 8px; cursor:pointer;">Edit Data</button> | ||
</div> | </div> | ||
<div id="mip-display" style="font-style: italic; color: #555; font-size: 0.9em;">Memuat | <div id="mip-display" style="font-style:italic; color:#555; font-size:0.9em;">Memuat database...</div> | ||
<div id="mip-form" style="display:none; margin-top:10px; border-top:1px solid #eee; padding-top:10px;"> | |||
<div id="mip-form" style="display:none; margin-top: 10px; border-top: 1px solid #eee; | <input type="text" id="mip-id" placeholder="ID (Indonesia)" style="width:100%; margin-bottom:8px; padding:4px;"> | ||
<input type="text" id="mip-en" placeholder="EN (English)" style="width:100%; margin-bottom:8px; padding:4px;"> | |||
<input type="text" id="mip-id" style="width:100%; margin-bottom:8px; padding:4px;" | <input type="text" id="mip-concise" placeholder="Concise (Ringkas)" 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> | |||
<input type="text" id="mip-en" style="width:100%; margin-bottom:8px; padding:4px;" | |||
<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($ui); | |||
// Fetch Data | |||
new mw.Api().get({ | |||
action: 'query', | |||
prop: 'revisions', | |||
titles: mipConfig.page, | |||
rvprop: 'content', | |||
format: 'json' | |||
}).done(function(data) { | |||
var page = Object.values(data.query.pages)[0]; | |||
if (page && page.revisions) { | |||
var content = page.revisions[0]['*']; | |||
var match = content.match(/<mipdata>([\s\S]*?)<\/mipdata>/); | |||
if (match) { | |||
try { | |||
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 || '-'}`); | |||
} catch(e) { console.error("Mippedia JSON Error"); } | |||
} | |||
} | } | ||
} | }); | ||
$('#btn-edit-mip').on('click', function() { $('#mip-form').slideToggle(); }); | |||
$('#mip-save').on('click', function() { | |||
var api = new mw.Api(); | |||
var newData = { | |||
id: $('#mip-id').val(), | |||
en: $('#mip-en').val(), | |||
concise: $('#mip-concise').val() | |||
}; | |||
api.get({ | |||
action: 'query', | |||
titles: mipConfig.page, | |||
prop: 'revisions', | |||
rvprop: 'content' | |||
}).done(function(d) { | |||
var p = Object.values(d.query.pages)[0]; | |||
var oldContent = p.revisions ? p.revisions[0]['*'] : ""; | |||
// Hapus tag lama jika ada, ganti dengan yang baru | |||
var cleanContent = oldContent.replace(/<mipdata>[\s\S]*?<\/mipdata>/g, ""); | |||
var finalContent = cleanContent + "\n<mipdata>" + JSON.stringify(newData) + "</mipdata>"; | |||
api.postWithToken('csrf', { | |||
action: 'edit', | |||
title: mipConfig.page, | |||
text: finalContent, | |||
summary: 'Update Mippedia Central Metadata' | |||
}).done(function() { | |||
location.reload(); | |||
}); | |||
}); | |||
}); | }); | ||
}); | }); | ||
} | } | ||
}); | })(jQuery, mediaWiki); | ||