Wowpedia
Advertisement
Wowpedia
229,881
pages
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_api = mw.loadData("Module:ElinksApiMulti/data")
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 function GetFlavorText(name, args)
	local flavors = flavor_module:GetFlavors(name, args.t)
	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(name, args)
	local elinks = elink_module:GetElinks(name, args.t)
	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 GetInfobox(name, args)
	local flavorText = GetFlavorText(name, args)
	local added, removed = patch_module:GetPatches(name)
	-- would check for only patchdata but events are not yet added
	if flavorText or #added > 0 then
		local s = '<div class="nomobile" style="float:right; clear:right">\n{| class="darktable" style="min-width:142px;"'
		if flavorText then
			s = s..string.format("\n|-\n! Game [[%s|Flavors]]\n|-\n| %s", comparison[args.t], flavorText)
		end
		-- always returns at least globe wut
		s = s.."\n|-\n! Links\n|-\n| "..GetElinksText(name, args)
		if #added > 0 then
			s = s.."\n|-\n! Patch"
			s = s.."\n|-\n| Added in "..added
			if #removed > 0 then
				s = s.."\n|-\n| Removed in "..removed
			end
		end
		s = s.."\n|}\n</div>"
		return s
	end
end

function m.main(f)
	local PAGENAME = f.args[1]
	local name = PAGENAME:gsub("API ", ""):gsub(" ", "_")
	-- dont show the infobox when multiple apis are documented on the same page 
	if not multi_api[PAGENAME] then
		return GetInfobox(name, f.args)
	end
end

return m