Module:EveryCRTImages: Difference between revisions
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) |
Update comments to reference {{EveryCRT gallery}} instead of {{CRT gallery}}/{{CRT model}}; change fallback default mode to nolines (via update-page on MediaWiki MCP Server) |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 28: | Line 28: | ||
end | end | ||
-- | -- Helper: get a named arg from frame.args first, then frame:getParent().args | ||
local | local function getArg(frame, name, default) | ||
local val = frame.args[name] | |||
if val and val ~= "" then return val end | |||
local parent = frame:getParent() | |||
if parent then | |||
val = parent.args[name] | |||
if val and val ~= "" then return val end | |||
end | |||
return default or "" | |||
end | |||
-- Extract the |images= value from the current page's wikitext. | |||
-- Reads the raw source via mw.title:getContent() and parses out | |||
-- the images parameter from the page's content template invocation | |||
-- (works with {{CRT model}}, {{AV device}}, or any template with an images= field). | |||
local function getImagesFromPageSource() | |||
local title = mw.title.getCurrentTitle() | |||
local content = title:getContent() | |||
if not content then return nil end | |||
-- | -- Match |images= value: capture everything after |images= up to the next | ||
-- | -- pipe-prefixed parameter (|paramname=) or closing braces (}}) | ||
local images = content:match("|images%s*=%s*([^|}]+)") | |||
if images then | |||
local | return trim(images) | ||
end | |||
return | return nil | ||
end | end | ||
-- | -- Auto-gallery: reads the current page's wikitext to find the images= field | ||
-- Called by {{ | -- from the page's content template, then renders a gallery. No parameters required. | ||
function p. | -- Called by {{EveryCRT gallery}}. | ||
if | function p.autoGallery(frame) | ||
-- Allow explicit override via images= parameter | |||
local imageList = getArg(frame, "images", "") | |||
-- If no explicit images, read from page source | |||
if imageList == "" then | |||
imageList = getImagesFromPageSource() or "" | |||
end | end | ||
if imageList == "" then return "" end | |||
local mode = | |||
local heights = | local mode = getArg(frame, "mode", "nolines") | ||
local heights = getArg(frame, "heights", "160") | |||
local lines = {} | local lines = {} | ||
for _, raw in ipairs(split_csv( | for _, raw in ipairs(split_csv(imageList)) do | ||
local title = normalize_file_title(raw) | local title = normalize_file_title(raw) | ||
if title then | if title then | ||
| Line 71: | Line 95: | ||
-- Emits SMW annotations for a multi-image list: | -- Emits SMW annotations for a multi-image list: | ||
-- [[Has images::File:...]] repeated | -- [[Has images::File:...]] repeated | ||
-- Called by {{CRT model}} and {{AV device}}. | |||
function p.annotate(frame) | function p.annotate(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
| Line 87: | Line 112: | ||
end | end | ||
-- Renders a gallery from | -- Renders a gallery from a comma-separated image list. | ||
-- Called by {{CRT model}} and {{AV device}} for their default inline gallery. | |||
function p.gallery(frame) | function p.gallery(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local list = args.images or "" | local list = args.images or "" | ||
local mode = args.mode or " | local mode = args.mode or "nolines" | ||
local heights = args.heights or "160" | local heights = args.heights or "160" | ||