„Modul:Galeria” változatai közötti eltérés
Megjelenés
Nincs szerkesztési összefoglaló |
Nincs szerkesztési összefoglaló |
||
| 5. sor: | 5. sor: | ||
-- ============================================================================= | -- ============================================================================= | ||
local function megtisztitString(s) | local function megtisztitString(s) | ||
if not s then return "" end | if not s then return "" end | ||
| 13. sor: | 12. sor: | ||
end | end | ||
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) | ||
if s:lower():find("^commons:") then | if s:lower():find("^commons:") then | ||
local tiszta_nev = s:sub(9) | local tiszta_nev = s:sub(9) | ||
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 | ||
local url_nev = tiszta_nev:gsub(" ", "_") | local url_nev = tiszta_nev:gsub(" ", "_") | ||
return { | return { | ||
| 34. sor: | 29. sor: | ||
} | } | ||
end | end | ||
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 { | ||
| 43. sor: | 37. sor: | ||
} | } | ||
end | end | ||
return { | return { | ||
tipus = "WIKI", | tipus = "WIKI", | ||
| 52. sor: | 45. sor: | ||
end | end | ||
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$") then | ||
return true | return true | ||
end | end | ||
return false | return false | ||
end | end | ||
local function kinyerForrasNev(url, eredeti_bemenet) | 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: | 72. sor: | ||
return domain | return domain | ||
end | end | ||
return "Külső link" | return "Külső link" | ||
end | end | ||
| 100. sor: | 91. sor: | ||
-- ------------------------------------------------------------------------- | -- ------------------------------------------------------------------------- | ||
-- | -- ÚJ, ATOMBIZTOS PARSER STRATÉGIA: Lineáris láncolás | ||
-- ------------------------------------------------------------------------- | -- ------------------------------------------------------------------------- | ||
local | local linearis_lista = {} | ||
-- Összegyűjtjük a normál numerikus paramétereket sorban | |||
local max_index = 0 | local max_index = 0 | ||
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 | ||
-- Felépítjük az alaptömböt, a hiányzó helyeket (lyukakat) jelöljük | |||
for i = 1, max_index do | for i = 1, max_index do | ||
if args[i] then | if args[i] and megtisztitString(args[i]) ~= "" then | ||
table.insert(linearis_lista, { szoveg = megtisztitString(args[i]), feldolgozott = false }) | |||
end | end | ||
end | end | ||
-- | -- Vadásszuk le a sérült Google/külső URL kulcsokat, és szúrjuk be őket | ||
-- közvetlenül a hozzájuk tartozó felirat ELÉ (ami ott maradt árván a listában) | |||
for k, v in pairs(args) do | for k, v in pairs(args) do | ||
if type(k) == "string" then | if type(k) == "string" then | ||
| 121. sor: | 115. sor: | ||
if tiszta_kulcs:find("^https?://") or tiszta_kulcs:find("^encrypted%-tbn") or tiszta_kulcs:find("gstatic%.com") then | 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 teljes_url = tiszta_kulcs .. "=" .. megtisztitString(v) | ||
local | -- Megkeressük a feliratot a listában | ||
for | local beszurt = false | ||
if | for idx, elem in ipairs(linearis_lista) do | ||
table.insert( | if not isKepFormatum(elem.szoveg) and not elem.feldolgozott then | ||
-- Ez a felirat tartozik a törött URL-hez! Beszúrjuk elé. | |||
table.insert(linearis_lista, idx, { szoveg = teljes_url, feldolgozott = false }) | |||
beszurt = true | |||
break | break | ||
end | end | ||
end | end | ||
if | -- Ha nem találtunk magányos feliratot, csak a lista végére rakjuk | ||
if not beszurt then | |||
table.insert(linearis_lista, { szoveg = teljes_url, feldolgozott = false }) | |||
end | end | ||
end | end | ||
| 142. sor: | 135. sor: | ||
end | end | ||
-- | -- Kigyűjtjük a tiszta stringeket a lineáris listából a végső feldolgozáshoz | ||
local rendezett_args = {} | local rendezett_args = {} | ||
for | for _, elem in ipairs(linearis_lista) do | ||
table.insert(rendezett_args, elem.szoveg) | |||
end | end | ||
| 164. sor: | 155. sor: | ||
if kepAdat then | if kepAdat then | ||
-- Megnézzük, hogy a következő elem felirat-e | |||
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 | kepAdat.felirat = kovetkezo | ||
i = i + 1 | i = i + 1 -- A feliratot átugorjuk a következő körben | ||
end | end | ||
end | end | ||
| 182. sor: | 174. sor: | ||
forras_nev = "Wikimedia Commons" | forras_nev = "Wikimedia Commons" | ||
else | else | ||
forras_nev = kinyerForrasNev(kepAdat.path, | forras_nev = kinyerForrasNev(kepAdat.path, v) | ||
end | end | ||
| 189. sor: | 181. sor: | ||
forras_nev, | forras_nev, | ||
tiszta_felirat) | tiszta_felirat) | ||
else | else | ||
if kepAdat.felirat and kepAdat.felirat ~= "" then | if kepAdat.felirat and kepAdat.felirat ~= "" then | ||
A lap 2026. június 17., 07:34-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 = 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,
felirat = nil
}
end
if s:find("^https?://") or s:find("^encrypted%-tbn") or s:find("gstatic%.com") then
return {
tipus = "URL",
path = s,
felirat = nil
}
end
return {
tipus = "WIKI",
path = s,
felirat = nil
}
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$") then
return true
end
return false
end
local function kinyerForrasNev(url, eredeti_bemenet)
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
-- -------------------------------------------------------------------------
-- ÚJ, ATOMBIZTOS PARSER STRATÉGIA: Lineáris láncolás
-- -------------------------------------------------------------------------
local linearis_lista = {}
-- Összegyűjtjük a normál numerikus paramétereket sorban
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
-- Felépítjük az alaptömböt, a hiányzó helyeket (lyukakat) jelöljük
for i = 1, max_index do
if args[i] and megtisztitString(args[i]) ~= "" then
table.insert(linearis_lista, { szoveg = megtisztitString(args[i]), feldolgozott = false })
end
end
-- Vadásszuk le a sérült Google/külső URL kulcsokat, és szúrjuk be őket
-- közvetlenül a hozzájuk tartozó felirat ELÉ (ami ott maradt árván a listában)
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)
-- Megkeressük a feliratot a listában
local beszurt = false
for idx, elem in ipairs(linearis_lista) do
if not isKepFormatum(elem.szoveg) and not elem.feldolgozott then
-- Ez a felirat tartozik a törött URL-hez! Beszúrjuk elé.
table.insert(linearis_lista, idx, { szoveg = teljes_url, feldolgozott = false })
beszurt = true
break
end
end
-- Ha nem találtunk magányos feliratot, csak a lista végére rakjuk
if not beszurt then
table.insert(linearis_lista, { szoveg = teljes_url, feldolgozott = false })
end
end
end
end
-- Kigyűjtjük a tiszta stringeket a lineáris listából a végső feldolgozáshoz
local rendezett_args = {}
for _, elem in ipairs(linearis_lista) do
table.insert(rendezett_args, elem.szoveg)
end
-- -------------------------------------------------------------------------
-- 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
-- Megnézzük, hogy a következő elem felirat-e
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 -- A feliratot átugorjuk 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(":", ":")
local forras_nev = ""
if kepAdat.path:find("commons%.wikimedia%.org") then
forras_nev = "Wikimedia Commons"
else
forras_nev = kinyerForrasNev(kepAdat.path, v)
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>',
biztonsagos_path,
forras_nev,
tiszta_felirat)
else
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