Wowpedia
Advertisement
Wowpedia
229,881
pages

Documentation for this module may be created at Module:API info/elink/doc

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",
	},
	{
		id = "tly_apidocs",
		label = "Blizzard Docs",
		icon = "Townlong-Yak_BAD",
		url = "https://www.townlong-yak.com/framexml/latest/Blizzard_APIDocumentation#%s",
		show = function(v, apiType)
			if apiType == "a" then
				if data.a[v] then
					local flags = data.a[v].flags
					return bit.band(flags, 0x2) > 0
				end
			elseif apiType == "e" then
				return data.e[v]
			end
		end,
	},
	{
		id = "gh_wowapiweb",
		label = "Offline /api",
		icon = "ProfIcons_engineering",
		url = "https://mrbuds.github.io/wow-api-web/?search=%s",
		show = function(v, apiType)
			if apiType == "a" then
				if data.a[v] then
					local flags = data.a[v].flags
					return bit.band(flags, 0x2) > 0
				end
			elseif apiType == "e" then
				return data.e[v]
			end
		end,
		url_params = function(v, apiType)
			if apiType == "a" then
				local apiName = GetApiBaseName(v)
				local system = data.a[v].system
				return string.format("api:%s:%s:%s", "function", apiName, system)
			elseif apiType == "e" then
				local info = data.e[v]
				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(v) return wowprog_data[v] end,
	},
}

function m:GetElinks(name, apiType)
	local t = {}
	for _, info in pairs(links) do
		if not info.show or info.show(name, apiType) then
			local params = info.url_params and info.url_params(name, apiType) 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