Module:CRTGallery

Revision as of 17:03, 10 February 2026 by Arclight-MCP-Bot (talk | contribs) (Rewrite to use mw.smw.getPropertyValues for direct Lua access to semantic properties — avoids frame:preprocess parsing issues (via update-page on MediaWiki MCP Server))

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
    if not pageName or pageName == "" then
        pageName = mw.title.getCurrentTitle().fullText
    end

    -- Use SMW Lua API to get image values directly
    local values = mw.smw.getPropertyValues(pageName, "Has images")
    if not values or #values == 0 then
        return ""
    end

    local lines = {}
    for _, val in ipairs(values) do
        local trimmed = mw.text.trim(tostring(val))
        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
MediaWiki Appliance - Powered by TurnKey Linux