Welcome to the Umamusume Wiki! If you want to contribute, please read the guidelines.

Module:Navbox items

From Umamusume Wiki
Jump to navigation Jump to search

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

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

function p.characters(frame)
	local query = {		
		limit = '1000',
		orderBy = "Characters.name_en ASC"
	}
	if frame.args[1] == 'horsegirls' then
		query.where = 'Characters.type="horsegirl" AND Characters.media IS NULL'
	elseif frame.args[1] == 'other' then
		query.where = 'NOT Characters.type="horsegirl" AND Characters.media IS NULL'
	elseif frame.args[1] == 'cinderellagray' then
		query.where = 'Characters.media="cinderellagray"'
	elseif frame.args[1] == 'starblossom' then
		query.where = 'Characters.media="starblossom"'
	elseif frame.args[1] == 'anime' then
		query.where = 'Characters.media="anime"'
	end

	local fields = { '_pageName', 'name_en' }
	local events = cargo.query('Characters',
	table.concat(fields, ','), query)

	local ul = mw.html.create("ul")

	for _, ch in ipairs(events) do
		if ch.name_en then
            local li = ul:tag("li")
            li:wikitext(string.format('[[%s|%s]]', ch._pageName, ch.name_en))  
		end
	end
	return tostring(ul)
end

function p.albums(frame)
    local query = {
        limit = '1000',
        orderBy = 'Albums.release_date ASC',
    }
    if (frame.args[1]) then
        query['where'] = 'Albums.type = "'.. frame.args[1]  ..'"'
    end
    local fields = {'_pageName', 'title'}
    local albums = cargo.query('Albums', table.concat(fields, ','), query)

    local ul = mw.html.create("ul")

    for _, al in ipairs(albums) do
        if al.title then
            local li = ul:tag("li")
            li:wikitext(string.format('[[%s|%s]]', al._pageName, al.title))  
        end
    end
    return tostring(ul)
end
return p