Modul:Sportslenker

Fra Wikipedia, den frie encyklopedi
Moduldokumentasjon

local genitiv = require('Modul:Genitiv')._genitiv
local entity = mw.wikibase.getEntityObject()
local claims = {}
if entity then
	claims = entity.claims
end
--[[ I denne oversikten er egenskaps-ID-en først («P###»),
	etter den kommer betegnelsen som er en del av lenka,
	og så teksten som beskriver hvilket nettsted det er på,
	og til slutt språkkoden for nettstedet. Formen er dermed:
		{ "EgenskapsID", "lenkebetegnelse", "lenkebeskrivelse", "språkkode" },
	]] 
local oversikt = {
	{ "P1285", "oppslag", "i Munzinger Sportsarchiv", "de" },
	{ "P1447", "profil", "på Sports-Reference (OL-resultater)", "en" },
	{ "P2323", "profil", "hos Sveriges olympiske komité", "sv"},
	{ "P2593", "profil", "hos Latvias olympiske komité", "lv"},
	{ "P536", "profil", "hos ATP World Tour", "en" },
	{ "P597", "profil", "hos WTA Tennis", "en" },
	{ "P599", "profil", "hos ITF Tennis", "en" },
	{ "P2641", "profil", "hos Davis Cup", "en" },
	{ "P2642", "profil", "hos FedCup", "en" },
	{ "P1146", "profil", "hos [[IAAF]]", "en" },
	{ "P2090", "profil", "hos Power of 10", "en" },
	{ "P2162", "profil", "hos Deutsche Ultramarathon Vereinigung", "en" },
	{ "P1409", "profil", "hos Cycling Archives", "en" },
	{ "P1541", "profil", "på Cycling Quotient", "en" },
	{ "P1664", "profil", "på CyclingDatabase.com", "en" },
	{ "P1663", "profil", "på ProCyclingStats", "en" },
	{ "P2350", "profil", "i Speedskatingbase.eu", "en" },
	{ "P2481", "profil", "på Eliteprospects.com", "en" },
	{ "P2602", "profil", "på Hockeydb.com", "en" },
	{ "P2601", "profil", "på Eurohockey.com", "en" },
	{ "P2459", "profil", "hos [[International Biathlon Union|IBU]]", "en" },
	{ "P858", "spillerprofil", "på ESPN Scrum", "en" },
	{ "P861", "spillerprofil", "hos Premiership Rugby", "en" },
	{ "P1825", "Major League-profil", "på Baseball-Reference.com", "en" },
	{ "P1826", "Minor League-profil", "på Baseball-Reference.com", "en" },
	{ "P2482", "profil", "hos Society for American Baseball Research", "en" },
	{ "P1967", "profil", "hos BoxRec", "en" },
	{ "P8990", "profil", "hos [[Det internasjonale roforbundet|FISA]]", "en" },
	{ "P2423", "profil", "hos [[Fédération internationale d’escrime|FIE]]", "en" },
	{ "P2640", "profil", "på swimrankings.net", "en" },
	{ "P1364", "profil", "hos [[ITTF]]", "en" },
	{ "P2696", "profil", "hos [[Det internasjonale turnforbundet|FIG]]", "en" },
	{ "P2694", "profil", "hos [[ISU]]", "en" },
	{ "P2727", "profil", "hos [[Fédération Internationale des Luttes Associées|FILA]]", "en" },
	{ "P2729", "profil", "hos [[Badminton World Federation|BWF]]", "en" },
	{ "P2730", "profil", "hos [[ISSF]]", "en" },
	{ "P1469", "spillerprofil", "hos [[FIFA]]", "en" },
	{ "P2276", "spillerprofil", "hos [[UEFA]]", "en" },
	{ "P2020", "profil", "på WorldFootball.net", "en" },
	{ "P2193", "spillerprofil", "på Soccerbase.com", "en" },
	{ "P2195", "managerprofil", "på Soccerbase.com", "en" },
	{ "P2369", "spillerprofil", "på Soccerway", "en" },
	{ "P2446", "spillerprofil", "på Transfermarkt", "en" },
	{ "P2447", "managerprofil", "på Transfermarkt", "en" },
	{ "P2574", "spillerprofil", "på national-football-teams.com", "en" },
	{ "P2398", "spillerprofil", "hos Major League Soccer", "en" },
	{ "P1238", "spillerprofil", "hos [[Sveriges fotballforbund]]", "sv" },
	{ "P2448", "spillerprofil", "hos [[Türkiye Futbol Federasyonu|Tyrkias fotballforbund]]", "en" },
	{ "P2449", "managerprofil", "hos [[Türkiye Futbol Federasyonu|Tyrkias fotballforbund]]", "en" },
	{ "P2458", "spillerprofil", "på Mackolik.com", "tr" },
	{ "P2697", "profil", "på espncricinfo.com", "en" },
	{ "P2705", "profil", "på Karate Records", "en" },
	{ "P1440", "profil", "hos [[Fédération internationale des échecs|FIDE]]", "en" },
	{ "P1665", "profil", "på chessgames.com", "en" }
}

local function etikett()
	if not entity then
		label = mw.title.getCurrentTitle().text
	else
		label = mw.wikibase.label(entity.id) or mw.title.getCurrentTitle().text
	return genitiv(label)
	end
end

local p = {}

function p.sportslenker(frame)
	local lenker = {}
	for _,v in ipairs(oversikt) do
		assert(v, 'Fant null, sjekk "oversikt" for tomme element')
		assert(4 == #v, 'Feil lengde, sjekk "oversikt" for avvikende lister')
		local prop, text, desc, lang = unpack(v)
		if claims[prop] and claims[prop][1] and claims[prop][1].mainsnak.datavalue then
			formaturlp = mw.wikibase.getEntity(prop).claims['P1630']
			if formaturlp and formaturlp[1] and formaturlp[1].mainsnak.datavalue then
				formaturl = formaturlp[1].mainsnak.datavalue.value
				lenker[#lenker+1] = "* " .. frame:expandTemplate{ title="Språkikon", args = { lang } } .. " [" .. string.gsub(formaturl, "$1", claims[prop][1].mainsnak.datavalue.value) .. " " .. etikett() .. " " .. text .. "] " .. desc
			end
		end
	end
	if entity then
		if #lenker == 0 then
			lenker[1+#lenker] = "''Artikkelen har ingen egenskaper for sportsdatabaser i Wikidata''"
			lenker[1+#lenker] = '[[Kategori:Artikler uten sportslenker fra Wikidata]]'
		else
			lenker[1+#lenker] = '[[Kategori:Artikler med sportslenker fra Wikidata]]'
		end
	else
		lenker[1+#lenker] = "''Artikkelen mangler oppslag i Wikidata!''"
		lenker[1+#lenker] = '[[Kategori:Artikler med sportslenker og uten kobling til Wikidata]]'
	end
	return table.concat(lenker,"\n")
end

return p