Jump to content

Module:Professional wrestling profiles

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Prefall (talk | contribs) at 07:44, 13 July 2023 (adjust table, add "Edit at Wikidata" to alternate function). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local getArgs = require('Module:Arguments').getArgs

local profiles = {
	cagematch = {
		name = "Cagematch.net",
		url = "https://www.cagematch.net/",
		person = { url = "?id=2&nr=%s", wikidata = "P2728" },
		team = { url = "?id=28&nr=%s", wikidata = "P2939" },
		stable = { url = "?id=29&nr=%s", wikidata = "P3042" }
	},
	wrestlingdata = {
		name = "Wrestlingdata.com",
		url = "https://www.wrestlingdata.com/index.php",
		person = { url = "?befehl=bios&wrestler=%s", wikidata = "P2764" },
		team = { url = "?befehl=stables&stable=%s", wikidata = "" },
		stable = { url = "?befehl=stables&stable=%s", wikidata = "" }
	},
	iwd = {
		name = "Internet Wrestling Database",
		url = "http://www.profightdb.com/",
		person = { url = "wrestlers/%s.html", wikidata = "P2829" },
		team = { url = "", wikidata = "" },
		stable = { url = "", wikidata = "" }
	}
}

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

local get_value = function(site, arg_value, property, entity)
	if arg_value then
		return { arg_value, nil }
	else
		local value = get_wikidata_value(entity, property)
		if value then
			return { value, "wd" }
		else
			return nil
		end
	end
end

local get_name = function(frame, name1, name2)
	return name1 or name2 or frame:expandTemplate{title = 'PAGENAMEBASE'}; 
end

local get_external_link = function(frame, text, property, category)
	local args = getArgs(frame)
	local id = args[1] or args["id"]
	if not id and property then
		id = get_wikidata_value(mw.wikibase.getEntityObject(), property)
		if id then
			text = text .. (frame:expandTemplate{ title = 'EditAtWikidata', args = { pid = property }} or "")
		end
	end
	if not id then
		return mw.title.getCurrentTitle().namespace == 0 and category or nil
	end
	return string.format(text, id, get_name(frame, args[2], args["name"]))
end

local p = {}

function p.cagematch(frame)
	local args = getArgs(frame)
	local profile_type = (args["type"] == "team" or args["type"] == "stable") and args["type"] or "person"
	return get_external_link(frame,
		"[" .. profiles["cagematch"]["url"] .. profiles["cagematch"][profile_type]["url"] .. " %s]'s profile at " .. profiles["cagematch"]["name"],
		profiles["cagematch"][profile_type]["wikidata"],
		""
	)
end

function p.wrestlingtitlespersonalities(frame)
	return get_external_link(frame,
		"[http://www.wrestling-titles.com/personalities/%s/ %s]'s profile at Wrestling-Titles.com",
		nil,
		"[[Category:Wrestling Titles template with no id set]]"
	)
end

function p.rohroster(frame)
	return get_external_link(frame,
		"[http://www.rohwrestling.com/wrestlers/%s %s]'s [[Ring of Honor]] profile",
		nil,
		""
	)
end

function p.njpw(frame)
	local args = getArgs(frame)
	return get_external_link(frame,
		"[" .. (args["newlink"] and "http://www.njpw1972.com/profile/%s" or "http://www.njpw.co.jp/english/data/detail_profile.php?f=%s") .. " %s]'s [[New Japan Pro-Wrestling]] profile",
		nil,
		""
	)
end

function p.gfw(frame)
	return get_external_link(frame,
		"[http://globalforcewrestling.com/roster/%s/ %s]'s [[Global Force Wrestling]] profile",
		nil,
		""
	)
end

function p.dragongateusa(frame)
	return get_external_link(frame,
		"[http://dgusa.tv/bio/%s %s]'s [[Dragon Gate USA]] profile",
		nil,
		""
	)
end

function p.chikara(frame)
	return get_external_link(frame,
		"[http://chikarapro.com/chikara-roster/%s %s]'s [[Chikara (professional wrestling)|Chikara]] profile",
		nil,
		""
	)
end

function p.profiles(frame)
	local args = getArgs(frame)
	local entity = mw.wikibase.getEntityObject()
	local profile_type = (args["type"] == "team" or args["type"] == "stable") and args["type"] or "person"
	local text = ""

	for site, data in pairs(profiles) do
		local value = get_value(site, args[site], data[profile_type]["wikidata"], entity)
		if value then
			text = string.format("[" .. data["url"] .. data[profile_type]["url"] .. " " .. data["name"] .. "]", value[1])
			.. (value[2] == "wd" and frame:expandTemplate{ title = 'EditAtWikidata', args = { pid = data[profile_type]["wikidata"] }} or "")
			.. ", "
			.. text
		end
	end

	if text == "" then
		return mw.title.getCurrentTitle().namespace == 0 and "[[Category:Professional wrestling profiles template without any identifiers]]" or nil
	end

	return get_name(frame, args["name"], nil) .. "'s profile at " .. string.sub(text, 1, -3)
end

return p