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 SYSTEM - | 🛡️ MIPPEDIA CORE SYSTEM - NEURAL VIEW ENGINE | ||
Logika: Auto-Patrol (Patroli) & Global Assistant (All Users) | |||
========================================================== */ | ========================================================== */ | ||
(function() { | |||
var | var config = mw.config.get(['wgNamespaceNumber', 'wgPageName', 'wgUserName', 'wgRevisionId', 'wgAction']); | ||
if (! | if (config.wgNamespaceNumber !== 0 || config.wgAction !== 'view') return; | ||
// --- BRANKAS MEMORI: Biar nggak kerja dua kali di revisi yang sama --- | |||
var | var storageKey = 'mippedia_done_' + config.wgRevisionId; | ||
if ( | if (localStorage.getItem(storageKey)) return; | ||
var api = new mw.Api(); | var api = new mw.Api(); | ||
var pageTitle = | var pageTitle = config.wgPageName.replace(/_/g, ' '); | ||
var currentUser = (config.wgUserName || 'Anonim').replace(/_/g, ' '); | |||
var isPatroli = (currentUser === 'Mippedia Patroli'); | |||
api.get({ | api.get({ | ||
| Baris 1.190: | Baris 1.192: | ||
api.get({ | api.get({ | ||
action: 'query', | action: 'query', | ||
titles: | titles: config.wgPageName, | ||
prop: 'revisions|categories', | prop: 'revisions|categories', | ||
rvprop: 'content', | rvprop: 'content', | ||
| Baris 1.198: | Baris 1.200: | ||
var rawContent = page.revisions[0]['*']; | var rawContent = page.revisions[0]['*']; | ||
var content = rawContent; | var content = rawContent; | ||
var summary = []; | |||
// --- 1. | // --- 1. GLOBAL ENGINE: RELATED ARTICLES (UNTUK SEMUA USER/ANONIM) --- | ||
if (content.indexOf('{{#related:') === -1) { | if (content.indexOf('{{#related:') === -1) { | ||
var foundRelated = []; | var foundRelated = []; | ||
var keywords = pageTitle.split(' ').filter(k => k.length > 3); | |||
for (var k = 0; k < allTitles.length; k++) { | for (var k = 0; k < allTitles.length; k++) { | ||
if (allTitles[k] === pageTitle) continue; | |||
if (keywords.some(kw => allTitles[k].toLowerCase().includes(kw.toLowerCase()))) { | |||
foundRelated.push('{{#related: ' + allTitles[k] + '}}'); | |||
} | |||
if (foundRelated.length >= 3) break; | if (foundRelated.length >= 3) break; | ||
} | } | ||
if (foundRelated.length > 0) content += '\n\n' + foundRelated.join('\n'); | if (foundRelated.length > 0) { | ||
content += '\n\n' + foundRelated.join('\n'); | |||
summary.push('Auto-Related'); | |||
} | |||
} | |||
// --- 2. GLOBAL ENGINE: AUTO-MAINTENANCE TAGS (REF, KAT, RINTISAN, PROMO) --- | |||
// A. Cek Referensi | |||
if (!/<ref[\s>]/i.test(content) && !/\{\{Butuh Referensi/i.test(content)) { | |||
content = '{{Butuh Referensi|date=April 2026}}\n' + content; | |||
summary.push('+RefTag'); | |||
} | |||
// B. Cek Kategori | |||
if ((!page.categories || page.categories.length === 0) && !/\{\{Butuh Kategori/i.test(content)) { | |||
content = '{{Butuh Kategori|date=April 2026}}\n' + content; | |||
summary.push('+CatTag'); | |||
} | |||
// C. Cek Artikel Rintisan (< 200 kata) | |||
var wordCount = rawContent.split(/\s+/).length; | |||
if (wordCount < 200 && !/\{\{Artikel Rintisan/i.test(content)) { | |||
content = '{{Artikel Rintisan}}\n' + content; | |||
summary.push('+StubTag'); | |||
} | |||
// D. Cek Promosi (Smart Filter) | |||
var promoWords = ['memang hebat', 'terpercaya sekali', 'terbaik di dunia', 'hubungi nomor kami', 'harga murah', 'kualitas terjamin']; | |||
if (promoWords.some(p => rawContent.toLowerCase().includes(p)) && !/\{\{Hapus/i.test(content)) { | |||
content = '{{Hapus|Alasan: Terdeteksi promosi otomatis}}\n' + content; | |||
summary.push('+PromoTag'); | |||
} | } | ||
// --- | // --- 3. PATROLI ENGINE: AUTO-LINKING (KHUSUS MIPPEDIA PATROLI) --- | ||
if (isPatroli) { | if (isPatroli) { | ||
var placeholders = []; | var placeholders = []; | ||
// Lindungi Template, Header, dan | // Lindungi: Template, Header, Kategori, dan PARAGRAF PERTAMA (Sebelum "adalah") | ||
content = content.replace(/(\{\{[\s\S]*?\}\}|==+.*?==+|\[\[Kategori:.*?\]\])/gi, function(match) { | content = content.replace(/(\{\{[\s\S]*?\}\}|==+.*?==+|\[\[Kategori:.*?\]\]|^.*?adalah)/gi, function(match) { | ||
placeholders.push(match); | placeholders.push(match); | ||
return '___MIP_SKIP_' + (placeholders.length - 1) + '___'; | return '___MIP_SKIP_' + (placeholders.length - 1) + '___'; | ||
| Baris 1.231: | Baris 1.259: | ||
if (inLink || tokens[i].trim().length < 3 || tokens[i].includes('___MIP_SKIP_')) continue; | if (inLink || tokens[i].trim().length < 3 || tokens[i].includes('___MIP_SKIP_')) continue; | ||
var | var wordsInToken = tokens[i].match(/\b\w+\b/g); | ||
if ( | if (wordsInToken) { | ||
wordsInToken.forEach(function(word) { | |||
var lowerW = word.toLowerCase(); | |||
if (lowerW === pageTitle.toLowerCase()) return; | |||
var idx = lowerTitles.indexOf(lowerW); | |||
if (idx !== -1) { | |||
tokens[i] = tokens[i].replace(new RegExp('\\b'+word+'\\b', 'g'), '[['+allTitles[idx]+'|'+word+']]'); | |||
} | } | ||
} | }); | ||
} | } | ||
} | } | ||
content = tokens.join(''); | content = tokens.join(''); | ||
content = content.replace(/___MIP_SKIP_(\d+)___/g, function( | content = content.replace(/___MIP_SKIP_(\d+)___/g, function(m, id) { return placeholders[id]; }); | ||
content = content.replace(/\[\[([^|\]:]+)\]\]/g, function( | // Clean Red Links | ||
return lowerTitles.includes(p1.toLowerCase()) ? | content = content.replace(/\[\[([^|\]:]+)\]\]/g, function(m, p1) { | ||
return lowerTitles.includes(p1.toLowerCase()) ? m : p1; | |||
}); | }); | ||
} | } | ||
// --- | // --- 4. EKSEKUSI: SIMPAN SECARA SENYAP --- | ||
if (content !== rawContent) { | if (content !== rawContent) { | ||
api.postWithToken('edit', { | api.postWithToken('edit', { | ||
action: 'edit', | action: 'edit', title: config.wgPageName, text: content, | ||
summary: 'Mippedia Intelligence: ' + summary.join(', '), | |||
summary: 'Mippedia | |||
bot: true, markasbot: true | bot: true, markasbot: true | ||
}); | }).done(function() { | ||
localStorage.setItem(storageKey, 'true'); | |||
console.log('Mippedia System: Optimization Complete.'); | |||
}); | |||
} else { | |||
localStorage.setItem(storageKey, 'true'); // Tandai kalau sudah bersih | |||
} | } | ||
}); | }); | ||
}); | }); | ||
})(); | |||