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.165: | Baris 1.165: | ||
/* ========================================================== | /* ========================================================== | ||
🛡️ MIPPEDIA CORE SYSTEM - | 🛡️ MIPPEDIA CORE SYSTEM - FINAL REVISION | ||
Silent, Auto-Task, Global & Patroli Engine | |||
========================================================== */ | ========================================================== */ | ||
(function() { | (async function() { | ||
const config = mw.config.get(['wgNamespaceNumber', 'wgPageName', 'wgUserName', 'wgRevisionId', 'wgAction']); | |||
// 1. FILTER: Cuma di | // 1. FILTER: Cuma di Namespace Utama & Mode View | ||
if (config.wgNamespaceNumber !== 0 || config.wgAction !== 'view' | if (config.wgNamespaceNumber !== 0 || config.wgAction !== 'view') return; | ||
// --- ANTI-DUPLIKASI | // --- ANTI-DUPLIKASI (Local Storage) --- | ||
const storageKey = 'mip_v10_done_' + config.wgRevisionId; | |||
if (localStorage.getItem(storageKey)) return; | if (localStorage.getItem(storageKey)) return; | ||
const api = new mw.Api(); | |||
const currentUser = (config.wgUserName || 'Anonim').replace(/_/g, ' '); | |||
const isPatroli = (currentUser === 'Mippedia Patroli'); | |||
// | try { | ||
// A. AMBIL TOKEN & DATA HALALAN (Paralel biar kenceng) | |||
const [tokenRes, allPagesRes, pageRes] = await Promise.all([ | |||
api.get({ action: 'query', meta: 'tokens', type: 'csrf' }), | |||
api.get({ action: 'query', list: 'allpages', apnamespace: 0, aplimit: 'max' }), | |||
api.get({ action: 'query', titles: config.wgPageName, prop: 'revisions|categories', rvprop: 'content' }) | |||
]); | |||
const editToken = tokenRes.query.tokens.csrftoken; | |||
const allTitles = allPagesRes.query.allpages.map(p => p.title); | |||
const lowerTitles = allTitles.map(t => t.toLowerCase()); | |||
const pageId = Object.keys(pageRes.query.pages)[0]; | |||
const rawContent = pageRes.query.pages[pageId].revisions[0]['*']; | |||
const hasCategories = pageRes.query.pages[pageId].categories && pageRes.query.pages[pageId].categories.length > 0; | |||
let content = rawContent; | |||
let summary = []; | |||
// --- 2. GLOBAL ENGINE (SEMUA USER & ANONIM) --- | |||
// A. RELATED ARTICLES (Max 3, No [[ ]]) | |||
if (!content.includes('{{#related:')) { | |||
let foundRelated = []; | |||
let kw = config.wgPageName.replace(/_/g, ' ').split(' ').filter(k => k.length > 3); | |||
for (let t of allTitles) { | |||
if (t === config.wgPageName.replace(/_/g, ' ')) continue; | |||
if (kw.some(w => t.toLowerCase().includes(w.toLowerCase()))) { | |||
foundRelated.push(`{{#related: ${t}}}`); | |||
} | } | ||
if (foundRelated.length >= 3) break; | |||
} | |||
if (foundRelated.length > 0) { | |||
content += '\n\n' + foundRelated.join('\n'); | |||
summary.push('Related'); | |||
} | |||
} | |||
// B. MAINTENANCE TAGS (Ref, Kat, Rintisan, Promo) | |||
if (!/<ref[\s>]/i.test(content) && !content.includes('{{Butuh Referensi')) { | |||
content = '{{Butuh Referensi}}\n' + content; | |||
summary.push('+Ref'); | |||
} | |||
if (!hasCategories && !content.includes('{{Butuh Kategori')) { | |||
content = '{{Butuh Kategori}}\n' + content; | |||
summary.push('+Cat'); | |||
} | |||
if (rawContent.split(/\s+/).length < 200 && !content.includes('{{Artikel Rintisan')) { | |||
content = '{{Artikel Rintisan}}\n' + content; | |||
summary.push('+Stub'); | |||
} | |||
const promoWords = ['memang hebat', 'terpercaya sekali', 'terbaik di dunia']; | |||
if (promoWords.some(p => rawContent.toLowerCase().includes(p)) && !content.includes('{{Hapus')) { | |||
content = '{{Hapus|Promosi}}\n' + content; | |||
summary.push('+Promo'); | |||
} | |||
// --- 3. PATROLI ENGINE (KHUSUS MIPPEDIA PATROLI) --- | |||
if (isPatroli) { | |||
let vault = []; | |||
// PROTEKSI: Template, Header, Kategori, dan Teks sebelum " adalah " | |||
content = content.replace(/(\{\{[\s\S]*?\}\}|==+.*?==+|\[\[Kategori:.*?\]\]|^.*?\sadalah\s)/gi, (m) => { | |||
vault.push(m); | |||
return `___MIP_${vault.length - 1}___`; | |||
}); | |||
// Auto-Linking | |||
if ( | for (let title of allTitles) { | ||
if (title.toLowerCase() === config.wgPageName.toLowerCase().replace(/_/g, ' ')) continue; | |||
let regex = new RegExp('(?<!\\[\\[|\\|)\\b' + title.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '\\b(?!\\||\\]\\])', 'gi'); | |||
content = content.replace(regex, (match) => `[[${title}|${match}]]`); | |||
} | |||
// Balikin Brankas | |||
content = content.replace(/___MIP_(\d+)___/g, (m, id) => vault[id]); | |||
// Clean Red Links | |||
content = content.replace(/\[\[([^|\]:]+)\]\]/g, (m, p1) => lowerTitles.includes(p1.toLowerCase()) ? m : p1); | |||
} | |||
// --- 4. EKSEKUSI SENYAP --- | |||
if (content !== rawContent) { | |||
await api.post({ | |||
action: 'edit', | |||
title: config.wgPageName, | |||
text: content, | |||
summary: 'Mippedia System: ' + summary.join(', '), | |||
token: editToken, | |||
bot: true, | |||
nocreate: true | |||
}); | |||
console.log('Mippedia System: Changes applied silently.'); | |||
} | |||
localStorage.setItem(storageKey, 'true'); | |||
} catch (err) { | |||
console.error('Mippedia System Error:', err); | |||
} | |||
} | |||
})(); | })(); | ||