Module:ImageGallery

From Umamusume Wiki
Revision as of 03:40, 5 March 2024 by Snep (talk | contribs) (Created page with "local p = {} local cargo = mw.ext.cargo function p.list(frame) local charName = frame.args[1] local header = frame.args[2] local imageType = frame.args[3] local query = { limit = '1000', where = 'Gallery_Image.characters HOLDS "' .. charName .. '"', } if imageType == 'other' then query.where = query.where .. ' AND (Gallery_Image.type == "other"' .. ' or Gallery_Image.type IS NULL)' else query.where = query.where .. ' AND Gallery_Image.type == "' .....")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:ImageGallery/doc

local p = {}
local cargo = mw.ext.cargo

function p.list(frame)
	local charName = frame.args[1]
	local header = frame.args[2]
	local imageType = frame.args[3]
	local query = {
		limit = '1000',
		where = 'Gallery_Image.characters HOLDS "' .. charName .. '"',
	}
	if imageType == 'other' then
		query.where = query.where .. ' AND (Gallery_Image.type == "other"'
			.. ' or Gallery_Image.type IS NULL)'
	else
		query.where = query.where .. ' AND Gallery_Image.type == "'
			.. imageType .. '"'
	end
	local fields = {'file','caption'}
	local images = cargo.query('Gallery_Image',
		table.concat(fields, ','), query)
	
	local build = '==' .. header .. '==\n<gallery heights="180px">\n'
	for _, img in ipairs(images) do
		build = build .. img.file .. '|' .. img.caption .. '\n'
	end
	return build .. '</gallery>'
end

return p