„Modul:Galeria” változatai közötti eltérés
Megjelenés
Nincs szerkesztési összefoglaló |
Nincs szerkesztési összefoglaló |
||
| 11. sor: | 11. sor: | ||
local tiszta_bemenet = megtisztitString(nyers_bemenet) | local tiszta_bemenet = megtisztitString(nyers_bemenet) | ||
if tiszta_bemenet == "" then return nil end | if tiszta_bemenet == "" then return nil end | ||
local kep_resz = tiszta_bemenet | local kep_resz = tiszta_bemenet | ||
local felirat = nil | local felirat = nil | ||
-- Megkeressük a '|' karaktert | -- Megkeressük a '|' karaktert | ||
local pipe_pos = tiszta_bemenet:find("|") | local pipe_pos = tiszta_bemenet:find("|") | ||
| 21. sor: | 21. sor: | ||
felirat = megtisztitString(tiszta_bemenet:sub(pipe_pos + 1)) | felirat = megtisztitString(tiszta_bemenet:sub(pipe_pos + 1)) | ||
end | end | ||
if felirat == "" then felirat = nil end | if felirat == "" then felirat = nil end | ||
-- 1. Internetes link | -- 1. Internetes link vizsgálata | ||
if kep_resz:find("^https?://") then | if kep_resz:find("^https?://") then | ||
return { tipus = "URL", path = kep_resz, felirat = felirat } | return { tipus = "URL", path = kep_resz, felirat = felirat } | ||
end | end | ||
-- 2. Wikimedia Commons átalakítása közvetlen külső URL-lé | -- 2. Wikimedia Commons átalakítása közvetlen külső URL-lé | ||
if kep_resz:find("^[Cc]ommons:") or kep_resz:find("^[Cc]:") then | if kep_resz:find("^[Cc]ommons:") or kep_resz:find("^[Cc]:") then | ||
| 34. sor: | 34. sor: | ||
:gsub("^[Ff]ájl:", ""):gsub("^[Ff]ile:", "") | :gsub("^[Ff]ájl:", ""):gsub("^[Ff]ile:", "") | ||
:match("^%s*(.-)%s*$") | :match("^%s*(.-)%s*$") | ||
-- Szóközök kicserélése aláhúzásra, ahogy a Commons tárolja | -- Szóközök kicserélése aláhúzásra, ahogy a Commons tárolja | ||
local tiszta_fajlnev = fajlnev:gsub(" ", "_") | local tiszta_fajlnev = fajlnev:gsub(" ", "_") | ||
-- Közvetlen URL generálása a Commons speciális elosztójához (Special:FilePath) | -- Közvetlen URL generálása a Commons speciális elosztójához (Special:FilePath) | ||
local commons_url = "https://commons.wikimedia.org/wiki/Special:FilePath/" .. tiszta_fajlnev | local commons_url = "https://commons.wikimedia.org/wiki/Special:FilePath/" .. tiszta_fajlnev | ||
return { tipus = "URL", path = commons_url, felirat = felirat or "Wikimedia Commons kép" } | return { tipus = "URL", path = commons_url, felirat = felirat or "Wikimedia Commons kép" } | ||
end | end | ||
-- 3. Helyi kép | -- 3. Helyi kép vizsgálata | ||
local helyi_fajl = kep_resz:gsub("^[Ff]ájl:", ""):gsub("^[Ff]ile:", "") | local helyi_fajl = kep_resz:gsub("^[Ff]ájl:", ""):gsub("^[Ff]ile:", "") | ||
return { tipus = "HELYI", path = megtisztitString(helyi_fajl), felirat = felirat } | return { tipus = "HELYI", path = megtisztitString(helyi_fajl), felirat = felirat } | ||
| 59. sor: | 59. sor: | ||
args = frame | args = frame | ||
end | end | ||
local html = {} | local html = {} | ||
table.insert(html, '<div class="egyedi-galeria-container">') | table.insert(html, '<div class="egyedi-galeria-container">') | ||
-- Szigorúan végigmegyünk a k1, k2, k3... nevesített paramétereken sorban | -- Szigorúan végigmegyünk a k1, k2, k3... nevesített paramétereken sorban | ||
for i = 1, 30 do | for i = 1, 30 do | ||
local kulcs = "k" .. i | local kulcs = "k" .. i | ||
local v = args[kulcs] | local v = args[kulcs] | ||
if v and v ~= "" then | if v and v ~= "" then | ||
local kepAdat = detektalKepTipus(v) | local kepAdat = detektalKepTipus(v) | ||
if kepAdat then | if kepAdat then | ||
local tartalom = "" | local tartalom = "" | ||
local tiszta_felirat = kepAdat.felirat or "" | local tiszta_felirat = kepAdat.felirat or "" | ||
if kepAdat.tipus == "URL" then | if kepAdat.tipus == "URL" then | ||
-- | -- JAVÍTÁS: A kettőspontot kicseréljük :-ra, hogy a frame:preprocess ne gyártson belőle linket az attribútumban! | ||
tartalom = string.format('<div class="kulso-url-doboz" data-src="%s"><span class="url-link-szoveg">Külső kép:<br/>[Link]</span><div class="galeria-felirat">%s</div></div>', | local biztonsagos_path = kepAdat.path:gsub(":", ":") | ||
tartalom = string.format('<div class="kulso-url-doboz" data-src="%s"><span class="url-link-szoveg">Külső kép:<br/>[Link]</span><div class="galeria-felirat">%s</div></div>', biztonsagos_path, tiszta_felirat) | |||
else -- HELYI | else -- HELYI | ||
if kepAdat.felirat then | if kepAdat.felirat then | ||
| 85. sor: | 87. sor: | ||
end | end | ||
end | end | ||
table.insert(html, ' <div class="galeria-elem">') | table.insert(html, ' <div class="galeria-elem">') | ||
table.insert(html, ' ' .. tartalom) | table.insert(html, ' ' .. tartalom) | ||
| 92. sor: | 94. sor: | ||
end | end | ||
end | end | ||
table.insert(html, '</div>') | table.insert(html, '</div>') | ||
local vegleges_html = table.concat(html, "\n") | local vegleges_html = table.concat(html, "\n") | ||
return frame:preprocess(vegleges_html) | return frame:preprocess(vegleges_html) | ||
A lap 2026. június 15., 00:22-kori változata
A modult a Modul:Galeria/doc lapon tudod dokumentálni
local p = {}
-- Letisztítja az összes láthatatlan karaktert és újsort a szöveg elejéről/végéről
local function megtisztitString(s)
if not s then return "" end
return s:match("^%s*(.-)%s*$")
end
-- 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 tiszta_bemenet = megtisztitString(nyers_bemenet)
if tiszta_bemenet == "" then return nil end
local kep_resz = tiszta_bemenet
local felirat = nil
-- Megkeressük a '|' karaktert
local pipe_pos = tiszta_bemenet:find("|")
if pipe_pos then
kep_resz = megtisztitString(tiszta_bemenet:sub(1, pipe_pos - 1))
felirat = megtisztitString(tiszta_bemenet:sub(pipe_pos + 1))
end
if felirat == "" then felirat = nil end
-- 1. Internetes link vizsgálata
if kep_resz:find("^https?://") then
return { tipus = "URL", path = kep_resz, felirat = felirat }
end
-- 2. Wikimedia Commons átalakítása közvetlen külső URL-lé
if kep_resz:find("^[Cc]ommons:") or kep_resz:find("^[Cc]:") then
local fajlnev = kep_resz:gsub("^[Cc]ommons:", ""):gsub("^[Cc]:", "")
:gsub("^[Ff]ájl:", ""):gsub("^[Ff]ile:", "")
:match("^%s*(.-)%s*$")
-- Szóközök kicserélése aláhúzásra, ahogy a Commons tárolja
local tiszta_fajlnev = fajlnev:gsub(" ", "_")
-- Közvetlen URL generálása a Commons speciális elosztójához (Special:FilePath)
local commons_url = "https://commons.wikimedia.org/wiki/Special:FilePath/" .. tiszta_fajlnev
return { tipus = "URL", path = commons_url, felirat = felirat or "Wikimedia Commons kép" }
end
-- 3. Helyi kép vizsgálata
local helyi_fajl = kep_resz:gsub("^[Ff]ájl:", ""):gsub("^[Ff]ile:", "")
return { tipus = "HELYI", path = megtisztitString(helyi_fajl), felirat = felirat }
end
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['k1'] then
args = frame.args
end
else
args = frame
end
local html = {}
table.insert(html, '<div class="egyedi-galeria-container">')
-- Szigorúan végigmegyünk a k1, k2, k3... nevesített paramétereken sorban
for i = 1, 30 do
local kulcs = "k" .. i
local v = args[kulcs]
if v and v ~= "" then
local kepAdat = detektalKepTipus(v)
if kepAdat then
local tartalom = ""
local tiszta_felirat = kepAdat.felirat or ""
if kepAdat.tipus == "URL" then
-- JAVÍTÁS: A kettőspontot kicseréljük :-ra, hogy a frame:preprocess ne gyártson belőle linket az attribútumban!
local biztonsagos_path = kepAdat.path:gsub(":", ":")
tartalom = string.format('<div class="kulso-url-doboz" data-src="%s"><span class="url-link-szoveg">Külső kép:<br/>[Link]</span><div class="galeria-felirat">%s</div></div>', biztonsagos_path, tiszta_felirat)
else -- HELYI
if kepAdat.felirat then
tartalom = string.format('[[Fájl:%s|thumb|180px|%s]]', kepAdat.path, tiszta_felirat)
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
end
table.insert(html, '</div>')
local vegleges_html = table.concat(html, "\n")
return frame:preprocess(vegleges_html)
end
return p