The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Documentation for this module may be created at Module:Professional wrestling profiles/doc

local getArgs = require('Module:Arguments').getArgs
local p = {}

local profiles = {
	{
		key = "wwe",
		name = "WWE",
		person = { url = "https://www.wwe.com/superstars/%s", wikidata = "P2857" },
		team = { url = "https://www.wwe.com/superstars/%s", wikidata = "P2857" },
		stable = { url = "https://www.wwe.com/superstars/%s", wikidata = "P2857" }
	},
	{
		key = "roh",
		name = "Ring of Honor",
		person = { url = "https://www.ringofhonor.com/active-roster/%s", wikidata = nil },
		team = { url = nil, wikidata = nil },
		stable = { url = nil, wikidata = nil }
	},
	{
		key = "njpw",
		name = "New Japan Pro-Wrestling",
		person = { url = "https://www.njpw1972.com/profile/%s", wikidata = nil },
		team = { url = nil, wikidata = nil },
		stable = { url = nil, wikidata = nil }
	},
	{
		key = "cagematch",
		name = "Cagematch",
		person = { url = "https://www.cagematch.net/?id=2&nr=%s", wikidata = "P2728" },
		team = { url = "https://www.cagematch.net/?id=28&nr=%s", wikidata = "P2939" },
		stable = { url = "https://www.cagematch.net/?id=29&nr=%s", wikidata = "P3042" }
	},
	{
		key = "wrestlingdata",
		name = "Wrestlingdata",
		person = { url = "https://www.wrestlingdata.com/index.php?befehl=bios&wrestler=%s", wikidata = "P2764" },
		team = { url = "https://www.wrestlingdata.com/index.php?befehl=stables&stable=%s", wikidata = nil },
		stable = { url = "https://www.wrestlingdata.com/index.php?befehl=stables&stable=%s", wikidata = nil }
	},
	{
		key = "iwd",
		name = "Internet Wrestling Database",
		person = { url = "http://www.profightdb.com/wrestlers/%s.html", wikidata = "P2829" },
		team = { url = nil, wikidata = nil },
		stable = { url = nil, wikidata = nil }
	},
	{
		key = "wrestlingtitles",
		name = "Wrestling-Titles",
		person = { url = "https://www.wrestling-titles.com/personalities/%s/", wikidata = nil },
		team = { url = nil, wikidata = nil },
		stable = { url = nil, wikidata = nil }
	}
}

local function fetch_wikidata(entity, property)
	if entity and property then
		local value = entity:getBestStatements(property)[1]
		if value then
			return value["mainsnak"]["datavalue"]["value"]
		end
	end
	return nil
end

function p.profiles(frame)
	local args = getArgs(frame)
	local entity = mw.wikibase.getEntity()
	local _type = "person"
	local text = ""

	-- Determine type
	if args["type"] and (args["type"] == "person" or args["type"] == "team" or args["type"] == "stable") then
		_type = args["type"]
	else
		local instance = fetch_wikidata(entity, "P31")	-- "instance of" on Wikidata
		local types = {
			["Q5"] = "person",							-- "human"
			["Q1066670"] = "team",						-- "tag team"
			["Q25178247"] = "stable"					-- "professional wrestling stable"
		}
		if instance and types[instance.id] then
			_type = types[instance.id]
		end
	end

	-- Parse profiles
	for index, data in ipairs(profiles) do
		local value = args[data["key"]] or fetch_wikidata(entity, data[_type]["wikidata"])
		if value and data[_type]["url"] then
			text = text
			.. string.format("[" .. data[_type]["url"] .. " " .. data["name"] .. "]", value)
			.. (args[data["key"]] and "" or frame:expandTemplate{title = 'EditAtWikidata', args = { pid = data[_type]["wikidata"] }})
			.. ", "
		end
	end
	if text == "" then
		return mw.title.getCurrentTitle().namespace == 0 and "[[Category:Professional wrestling profiles template without any identifiers]]" or nil
	end

	return (args["name"] or frame:expandTemplate{title = 'PAGENAMEBASE'}) .. "'s profile at " .. string.sub(text, 1, -3)
end

return p