Module:ImageGallery: Difference between revisions

From Umamusume Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 25: Line 25:
local gallery = mw.html.create('gallery')
local gallery = mw.html.create('gallery')
for _, img in ipairs(images) do
for _, img in ipairs(images) do
gallery:wikitext('\n' .. img.file .. '|' .. img.caption .. '\n')
gallery:wikitext('\n\n' .. img.file .. '|' .. img.caption .. '\n')
end
end
root:node(gallery)
root:node(gallery)

Revision as of 03:51, 5 March 2024

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 root = mw.html.create()
	root:wikitext('==' .. header .. '==\n')
	local gallery = mw.html.create('gallery')
	for _, img in ipairs(images) do
		gallery:wikitext('\n\n' .. img.file .. '|' .. img.caption .. '\n')
	end
	root:node(gallery)
	return root
end

return p