Module:CRTGallery: Difference between revisions
New module: queries Has images semantic property from current page and renders a gallery, for use with {{CRT gallery}} (via create-page on MediaWiki MCP Server) |
Arclight changed the content model of the page Module:CRTGallery from "wikitext" to "Scribunto module" |
(No difference)
| |
Revision as of 17:00, 10 February 2026
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 query = string.format(
'{{#ask:[[%s]]|?Has images|mainlabel=-|headers=hide|link=none|sep=<DELIM>|limit=50}}',
pageName
)
local result = frame:preprocess(query)
if not result or result == "" then
return ""
end
-- Split on delimiter; each value is a File: title
local lines = {}
for part in result:gmatch("([^<DELIM>]+)") 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