„Modul:Galeria” változatai közötti eltérés
Megjelenés
Nincs szerkesztési összefoglaló |
Nincs szerkesztési összefoglaló |
||
| 4. sor: | 4. sor: | ||
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 | ||
-- Szétválasztás a '|' karakter mentén | -- Szétválasztás a '|' karakter mentén | ||
local kep_resz, felirat = nyers_bemenet:match("^%s*([^|]+)%s*|%s*(.*)%s*$") | local kep_resz, felirat = nyers_bemenet:match("^%s*([^|]+)%s*|%s*(.*)%s*$") | ||
if not kep_resz then | if not kep_resz then | ||
kep_resz = nyers_bemenet | kep_resz = nyers_bemenet | ||
felirat = nil | felirat = nil | ||
end | end | ||
-- Trim (szóközök | -- Trim (szóközök letakarítása) | ||
local tiszta = kep_resz:match("^%s*(.-)%s*$") | local tiszta = kep_resz:match("^%s*(.-)%s*$") | ||
local tiszta_felirat = felirat and felirat:match("^%s*(.-)%s*$") | local tiszta_felirat = felirat and felirat:match("^%s*(.-)%s*$") | ||
if tiszta_felirat == "" then tiszta_felirat = nil end | if tiszta_felirat == "" then tiszta_felirat = nil end | ||
-- 1. Internetes link | -- 1. Internetes link | ||
if tiszta:find("^https?://") then | if tiszta:find("^https?://") then | ||
return { tipus = "URL", path = tiszta, felirat = tiszta_felirat } | return { tipus = "URL", path = tiszta, felirat = tiszta_felirat } | ||
end | end | ||
-- 2. Wikimedia Commons tisztítás | -- 2. Wikimedia Commons tisztítás | ||
if tiszta:find("^[Cc]ommons:") or tiszta:find("^ | if tiszta:find("^[Cc]ommons:") or tiszta:find("^[Cc]:") then | ||
local fajlnev = tiszta:gsub("^[Cc]ommons:", ""):gsub("^ | local fajlnev = tiszta:gsub("^[Cc]ommons:", ""):gsub("^[Cc]:", "") | ||
:gsub("^[Ff]ájl:", ""):gsub("^[Ff]ile:", "") | :gsub("^[Ff]ájl:", ""):gsub("^[Ff]ile:", "") | ||
:match("^%s*(.-)%s*$") | :match("^%s*(.-)%s*$") | ||
return { tipus = "COMMONS", path = fajlnev, felirat = tiszta_felirat } | return { tipus = "COMMONS", path = fajlnev, felirat = tiszta_felirat } | ||
end | end | ||
-- 3. Helyi kép tisztítás | -- 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:", "") | ||
| 38. sor: | 38. sor: | ||
function p.generalGaleria(frame) | function p.generalGaleria(frame) | ||
local args = {} | local args = {} | ||
-- | -- Sablon környezet detektálása | ||
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 | ||
| 48. sor: | 48. sor: | ||
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>' | ||
| 55. sor: | 55. sor: | ||
local html = {} | local html = {} | ||
table.insert(html, '<div class="egyedi-galeria-container">') | table.insert(html, '<div class="egyedi-galeria-container">') | ||
-- | -- Szigorúan csak a számozott paramétereken megyünk végig sorban! | ||
-- Ez kiszűri a MediaWiki összes rejtett, szöveges kulcsú meta-paraméterét. | |||
local i = 1 | |||
while args[i] or args[tostring(i)] do | |||
local v = args[i] or args[tostring(i)] | |||
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 (escaped HTML-lel a data attribútumban) | |||
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 | |||
-- Ha be van kapcsolva az InstantCommons, a sima Fájl: is jó, de biztosra megyünk a c: prefix-szel (kisbetűvel!) | |||
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) | |||
else | |||
end | 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 | ||
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 | ||
i = i + 1 | |||
end | end | ||
table.insert(html, '</div>') | table.insert(html, '</div>') | ||
local vegleges_html = table.concat(html, "\n") | local vegleges_html = table.concat(html, "\n") | ||
-- | -- Feldolgozás a parserrel | ||
if type(frame) == "table" and type(frame.preprocess) == "function" then | if type(frame) == "table" and type(frame.preprocess) == "function" then | ||
return frame:preprocess(vegleges_html) | return frame:preprocess(vegleges_html) | ||
| 111. sor: | 112. sor: | ||
return vegleges_html | return vegleges_html | ||
end | end | ||
end | end | ||
return p | return p | ||
A lap 2026. június 6., 23:04-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 letakarítása)
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
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("^[Cc]:") then
local fajlnev = tiszta:gsub("^[Cc]ommons:", ""):gsub("^[Cc]:", "")
: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 = {}
-- Sablon környezet detektálása
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">')
-- Szigorúan csak a számozott paramétereken megyünk végig sorban!
-- Ez kiszűri a MediaWiki összes rejtett, szöveges kulcsú meta-paraméterét.
local i = 1
while args[i] or args[tostring(i)] do
local v = args[i] or args[tostring(i)]
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 (escaped HTML-lel a data attribútumban)
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
-- Ha be van kapcsolva az InstantCommons, a sima Fájl: is jó, de biztosra megyünk a c: prefix-szel (kisbetűvel!)
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
i = i + 1
end
table.insert(html, '</div>')
local vegleges_html = table.concat(html, "\n")
-- Feldolgozás a parserrel
if type(frame) == "table" and type(frame.preprocess) == "function" then
return frame:preprocess(vegleges_html)
else
return vegleges_html
end
end
return p