Difference between revisions of "Module:HerbGallery"
From A Wiki in the Desert
| Line 24: | Line 24: | ||
if type( queryResult ) == "table" then | if type( queryResult ) == "table" then | ||
| − | |||
for k,v in pairs( queryResult.results ) do | for k,v in pairs( queryResult.results ) do | ||
if type( v ) == "table" and type(v.printouts) == "table" and not v.printouts.image == nil then | if type( v ) == "table" and type(v.printouts) == "table" and not v.printouts.image == nil then | ||
| Line 35: | Line 34: | ||
end | end | ||
end | end | ||
| − | return | + | |
| + | local myResult = "" | ||
| + | for k,v in pairs( galleryArgs ) do | ||
| + | myResult = myResult .. ' ' .. k .. ' ' .. v .. '\n' | ||
| + | end | ||
| + | return myResult | ||
end | end | ||
Revision as of 03:30, 15 May 2021
Documentation for this module may be created at Module:HerbGallery/doc
local p = {} --p stands for package
function p.gallery( frame )
if not mw.smw then
return "mw.smw module not found"
end
if frame:getParent().args[1] == nil then
return "no parameter found"
end
local queryResult = mw.smw.getQueryResult( '[[Herb/'.. frame:getParent().args[1] ..']]|?Is similar to.Has image=image' )
if queryResult == nil then
return "(no values)"
end
local currentIndex = 1
local galleryArgs = {
width="200",
height="200",
mode="packed"
}
if type( queryResult ) == "table" then
for k,v in pairs( queryResult.results ) do
if type( v ) == "table" and type(v.printouts) == "table" and not v.printouts.image == nil then
for kR,vR in pairs( v.printouts.image ) do
galleryArgs[currentIndex] = vR.fulltext
currentIndex = currentIndex + 1
end
else
return 'input:'..frame:getParent().args[1]
end
end
local myResult = ""
for k,v in pairs( galleryArgs ) do
myResult = myResult .. ' ' .. k .. ' ' .. v .. '\n'
end
return myResult
end
return ""
end
return p