Documentation for this module may be created at Module:CRTGallery/doc
local p = {}
function p.gallery(frame)
local args = frame:getParent().args
local mode = args.mode or "packed"
local heights = args.heights or "160"
local pageName = args.page or mw.title.getCurrentTitle().fullText
-- Query all "Has images" values stored by {{CRT model}} on this page
local delim = "~!~"
local query = string.format(
'{{#ask:[[%s]]|?Has images|mainlabel=-|headers=hide|link=none|sep=%s|limit=50}}',
pageName, delim
)
local result = frame:preprocess(query)
if not result or result == "" then
return ""
end
-- Split on delimiter using plain string match
local parts = mw.text.split(result, delim, true)
local lines = {}
for _, part in ipairs(parts) do
local trimmed = mw.text.trim(part)
if trimmed ~= "" then
-- Ensure File: prefix
if not trimmed:match("^[Ff]ile:") then
trimmed = "File:" .. trimmed
end
table.insert(lines, trimmed)
end
end
if #lines == 0 then return "" end
local wikitext = string.format(
'<gallery mode="%s" heights="%s">\n%s\n</gallery>',
mode, heights, table.concat(lines, "\n")
)
return frame:preprocess(wikitext)
end
return p