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ó
 
(9 közbenső módosítás ugyanattól a felhasználótól nincs mutatva)
5. sor: 5. sor:
-- =============================================================================
-- =============================================================================


-- Eltávolítja a felesleges szóközöket és a láthatatlan sortörés karaktereket
local function megtisztitString(s)
local function megtisztitString(s)
     if not s then return "" end
     if not s then return "" end
    s = tostring(s)
     s = s:gsub("^%s*(.-)%s*$", "%1")
     s = s:gsub("^%s*(.-)%s*$", "%1")
     s = s:gsub("[\n\r]", "")
     s = s:gsub("[\n\r]", "")
13. sor: 13. sor:
end
end


-- Felismeri a kép típusát és visszaadja a letisztított elérési utat
local function detektalKepTipus(nyers_bemenet)
local function detektalKepTipus(nyers_bemenet)
     if not nyers_bemenet or nyers_bemenet == "" then return nil end
     if not nyers_bemenet or nyers_bemenet == "" then return nil end
 
   
     local s = megtisztitString(nyers_bemenet)
     local s = megtisztitString(nyers_bemenet)
 
      
     -- 1. Eset: Wikimedia Commons hivatkozás
     if s:lower():find("^commons:") then
     if s:lower():find("^commons:") then
         local tiszta_nev = s:sub(9) -- levágjuk a "commons:" részt
         local tiszta_nev = s:sub(9)
        -- Ha a "File:" vagy "Fájl:" sincs ott, kiegészítjük
         if not tiszta_nev:lower():find("^file:") and not tiszta_nev:lower():find("^fájl:") then
         if not tiszta_nev:lower():find("^file:") and not tiszta_nev:lower():find("^fájl:") then
             tiszta_nev = "File:" .. tiszta_nev
             tiszta_nev = "File:" .. tiszta_nev
         end
         end
        -- Átalakítjuk közvetlen URL-lé, hogy a LightGallery külső képként kezelhesse
         local url_nev = tiszta_nev:gsub(" ", "_")
         local url_nev = tiszta_nev:gsub(" ", "_")
         return {
         return {
             tipus = "URL",
             tipus = "URL",
             path = "https://commons.wikimedia.org/wiki/Special:FilePath/" .. url_nev,
             path = "https://commons.wikimedia.org/wiki/Special:FilePath/" .. url_nev
            felirat = nil
         }
         }
     end
     end
 
      
     -- 2. Eset: Külső HTTP/HTTPS vagy Google Cache URL
     if s:find("^https?://") or s:find("^encrypted%-tbn") or s:find("gstatic%.com") then
     if s:find("^https?://") or s:find("^encrypted%-tbn") or s:find("gstatic%.com") then
         return {
         return {
             tipus = "URL",
             tipus = "URL",
             path = s,
             path = s
            felirat = nil
         }
         }
     end
     end
 
      
     -- 3. Eset: Helyi wiki kép
     return {
     return {
         tipus = "WIKI",
         tipus = "WIKI",
         path = s,
         path = s
        felirat = nil
     }
     }
end
end


-- Eldönti egy stringről, hogy kép-e vagy pedig felirat
local function isKepFormatum(szoveg)
local function isKepFormatum(szoveg)
     if not szoveg or szoveg == "" then return false end
     if not szoveg or szoveg == "" then return false end
     local s = megtisztitString(szoveg):lower()
     local s = megtisztitString(szoveg):lower()
 
   
     if s:find("^https?://") or s:find("^encrypted%-tbn") or s:find("gstatic%.com") or s:find("^commons:") then
     if s:find("^https?://") or s:find("^encrypted%-tbn") or s:find("gstatic%.com") or s:find("^commons:") then
         return true
         return true
     end
     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
     if s:find("%.jpg$") or s:find("%.jpeg$") or s:find("%.png$") or s:find("%.gif$") or s:find("%.svg$") or s:find("%.webp$") or s:find("%.jpg[^%%a]") or s:find("%.jpeg[^%%a]") then
         return true
         return true
     end
     end
 
   
     return false
     return false
end
end


-- Kinyeri a domaint a külső URL-ekből a forrás megjelöléséhez
local function kinyerForrasNev(url)
local function kinyerForrasNev(url, eredeti_bemenet)
     if not url or url == "" then return "Külső forrás" end
     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
     if url:find("google%.com") or url:find("gstatic%.com") or url:find("^encrypted%-tbn") then
         return "Google Cache"
         return "Google Cache"
     end
     end
 
   
     local domain = url:match("^https?://([^/]+)")
     local domain = url:match("^https?://([^/]+)")
     if domain then
     if domain then
81. sor: 70. sor:
         return domain
         return domain
     end
     end
 
   
     return "Külső link"
     return "Külső link"
end
end
99. sor: 88. sor:
     end
     end


     -- -------------------------------------------------------------------------
     -- 1. Kigyűjtjük a törött Google linkeket
     -- BOMBABIZTOS ELŐFELDOLGOZÁS: Újraépítjük a listát sorrendhelyesen
    local elrontott_google_linkek = {}
     -- -------------------------------------------------------------------------
     for k, v in pairs(args) do
    local nyers_elemek = {}
        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(elrott_google_linkek, teljes_url)
            end
        end
    end
 
     -- 2. Lineáris lista másolása
     local max_index = 0
     local max_index = 0
    -- 1. Lépés: Gyűjtsük ki a tiszta numerikus paramétereket
     for k, v in pairs(args) do
     for k, v in pairs(args) do
         if type(k) == "number" and k > max_index then max_index = k end
         if type(k) == "number" and k > max_index then max_index = k end
     end
     end
    local ideiglenes_lista = {}
     for i = 1, max_index do
     for i = 1, max_index do
         if args[i] then
         if args[i] then
             nyers_elemek[i] = megtisztitString(args[i])
             table.insert(ideiglenes_lista, megtisztitString(args[i]))
         end
         end
     end
     end


     -- 2. Lépés: Vadásszuk le a sérült Google/külső URL kulcsokat
     -- 3. Rekonstrukció eltolással
     for k, v in pairs(args) do
     local rendezett_args = {}
        if type(k) == "string" then
    local google_idx = 1
            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)


                local beszurt_hely = nil
    local idx = 1
                for i = 1, max_index + 5 do
    while ideiglenes_lista[idx] do
                    if nyers_elemek[i] and not isKepFormatum(nyers_elemek[i]) and nyers_elemek[i] ~= "" then
        local aktualis = ideiglenes_lista[idx]
                        table.insert(nyers_elemek, i, teljes_url)
                        beszurt_hely = i
                        break
                    elseif not nyers_elemek[i] or nyers_elemek[i] == "" then
                        nyers_elemek[i] = teljes_url
                        beszurt_hely = i
                        break
                    end
                end


                if beszurt_hely and beszurt_hely > max_index then
        if elrontott_google_linkek[google_idx] and not isKepFormatum(aktualis) then
                    max_index = beszurt_hely
            local utolso_rendezett = rendezett_args[#rendezett_args]
                 end
            if not utolso_rendezett or not isKepFormatum(utolso_rendezett) then
                 table.insert(rendezett_args, elrontott_google_linkek[google_idx])
                google_idx = google_idx + 1
             end
             end
         end
         end
        table.insert(rendezett_args, aktualis)
        idx = idx + 1
     end
     end


     -- 3. Lépés: Tömörítés és a rendezett_args véglegesítése
     while elrontott_google_linkek[google_idx] do
    local rendezett_args = {}
         table.insert(rendezett_args, elrontott_google_linkek[google_idx])
    for i = 1, max_index + 5 do
         google_idx = google_idx + 1
         if nyers_elemek[i] and nyers_elemek[i] ~= "" then
            table.insert(rendezett_args, nyers_elemek[i])
         end
     end
     end


     -- -------------------------------------------------------------------------
     -- 4. FŐ RENDERELŐ CIKLUS
    -- FŐ RENDERELŐ CIKLUS
    -- -------------------------------------------------------------------------
     local html = {}
     local html = {}
     table.insert(html, '<div class="egyedi-galeria-container">')
     table.insert(html, '<div class="egyedi-galeria-container">')
164. sor: 150. sor:


             if kepAdat then
             if kepAdat then
                local felirat_resz = ""
                 if rendezett_args[i+1] then
                 if rendezett_args[i+1] then
                     local kovetkezo = rendezett_args[i+1]
                     local kovetkezo = rendezett_args[i+1]
                     if kovetkezo ~= "" and not isKepFormatum(kovetkezo) then
                     if kovetkezo ~= "" and not isKepFormatum(kovetkezo) then
                         kepAdat.felirat = kovetkezo
                         felirat_resz = kovetkezo
                         i = i + 1
                         i = i + 1
                     end
                     end
173. sor: 160. sor:


                 local tartalom = ""
                 local tartalom = ""
                local tiszta_felirat = kepAdat.felirat or ""


                 if kepAdat.tipus == "URL" then
                 if kepAdat.tipus == "URL" then
                    local biztonsagos_path = kepAdat.path:gsub(":", "&#58;")
                     local forras_nev = ""
                     local forras_nev = ""
                     if kepAdat.path:find("commons%.wikimedia%.org") then
                     if kepAdat.path:find("commons%.wikimedia%.org") then
                         forras_nev = "Wikimedia Commons"
                         forras_nev = "Wikimedia Commons"
                     else
                     else
                         forras_nev = kinyerForrasNev(kepAdat.path, rendezett_args[i])
                         forras_nev = kinyerForrasNev(kepAdat.path)
                     end
                     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>',
                    -- BIZTONSÁGOS GENERÁLÁS: Csak tiszta adatok attribútumokban, nincs <img> tag, amit a böngésző letilthatna!
                                                 biztonsagos_path,
                    -- A CSS fog neki adni egy elegáns és egyedi placeholder kinézetet a MediaWiki:Common.css-ből.
                     tartalom = string.format('<div class="kulso-url-doboz" data-src="%s" data-forras-nev="%s"><div class="kulso-link-ikon">🌐</div><span class="galeria-felirat">%s</span><br><small class="forras-felirat">%s</small></div>',
                                                 kepAdat.path,
                                                 forras_nev,
                                                 forras_nev,
                                                 tiszta_felirat)
                                                 felirat_resz,
 
                                                forras_nev)
                 else
                 else
                     if kepAdat.felirat and kepAdat.felirat ~= "" then
                    -- HELYI WIKI KÉP
                         tartalom = string.format('[[Fájl:%s|thumb|180px|%s]]', kepAdat.path, tiszta_felirat)
                     if felirat_resz ~= "" then
                         tartalom = string.format('[[Fájl:%s|thumb|200x200px|%s]]', kepAdat.path, felirat_resz)
                     else
                     else
                         tartalom = string.format('[[Fájl:%s|thumb|180px]]', kepAdat.path)
                         tartalom = string.format('[[Fájl:%s|thumb|200x200px]]', kepAdat.path)
                     end
                     end
                 end
                 end

A lap jelenlegi, 2026. június 19., 07:58-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$") or s:find("%.jpg[^%%a]") or s:find("%.jpeg[^%%a]") 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. Kigyűjtjük a törött Google linkeket
    local elrontott_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(elrott_google_linkek, teljes_url)
            end
        end
    end

    -- 2. Lineáris lista másolása
    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

    local ideiglenes_lista = {}
    for i = 1, max_index do
        if args[i] then
            table.insert(ideiglenes_lista, megtisztitString(args[i]))
        end
    end

    -- 3. Rekonstrukció eltolással
    local rendezett_args = {}
    local google_idx = 1

    local idx = 1
    while ideiglenes_lista[idx] do
        local aktualis = ideiglenes_lista[idx]

        if elrontott_google_linkek[google_idx] and not isKepFormatum(aktualis) then
            local utolso_rendezett = rendezett_args[#rendezett_args]
            if not utolso_rendezett or not isKepFormatum(utolso_rendezett) then
                table.insert(rendezett_args, elrontott_google_linkek[google_idx])
                google_idx = google_idx + 1
            end
        end

        table.insert(rendezett_args, aktualis)
        idx = idx + 1
    end

    while elrontott_google_linkek[google_idx] do
        table.insert(rendezett_args, elrontott_google_linkek[google_idx])
        google_idx = google_idx + 1
    end

    -- 4. 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
                    end
                end

                local tartalom = ""

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

                    -- BIZTONSÁGOS GENERÁLÁS: Csak tiszta adatok attribútumokban, nincs <img> tag, amit a böngésző letilthatna!
                    -- A CSS fog neki adni egy elegáns és egyedi placeholder kinézetet a MediaWiki:Common.css-ből.
                    tartalom = string.format('<div class="kulso-url-doboz" data-src="%s" data-forras-nev="%s"><div class="kulso-link-ikon">🌐</div><span class="galeria-felirat">%s</span><br><small class="forras-felirat">%s</small></div>',
                                                kepAdat.path,
                                                forras_nev,
                                                felirat_resz,
                                                forras_nev)
                else
                    -- HELYI WIKI KÉP
                    if felirat_resz ~= "" then
                        tartalom = string.format('[[Fájl:%s|thumb|200x200px|%s]]', kepAdat.path, felirat_resz)
                    else
                        tartalom = string.format('[[Fájl:%s|thumb|200x200px]]', 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