Modulis:Sporta ārējās saites/Smilšu kaste

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ā.

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

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

function wtaLink( id )
    if not string.match( id, '^[1-9][0-9]*$' ) then
        return false
    end
    return 'http://www.wtatennis.com/players/player/' .. 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 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 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 socwLink( id )
    return 'http://www.soccerway.com/players/' .. 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 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 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 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://services.biathlonresults.com/athletes.aspx?IbuId=' .. id
end

function boxrecLink( id )
    if not string.match( id, '^[0-9]*$' ) then
        return false
    end
    return 'http://boxrec.com/list_bouts.php?human_id=' .. id .. '&cat=boxer'
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 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>[[Kategorija:Raksti ar nederīgiem ārējo saišu identifikatoriem]]'
    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' },
	--riteņbraukšana
    { 'cyc archives', "''Cycling Archives'' profils", 1409, cycaLink, 'en' },
    { 'cyc quot', "''Cycling Quotient'' profils", 1541, cycqLink, 'en' },
    { 'cycdb', "''CyclingDatabase'' profils", 1664, cycdLink, 'en' },
    { 'procyc', "''ProCyclingStats'' profils", 1663, procLink, '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' },
    { 'soccerway', "''Soccerway'' profils", 2369, socwLink, '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' },
	--beisbols
    { 'br maj', "''Baseball-Reference'' MLB profils", 1825, brmajLink, 'en' },
    { 'br min', "''Baseball-Reference'' mazo līgu profils", 1826, brminLink, 'en' },
	--hokejs
    { 'elitepr', "''Eliteprospects'' profils", 2481, eliteLink, 'en' },
    { 'hockeydb', "''Internet Hockey Database'' profils", 2602, hockeydbLink, 'en' },
    { 'euroh', "''Eurohockey'' profils", 2601, eurohLink, 'en' },
	--citi sporta veidi
    { 'iaaf', "IAAF profils", 1146, iaafLink, 'en' },
    { 'speedskb', "''Speedskatingbase'' profils", 2350, speedskLink, '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' },
}
-- 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] = '' -- this makes the category non-mandatory
			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 -- this is the place where you can define the category
					params[6] = '[[Category:Raksti ar lokālajiem parametriem]]'
				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 = '' -- non-mandatory 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] ) -- here you append either the category, or an empty string
			rct = rct + 1
		end
	end

	if rct == 0 then
		return '[[Kategorija:Raksti ar tukšu sporta ārējo saišu veidni]]'
	else
		return table.concat( elements, "\n" )
	end
end

return p