Wowpedia
Advertisement

local bit = require "bit32"
local data = {
	a = mw.loadData("Module:API_info/elink/api"),
	e = mw.loadData("Module:API_info/elink/event")
}
local wowprog_data = mw.loadData("Module:API_info/wowprog")

local m = {}
local ICON_FORMAT = "[[Image:%s.png|16px|link=%s]]"

local function GetApiBaseName(v)
	if v:find("%.") then
		v = v:match(".-%.(.+)")
	end
	return v
end

local links = {
	{
		id = "tly_globewut",
		label = "Globe wut",
		icon = "Townlong-Yak_Globe",
		url = "https://www.townlong-yak.com/globe/wut/#q:%s",
		show = function() return true end,
	},
	{
		id = "tly_apidocs",
		label = "Blizzard Docs",
		icon = "Townlong-Yak_BAD",
		url = "https://www.townlong-yak.com/framexml/latest/Blizzard_APIDocumentation#%s",
		show = function(apiType, name)
			return data[apiType][name]
		end,
	},
	{
		id = "gh_wowapiweb",
		label = "Offline /api",
		icon = "ProfIcons_engineering",
		url = "https://mrbuds.github.io/wow-api-web/?search=%s",
		show = function(apiType, name)
			return data[apiType][name]
		end,
		url_params = function(apiType, name)
			if apiType == "a" then
				local apiName = GetApiBaseName(name)
				local system = data.a[name]
				return string.format("api:%s:%s:%s", "function", apiName, system)
			elseif apiType == "e" then
				local info = data.e[name]
				if info then
					return string.format("api:%s:%s:%s", "event", info.Name, info.System)
				end
			end
		end,
	},
	{
		id = "wowprog",
		label = "Wowprogramming",
		icon = "Wowprogramming",
		url = "https://wowprogramming.com/docs/api/%s.html",
		show = function(_, name) return wowprog_data[name] end,
	},
}

function m:GetElinks(apiType, name)
	local t = {}
	for _, info in pairs(links) do
		if info.show(apiType, name) then
			local params = info.url_params and info.url_params(apiType, name) or name
			local url = info.url:format(params)
			table.insert(t, {
				icon = ICON_FORMAT:format(info.icon, url),
				link = string.format("[%s %s]", url, info.label),
			})
		end
	end
	return t
end

return m
Advertisement