MediaWiki:Common.js: различия между версиями

закрытие уязвимости в нигилизме
Метка: отменено
Откат правки 362378 участника Тэйтанка-птекила (обс.)
Метка: отмена
 
(не показано 29 промежуточных версий этого же участника)
Строка 1: Строка 1:
/* Нигилистические фокусы (см. шаблон {{Нигилизм}}) */
/* Нигилистические фокусы (см. шаблон {{tl|Нигилизм}}) */
$(function () {
$(function () {
     var nihilism = $('#nihilism');
     var nihilism = $('#nihilism');
     if (!nihilism[0] || document.location.href.match("diff")) {
     if (nihilism[0] && !document.location.href.match("diff")) {
         return;
         var msg = nihilism.html();
    }
        if (!nihilism.hasClass('nihilism-no-white')) {
   
        $('body').css('background-color', 'white');
    var msg = nihilism.text();
        }
   
        var scripts = $('script');
    if (!nihilism.hasClass('nihilism-no-white')) {
        var bodyNihilism = $('body').html('');
        $('body').css('background-color', 'white');
        var divNihilism = $('<div class="mw-parser-output"></div>').html(msg);
    }
        if (nihilism.css('top') == '0px') {
   
        bodyNihilism.css('top', '0px').css('left', '0px');
    $('body').empty();
        }
   
        bodyNihilism.append(divNihilism).append(scripts);
    var divNihilism = $('<div class="mw-parser-output"></div>').text(msg);
        $(document).dblclick(function () {
   
        window.location = mw.util.getUrl(null, {'action': 'edit'});
    if (nihilism.css('top') == '0px') {
        });
        $('body').css({'top': '0px', 'left': '0px'});
     }
     }
   
    $('body').append(divNihilism);
   
    $(document).dblclick(function () {
        window.location = mw.util.getUrl(null, {'action': 'edit'});
    });
});
});


/* Стирание памяти для [[MIB]] («Людей в чёрном») */
/* Стирание памяти для [[MIB]] («Людей в чёрном») */
Строка 75: Строка 67:




/* Функция для вставки VK-видео на страницу для шаблона {{VKVideo}} */
/* Вставка VK-видео на страницу для шаблона {{VKVideo}} */
(function() {
(function() {
     'use strict';
     'use strict';
Строка 89: Строка 81:
             var height = container.getAttribute('data-height') || '315';
             var height = container.getAttribute('data-height') || '315';
              
              
             if (oid && id && oid !== 'null' && id !== 'null' &&  
            width = parseInt(width) || 560;
                /^[-_a-zA-Z0-9]+$/.test(oid) && /^[-_a-zA-Z0-9]+$/.test(id)) {
            height = parseInt(height) || 315;
               
            if (width > 1920) width = 1920;
            if (height < 100) height = 100;
            if (height > 1080) height = 1080;
           
             if (oid && id && oid !== 'null' && id !== 'null' && /^[a-zA-Z0-9_-]{1,100}$/.test(oid) && /^[-_a-zA-Z0-9]+$/.test(id)) {
                 var iframe = document.createElement('iframe');
                 var iframe = document.createElement('iframe');
                 iframe.src = 'https://vk.com/video_ext.php?oid=' + encodeURIComponent(oid) + '&id=' + encodeURIComponent(id);
                 iframe.src = 'https://vk.com/video_ext.php?oid=' + encodeURIComponent(oid) + '&id=' + encodeURIComponent(id);
Строка 98: Строка 94:
                 iframe.frameBorder = '0';
                 iframe.frameBorder = '0';
                 iframe.allowFullscreen = true;
                 iframe.allowFullscreen = true;
               
                iframe.sandbox = 'allow-scripts allow-same-origin allow-presentation allow-fullscreen';
                iframe.allow = 'fullscreen';
                iframe.referrerPolicy = 'no-referrer';
                iframe.loading = 'lazy';
                 iframe.style.border = 'none';
                 iframe.style.border = 'none';
                  
                  
Строка 104: Строка 105:
                 }
                 }
                 container.appendChild(iframe);
                 container.appendChild(iframe);
               
             } else {
             } else {
                 var errorDiv = document.createElement('div');
                 var errorDiv = document.createElement('div');
                 errorDiv.style.cssText = 'color: red; padding: 10px; text-align: center; border: 1px solid red;';
               
                 errorDiv.style.color = 'red';
                errorDiv.style.padding = '10px';
                errorDiv.style.textAlign = 'center';
                errorDiv.style.border = '1px solid';
                errorDiv.style.backgroundColor = '#fff';
                errorDiv.style.fontFamily = 'Arial, sans-serif';
                errorDiv.style.fontSize = '14px';
                errorDiv.style.margin = '5px 0';
 
                 errorDiv.textContent = 'Ошибка: неверные параметры видео';
                 errorDiv.textContent = 'Ошибка: неверные параметры видео';
                  
                  
Строка 123: Строка 132:
         initVKVideo();
         initVKVideo();
     }
     }
})();
/* Функция для вставки Rutube-видео на страницу для шаблона {{Rutube}} */
(function() {
    'use strict';
   
    function initRutubeEmbeds() {
        var embeds = document.querySelectorAll('.rutube-video-embed:not([data-processed])');
       
        embeds.forEach(function(embed) {
            var videoId = embed.getAttribute('data-video-id');
            var width = embed.getAttribute('data-width') || '560';
            var height = embed.getAttribute('data-height') || '315';
           
            if (videoId) {
                var iframe = document.createElement('iframe');
                iframe.src = 'https://rutube.ru/play/embed/' + videoId;
                iframe.width = width;
                iframe.height = height;
                iframe.frameBorder = '0';
                iframe.allow = 'autoplay; fullscreen; picture-in-picture';
                iframe.allowFullscreen = true;
                iframe.style.border = 'none';
                iframe.style.display = 'block';
                iframe.style.maxWidth = '100%';
               
                embed.appendChild(iframe);
                embed.setAttribute('data-processed', 'true');
            }
        });
    }
   
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', initRutubeEmbeds);
    } else {
        initRutubeEmbeds();
    }
    if (typeof mw !== 'undefined' && mw.hook) {
        mw.hook('wikipage.content').add(initRutubeEmbeds);
    }
   
})();
})();