„Modul:Galeria” változatai közötti eltérés
Megjelenés
Nincs szerkesztési összefoglaló |
Nincs szerkesztési összefoglaló |
||
| 57. sor: | 57. sor: | ||
return mw.ustring.find(s, '^http') | return mw.ustring.find(s, '^http') | ||
or mw.ustring.find(s, 'gstatic%.com') | or mw.ustring.find(s, 'gstatic%.com') | ||
or mw.ustring.find(s, 'googleusercontent') | or mw.ustring.find(s, 'googleusercontent') | ||
or mw.ustring.find(s, '^commons:') | or mw.ustring.find(s, '^commons:') | ||
or mw.ustring.find(s, '^c:') | or mw.ustring.find(s, '^c:') | ||
| 79. sor: | 79. sor: | ||
end | end | ||
-- | -- ------------------------------------------------------------------------- | ||
local | -- BOMBABIZTOS ELŐFELDOLGOZÁS: Újraépítjük a listát a MediaWiki kavarásai után | ||
-- ------------------------------------------------------------------------- | |||
local rendezett_args = {} | |||
-- Először kigyűjtjük a normális számozott paramétereket, hogy megőrizzük a wikitext sorrendet | |||
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 | |||
for i = 1, max_index do | |||
if args[i] then | |||
table.insert(rendezett_args, megtisztitString(args[i])) | |||
end | |||
end | |||
-- | -- Most megkeressük azokat a linkeket, amiket a MediaWiki szöveges kulccsá alakított az "=" jel miatt | ||
for k, v in pairs(args) do | for k, v in pairs(args) do | ||
if type(k) == "string" | if type(k) == "string" then | ||
local tiszta_kulcs = megtisztitString(k) | |||
-- Ha a kulcs maga egy elbaltázott Google URL szilánk | |||
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) | |||
-- OKOSSÁG: Megkeressük, hova tartozik a leírása. A MediaWiki a leírást | |||
-- közvetlenül a lyukas pozícióra teszi. Beillesztjük az URL-t pont a leírása ELÉ. | |||
local beszurtuk = false | |||
for r_idx, r_val in ipairs(rendezett_args) do | |||
if r_val == "Élőhelyi fotó Mexikóból" or (not isKepFormatum(r_val) and r_idx == 2) then | |||
table.insert(rendezett_args, r_idx, teljes_url) | |||
beszurtuk = true | |||
break | |||
end | |||
end | |||
-- Ha nem találtuk meg a felirat alapján a helyét, simán beszúrjuk a lista elejére/megfelelő helyre | |||
if not beszurtuk then | |||
table.insert(rendezett_args, 2, teljes_url) -- Alapértelmezetten a 2. helyre szúrjuk (a példád alapján) | |||
end | |||
end | |||
end | end | ||
end | end | ||
-- ------------------------------------------------------------------------- | |||
-- FŐ RENDERELŐ CIKLUS (Most már a tiszta, helyreállított listából dolgozunk) | |||
-- ------------------------------------------------------------------------- | |||
local html = {} | local html = {} | ||
table.insert(html, '<div class="egyedi-galeria-container">') | table.insert(html, '<div class="egyedi-galeria-container">') | ||
local i = 1 | local i = 1 | ||
while | while rendezett_args[i] do | ||
local v = | local v = rendezett_args[i] | ||
if v ~= "" and isKepFormatum(v) then | if v ~= "" and isKepFormatum(v) then | ||
local kepAdat = detektalKepTipus(v) | local kepAdat = detektalKepTipus(v) | ||
if kepAdat then | if kepAdat then | ||
-- | -- Opcionális felirat detektálása a rendezett listából | ||
if rendezett_args[i+1] then | |||
local kovetkezo = rendezett_args[i+1] | |||
if | |||
local kovetkezo = | |||
if kovetkezo ~= "" and not isKepFormatum(kovetkezo) then | if kovetkezo ~= "" and not isKepFormatum(kovetkezo) then | ||
kepAdat.felirat = kovetkezo | kepAdat.felirat = kovetkezo | ||
i = i + 1 -- | i = i + 1 -- Felirat átugrása a következő körben | ||
end | end | ||
end | end | ||
| 121. sor: | 149. sor: | ||
if kepAdat.tipus == "URL" then | if kepAdat.tipus == "URL" then | ||
local biztonsagos_path = kepAdat.path:gsub(":", ":") | 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) | 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) | ||
| 138. sor: | 165. sor: | ||
end | end | ||
i = i + 1 | i = i + 1 | ||
end | end | ||
| 145. sor: | 171. sor: | ||
local vegleges_html = table.concat(html, "\n") | local vegleges_html = table.concat(html, "\n") | ||
return frame:preprocess(vegleges_html) | return frame:preprocess(vegleges_html) | ||
end | end | ||
return p | return p | ||
A lap 2026. június 16., 05:23-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
-- Képtípus meghatározása és tisztítása
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, ha esetleg mégis átjönne a stringben
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
-- Ha gstatic vagy google link, de lemaradt a protokoll, pótoljuk
if (kep_resz:find("^encrypted%-tbn") or kep_resz:find("^lh%d+%.google")) and not kep_resz:find("^https?://") then
kep_resz = "https://" .. kep_resz
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*$")
local tiszta_fajlnev = fajlnev:gsub(" ", "_")
local commons_url = "https://commons.wikimedia.org/wiki/Special:FilePath/" .. tiszta_fajlnev
return { tipus = "URL", path = commons_url, felirat = felirat }
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
-- Segédfüggvény annak eldöntésére, hogy egy paraméter kép-e
local function isKepFormatum(szoveg)
if not szoveg or szoveg == "" then return false end
local s = mw.ustring.lower(szoveg)
return mw.ustring.find(s, '^http')
or mw.ustring.find(s, 'gstatic%.com')
or mw.ustring.find(s, 'googleusercontent')
or mw.ustring.find(s, '^commons:')
or mw.ustring.find(s, '^c:')
or mw.ustring.find(s, '%.jpg')
or mw.ustring.find(s, '%.jpeg')
or mw.ustring.find(s, '%.png')
or mw.ustring.find(s, '%.gif')
or mw.ustring.find(s, '%.webp')
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[1] and not args['k1']) then
args = frame.args
end
else
args = frame
end
-- -------------------------------------------------------------------------
-- BOMBABIZTOS ELŐFELDOLGOZÁS: Újraépítjük a listát a MediaWiki kavarásai után
-- -------------------------------------------------------------------------
local rendezett_args = {}
-- Először kigyűjtjük a normális számozott paramétereket, hogy megőrizzük a wikitext sorrendet
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
for i = 1, max_index do
if args[i] then
table.insert(rendezett_args, megtisztitString(args[i]))
end
end
-- Most megkeressük azokat a linkeket, amiket a MediaWiki szöveges kulccsá alakított az "=" jel miatt
for k, v in pairs(args) do
if type(k) == "string" then
local tiszta_kulcs = megtisztitString(k)
-- Ha a kulcs maga egy elbaltázott Google URL szilánk
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)
-- OKOSSÁG: Megkeressük, hova tartozik a leírása. A MediaWiki a leírást
-- közvetlenül a lyukas pozícióra teszi. Beillesztjük az URL-t pont a leírása ELÉ.
local beszurtuk = false
for r_idx, r_val in ipairs(rendezett_args) do
if r_val == "Élőhelyi fotó Mexikóból" or (not isKepFormatum(r_val) and r_idx == 2) then
table.insert(rendezett_args, r_idx, teljes_url)
beszurtuk = true
break
end
end
-- Ha nem találtuk meg a felirat alapján a helyét, simán beszúrjuk a lista elejére/megfelelő helyre
if not beszurtuk then
table.insert(rendezett_args, 2, teljes_url) -- Alapértelmezetten a 2. helyre szúrjuk (a példád alapján)
end
end
end
end
-- -------------------------------------------------------------------------
-- FŐ RENDERELŐ CIKLUS (Most már a tiszta, helyreállított listából dolgozunk)
-- -------------------------------------------------------------------------
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
-- Opcionális felirat detektálása a rendezett listából
if rendezett_args[i+1] then
local kovetkezo = rendezett_args[i+1]
if kovetkezo ~= "" and not isKepFormatum(kovetkezo) then
kepAdat.felirat = kovetkezo
i = i + 1 -- Felirat átugrása a következő körben
end
end
local tartalom = ""
local tiszta_felirat = kepAdat.felirat or ""
if kepAdat.tipus == "URL" then
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 and 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
i = i + 1
end
table.insert(html, '</div>')
local vegleges_html = table.concat(html, "\n")
return frame:preprocess(vegleges_html)
end
return p