Module:Professional wrestling

From Omniversalis

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

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

function getpropertyvalue(ent, prop)
	local id = nil;
	if (ent and prop) then value = ent:getBestStatements(prop)[1] else return nil end
	if value then return value["mainsnak"]["datavalue"]["value"] end;

function getpropertyvaluewithdefaultvalues(ent, prop, value1, value2)
	return value1 or value2 or getpropertyvalue(ent, prop);

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

function getexternallink(frame, linkformat, urlformat, prop, cat)
		local args = getArgs(frame); 
		local id = args[1] or args["id"];
		if (not id and prop) then id = getpropertyvalue(mw.wikibase.getEntityObject(), prop); end;
		if not id then return cat end	
	    local name = getname(frame, args[2], args["name"]);
	    local url = string.format(urlformat, id);
	    local code = string.format(linkformat, url, name);
	    return code;

local p = {}
function p.getpropertyvalue(frame)
local ent = mw.wikibase.getEntityObject();
local prop = frame.args[1];
return getpropertyvalue(ent, prop);

function p.cagematch(frame)
	return getexternallink(frame, "[%s %s]'s profile at", "", 'P2728', "");

function p.wrestlingtitlespersonalities(frame)
	return getexternallink(frame, "[%s %s]'s profile at", "", nil, "[[Category:Wrestling Titles template with no id set]]");

function p.rohroster(frame)
	return getexternallink(frame, "[%s %s]'s [[Ring of Honor]] profile", "", nil, "");	

function p.njpw(frame)
	local args = getArgs(frame);
	if args["newlink"] then return getexternallink(frame, "[%s %s]'s [[New Japan Pro Wrestling]] profile", "", nil, "");
		else return getexternallink(frame, "[%s %s]'s [[New Japan Pro Wrestling]] profile", "", nil, "");	

function p.gfw(frame)
	return getexternallink(frame, "[%s %s]'s [[Global Force Wrestling]] profile", "", nil, "");	

function p.dragongateusa(frame)
	return getexternallink(frame, "[%s %s] at the official [[Dragon Gate USA]] website", "", nil, "");

function p.chikara(frame)
	return getexternallink(frame, "[%s %s] at the official [[Chikara_(professional_wrestling)|Chikara]] website", "", nil, "");

function p.profiles(frame)
	local args = getArgs(frame);
	local ent = mw.wikibase.getEntityObject();
	local cagematchid = getpropertyvaluewithdefaultvalues(ent, 'P2728', args["cagematch"], nil);		
	local wrestlingdataid = getpropertyvaluewithdefaultvalues(ent, 'P2764', args["wrestlingdata"], nil);
	local iwdid = getpropertyvaluewithdefaultvalues(ent, 'P2829', args["iwd"], nil);
	if (not cagematchid) and (not wrestlingdataid) and (not iwdid) then return "[[Category:Professional wrestling profiles template without any identifiers]]" end
	local name = getname(frame, args["name"], nil);
	local text = name .. "'s profile at "; 
	if cagematchid then text = text .. "[" .. cagematchid .. "], " end
	if wrestlingdataid then text = text .. "[" .. wrestlingdataid .. "], " end
	if iwdid then text = text .. "[" .. iwdid .. ".html Internet Wrestling Database], " end
	return string.sub(text, 1, -3);

return p