Modulis:Sporta ārējās saites

Vikipēdijas lapa
Jump to navigation Jump to search
Dokumentācijas ikona Moduļa dokumentācija[skatīt] [labot] [hronoloģija] [pārlādēt]

Šajā modulī tiek implementēta {{Sporta ārējās saites}} veidne. Plašāku dokumentāciju skatīt veidnes apraksta lapā.

local categories = {
	["invalid"] = "[[Kategorija:Raksti ar nederīgiem ārējo saišu identifikatoriem]]",
	["localpar"] = "[[Kategorija:Raksti ar lokālajiem ārējo saišu veidnes parametriem]]",
	["empty"] = "[[Kategorija:Raksti ar tukšu sporta ārējo saišu veidni]]"
}

function srLink( id )
    return 'http://www.sports-reference.com/olympics/athletes/' .. id .. '.html'
end

function espnLink( id )
    return 'http://sports.espn.go.com/' .. id
end

function atpLink( id )
    return 'http://www.atpworldtour.com/en/players/wikidata/' .. id .. '/overview'
end

function wtaLink( id )
    return 'http://www.wtatennis.com/player-profile/' .. id
end

function itfLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.itftennis.com/procircuit/players/player/profile.aspx?playerid=' .. id
end

function davisLink( id )
    if not string.match( id, '^[0-9]*$' ) then
        return false
    end
    return 'http://www.daviscup.com/en/players/player/profile.aspx?playerid=' .. id
end

function fedLink( id )
    if not string.match( id, '^[0-9]*$' ) then
        return false
    end
    return 'https://www.fedcup.com/en/players/player.aspx?id=' .. id
end

function tennishofLink( id )
    return 'https://www.tennisfame.com/hall-of-famers/inductees/' .. id
end

function cycaLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.cyclingarchives.com/coureurfiche.php?coureurid=' .. id
end

function cycqLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.cqranking.com/men/asp/gen/rider.asp?riderid=' .. id
end

function cycqwLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.cqranking.com/women/asp/gen/rider.asp?riderid=' .. id
end

function cycdLink( id )
    return 'https://www.cyclingdatabase.com/' .. id
end

function procLink( id )
    --[=[if not string.match( id, '^[1-9][0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?[0-9]?$' ) then
        return false
    end]=]
    return 'http://www.procyclingstats.com/rider/' .. id
end

function fifaLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.fifa.com/worldfootball/statisticsandrecords/players/player=' .. id
end

function uefaLink( id )
    if not string.match( id, '^[1-9][0-9][0-9][0-9][0-9][0-9]?[0-9]?[0-9]?[0-9]?$' ) then
        return false
    end
    return 'http://www.uefa.com/teamsandplayers/players/player=' .. id
end

function worldfLink( id )
    return 'http://www.worldfootball.net/player_summary/' .. id
end

function socbpLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.soccerbase.com/players/player.sd?player_id=' .. id
end

function socbmLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.soccerbase.com/managers/manager.sd?manager_id=' .. id
end

function scoreswayLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.scoresway.com/?sport=soccer&page=person&id=' .. id
end

function nftLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.national-football-teams.com/player/' .. id .. '.html'
end

function transfpLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.transfermarkt.com/transfermarkt/profil/spieler/' .. id
end

function transmpLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.transfermarkt.com/transfermarkt/profil/trainer/' .. id
end

function mlsLink( id )
    if not string.match( id, '^[-a-z]+[0-9]*$' ) then
        return false
    end
    return 'http://www.mlssoccer.com/players/' .. id
end

function fideLink( id )
    return 'https://ratings.fide.com/card.phtml?event=' .. id
end

function chessLink( id )
    return 'http://www.chessgames.com/perl/chessplayer?pid=' .. id
end

function chess365Link( id )
    return 'http://www.365chess.com/players/' .. id
end

function brmajLink( id )
    return 'http://www.baseball-reference.com/players/' .. id .. '.shtml'
end

function brminLink( id )
    return 'http://www.baseball-reference.com/minors/player.cgi?id=' .. id
end

function sabrLink( id )
    return 'http://sabr.org/bioproj/person/' .. id
end

function eliteLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.eliteprospects.com/player.php?player=' .. id
end

function hockeydbLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.hockeydb.com/ihdb/stats/pdisplay.php?pid=' .. id
end

function eurohLink( id )
    return 'http://www.eurohockey.com/player/' .. id .. '.html'
end

function nhlLink( id )
    return 'http://www.nhl.com/ice/player.htm?id=' .. id
end

function hockeyrefLink( id )
    return 'http://www.hockey-reference.com/players/' .. id .. '.html'
end

function lokLink( id )
    return 'http://olimpiade.lv/lv/latvijas-olimpiesi/' .. id
end

function iaafLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.iaaf.org/athletes/athlete=' .. id
end

function speedskLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.speedskatingbase.eu/?section=skaters&subsection=skater&skaterid=' .. id
end

function ibuLink( id )
    return 'http://www.biathlonworld.com/athletes/id/' .. id .. '/'
end

function boxrecLink( id )
    if not string.match( id, '^[0-9]*$' ) then
        return false
    end
    return 'http://boxrec.com/boxer/' .. id
end

function rowLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.worldrowing.com/athletes/athlete/' .. id .. '/'
end

function fieLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://fie.org/fencers/fencer/' .. id
end

function swimLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'https://www.swimrankings.net/index.php?page=athleteDetail&athleteId=' .. id
end

function isuLink( id )
    if not string.match( id, '^[0-9]*$' ) then
        return false
    end
    return 'http://www.isuresults.com/bios/isufs' .. id .. '.htm'
end

function figLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'https://database.fig-gymnastics.com/public/gymnasts/biography/' .. id .. '/true?backUrl='
end

function cricinfoLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.espncricinfo.com/ci/content/player/' .. id .. '.html'
end

function cricarchiveLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    id2 = math.floor(tonumber(id)/1000)
    return 'http://www.cricketarchive.com/Archive/Players/' .. id2 .. '/' .. id .. '/' .. id .. '.html'
end

function ittfLink( id )
    return 'http://www.ittf.com/ittf_ranking/world_ranking_per_name.asp?Player_ID=' .. id
end

function uipmLink( id )
    return 'http://www.uipmworld.org/athlete/' .. id
end

function filaLink( id )
    if not string.match( id, '^[A-Z0-9]*$' ) then
        return false
    end
    return 'https://www.iat.uni-leipzig.de/datenbanken/dbwrestling/daten.php?spid=' .. id
end

function fivbLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.fivb.org/EN/BeachVolleyball/Player_DataDB.asp?No=' .. id
end

function bvbLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.bvbinfo.com/player.asp?ID=' .. id
end

function isafLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.sailing.org/biog?memberid=' .. id
end

function iatTriatLink( id )
    if not string.match( id, '^[A-F0-9]*$' ) then
        return false
    end
    return 'https://www.iat.uni-leipzig.de/datenbanken/dbtriathlon/daten.php?spid=' .. id
end

function iatSvarcLink( id )
    if not string.match( id, '^[A-F0-9]*$' ) then
        return false
    end
    return 'https://www.iat.uni-leipzig.de/datenbanken/dbgwh/daten.php?spid=' .. id
end

function iatDailLink( id )
    if not string.match( id, '^[0-9]*$' ) then
        return false
    end
    return 'https://www.iat.uni-leipzig.de/datenbanken/dbdiving/daten.php?spid=' .. id
end

function cagematchLink( id )
    if not string.match( id, '^[0-9]*$' ) then
        return false
    end
    return 'http://www.cagematch.net/?id=2&nr=' .. id
end

function wrestlingdataLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://wrestlingdata.com/index.php?befehl=bios&wrestler=' .. id
end

function sherdogLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.sherdog.com/fightfinder/fightfinder.asp?FighterID=' .. id
end

function badmintonLink( id )
    if not string.match( id, '^[A-Z0-9-]*$' ) then
        return false
    end
    return 'http://bwfcontent.tournamentsoftware.com/profile/default.aspx?id=' .. id
end

function issfLink( id )
    if not string.match( id, '^[A-Z0-9]*$' ) then
        return false
    end
    return 'http://www.issf-sports.org/athletes/athlete.ashx?personissfid=' .. id
end

function judoLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.judoinside.com/judoka/view/' .. id .. '/'
end

function fisALLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://data.fis-ski.com/dynamic/athlete-biography.html?sector=AL&competitorid=' .. id
end

function fisCCLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://data.fis-ski.com/dynamic/athlete-biography.html?sector=CC&competitorid=' .. id
end

function fisJPLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://data.fis-ski.com/dynamic/athlete-biography.html?sector=JP&competitorid=' .. id
end

function fisNKLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://data.fis-ski.com/dynamic/athlete-biography.html?sector=NK&competitorid=' .. id
end

function fisFSLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://data.fis-ski.com/dynamic/athlete-biography.html?sector=FS&competitorid=' .. id
end

function fisSBLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://data.fis-ski.com/dynamic/athlete-biography.html?sector=SB&competitorid=' .. id
end

function pgaLink( id )
    if not string.match( id, '^[0-9]*$' ) then
        return false
    end
    return 'http://www.pgatour.com/players/player.' .. id .. '.html'
end

function lpgaLink( id )
    return 'http://www.lpga.com/players/' .. id .. '/overview'
end

function taekwondoLink( id )
    return 'http://www.taekwondodata.com/' .. id .. '.html'
end

function lugeLink( id )
    return 'http://www.fil-luge.org/en/athletes/' .. id
end


function ibsfLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.ibsf.org/en/athletes/athlete/' .. id
end


function archeryLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'https://worldarchery.org/athlete/' .. id
end

function isuShortTrack( id )
    return 'http://www.shorttrackonline.info/skaterbio.php?id=' .. id
end

function feiLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.fei.org/bios/Person/' .. id
end

function append(str, c, length)
    while str:len() < length do
        str = c .. str
    end
    return str
end

function getIdsFromWikidata( item, property )
    local ids = {}
    if not item.claims[property] then
        return ids
    end
    for _, statement in pairs( item.claims[property] ) do
		if statement.mainsnak.datavalue then
			table.insert( ids, statement.mainsnak.datavalue.value )
		end
    end
    return ids
end

function createRow( id, label, rawValue, link, lang )
    if link then
        return '* [' .. link .. ' ' .. label .. '] ' .. lang
    else
        return '* <span class="error">' .. id .. ' identifikators ' .. rawValue .. ' nav derīgs.</span>' .. categories.invalid
    end
end

--In this order: name of the parameter, label, propertyId in Wikidata, formatting function, language
local conf = {
	--vispārējie
    { 'sr', "''Sports-Reference'' profils", 1447, srLink, 'en' },
    { 'lok', "LOK profils", 2593, lokLink, 'lv' },
	--teniss
    { 'atp', "ATP profils", 536, atpLink, 'en' },
    { 'wta', "WTA profils", 597, wtaLink, 'en' },
    { 'itf', "ITF profils", 599, itfLink, 'en' },
    { 'davis', "Deivisa kausa profils", 2641, davisLink, 'en' },
    { 'fedcup', "Federācijas kausa profils", 2642, fedLink, 'en' },
    { 'tennis-hof', "Starptautiskās tenisa slavas zāles profils", 3363, tennishofLink, 'en' },
	--riteņbraukšana
    { 'procyc', "''ProCyclingStats'' profils", 1663, procLink, 'en' },
    { 'cyc archives', "''Cycling Archives'' profils", 1409, cycaLink, 'en' },
    { 'cycquot', "''Cycling Quotient'' profils", 1541, cycqLink, 'en' },--vīrieši
    { 'cycquotw', "''Cycling Quotient'' profils", 2709, cycqwLink, 'en' },--sievietes
    { 'cycdb', "''CyclingDatabase'' profils", 1664, cycdLink, 'en' },
	--futbols
    { 'fifa', "FIFA profils", 1469, fifaLink, 'en' },
    { 'uefa', "UEFA profils", 2276, uefaLink, 'en' },
    { 'worldfootball', "''WorldFootball'' profils", 2020, worldfLink, 'en' },
    { 'soccerbase', "''Soccerbase'' spēlētāja profils", 2193, socbpLink, 'en' },
    { 'soccerbase tr', "''Soccerbase'' trenera profils", 2195, socbmLink, 'en' },
    { 'scoresway', "''Scoresway'' profils", 3043, scoreswayLink, 'en' },
    { 'nft', "''National-Football-Teams'' profils", 2574, nftLink, 'en' },
    { 'transf', "''Transfermarkt'' spēlētāja profils", 2446, transfpLink, 'en' },
    { 'transf tr', "''Transfermarkt'' trenera profils", 2447, transmpLink, 'en' },
    { 'mls', "MLS profils", 2398, mlsLink, 'en' },
	--šahs
    { 'fide', "FIDE profils", 1440, fideLink, 'en' },
    { 'chessg', "''Chess Games'' profils", 1665, chessLink, 'en' },
    { '365chess', "''365Chess.com'' profils", 0, chess365Link, 'en' },
	--beisbols
    { 'br maj', "''Baseball-Reference'' MLB profils", 1825, brmajLink, 'en' },
    { 'br min', "''Baseball-Reference'' mazo līgu profils", 1826, brminLink, 'en' },
    { 'sabr', "SABR profils", 2482, sabrLink, 'en' },
	--hokejs
    { 'elitepr', "''Eliteprospects'' profils", 2481, eliteLink, 'en' },
    { 'hockeydb', "''Internet Hockey Database'' profils", 2602, hockeydbLink, 'en' },
    { 'euroh', "''Eurohockey'' profils", 2601, eurohLink, 'en' },
    { 'nhl', "NHL profils", 0, nhlLink, 'en' },
    { 'hockey-ref', "''Hockey-Reference'' profils", 0, hockeyrefLink, 'en' },
	--krikets
    { 'cricinfo', "''ESPNcricinfo'' profils", 2697, cricinfoLink, 'en' },
    { 'cricarchive', "''CricketArchive'' profils", 2698, cricarchiveLink, 'en' },
	--mma
    { 'cagematch', "''CageMatch'' profils", 2728, cagematchLink, 'en' },
    { 'wrestlingdata', "''Wrestlingdata'' profils", 2764, cagematchLink, 'en' },
    { 'sherdog', "''Sherdog'' profils", 2818, sherdogLink, 'en' },
	--pludmales volejbols
    { 'bvbinfo', "''Beach Volleyball Database'' profils", 2800, bvbLink, 'en' },
    { 'fivbbv', "FIVB profils", 2801, fivbLink, 'en' },
	--golfs
    { 'pga', "PGA profils", 2811, pgaLink, 'en' },
    { 'lpga', "LPGA profils", 2810, lpgaLink, 'en' },
	--citi sporta veidi
    { 'iaaf', "IAAF profils", 1146, iaafLink, 'en' },
    { 'speedskb', "''Speedskatingbase'' profils", 2350, speedskLink, 'en' },
    { 'isusorttreks', "''ShorttrackOnLine'' profils", 3693, isuShortTrack, 'en' },
    { 'ibu', "IBU profils", 2459, ibuLink, 'en' },
    { 'boxrec', "''BoxRec'' profils", 1967, boxrecLink, 'en' },
    { 'wrowing', "''WorldRowing'' profils", 2091, rowLink, 'en' },
    { 'fie', "FIE profils", 2423, fieLink, 'en' },
    { 'ittf', "ITTF profils", 1364, ittfLink, 'en' },
    { 'swimr', "''Swimrankings'' profils", 2640, swimLink, 'en' },
    { 'isu', "ISU profils", 2694, isuLink, 'en' },
    { 'fig', "FIG profils", 2696, figLink, 'en' },
    { 'uipm', "UIPM profils", 2726, uipmLink, 'en' },
    { 'fila', "FILA profils", 2727, filaLink, 'en' },
    { 'iattriatlons', "''Institut für Angewandte Trainingswissenschaft'' profils", 2778, iatTriatLink, 'en' },
    { 'iatsvarcelsana', "''Institut für Angewandte Trainingswissenschaft'' profils", 2779, iatSvarcLink, 'de' },
    { 'iatdailleksana', "''Institut für Angewandte Trainingswissenschaft'' profils", 2780, iatDailLink, 'de' },
    { 'bwf', "BWF profils", 2729, badmintonLink, 'en' },
    { 'issf', "ISSF profils", 2730, issfLink, 'en' },
    { 'isaf', "ISAF profils", 2804, isafLink, 'en' },
    { 'judo', "''JudoInside'' profils", 2767, judoLink, 'en' },
    { 'taekwondo', "''Taekwondo Data'' profils", 2987, taekwondoLink, 'en' },
    { 'luge', "FIL profils", 2990, lugeLink, 'en' },
    { 'ibsf', "IBSF profils", 2991, ibsfLink, 'en' },
    { 'archery', "''World Archery'' profils", 3010, archeryLink, 'en' },
    { 'fei', "FEI profils", 3111, feiLink, 'en' },
	--FIS
    { 'fisal', "FIS profils (kalnu slēpošana)", 2772, fisALLink, 'en' },
    { 'fiscc', "FIS profils (distanču slēpošana)", 2773, fisCCLink, 'en' },
    { 'fisfs', "FIS profils (frīstaila slēpošana)", 2774, fisFSLink, 'en' },
    { 'fisjp', "FIS profils (tramplīnlēkšana)", 2775, fisJPLink, 'en' },
    { 'fisnk', "FIS profils (ziemeļu divcīņa)", 2776, fisNKLink, 'en' },
    { 'fissb', "FIS profils (snovbords)", 2777, fisSBLink, 'en' },
    { 'espn', "ESPN profils", 0, espnLink, 'en' },
}
-- parametru kā pēdējo likt, lai var ielikt arī alias

local p = {}

function p.main( frame )
    local parentArgs = frame:getParent().args
    --Create rows
    local elements = {}

    --Wikidata fallback if requested
	local item = mw.wikibase.getEntityObject()
	if item and item.claims then
		for _, params in pairs( conf ) do
			params[6] = ''
			if params[3] ~= 0 then
				local val = parentArgs[params[1]]
				if not val or val == '' then
					local wikidataIds = getIdsFromWikidata( item, 'P' .. params[3] )
					if wikidataIds[1] then
						parentArgs[params[1]] = wikidataIds[1]
					end
				else
					params[6] = categories.localpar
				end
		else
			local val = parentArgs[params[1]]
			if val then
					params[6] = categories.localpar
				end
			end
		end
	end

	--Configured rows
	local rct = 0
	for k, params in pairs( conf ) do
		local val = parentArgs[params[1]]
		if val and val ~= '' then
			local icon = ''
			if params[5] and params[5] ~= '' and params[5] ~= 'lv' then
				icon = frame:expandTemplate{ title = params[5] .. " ikona" }
			end
			table.insert( elements, createRow( params[1], params[2], val, params[4]( val ), icon ) .. (params[6] or '') )
			rct = rct + 1
		end
	end

	if rct == 0 then
		return categories.empty
	else
		return table.concat( elements, "\n" )
	end
end

return p