Module:CRTGallery: Difference between revisions

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)
Use mw.smw.ask instead of getPropertyValues — more widely available in Semantic Scribunto (via update-page on MediaWiki MCP Server)
 
Line 10: Line 10:
     end
     end


     -- Use SMW Lua API to get image values directly
     -- Use mw.smw.ask to query Has images property
     local values = mw.smw.getPropertyValues(pageName, "Has images")
     local queryResult = mw.smw.ask("[[" .. pageName .. "]]|?Has images|mainlabel=-|limit=50")
     if not values or #values == 0 then
 
     if not queryResult or type(queryResult) ~= "table" or #queryResult == 0 then
         return ""
         return ""
     end
     end


     local lines = {}
     local lines = {}
     for _, val in ipairs(values) do
     for _, row in ipairs(queryResult) do
         local trimmed = mw.text.trim(tostring(val))
         local images = row["Has images"]
        if trimmed ~= "" then
        if images then
            -- Ensure File: prefix
            -- images may be a single string or a table of strings
            if not trimmed:match("^[Ff]ile:") then
            if type(images) == "string" then
                trimmed = "File:" .. trimmed
                images = { images }
            end
            for _, img in ipairs(images) do
                local trimmed = mw.text.trim(tostring(img))
                if trimmed ~= "" then
                    if not trimmed:match("^[Ff]ile:") then
                        trimmed = "File:" .. trimmed
                    end
                    table.insert(lines, trimmed)
                end
             end
             end
            table.insert(lines, trimmed)
         end
         end
     end
     end
MediaWiki Appliance - Powered by TurnKey Linux