Module:ImageGallery: Difference between revisions

From Umamusume Wiki
Jump to navigation Jump to search
(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 == "' .....")
 
No edit summary
 
(11 intermediate revisions by the same user not shown)
Line 11: Line 11:
}
}
if imageType == 'other' then
if imageType == 'other' then
query.where = query.where .. ' AND (Gallery_Image.type == "other"'
query.where = query.where .. ' AND (Gallery_Image.type = "other"'
.. ' or Gallery_Image.type IS NULL)'
.. ' OR Gallery_Image.type IS NULL)'
else
else
query.where = query.where .. ' AND Gallery_Image.type == "'
query.where = query.where .. ' AND Gallery_Image.type = "'
.. imageType .. '"'
.. imageType .. '"'
end
end
Line 21: Line 21:
table.concat(fields, ','), query)
table.concat(fields, ','), query)
local build = '==' .. header .. '==\n<gallery heights="180px">\n'
if #images == 0 then
return ''
end
local wikitext = '==' .. header .. '==\n'
wikitext = wikitext .. '<gallery>\n'
for _, img in ipairs(images) do
for _, img in ipairs(images) do
build = build .. img.file .. '|' .. img.caption .. '\n'
wikitext = wikitext .. img.file .. '|' .. img.caption .. '\n'
end
end
return build .. '</gallery>'
wikitext = wikitext .. '</gallery>\n'
return frame:preprocess(wikitext)
end
end


return p
return p

Latest revision as of 03:59, 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)
	
	if #images == 0 then
		return ''
	end
	
	local wikitext = '==' .. header .. '==\n'
	wikitext = wikitext .. '<gallery>\n'
	for _, img in ipairs(images) do
		wikitext = wikitext .. img.file .. '|' .. img.caption .. '\n'
	end
	wikitext = wikitext .. '</gallery>\n'
	return frame:preprocess(wikitext)
end

return p