Modul:SportsReference

Documentation icon Dokumentacija modula[predogled] [uredi] [zgodovina] [osveži]

Uporaba uredi

Modul vrne povezavo na stran Sports-Reference.com. URL jemlje iz Wikidata, če tam be obstaja, pa neobvezni rezervni parameter iz članka. Če ni niti tega, izpiše napako.

Modul ima edino funkcijo link, ki vrne zunanjo povezavo pripravljeno za uporabo. Uporablja naj jo predloga {{Sports-reference}} kot:

{{#invoke:SportsReference|link|neobvezni rezervni parameter}}.

Modul preferira podatke iz Wikidata pred lokalnimi, ker je na ta način lažje popravljati napačne povezave, ki so tako popravljene povsod. Wikidata tudi podpira različne omejitve, s čimer je lahko preveriti vnesene vrednosti.


local function linktext(s1,s2,s3)
	if (s3 == nil) or (s3 == "") then
		return "[https://www.sports-reference.com/olympics/athletes/" .. s1 .. ".html " .. s2 .. "] na sports-reference.com"
	else
		return "[https://www.sports-reference.com/olympics/athletes/" .. s1 .. ".html " .. s2 .. "] na sports-reference.com ([https://web.archive.org/web/" .. s3 .. "/https://www.sports-reference.com/olympics/athletes/" .. s1 .. ".html archive])"
	end
end

local function category(s)
	if mw.title.getCurrentTitle().namespace ~= 0 then
		return ""
	end
	return "[[Kategorija:Predloga Sports-Reference" .. s .. "]]"
end

local p = {}

function p.link(frame)

	-- Optional first parameter contains ID portion of Sports-Reference URL.
	-- Trim any leading or trailing spaces. If it contains ".html", remove it.

	local id = string.gsub((mw.text.trim(frame.args[1]) or ""), ".html", "")

	-- Optional second parameter contains name for link. Trim leading or trailing spaces.
	-- If name is not provided, use article name without disambiguation.

	local name = mw.text.trim(frame.args[2])
	if (name == nil) or (name == "") then
		name = string.gsub(mw.title.getCurrentTitle().text, "%s+%b()$", "", 1)
	end

	-- Optional third parameter contains date/time portion of Archive.org URL.

	local archive = mw.text.trim(frame.args[3])

	-- For articles without Wikidata property:
	-- if ID not provided, return error text and tracking category
	-- if ID is provided, return link and tracking category

	local entity = mw.wikibase.getEntityObject() or {}
	local claims = entity.claims or {}
	local hasProp = claims["P1447"]
	if not hasProp then
		if (id == nil) or (id == "") then
			return "<span class='error'>Predloga Sports-Reference brez ID in nima vnosa v Wikipodatkih.</span> [[Predloga:Sports-reference#Add ID in Wikidata|KAko naj to popravim?]]" .. category("manjka ID in ni v Wikipodatkih")
		else
			return linktext(id,name,archive) .. category("z ID ni v Wikipodatkih")
		end
	end

	-- For articles with Wikidata property:
	-- if ID not provided, return link (using Wikidata) and tracking category
	-- if ID is provided, return link (using ID) and one of two tracking categories

	local propValue = hasProp[1].mainsnak.datavalue.value
	if (id == nil) or (id == "") then
		return linktext(propValue,name,archive) .. " [[File:Blue pencil.svg |frameless |text-top |10px |alt=Uredite to v Wikipodatkih |link=https://www.wikidata.org/wiki/" .. entity.id .. "#P1447|Uredite to v Wikipodatkih]]" .. category(", ki uporablja Wikipodatke")
	end
	if id == propValue then
		return linktext(id,name,archive) .. category(" z enakim ID kot na Wikipodatkih")
	else
		return linktext(id,name,archive) .. category(" z različnim ID od Wikipodatkov")
	end

end

return p