(Створена сторінка: local p = {} -- Список сторінок для пошуку цікавих фактів local pages_to_search = { "Перший сезон", "Другий сезон", "Третій сезон", "Четвертий сезон", "П'ятий сезон", "Шостий сезон", "Сьомий сезон", "Восьмий сезон", "Дев'ятий сезон", "Get Names 01", "Get Names 02", "Get N...)
 
Немає опису редагування
Рядок 1: Рядок 1:
local p = {}
local p = {}


-- Список сторінок для пошуку цікавих фактів
local pages_to_search = {
local pages_to_search = {
     "Перший сезон",
     "Перший сезон",
Рядок 35: Рядок 34:
}
}


--- Отримує секцію "Цікаві факти" зі сторінки
local function get_facts_section(page_title)
local function get_facts_section(page_title)
     local title = mw.title.new(page_title)
     local title = mw.title.new(page_title)
Рядок 47: Рядок 45:
     end
     end
      
      
    -- Шукаємо секцію "Цікаві факти" (різні варіанти написання)
     local section_start = mw.ustring.find(content, "==%s*[Цц]ікаві%s*[Фф]акти%s*==")
     local section_start = mw.ustring.find(content, "==%s*[Цц]ікаві%s*[Фф]акти%s*==")
      
      
Рядок 54: Рядок 51:
     end
     end
      
      
    -- Знаходимо кінець секції (наступний заголовок == або кінець файлу)
     local section_end = mw.ustring.find(content, "\n==[^=]", section_start + 1)
     local section_end = mw.ustring.find(content, "\n==[^=]", section_start + 1)
      
      
Рядок 67: Рядок 63:
end
end


--- Перевіряє чи факт містить посилання на гравця
local function fact_contains_player(fact, player_name)
local function fact_contains_player(fact, player_name)
    -- Екрануємо спеціальні символи в імені гравця
     local escaped_name = mw.ustring.gsub(player_name, "([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1")
     local escaped_name = mw.ustring.gsub(player_name, "([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1")
      
      
    -- Шукаємо [[Гравець]] або [[Гравець|текст]]
     local pattern1 = "%[%[" .. escaped_name .. "%]%]"
     local pattern1 = "%[%[" .. escaped_name .. "%]%]"
     local pattern2 = "%[%[" .. escaped_name .. "|[^%]]+%]%]"
     local pattern2 = "%[%[" .. escaped_name .. "|[^%]]+%]%]"
Рядок 83: Рядок 76:
end
end


--- Витягує окремі факти (рядки що починаються з *)
local function extract_facts(section_content)
local function extract_facts(section_content)
     local facts = {}
     local facts = {}
Рядок 94: Рядок 86:
end
end


--- Додає джерело до факту
local function add_source_to_fact(fact, page_title)
    -- Прибираємо початкову зірочку та пробіли
    local clean_fact = mw.ustring.gsub(fact, "^%*%s*", "")
   
    -- Додаємо посилання на джерело в кінці
    return string.format("* %s <small>([[%s|джерело]])</small>", clean_fact, page_title)
end
----------------------------------------------------------------------
-- ГОЛОВНА ФУНКЦІЯ
----------------------------------------------------------------------
function p.facts(frame)
function p.facts(frame)
     local player_name = frame.args.player or frame.args[1]
     local player_name = frame.args.player or frame.args[1]
Рядок 113: Рядок 93:
     end
     end
      
      
     local found_facts = {}
     local result_parts = {}
      
      
    -- Проходимо по всіх сторінках
     for _, page_title in ipairs(pages_to_search) do
     for _, page_title in ipairs(pages_to_search) do
         local section = get_facts_section(page_title)
         local section = get_facts_section(page_title)
Рядок 121: Рядок 100:
         if section then
         if section then
             local facts = extract_facts(section)
             local facts = extract_facts(section)
            local player_facts = {}
              
              
             for _, fact in ipairs(facts) do
             for _, fact in ipairs(facts) do
                 if fact_contains_player(fact, player_name) then
                 if fact_contains_player(fact, player_name) then
                     local fact_with_source = add_source_to_fact(fact, page_title)
                     table.insert(player_facts, fact)
                     table.insert(found_facts, fact_with_source)
                end
            end
           
            if #player_facts > 0 then
                table.insert(result_parts, string.format("=== [[%s]] ===", page_title))
                for _, fact in ipairs(player_facts) do
                     table.insert(result_parts, fact)
                 end
                 end
             end
             end
Рядок 131: Рядок 117:
     end
     end
      
      
     if #found_facts == 0 then
     if #result_parts == 0 then
         return "" -- Повертаємо пустий рядок якщо нічого не знайдено
         return ""
     end
     end
      
      
     return table.concat(found_facts, "\n")
     return table.concat(result_parts, "\n")
end
end


----------------------------------------------------------------------
-- ФУНКЦІЯ ДЛЯ ПІДРАХУНКУ КІЛЬКОСТІ ФАКТІВ
----------------------------------------------------------------------
function p.facts_count(frame)
function p.facts_count(frame)
     local player_name = frame.args.player or frame.args[1]
     local player_name = frame.args.player or frame.args[1]

Версія за 17:23, 28 листопада 2025

Документацію для цього модуля можна створити у Модуль:FetchData4/документація

local p = {}

local pages_to_search = {
    "Перший сезон",
    "Другий сезон",
    "Третій сезон",
    "Четвертий сезон",
    "П'ятий сезон",
    "Шостий сезон",
    "Сьомий сезон",
    "Восьмий сезон",
    "Дев'ятий сезон",
    "Get Names 01",
    "Get Names 02",
    "Get Names 03",
    "Get Names 04",
    "Get Names 05",
    "Get Names 06",
    "Get Names 07",
    "Get Names 08",
    "Get Names 09",
    "Women's Closed Cup I",
    "Women's Closed Cup II",
    "Men's Closed Cup I",
    "Men's Closed Cup II",
    "Combined Closed Cup I",
    "Combined Closed Cup II",
    "Score Open Battle I",
    "Score Open Battle II",
    "Mafia Closed Cup I",
    "Mafia Closed Cup I Online",
    "My Closest Circle I",
    "Фінал Року"
}

local function get_facts_section(page_title)
    local title = mw.title.new(page_title)
    if not title or not title.exists then
        return nil
    end
    
    local content = title:getContent()
    if not content then
        return nil
    end
    
    local section_start = mw.ustring.find(content, "==%s*[Цц]ікаві%s*[Фф]акти%s*==")
    
    if not section_start then
        return nil
    end
    
    local section_end = mw.ustring.find(content, "\n==[^=]", section_start + 1)
    
    local section_content
    if section_end then
        section_content = mw.ustring.sub(content, section_start, section_end - 1)
    else
        section_content = mw.ustring.sub(content, section_start)
    end
    
    return section_content
end

local function fact_contains_player(fact, player_name)
    local escaped_name = mw.ustring.gsub(player_name, "([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1")
    
    local pattern1 = "%[%[" .. escaped_name .. "%]%]"
    local pattern2 = "%[%[" .. escaped_name .. "|[^%]]+%]%]"
    
    if mw.ustring.find(fact, pattern1) or mw.ustring.find(fact, pattern2) then
        return true
    end
    
    return false
end

local function extract_facts(section_content)
    local facts = {}
    
    for fact in mw.ustring.gmatch(section_content, "%*[^\n]+") do
        table.insert(facts, fact)
    end
    
    return facts
end

function p.facts(frame)
    local player_name = frame.args.player or frame.args[1]
    
    if not player_name or player_name == "" then
        player_name = mw.title.getCurrentTitle().text
    end
    
    local result_parts = {}
    
    for _, page_title in ipairs(pages_to_search) do
        local section = get_facts_section(page_title)
        
        if section then
            local facts = extract_facts(section)
            local player_facts = {}
            
            for _, fact in ipairs(facts) do
                if fact_contains_player(fact, player_name) then
                    table.insert(player_facts, fact)
                end
            end
            
            if #player_facts > 0 then
                table.insert(result_parts, string.format("=== [[%s]] ===", page_title))
                for _, fact in ipairs(player_facts) do
                    table.insert(result_parts, fact)
                end
            end
        end
    end
    
    if #result_parts == 0 then
        return ""
    end
    
    return table.concat(result_parts, "\n")
end

function p.facts_count(frame)
    local player_name = frame.args.player or frame.args[1]
    
    if not player_name or player_name == "" then
        player_name = mw.title.getCurrentTitle().text
    end
    
    local count = 0
    
    for _, page_title in ipairs(pages_to_search) do
        local section = get_facts_section(page_title)
        
        if section then
            local facts = extract_facts(section)
            
            for _, fact in ipairs(facts) do
                if fact_contains_player(fact, player_name) then
                    count = count + 1
                end
            end
        end
    end
    
    return tostring(count)
end

return p