Module:EveryCRTImages: Difference between revisions

Fix: read images from frame.args (direct #invoke params) not frame:getParent().args; same for recallGallery mode/heights (via update-page on MediaWiki MCP Server)
Replace storeImages/recallGallery with autoGallery — reads current page wikitext via mw.title:getContent() to extract images= field, no cross-template state needed (via update-page on MediaWiki MCP Server)
Line 40: Line 40:
end
end


-- Module-level storage: persists across all #invoke calls within one page parse
-- Extract the |images= value from the current page's wikitext.
local storedImages = nil
-- Reads the raw source via mw.title:getContent() and parses out
-- the images parameter from the {{CRT model}} template invocation.
local function getImagesFromPageSource()
  local title = mw.title.getCurrentTitle()
  local content = title:getContent()
  if not content then return nil end


-- Store the images list for later retrieval by recallGallery.
  -- Match |images= value: capture everything after |images= up to the next
-- Called by {{CRT model}} when suppress_gallery is set.
  -- pipe-prefixed parameter (|paramname=) or closing braces (}})
-- Outputs nothing.
   local images = content:match("|images%s*=%s*([^|}]+)")
function p.storeImages(frame)
  if images then
   storedImages = getArg(frame, "images", "")
    return trim(images)
   return ""
  end
   return nil
end
end


-- Render a gallery using the images previously stored by storeImages.
-- Auto-gallery: reads the current page's wikitext to find the images= field
-- from {{CRT model}}, then renders a gallery. No parameters required.
-- Called by {{CRT gallery}}.
-- Called by {{CRT gallery}}.
function p.recallGallery(frame)
function p.autoGallery(frame)
   if not storedImages or storedImages == "" then
  -- Allow explicit override via images= parameter
     return ""
  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 = getArg(frame, "mode", "packed")
   local mode = getArg(frame, "mode", "packed")
Line 62: Line 75:


   local lines = {}
   local lines = {}
   for _, raw in ipairs(split_csv(storedImages)) do
   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
MediaWiki Appliance - Powered by TurnKey Linux