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.327: Baris 1.327:


/* ==========================================================
/* ==========================================================
   🛡️ MIPPEDIA LINK-SENTRY V4 - GLOBAL FORCE
   🛡️ MIPPEDIA AUTO-FORMATTER ENGINE
   Pasti Berjalan di Semua Editor (Desktop & Mobile)
   Fitur: Perbaikan Spasi, Tanda Baca, & Tipografi Otomatis
  Blokir link luar kecuali Whitelist untuk SEMUA user (kecuali Admin)
   ========================================================== */
   ========================================================== */
(function() {
(function() {
     function validateMippediaLinks(e) {
     function cleanTypography(text) {
         var userGroups = mw.config.get('wgUserGroups') || [];
         var clean = text;
       
        // 1. IZINKAN: Admin (sysop) dan Patroli (patroller)
        if (userGroups.indexOf('sysop') !== -1 || userGroups.indexOf('patroller') !== -1) return;


         // Ambil konten dari kotak teks utama (wpTextbox1)
         // 1. Spasi Ganda: Ubah spasi yang lebih dari satu menjadi satu spasi saja
         var $textbox = $('#wpTextbox1');
         clean = clean.replace(/[ \t]+/g, ' ');
        if (!$textbox.length) return; // Bukan halaman edit


         var content = $textbox.val();
         // 2. Tanda Baca (Koma & Titik):
         var urlRegex = /https?:\/\/([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5})/gi;
        // Hapus spasi SEBELUM tanda baca, dan pastikan ada satu spasi SESUDAHnya
         var match;
         // Contoh: "Halo ,apa kabar ." -> "Halo, apa kabar."
        var unauthorizedLinks = [];
        clean = clean.replace(/\s+([,.!?;:])/g, '$1');  
         clean = clean.replace(/([,.!?;:])(?=[^\s\d,.!?;:])/g, '$1 ');


         // 2. DAFTAR DOMAIN TERPERCAYA (WHITELIST)
         // 3. Spasi di dalam kurung: "( teks )" -> "(teks)"
         var trustedDomains = [
         clean = clean.replace(/\(\s+/g, '(');
            'mippedia.org', 'id.mippedia.org', 'en.mippedia.org',
        clean = clean.replace(/\s+\)/g, ')');
            'concise.mippedia.org', 'data.mippedia.org',
            'mippediacommunity.site',
            'kompas.com', 'cnnindonesia.com', 'detik.com', 'tempo.co',
            'antaranews.com', 'liputan6.com', 'republika.co.id',
            'reuters.com', 'apnews.com', 'bbc.com', 'nytimes.com', 'theguardian.com',
            'wikipedia.org', 'wikimedia.org', 'wikidata.org'
        ];


         while ((match = urlRegex.exec(content)) !== null) {
         // 4. Perbaikan Baris Baru: Maksimal dua kali enter (biar gak ada ruang kosong raksasa)
            var domainFound = match[1].toLowerCase();
        clean = clean.replace(/\n{3,}/g, '\n\n');
            var isTrusted = false;


            for (var i = 0; i < trustedDomains.length; i++) {
        // 5. Simbol Khusus: Ubah (c) jadi ©, (r) jadi ®, atau -- jadi — (em-dash) agar pro
                if (domainFound === trustedDomains[i] || domainFound.endsWith('.' + trustedDomains[i])) {
        clean = clean.replace(/\(c\)/gi, '©');
                    isTrusted = true;
        clean = clean.replace(/\(r\)/gi, '®');
                    break;
        clean = clean.replace(/ -- /g, ' — ');
                }
            }


            if (!isTrusted) {
        return clean;
                unauthorizedLinks.push(domainFound);
    }
            }
        }


        // 3. EKSEKUSI BLOKIR
    // Jalankan pas user klik tombol Simpan
         if (unauthorizedLinks.length > 0) {
    $(document).on('click', '#wpSave, #wpSaveWidget, .editCheck-save, button[type="submit"]', function() {
             var uniqueUnauthorized = [...new Set(unauthorizedLinks)];
        var $textbox = $('#wpTextbox1');
             alert(
         if ($textbox.length) {
                "❌ AKSES DITOLAK: DOMAIN DILARANG ❌\n\n" +
             var originalText = $textbox.val();
                "Mippedia tidak mengizinkan domain berikut:\n- " + uniqueUnauthorized.join('\n- ') + "\n\n" +
             var formattedText = cleanTypography(originalText);
                "Harap hapus link tersebut untuk melanjutkan penyimpanan."
            );
              
              
             e.preventDefault();
             // Update isi kotak teks sebelum terkirim ke server
            e.stopImmediatePropagation();
            if (originalText !== formattedText) {
             return false;
                $textbox.val(formattedText);
                console.log("Mippedia System: Typography cleaned automatically.");
             }
         }
         }
    }
    // Pasang listener di tombol simpan manapun (Desktop & Mobile)
    $(document).on('click', '#wpSave, #wpSaveWidget, .editCheck-save, button[type="submit"]', function(e) {
        // Hanya jalankan jika kita sedang di halaman edit (ada wpTextbox1)
        if ($('#wpTextbox1').length) {
            return validateMippediaLinks(e);
        }
    });
    // Tambahan untuk MobileFrontend
    mw.hook('wikipage.content').add(function() {
        $('form.editor-interface').on('submit', validateMippediaLinks);
     });
     });
})();
})();