Ugrás a tartalomhoz

„Modul:CactaceaeTaxonok” változatai közötti eltérés

Innen: MKOE wiki
Nincs szerkesztési összefoglaló
Címke: Visszaállítva
Nincs szerkesztési összefoglaló
(16 közbenső módosítás ugyanattól a felhasználótól nincs mutatva)
1. sor: 1. sor:
local p = {}
local p = {}


-- Segédfüggvény a szimbólumokhoz (Unicode-biztos)
-- Szupergyors tisztító: csak sima string műveleteket használ
local function formazSzinonimak(szoveg)
local function gyorsTisztitas(szoveg)
     if not szoveg or szoveg == "" then return "" end
     if not szoveg or szoveg == "" then return "" end
     local tiszta = mw.ustring.gsub(szoveg, "[đ÷]", "")
     -- Eltávolítjuk a speciális bájtokat, amik a đ, ÷, ¤ jeleket alkotják
    tiszta = mw.ustring.gsub(tiszta, "¤+", "")
     -- đ = \196\145, ÷ = \195\183, ¤ = \194\164
     tiszta = mw.ustring.gsub(tiszta, ">−", "−")
     local tiszta = szoveg:gsub("\196\145", ""):gsub("\195\183", ""):gsub("\194\164", "")
    tiszta = mw.ustring.gsub(tiszta, ">≡", "≡")
     tiszta = tiszta:gsub(">%-", "−"):gsub(">≡", "≡"):gsub(">=", "=")
     tiszta = mw.ustring.gsub(tiszta, ">=", "=")
     return tiszta
    tiszta = mw.ustring.gsub(tiszta, "≡≡", "|≡")
    tiszta = mw.ustring.gsub(tiszta, "==", "|=")
     tiszta = mw.ustring.gsub(tiszta, "−−", "|−")
    tiszta = mw.ustring.gsub(tiszta, "%-%-", "|−")
 
    local lista_elemek = {}
    for resz in mw.text.gsplit(tiszta, "|", true) do
        local tiszta_resz = mw.text.trim(resz)
        if tiszta_resz ~= "" then
            local szavak = {}
            for szo in mw.ustring.gmatch(tiszta_resz, "%S+") do
                if mw.ustring.find(szo, "[=−,]") or szo == "var." or szo == "subsp." or szo == "f." or szo == "Type:" then
                    table.insert(szavak, szo)
                else
                    table.insert(szavak, "''" .. szo .. "''")
                end
            end
            table.insert(lista_elemek, "<li>" .. table.concat(szavak, " ") .. "</li>")
        end
    end
   
    if #lista_elemek > 0 then
        return '<ul style="margin-left: 1.1em; list-style-type: disc; padding: 0; margin: 0;">' .. table.concat(lista_elemek) .. "</ul>"
    end
     return ""
end
end


function p.tablazat(frame)
function p.tablazat(frame)
     local status, adatModul = pcall(require, 'Modul:CactaceaeTaxonokData')
     local args = frame:getParent().args
     if not status then return "Hiba: A 'Modul:CactaceaeTaxonokData' nem található!" end
     local szuro = args[1] and mw.text.trim(args[1]) or ""
      
      
     local nyers_adat = adatModul.getAdatok()
     if szuro == "" then
        return "<div style='color:red;'>Hiba: Adj meg egy nemzetséget!</div>"
    end


    -- 1. Keresés vezérlő (Checkboxok)
     local status, dataModul = pcall(require, 'Modul:CactaceaeTaxonokData')
     local controls = [[
     if not status then return "Hiba: Adatmodul hiányzik." end
<div style="margin-bottom: 10px; padding: 8px; background: #f8f9fa; border: 1px solid #a2a9b1; border-radius: 2px; font-size: 90%;">
     local nyers = dataModul.getAdatok()
    <strong>Keresés itt:</strong>
     <label style="margin-right: 15px;"><input type="checkbox" id="search-taxon" checked> Taxonnév</label>
     <label><input type="checkbox" id="search-szinonima" checked> Szinonimák</label>
</div>
]]


     -- 2. Táblázat generálása
     local rows = {}
     local res = '{| class="wikitable sortable datatable-hook stripe hover compact" id="cactus-table" data-page-length="50" style="width:100%; font-size:90%;"\n'
     local counter = 0
     res = res .. "! # !! Taxonnév !! Típusfaj, szinonima\n"
     local isVisible = false
 
   
     local sorszam = 0
     -- Soronkénti feldolgozás bájtszinten (ez a leggyorsabb)
     for sor in mw.ustring.gmatch(nyers_adat, "[^\r\n]+") do
     for sor in nyers:gmatch("[^\r\n]+") do
         local taxon, szinonimak = "", ""
         local b1 = sor:byte(1)
         if mw.ustring.match(sor, "^ß") then
       
            local nemzettseg, tipus = mw.ustring.match(sor, "^ß%s*([^:]+)::%s*(.+)")
        -- ß karakter (195 159)
            if nemzettseg then
         if b1 == 195 and sor:byte(2) == 159 then
                taxon = "'''" .. mw.text.trim(nemzettseg):gsub("¤+", "") .. "'''"
            if sor:find(szuro, 1, true) then
                 szinonimak = tipus
                local nemz = sor:match("ß%s*([^:]+)")
             end
                if nemz and mw.text.trim(nemz):gsub("\194\164", "") == szuro then
         elseif mw.ustring.match(sor, "^Ł") then
                    isVisible = true
            local tiszta_sor = mw.ustring.gsub(sor, "^Ł%s*", "")
                    counter = counter + 1
             local t, sz = mw.ustring.match(tiszta_sor, "([^¤]+)¤¤¤(.*)")
                    local tip = sor:match("::%s*(.+)") or ""
                    table.insert(rows, {counter, "'''[[:Kategória:"..szuro.."|"..szuro.."]]'''", tip})
                 else isVisible = false end
             else isVisible = false end
           
         -- Ł karakter (197 129)
        elseif isVisible and b1 == 197 and sor:byte(2) == 129 then
             local t, sz = sor:match("Ł%s*([^¤]+)¤¤¤(.*)")
             if t then
             if t then
                 taxon = "''" .. mw.text.trim(t) .. "''"
                 counter = counter + 1
                szinonimak = sz
                table.insert(rows, {counter, "''[["..mw.text.trim(t).."]]''", sz})
             end
             end
         end
         end
        if counter >= 1000 then break end
    end


         if taxon ~= "" then
    if #rows == 0 then return "Nincs találat: " .. szuro end
             sorszam = sorszam + 1
 
            res = res .. "|-\n| " .. sorszam .. '\n| style="white-space: nowrap;" | ' .. taxon .. "\n| " .. formazSzinonimak(szinonimak) .. "\n"
    -- TÁBLÁZAT ÖSSZEÁLLÍTÁSA (Csak itt formázunk, hogy spóroljunk a CPU-val)
    local finalRows = {}
    for i, data in ipairs(rows) do
        local szinonimak = ""
         if data[3] ~= "" then
             local t = gyorsTisztitas(data[3])
            local lista = {}
            -- Egyszerű darabolás
            for r in t:gmatch("[^|≡=−]+") do
                local tr = mw.text.trim(r)
                if tr ~= "" and tr ~= "''" then
                    table.insert(lista, "<li>''" .. tr .. "''</li>")
                end
            end
            if #lista > 0 then
                szinonimak = '<ul style="margin-left:1.1em; list-style-type:disc; padding:0; margin:0;">' .. table.concat(lista) .. "</ul>"
            end
         end
         end
        table.insert(finalRows, "|-\n| " .. data[1] .. "\n| " .. data[2] .. "\n| " .. szinonimak)
     end
     end
    res = res .. "|}"
    -- 3. JavaScript a szűréshez
    -- Ez a kód figyeli a checkboxokat és módosítja a DataTable keresési logikáját
    local script = [[
<script>
document.addEventListener('DOMContentLoaded', function() {
    var table = $('#cactus-table').DataTable();
   
    // Alapértelmezett keresőmező elrejtése vagy átvétele
    $('.dataTables_filter input').on('keyup', function() {
        var term = this.value;
        var searchTaxon = document.getElementById('search-taxon').checked;
        var searchSzin = document.getElementById('search-szinonima').checked;
       
        // Összes keresés törlése
        table.columns().search('');
       
        if (searchTaxon && searchSzin) {
            table.search(term).draw(); // Globális keresés
        } else if (searchTaxon) {
            table.column(1).search(term).draw(); // Csak Taxonnév (2. oszlop)
            table.column(2).search('');
        } else if (searchSzin) {
            table.column(2).search(term).draw(); // Csak Szinonima (3. oszlop)
            table.column(1).search('');
        } else {
            table.search('^$', true, false).draw(); // Semmi (üres keresés)
        }
    });
});
</script>
]]


     return frame:preprocess(controls .. res .. script)
    local head = '{| class="wikitable sortable datatable-hook stripe hover compact" style="width:100%; font-size:90%;"\n! # !! Taxonnév !! Típusfaj, szinonima\n'
     return frame:preprocess(head .. table.concat(finalRows, "\n") .. "\n|}")
end
end


return p
return p

A lap 2026. január 7., 10:36-kori változata

A modult a Modul:CactaceaeTaxonok/doc lapon tudod dokumentálni

local p = {}

-- Szupergyors tisztító: csak sima string műveleteket használ
local function gyorsTisztitas(szoveg)
    if not szoveg or szoveg == "" then return "" end
    -- Eltávolítjuk a speciális bájtokat, amik a đ, ÷, ¤ jeleket alkotják
    -- đ = \196\145, ÷ = \195\183, ¤ = \194\164
    local tiszta = szoveg:gsub("\196\145", ""):gsub("\195\183", ""):gsub("\194\164", "")
    tiszta = tiszta:gsub(">%-", "−"):gsub(">≡", "≡"):gsub(">=", "=")
    return tiszta
end

function p.tablazat(frame)
    local args = frame:getParent().args
    local szuro = args[1] and mw.text.trim(args[1]) or ""
    
    if szuro == "" then
        return "<div style='color:red;'>Hiba: Adj meg egy nemzetséget!</div>"
    end

    local status, dataModul = pcall(require, 'Modul:CactaceaeTaxonokData')
    if not status then return "Hiba: Adatmodul hiányzik." end
    local nyers = dataModul.getAdatok()

    local rows = {}
    local counter = 0
    local isVisible = false
    
    -- Soronkénti feldolgozás bájtszinten (ez a leggyorsabb)
    for sor in nyers:gmatch("[^\r\n]+") do
        local b1 = sor:byte(1)
        
        -- ß karakter (195 159)
        if b1 == 195 and sor:byte(2) == 159 then
            if sor:find(szuro, 1, true) then
                local nemz = sor:match("ß%s*([^:]+)")
                if nemz and mw.text.trim(nemz):gsub("\194\164", "") == szuro then
                    isVisible = true
                    counter = counter + 1
                    local tip = sor:match("::%s*(.+)") or ""
                    table.insert(rows, {counter, "'''[[:Kategória:"..szuro.."|"..szuro.."]]'''", tip})
                else isVisible = false end
            else isVisible = false end
            
        -- Ł karakter (197 129)
        elseif isVisible and b1 == 197 and sor:byte(2) == 129 then
            local t, sz = sor:match("Ł%s*([^¤]+)¤¤¤(.*)")
            if t then
                counter = counter + 1
                table.insert(rows, {counter, "''[["..mw.text.trim(t).."]]''", sz})
            end
        end
        if counter >= 1000 then break end
    end

    if #rows == 0 then return "Nincs találat: " .. szuro end

    -- TÁBLÁZAT ÖSSZEÁLLÍTÁSA (Csak itt formázunk, hogy spóroljunk a CPU-val)
    local finalRows = {}
    for i, data in ipairs(rows) do
        local szinonimak = ""
        if data[3] ~= "" then
            local t = gyorsTisztitas(data[3])
            local lista = {}
            -- Egyszerű darabolás
            for r in t:gmatch("[^|≡=−]+") do
                local tr = mw.text.trim(r)
                if tr ~= "" and tr ~= "''" then
                    table.insert(lista, "<li>''" .. tr .. "''</li>")
                end
            end
            if #lista > 0 then
                szinonimak = '<ul style="margin-left:1.1em; list-style-type:disc; padding:0; margin:0;">' .. table.concat(lista) .. "</ul>"
            end
        end
        table.insert(finalRows, "|-\n| " .. data[1] .. "\n| " .. data[2] .. "\n| " .. szinonimak)
    end

    local head = '{| class="wikitable sortable datatable-hook stripe hover compact" style="width:100%; font-size:90%;"\n! # !! Taxonnév !! Típusfaj, szinonima\n'
    return frame:preprocess(head .. table.concat(finalRows, "\n") .. "\n|}")
end

return p