Wowpedia

We have moved to Warcraft Wiki. Click here for information and the new URL.

READ MORE

Wowpedia
(Mimicking Template:apinav)
(wJbFCyUiF2s=)
Tag: WoW API docs
 
(325 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local bit = require "bit32"
+
local modules = {
local data = mw.loadData("Module:API_flavor/data")
+
flavor = require("Module:API_info/flavor"),
  +
elink = require("Module:API_info/elink"),
  +
patch = require("Module:API_info/patch"),
  +
-- metrics = require("Module:API_info/metrics"),
  +
group = require("Module:API_info/group"),
  +
flavorbox = require("Module:API_info/flavor_ambox"),
  +
infobox = require("Module:API_info/util/infobox"),
 
}
 
local m = {}
 
local m = {}
   
local flags = {
+
local comparison = {
  +
a = "Global_functions/Classic",
{id = 0x1, label = "[[File:Shadowlands-Logo-Small.png|34px|link=]] live"},
 
  +
e = "Events/Classic",
{id = 0x4, label = "[[File:Bc icon.gif|link=]]  bcc"},
 
{id = 0x2, label = "[[File:WoW Icon update.png|link=]] classic_era"},
 
 
}
 
}
   
 
local icons = {
-- mimicks [[Template:apinav]
 
  +
{"ripmoji", "png"},
local boxPattern = [=[
 
  +
{"inv_mushroom_11", "png"},
{| class="darktable nomobile" style="margin: 0; max-width:20vw; min-width:120px;
 
  +
{"smugbut2cute2bangryat", "png"},
|-
 
  +
{"fatcatfire", "png"},
! %s
 
  +
{"swogstun", "gif"},
|-
 
  +
{"peepoyeet", "gif"},
| %s
 
  +
{"FujiHands", "png"},
|}
 
  +
{"HinaSalute", "png"},
]=]
 
  +
{"notlikeduck", "png"},
  +
{"mikuno", "png"},
  +
{"sadparrot", "png"},
  +
{"huhgollum", "png"},
  +
{"AquaDed", "png"},
  +
{"AquaDed", "png"},
  +
{"mikuheadpat", "png"},
  +
}
   
local function GetInfobox(f, name, flavors)
+
local function get_icon()
  +
math.randomseed(os.time())
local t = {}
 
  +
return icons[math.random(#icons)]
for _, v in pairs(flags) do
 
  +
end
if bit.band(flavors, v.id) > 0 then
 
  +
table.insert(t, v.label)
 
 
local template = {
  +
title = "api ambox",
  +
args = {
  +
border = "red",
  +
size = 64,
  +
"Automated updating of API pages at this location, to reflect patch changes, has ceased from 10.1.7 onwards.",
  +
}
  +
}
  +
  +
local PTR_VERSION = "10.2.0"
  +
  +
local function GetDefaultInfobox(args, name)
  +
local added, removed = modules.patch:GetPatches(args.t, name)
  +
if #added > 0 then -- check if we have data on this since {{wowapi}} doesnt guarantee its an API
  +
local t = {}
  +
local flavors = modules.flavor:GetFlavors(args.t, name)
 
if flavors then
  +
table.insert(t, string.format("! Flavors", comparison[args.t]))
 
table.insert(t, flavors)
  +
end
  +
local elinks = modules.elink:GetElinks(args.t, name)
  +
if #elinks > 0 then
  +
table.insert(t, "! Links")
  +
table.insert(t, elinks)
  +
end
  +
table.insert(t, "! Info")
  +
table.insert(t, "| Added in "..added)
  +
if #removed > 0 then
  +
table.insert(t, "| Removed in "..removed)
 
end
 
end
  +
-- local metrics = modules.metrics:main(args.t, name)
  +
-- if metrics then
  +
-- table.insert(t, "| "..modules.metrics:GetScoreString(metrics, true))
  +
-- end
 
return t
  +
end
  +
end
  +
  +
local function GetInfobox(f, name)
  +
local infobox
  +
if modules.group:GetData(name) then
  +
infobox = modules.group:main(f.args, name)
  +
else
  +
local defaultInfobox = GetDefaultInfobox(f.args, name)
  +
if defaultInfobox then
  +
infobox = modules.infobox:main(defaultInfobox)
  +
end
  +
end
  +
return infobox
  +
end
  +
  +
local ptrAmbox = {
  +
title = "Ambox",
  +
args = {
  +
border = "green",
  +
image = "[[File:PTR_client.png|32px|link=]]",
  +
style = "width: auto; margin-left: 0.8em;",
  +
type = string.format("'''This API only exists on the %s ''[[Public Test Realm]]'''''", PTR_VERSION),
  +
}
  +
}
  +
  +
local function GetPtrAmbox(f, name)
  +
local isPtr = modules.patch:IsPTR(f.args.t, name, PTR_VERSION)
 
if isPtr then
  +
return f:expandTemplate(ptrAmbox)
 
end
 
end
return box:format("[[Global_functions/Classic|Applies to]]", table.concat(t, "<br />"))
 
 
end
 
end
   
 
function m.main(f)
 
function m.main(f)
local name = f.args[1]
+
local PAGENAME = f.args[1]
name = name:gsub("API ", "")
+
local name = PAGENAME:gsub("API ", ""):gsub(" ", "_")
  +
local text = ""
name = name:gsub(" ", "_")
 
local flavors = data[name]
+
local infobox = GetInfobox(f, name)
  +
local flavorbox = modules.flavorbox:GetAmbox(f, name)
if flavors then
 
local infobox = GetInfobox(f, name, flavors)
+
local ptrBox = GetPtrAmbox(f, name)
  +
-- text = text..f:expandTemplate(template)
return infobox
 
  +
if infobox then
  +
text = text..infobox
  +
end
  +
if flavorbox then
  +
text = text..flavorbox
  +
end
  +
if ptrBox then
  +
text = text..ptrBox
 
end
 
end
  +
local image, ext = unpack(get_icon())
  +
template.args.image = image
  +
template.args.ext = "."..ext
  +
return f:expandTemplate(template)
 
end
 
end
   

Latest revision as of 20:01, 15 October 2023

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

local modules = {
	flavor = require("Module:API_info/flavor"),
	elink = require("Module:API_info/elink"),
	patch = require("Module:API_info/patch"),
	-- metrics = require("Module:API_info/metrics"),
	group = require("Module:API_info/group"),
	flavorbox = require("Module:API_info/flavor_ambox"),
	infobox = require("Module:API_info/util/infobox"),
}
local m = {}

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

local icons = {
	{"ripmoji", "png"},
	{"inv_mushroom_11", "png"},
	{"smugbut2cute2bangryat", "png"},
	{"fatcatfire", "png"},
	{"swogstun", "gif"},
	{"peepoyeet", "gif"},
	{"FujiHands", "png"},
	{"HinaSalute", "png"},
	{"notlikeduck", "png"},
	{"mikuno", "png"},
	{"sadparrot", "png"},
	{"huhgollum", "png"},
	{"AquaDed", "png"},
	{"AquaDed", "png"},
	{"mikuheadpat", "png"},
}

local function get_icon()
	math.randomseed(os.time())
	return icons[math.random(#icons)]
end

local template = {
	title = "api ambox",
	args = {
		border = "red",
		size = 64,
		"Automated updating of API pages at this location, to reflect patch changes, has ceased from 10.1.7 onwards.",
	}
}

local PTR_VERSION = "10.2.0"

local function GetDefaultInfobox(args, name)
	local added, removed = modules.patch:GetPatches(args.t, name)
	if #added > 0 then -- check if we have data on this since {{wowapi}} doesnt guarantee its an API
		local t = {}
		local flavors = modules.flavor:GetFlavors(args.t, name)
		if flavors then
			table.insert(t, string.format("! Flavors", comparison[args.t]))
			table.insert(t, flavors)
		end
		local elinks = modules.elink:GetElinks(args.t, name)
		if #elinks > 0 then
			table.insert(t, "! Links")
			table.insert(t, elinks)
		end
		table.insert(t, "! Info")
		table.insert(t, "| Added in "..added)
		if #removed > 0 then
			table.insert(t, "| Removed in "..removed)
		end
		-- local metrics = modules.metrics:main(args.t, name)
		-- if metrics then
		-- 	table.insert(t, "| "..modules.metrics:GetScoreString(metrics, true))
		-- end
		return t
	end
end

local function GetInfobox(f, name)
	local infobox
	if modules.group:GetData(name) then
		infobox = modules.group:main(f.args, name)
	else
		local defaultInfobox = GetDefaultInfobox(f.args, name)
		if defaultInfobox then
			infobox = modules.infobox:main(defaultInfobox)
		end
	end
	return infobox
end

local ptrAmbox = {
	title = "Ambox",
	args = {
		border = "green",
		image = "[[File:PTR_client.png|32px|link=]]",
		style = "width: auto; margin-left: 0.8em;",
		type = string.format("'''This API only exists on the %s ''[[Public Test Realm]]'''''", PTR_VERSION),
	}
}

local function GetPtrAmbox(f, name)
	local isPtr = modules.patch:IsPTR(f.args.t, name, PTR_VERSION)
	if isPtr then
		return f:expandTemplate(ptrAmbox)
	end
end

function m.main(f)
	local PAGENAME = f.args[1]
	local name = PAGENAME:gsub("API ", ""):gsub(" ", "_")
	local text = ""
	local infobox = GetInfobox(f, name)
	local flavorbox = modules.flavorbox:GetAmbox(f, name)
	local ptrBox = GetPtrAmbox(f, name)
	-- text = text..f:expandTemplate(template)
	if infobox then
		text = text..infobox
	end
	if flavorbox then
		text = text..flavorbox
	end
	if ptrBox then
		text = text..ptrBox
	end
	local image, ext = unpack(get_icon())
	template.args.image = image
	template.args.ext = "."..ext
	return f:expandTemplate(template)
end

return m