Module:CRTGallery: Difference between revisions
Arclight changed the content model of the page Module:CRTGallery from "wikitext" to "Scribunto module" |
Use mw.smw.ask instead of getPropertyValues — more widely available in Semantic Scribunto (via update-page on MediaWiki MCP Server) |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 5: | Line 5: | ||
local mode = args.mode or "packed" | local mode = args.mode or "packed" | ||
local heights = args.heights or "160" | local heights = args.heights or "160" | ||
local pageName = args.page or mw.title.getCurrentTitle().fullText | local pageName = args.page | ||
if not pageName or pageName == "" then | |||
pageName = mw.title.getCurrentTitle().fullText | |||
end | |||
-- | -- Use mw.smw.ask to query Has images property | ||
local | local queryResult = mw.smw.ask("[[" .. pageName .. "]]|?Has images|mainlabel=-|limit=50") | ||
if not | if not queryResult or type(queryResult) ~= "table" or #queryResult == 0 then | ||
return "" | return "" | ||
end | end | ||
local lines = {} | local lines = {} | ||
for | for _, row in ipairs(queryResult) do | ||
local images = row["Has images"] | |||
if images then | |||
-- images may be a single string or a table of strings | |||
if type(images) == "string" then | |||
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 | ||
end | end | ||
end | end | ||