„Modul:Galeria” változatai közötti eltérés
Megjelenés
Nincs szerkesztési összefoglaló |
Nincs szerkesztési összefoglaló |
||
| 1. sor: | 1. sor: | ||
local p = {} | local p = {} | ||
-- | -- Biztonságos segédfüggvény a képtípus meghatározására és tisztítására | ||
local function detektalKepTipus(nyers_bemenet) | local function detektalKepTipus(nyers_bemenet) | ||
if not nyers_bemenet or nyers_bemenet == "" then return nil end | |||
if not | |||
-- | -- Szétválasztás a '|' karakter mentén | ||
local kep_resz, felirat = nyers_bemenet:match("^%s*([^|]+)%s*|%s*(.*)%s*$") | |||
if not kep_resz then | |||
kep_resz = nyers_bemenet | |||
felirat = nil | |||
end | |||
-- Trim (szóközök eltávolítása az elejéről és végéről) | |||
local tiszta = kep_resz:match("^%s*(.-)%s*$") | local tiszta = kep_resz:match("^%s*(.-)%s*$") | ||
local tiszta_felirat = felirat and felirat:match("^%s*(.-)%s*$") | |||
if tiszta_felirat == "" then tiszta_felirat = nil end | |||
-- 1. Internetes link | -- 1. Internetes link vizsgatata | ||
if tiszta:find("^https?://") then | if tiszta:find("^https?://") then | ||
return { tipus = "URL", path = tiszta, felirat = | return { tipus = "URL", path = tiszta, felirat = tiszta_felirat } | ||
end | end | ||
-- 2. Wikimedia Commons | -- 2. Wikimedia Commons tisztítás | ||
if tiszta:find("^[Cc]ommons:") or tiszta:find("^c:") then | if tiszta:find("^[Cc]ommons:") or tiszta:find("^c:") then | ||
local fajlnev = tiszta:gsub("^[Cc]ommons:", ""):gsub("^c:", "") | local fajlnev = tiszta:gsub("^[Cc]ommons:", ""):gsub("^c:", "") | ||
:gsub("^[Ff]ájl:", ""):gsub("^[Ff]ile:", "") | :gsub("^[Ff]ájl:", ""):gsub("^[Ff]ile:", "") | ||
return { tipus = "COMMONS", path = fajlnev, felirat = | :match("^%s*(.-)%s*$") | ||
return { tipus = "COMMONS", path = fajlnev, felirat = tiszta_felirat } | |||
end | end | ||
-- 3. Helyi kép | -- 3. Helyi kép tisztítás | ||
local helyi_fajl = tiszta:gsub("^[Ff]ájl:", ""):gsub("^[Ff]ile:", "") | local helyi_fajl = tiszta:gsub("^[Ff]ájl:", ""):gsub("^[Ff]ile:", "") | ||
return { tipus = "HELYI", path = helyi_fajl, felirat = | :match("^%s*(.-)%s*$") | ||
return { tipus = "HELYI", path = helyi_fajl, felirat = tiszta_felirat } | |||
end | end | ||
| 31. sor: | 39. sor: | ||
local args = {} | local args = {} | ||
-- | -- Környezet detektálása (Sablon vs Offline) | ||
if type(frame) == "table" and type(frame.getParent) == "function" then | if type(frame) == "table" and type(frame.getParent) == "function" then | ||
args = frame:getParent().args | args = frame:getParent().args | ||
if not args or not args[1] then | if not args or not args[1] then | ||
args = frame.args | args = frame.args | ||
end | end | ||
else | else | ||
args = frame | args = frame | ||
end | end | ||
if not args or not args[1] then | if not args or not args[1] then | ||
return '<span style="color:red; font-weight:bold;">[Hiba: A galéria nem kapott képeket!]</span>' | return '<span style="color:red; font-weight:bold;">[Hiba: A galéria nem kapott képeket!]</span>' | ||
| 52. sor: | 56. sor: | ||
table.insert(html, '<div class="egyedi-galeria-container">') | table.insert(html, '<div class="egyedi-galeria-container">') | ||
for k, v in | -- Végigmegyünk a paramétereken (támogatja a nevesített és számozott formát is) | ||
local kepAdat = detektalKepTipus(v) | for k, v in pairs(args) do | ||
-- Csak a számozott (vagy sorszámos) paraméterekkel foglalkozunk, a sablon esetleges egyéb neveit kihagyjuk | |||
if type(k) == "number" or tonumber(k) then | |||
local kepAdat = detektalKepTipus(v) | |||
if kepAdat then | |||
local imgTag = "" | |||
local feliratHTML = "" | |||
local tiszta_felirat = kepAdat.felirat or "" | |||
if kepAdat.tipus == "URL" then | |||
-- Külső kép LightGallery struktúrában | |||
imgTag = string.format('<a href="%s" class="lg-vegyes-item" data-src="%s" data-sub-html="<h4>%s</h4>"><img src="%s" alt="%s" class="galeria-kep url-kep" /></a>', | |||
kepAdat.path, kepAdat.path, tiszta_felirat, kepAdat.path, tiszta_felirat) | |||
if kepAdat.felirat then | |||
feliratHTML = string.format('<div class="galeria-felirat">%s</div>', tiszta_felirat) | |||
end | |||
elseif kepAdat.tipus == "COMMONS" then | |||
-- Commons kép esetén explicit megadjuk a k: vagy commons: prefixet a parsernek | |||
if kepAdat.felirat then | |||
imgTag = string.format('[[Fájl:c:%s|thumb|180px|%s]]', kepAdat.path, tiszta_felirat) | |||
else | |||
imgTag = string.format('[[Fájl:c:%s|thumb|180px]]', kepAdat.path) | |||
end | |||
else -- HELYI | |||
if kepAdat.felirat then | |||
imgTag = string.format('[[Fájl:%s|thumb|180px|%s]]', kepAdat.path, tiszta_felirat) | |||
else | |||
imgTag = string.format('[[Fájl:%s|thumb|180px]]', kepAdat.path) | |||
end | |||
end | |||
table.insert(html, ' <div class="galeria-elem">') | |||
table.insert(html, ' <div class="galeria-kep-doboz">' .. imgTag .. '</div>') | |||
if kepAdat.tipus == "URL" and feliratHTML ~= "" then | |||
table.insert(html, ' ' .. feliratHTML) | |||
end | |||
table.insert(html, ' </div>') | |||
end | end | ||
end | end | ||
end | end | ||
table.insert(html, ' | table.insert(html, '</div>') | ||
local vegleges_html = table.concat(html, "\n") | |||
-- | -- HA WIKIBEN VANNAK, ÁTFUTTATJUK A PARSEREN, HOGY ENGEDÉLYEZZE A HTML-T ÉS A FÁJLOKAT | ||
if type(frame) == "table" and type(frame.preprocess) == "function" then | |||
return frame:preprocess(vegleges_html) | |||
else | |||
return vegleges_html | |||
end | |||
end | |||
-- | -- Intelligens offline teszt | ||
if not mw then | |||
local teszt_adatok = { | |||
"https://media.giromagi.com/prodotti/thumbs/202408/IMG_20240828_150500.jpg| Mammillaria sp. helyi leírás", | |||
"commons:File:Turbinicarpus_schwarzii_%286109187841%29.jpg", | |||
"Lithops dinterii 1.jpg|Fotó: Lukoczki Zoltán" | |||
} | |||
print(p.generalGaleria(teszt_adatok)) | |||
end | |||
return p | return p | ||
A lap 2026. június 6., 23:01-kori változata
A modult a Modul:Galeria/doc lapon tudod dokumentálni
local p = {}
-- Biztonságos segédfüggvény a képtípus meghatározására és tisztítására
local function detektalKepTipus(nyers_bemenet)
if not nyers_bemenet or nyers_bemenet == "" then return nil end
-- Szétválasztás a '|' karakter mentén
local kep_resz, felirat = nyers_bemenet:match("^%s*([^|]+)%s*|%s*(.*)%s*$")
if not kep_resz then
kep_resz = nyers_bemenet
felirat = nil
end
-- Trim (szóközök eltávolítása az elejéről és végéről)
local tiszta = kep_resz:match("^%s*(.-)%s*$")
local tiszta_felirat = felirat and felirat:match("^%s*(.-)%s*$")
if tiszta_felirat == "" then tiszta_felirat = nil end
-- 1. Internetes link vizsgatata
if tiszta:find("^https?://") then
return { tipus = "URL", path = tiszta, felirat = tiszta_felirat }
end
-- 2. Wikimedia Commons tisztítás
if tiszta:find("^[Cc]ommons:") or tiszta:find("^c:") then
local fajlnev = tiszta:gsub("^[Cc]ommons:", ""):gsub("^c:", "")
:gsub("^[Ff]ájl:", ""):gsub("^[Ff]ile:", "")
:match("^%s*(.-)%s*$")
return { tipus = "COMMONS", path = fajlnev, felirat = tiszta_felirat }
end
-- 3. Helyi kép tisztítás
local helyi_fajl = tiszta:gsub("^[Ff]ájl:", ""):gsub("^[Ff]ile:", "")
:match("^%s*(.-)%s*$")
return { tipus = "HELYI", path = helyi_fajl, felirat = tiszta_felirat }
end
function p.generalGaleria(frame)
local args = {}
-- Környezet detektálása (Sablon vs Offline)
if type(frame) == "table" and type(frame.getParent) == "function" then
args = frame:getParent().args
if not args or not args[1] then
args = frame.args
end
else
args = frame
end
if not args or not args[1] then
return '<span style="color:red; font-weight:bold;">[Hiba: A galéria nem kapott képeket!]</span>'
end
local html = {}
table.insert(html, '<div class="egyedi-galeria-container">')
-- Végigmegyünk a paramétereken (támogatja a nevesített és számozott formát is)
for k, v in pairs(args) do
-- Csak a számozott (vagy sorszámos) paraméterekkel foglalkozunk, a sablon esetleges egyéb neveit kihagyjuk
if type(k) == "number" or tonumber(k) then
local kepAdat = detektalKepTipus(v)
if kepAdat then
local imgTag = ""
local feliratHTML = ""
local tiszta_felirat = kepAdat.felirat or ""
if kepAdat.tipus == "URL" then
-- Külső kép LightGallery struktúrában
imgTag = string.format('<a href="%s" class="lg-vegyes-item" data-src="%s" data-sub-html="<h4>%s</h4>"><img src="%s" alt="%s" class="galeria-kep url-kep" /></a>',
kepAdat.path, kepAdat.path, tiszta_felirat, kepAdat.path, tiszta_felirat)
if kepAdat.felirat then
feliratHTML = string.format('<div class="galeria-felirat">%s</div>', tiszta_felirat)
end
elseif kepAdat.tipus == "COMMONS" then
-- Commons kép esetén explicit megadjuk a k: vagy commons: prefixet a parsernek
if kepAdat.felirat then
imgTag = string.format('[[Fájl:c:%s|thumb|180px|%s]]', kepAdat.path, tiszta_felirat)
else
imgTag = string.format('[[Fájl:c:%s|thumb|180px]]', kepAdat.path)
end
else -- HELYI
if kepAdat.felirat then
imgTag = string.format('[[Fájl:%s|thumb|180px|%s]]', kepAdat.path, tiszta_felirat)
else
imgTag = string.format('[[Fájl:%s|thumb|180px]]', kepAdat.path)
end
end
table.insert(html, ' <div class="galeria-elem">')
table.insert(html, ' <div class="galeria-kep-doboz">' .. imgTag .. '</div>')
if kepAdat.tipus == "URL" and feliratHTML ~= "" then
table.insert(html, ' ' .. feliratHTML)
end
table.insert(html, ' </div>')
end
end
end
table.insert(html, '</div>')
local vegleges_html = table.concat(html, "\n")
-- HA WIKIBEN VANNAK, ÁTFUTTATJUK A PARSEREN, HOGY ENGEDÉLYEZZE A HTML-T ÉS A FÁJLOKAT
if type(frame) == "table" and type(frame.preprocess) == "function" then
return frame:preprocess(vegleges_html)
else
return vegleges_html
end
end
-- Intelligens offline teszt
if not mw then
local teszt_adatok = {
"https://media.giromagi.com/prodotti/thumbs/202408/IMG_20240828_150500.jpg| Mammillaria sp. helyi leírás",
"commons:File:Turbinicarpus_schwarzii_%286109187841%29.jpg",
"Lithops dinterii 1.jpg|Fotó: Lukoczki Zoltán"
}
print(p.generalGaleria(teszt_adatok))
end
return p