Ugrás a tartalomhoz

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

Innen: MKOE wiki
Nincs szerkesztési összefoglaló
Nincs szerkesztési összefoglaló
88. sor: 88. sor:
     end
     end


     -- 1. LÉPÉS: Kiválogatjuk a MediaWiki által elrontott Google string-kulcsokat
     -- 1. LÉPÉS: Határozzuk meg a maximális numerikus indexet
    local max_index = 0
    for k, v in pairs(args) do
        if type(k) == "number" and k > max_index then max_index = k end
    end
 
    -- 2. LÉPÉS: Térképezzük fel a hiányzó lyukakat és mentsük ki a törött Google linkeket
     local javitott_google_linkek = {}
     local javitott_google_linkek = {}
     for k, v in pairs(args) do
     for k, v in pairs(args) do
94. sor: 100. sor:
             local tiszta_kulcs = megtisztitString(k)
             local tiszta_kulcs = megtisztitString(k)
             if tiszta_kulcs:find("^https?://") or tiszta_kulcs:find("^encrypted%-tbn") or tiszta_kulcs:find("gstatic%.com") then
             if tiszta_kulcs:find("^https?://") or tiszta_kulcs:find("^encrypted%-tbn") or tiszta_kulcs:find("gstatic%.com") then
                -- Összefűzzük a teljes URL-t az "=" jellel
                 local teljes_url = tiszta_kulcs .. "=" .. megtisztitString(v)
                 local teljes_url = tiszta_kulcs .. "=" .. megtisztitString(v)
                 table.insert(javitott_google_linkek, teljes_url)
                 table.insert(javitott_google_linkek, teljes_url)
101. sor: 106. sor:
     end
     end


     -- 2. LÉPÉS: Lineáris, tiszta lista felépítése
     -- Előkészítünk egy fix méretű nyers tömböt
     local rendezett_args = {}
     local nyers_lista = {}
     local max_index = 0
     for i = 1, max_index do
    for k, v in pairs(args) do
         if args[i] then
         if type(k) == "number" and k > max_index then max_index = k end
            nyers_lista[i] = megtisztitString(args[i])
        end
     end
     end


     local google_beillesztve = false
    -- Befoltozzuk a lyukakat a megmentett Google linkekkel sorrendben
     local google_idx = 1
     for i = 1, max_index do
     for i = 1, max_index do
         if args[i] then
         if (not nyers_lista[i] or nyers_lista[i] == "") and javitott_google_linkek[google_idx] then
            local tiszta_elem = megtisztitString(args[i])
            nyers_lista[i] = javitott_google_linkek[google_idx]
            if tiszta_elem ~= "" then
            google_idx = google_idx + 1
               
                -- Ha a listában egy olyan felirathoz érunk, ami nem kép, ÉS van megmentett Google linkünk,
                -- akkor a Google linket pont ezen felirat ELÉ szúrjuk be!
                if not isKepFormatum(tiszta_elem) and #javitott_google_linkek > 0 and not google_beillesztve then
                    for _, g_url in ipairs(javitott_google_linkek) do
                        table.insert(rendezett_args, g_url)
                    end
                    google_beillesztve = true
                end
               
                table.insert(rendezett_args, tiszta_elem)
            end
         end
         end
     end
     end


     -- Biztonsági játék: ha volt Google link, de nem volt hozzá semmilyen felirat, a lista végére rakjuk
     -- Ha maradt még Google link (pl. a lista legvégén volt), hozzáadjuk a végéhez
     if #javitott_google_linkek > 0 and not google_beillesztve then
     while javitott_google_linkek[google_idx] do
         for _, g_url in ipairs(javitott_google_linkek) do
         table.insert(nyers_lista, javitott_google_linkek[google_idx])
             table.insert(rendezett_args, g_url)
        google_idx = google_idx + 1
    end
 
    -- Kitömörítjük a listát (eltávolítjuk az esetlegesen megmaradt üres helyeket)
    local rendezett_args = {}
    for i = 1, #nyers_lista do
        if nyers_lista[i] and nyers_lista[i] ~= "" then
             table.insert(rendezett_args, nyers_lista[i])
         end
         end
     end
     end
147. sor: 149. sor:


             if kepAdat then
             if kepAdat then
                -- Megnézzük, hogy a következő elem felirat-e
                 local felirat_resz = ""
                 local felirat_resz = ""
                 if rendezett_args[i+1] then
                 if rendezett_args[i+1] then
153. sor: 154. sor:
                     if kovetkezo ~= "" and not isKepFormatum(kovetkezo) then
                     if kovetkezo ~= "" and not isKepFormatum(kovetkezo) then
                         felirat_resz = kovetkezo
                         felirat_resz = kovetkezo
                         i = i + 1 -- A feliratot átugorjuk a következő körben
                         i = i + 1 -- Felirat átugrása a következő iterációban
                     end
                     end
                 end
                 end

A lap 2026. június 17., 07:56-kori változata

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

local p = {}

-- =============================================================================
-- SEGÉDFÜGGVÉNYEK
-- =============================================================================

local function megtisztitString(s)
    if not s then return "" end
    s = tostring(s)
    s = s:gsub("^%s*(.-)%s*$", "%1")
    s = s:gsub("[\n\r]", "")
    return s
end

local function detektalKepTipus(nyers_bemenet)
    if not nyers_bemenet or nyers_bemenet == "" then return nil end
    
    local s = megtisztitString(nyers_bemenet)
    
    if s:lower():find("^commons:") then
        local tiszta_nev = s:sub(9)
        if not tiszta_nev:lower():find("^file:") and not tiszta_nev:lower():find("^fájl:") then
            tiszta_nev = "File:" .. tiszta_nev
        end
        local url_nev = tiszta_nev:gsub(" ", "_")
        return {
            tipus = "URL",
            path = "https://commons.wikimedia.org/wiki/Special:FilePath/" .. url_nev
        }
    end
    
    if s:find("^https?://") or s:find("^encrypted%-tbn") or s:find("gstatic%.com") then
        return {
            tipus = "URL",
            path = s
        }
    end
    
    return {
        tipus = "WIKI",
        path = s
    }
end

local function isKepFormatum(szoveg)
    if not szoveg or szoveg == "" then return false end
    local s = megtisztitString(szoveg):lower()
    
    if s:find("^https?://") or s:find("^encrypted%-tbn") or s:find("gstatic%.com") or s:find("^commons:") then
        return true
    end
    
    if s:find("%.jpg$") or s:find("%.jpeg$") or s:find("%.png$") or s:find("%.gif$") or s:find("%.svg$") or s:find("%.webp$") then
        return true
    end
    
    return false
end

local function kinyerForrasNev(url)
    if not url or url == "" then return "Külső forrás" end
    
    if url:find("google%.com") or url:find("gstatic%.com") or url:find("^encrypted%-tbn") then
        return "Google Cache"
    end
    
    local domain = url:match("^https?://([^/]+)")
    if domain then
        domain = domain:gsub("^www%.", "")
        return domain
    end
    
    return "Külső link"
end

-- =============================================================================
-- FŐ FUNKCIÓ: GALÉRIA GENERÁLÁSA
-- =============================================================================
function p.generalGaleria(frame)
    local args = {}
    if type(frame) == "table" and type(frame.getParent) == "function" then
        args = frame:getParent().args
        if not args or (not args[1] and not args['k1']) then
            args = frame.args
        end
    else
        args = frame
    end

    -- 1. LÉPÉS: Határozzuk meg a maximális numerikus indexet
    local max_index = 0
    for k, v in pairs(args) do
        if type(k) == "number" and k > max_index then max_index = k end
    end

    -- 2. LÉPÉS: Térképezzük fel a hiányzó lyukakat és mentsük ki a törött Google linkeket
    local javitott_google_linkek = {}
    for k, v in pairs(args) do
        if type(k) == "string" then
            local tiszta_kulcs = megtisztitString(k)
            if tiszta_kulcs:find("^https?://") or tiszta_kulcs:find("^encrypted%-tbn") or tiszta_kulcs:find("gstatic%.com") then
                local teljes_url = tiszta_kulcs .. "=" .. megtisztitString(v)
                table.insert(javitott_google_linkek, teljes_url)
            end
        end
    end

    -- Előkészítünk egy fix méretű nyers tömböt
    local nyers_lista = {}
    for i = 1, max_index do
        if args[i] then
            nyers_lista[i] = megtisztitString(args[i])
        end
    end

    -- Befoltozzuk a lyukakat a megmentett Google linkekkel sorrendben
    local google_idx = 1
    for i = 1, max_index do
        if (not nyers_lista[i] or nyers_lista[i] == "") and javitott_google_linkek[google_idx] then
            nyers_lista[i] = javitott_google_linkek[google_idx]
            google_idx = google_idx + 1
        end
    end

    -- Ha maradt még Google link (pl. a lista legvégén volt), hozzáadjuk a végéhez
    while javitott_google_linkek[google_idx] do
        table.insert(nyers_lista, javitott_google_linkek[google_idx])
        google_idx = google_idx + 1
    end

    -- Kitömörítjük a listát (eltávolítjuk az esetlegesen megmaradt üres helyeket)
    local rendezett_args = {}
    for i = 1, #nyers_lista do
        if nyers_lista[i] and nyers_lista[i] ~= "" then
            table.insert(rendezett_args, nyers_lista[i])
        end
    end

    -- 3. LÉPÉS: FŐ RENDERELŐ CIKLUS
    local html = {}
    table.insert(html, '<div class="egyedi-galeria-container">')

    local i = 1
    while rendezett_args[i] do
        local v = rendezett_args[i]

        if v ~= "" and isKepFormatum(v) then
            local kepAdat = detektalKepTipus(v)

            if kepAdat then
                local felirat_resz = ""
                if rendezett_args[i+1] then
                    local kovetkezo = rendezett_args[i+1]
                    if kovetkezo ~= "" and not isKepFormatum(kovetkezo) then
                        felirat_resz = kovetkezo
                        i = i + 1 -- Felirat átugrása a következő iterációban
                    end
                end

                local tartalom = ""

                if kepAdat.tipus == "URL" then
                    local biztonsagos_path = kepAdat.path:gsub(":", "&#58;")

                    local forras_nev = ""
                    if kepAdat.path:find("commons%.wikimedia%.org") then
                        forras_nev = "Wikimedia Commons"
                    else
                        forras_nev = kinyerForrasNev(kepAdat.path)
                    end

                    tartalom = string.format('<div class="kulso-url-doboz" data-src="%s" data-forras-nev="%s"><span class="url-link-szoveg">Külső kép:<br/>[Link]</span><div class="galeria-felirat">%s</div></div>',
                                                biztonsagos_path,
                                                forras_nev,
                                                felirat_resz)
                else
                    -- HELYI WIKI KÉP
                    if felirat_resz ~= "" then
                        tartalom = string.format('[[Fájl:%s|thumb|180px|%s]]', kepAdat.path, felirat_resz)
                    else
                        tartalom = string.format('[[Fájl:%s|thumb|180px]]', kepAdat.path)
                    end
                end

                table.insert(html, '  <div class="galeria-elem">')
                table.insert(html, '    ' .. tartalom)
                table.insert(html, '  </div>')
            end
        end

        i = i + 1
    end

    table.insert(html, '</div>')

    local vegleges_html = table.concat(html, "\n")
    return frame:preprocess(vegleges_html)
end

return p