Module:EveryCRTImages: Difference between revisions
No edit summary |
Add storeImages/recallGallery functions — uses Lua module state to pass image list between CRT model and CRT gallery templates within same page parse (via update-page on MediaWiki MCP Server) |
||
| Line 26: | Line 26: | ||
end | end | ||
return out | return out | ||
end | |||
-- Module-level storage: persists across all #invoke calls within one page parse | |||
local storedImages = nil | |||
-- Store the images list for later retrieval by recallGallery. | |||
-- Called by {{CRT model}} when suppress_gallery is set. | |||
-- Outputs nothing. | |||
function p.storeImages(frame) | |||
local args = frame:getParent().args | |||
storedImages = args.images or "" | |||
return "" | |||
end | |||
-- Render a gallery using the images previously stored by storeImages. | |||
-- Called by {{CRT gallery}}. | |||
function p.recallGallery(frame) | |||
if not storedImages or storedImages == "" then | |||
return "" | |||
end | |||
local args = frame:getParent().args | |||
local mode = args.mode or "packed" | |||
local heights = args.heights or "160" | |||
local lines = {} | |||
for _, raw in ipairs(split_csv(storedImages)) do | |||
local title = normalize_file_title(raw) | |||
if title then | |||
table.insert(lines, title) | |||
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 | end | ||