Wowpedia
Advertisement

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

-- cant use dots in github search
-- https://docs.github.com/en/github/searching-for-information-on-github/searching-on-github/searching-code#considerations-for-code-search
local function GetApiBaseName(v)
	if v:find("%.") then
		v = v:match(".-%.(.+)")
	end
	return v
end

-- github forks are not searchable unless they have more stars, just cloned it instead
-- https://stackoverflow.com/questions/33626326/how-to-search-a-github-fork-for-code-using-the-github-search-api
local flavors = {
	mainline = {
		label = "mainline",
		flag = 0x1,
		icon = "[[File:Shadowlands-Icon-Inline.png|36px|link=%s]]",
		url = "https://github.com/Gethe/wow-ui-source/search?q=%s",
	},
	vanilla = {
		label = "vanilla",
		flag = 0x2,
		icon = "[[File:WoW Icon update.png|36px|link=%s]]",
		url = "https://github.com/Ketho/wow-ui-source-vanilla/search?q=%s",
	},
	tbc = {
		label = "tbc",
		flag = 0x4,
		icon = "[[File:Bc icon.gif|36px|link=%s]]",
		url = "https://github.com/Ketho/wow-ui-source-tbc/search?q=%s",
	},
}

local function AddFlavorInfo(tbl, name, info)
	local baseName = GetApiBaseName(name)
	local url = info.url:format(baseName)
	table.insert(tbl, {
		icon = info.icon:format(url),
		link = string.format("[%s %s]", url, info.label),
	})
end

function m:GetFlavors(apiType, name)
	local flags = data[apiType][name]
	if flags then
		local t = {}
		if bit.band(flags, flavors.mainline.flag) > 0 then
			AddFlavorInfo(t, name, flavors.mainline)
		end
		-- dont show vanilla if it also exists in TBC
		if bit.band(flags, flavors.tbc.flag) > 0 then
			AddFlavorInfo(t, name, flavors.tbc)
		elseif bit.band(flags, flavors.vanilla.flag) > 0 then
			AddFlavorInfo(t, name, flavors.vanilla)
		end
		return t
	end
end

return m
Advertisement