Wowpedia
Advertisement

local flavor_module = require("Module:API_info/flavor")
local elink_module = require("Module:API_info/elink")
local patch_module = require("Module:API_info/patch")
local multi_module = require("Module:API_info/multi")
local m = {}

local comparison = {
	a = "Global_functions/Classic",
	e = "Events/Classic",
}

local HTML_LIST_START = '<ul class="plainlinks elinks">\n'
local HTML_LIST_ITEM = '<li style="padding-left: 0px; min-height: %dpx">%s %s</li>\n'
local HTML_LIST_END = '</ul>'

local INFOBOX_STYLE = '<div class="nomobile" style="float:right; clear:right">\n%s\n</div>'

local function GetFlavorText(args, name)
	local flavors = flavor_module:GetFlavors(args.t, name)
	if flavors then
		local s = HTML_LIST_START
		for _, info in pairs(flavors) do
			s = s..HTML_LIST_ITEM:format(0, info.icon, info.link)
		end
		s = s..HTML_LIST_END
		return s
	end
end

local function GetElinksText(args, name)
	local elinks = elink_module:GetElinks(args.t, name)
	local s = HTML_LIST_START
	for _, info in pairs(elinks) do
		s = s..HTML_LIST_ITEM:format(25, info.icon, "&nbsp;"..info.link)
	end
	s = s..HTML_LIST_END
	return s
end

local function GetDefaultInfobox(args, name)
	local added, removed = patch_module:GetPatches(args.t, name)
	if #added > 0 then -- check if we have data on this since {{wowapi}} doesnt guarantee its an API
		local s = '{| class="darktable" style="min-width:142px;"'
		local flavorText = GetFlavorText(args, name)
		if flavorText then
			s = s..string.format("\n|-\n! Game [[%s|Flavors]]\n|-\n| %s", comparison[args.t], flavorText)
		end
		s = s.."\n|-\n! Links\n|-\n| "..GetElinksText(args, name)
		s = s.."\n|-\n! Patch\n|-\n| Added in "..added
		if #removed > 0 then
			s = s.."\n|-\n| Removed in "..removed
		end
		s = s.."\n|}"
		return s
	end
end

local function GetInfobox(f, name)
	if multi_module.data[name] then
		return multi_module:GetInfobox(f.args, name, multi_module.data[name])
	else
		return GetDefaultInfobox(f.args, name)
	end
end

function m.main(f)
	local PAGENAME = f.args[1]
	local name = PAGENAME:gsub("API ", ""):gsub(" ", "_")
	local infobox = GetInfobox(f, name)
	if infobox then
		return string.format(INFOBOX_STYLE, infobox)
	end
end

return m
Advertisement