Dokumentācijas ikona Moduļa dokumentācija[skatīt] [labot] [hronoloģija] [pārlādēt]

This module returns a link to Sports-Reference.com. The URL is taken from Wikidata, unless there is no link on Wikidata. If that's the case, the module uses the link from the optional backup parameter; if there is no link on Wikidata and no backup parameter, it will return an error message explaining how to fix the issue.

The module only has one function, link, which returns the external link text ready for use. It should be used in the {{Sports-reference}} template thusly:

{{#invoke:SportsReference|link|optional backup parameter}}

The reason the module prefers links from Wikidata rather than the links given in the backup parameter is that it is much simpler to correct the links in Wikidata, and that will benefit all projects and not just this wiki; also, Wikidata supports various constraints so that the items and values can easily be checked for errors.

-- This is the code to insert a template to indicate that the link is in English:
-- frame:expandTemplate{ title = "LANGUAGETEMPLATENAME", args = { "en" } }
-- It is obviously not used in the English Wikipedia itself.
local function linktext(s)
	entity = mw.wikibase.getEntityObject()
	if not entity then
		label = mw.title.getCurrentTitle().text
	else
		label = mw.wikibase.label(entity.id) or mw.title.getCurrentTitle().text
	end
	if (s == nil) or (s == "") then
		-- This text returns an error that says that the Sports Reference ID is neither
		-- present on Wikidata nor in the article, and categorises the page as missing
		-- the Wikidata property.
		return "<span class='error'>''Sports Reference'' ID nav atrodams ne rakstā, ne Vikidatos!</span> \
		[[Veidne:SR profils#Add ID in Wikidata|Palīdzība]]\
		[[Kategorija:P1447: nav Vikidatos]]"
	else
		-- This is the text that is returned if there is a Sports Reference ID on Wikidata or in the article.
		-- In this line, you can use the parameter "label" which displays the athlete's name. I have not included it because the {{SR profils}} template didn't use it.
		return "[http://www.sports-reference.com/olympics/athletes/" .. s .. ".html ''Sports Reference'' profils]"
	end
end

local p = {}

function p.link(frame)
	-- This is a check to see if the optional first parameter contains ".html", and then a check to see if it contains "olympics/athletes/". If it does, remove it.
	id = string.gsub((frame.args[1] or ""), ".html", "")
	id = string.gsub(id, "[/]?olympics/athletes/", "")
	if not mw.wikibase then
		return linktext(id)
	end
	local entity = mw.wikibase.getEntityObject()
	local claims = entity.claims or {}
	local hasProp = claims["P1447"]
	if not hasProp then
		-- Category for articles that don't have the Sports Reference property on Wikidata.
		return linktext(id) .. "[[Category:P1447: nav Vikidatos]]"
	end
	local propValue = hasProp[1].mainsnak.datavalue.value
	return linktext(propValue)
end

return p