Mòdul:Cycling race: diferència entre les revisions

De la Viquipèdia, l'enciclopèdia lliure
Contingut suprimit Contingut afegit
upgrade a 20191203 versiion
update
Línia 4: Línia 4:
wiki = "fr"
wiki = "fr"
end
end

local contentLanguage = mw.getContentLanguage()
local contentLanguage = mw.getContentLanguage()
local wikilang = contentLanguage:getCode()
local wikilang = contentLanguage:getCode()
Línia 23: Línia 24:
----- B) Calendar
----- B) Calendar
----- C) Victory
----- C) Victory
----- Cbis) Function for infobox
----- D) Stage infobox
----- D) Stage infobox
----- E) List of teams
----- E) List of teams
Línia 72: Línia 74:
floatinfobox = "left"
floatinfobox = "left"
end
end

local standardtablecss="border:1px solid rgb(200,200,200); color:black; margin:0 0 0.5em 0;"..
"background-color:rgb(255, 255, 255); padding:5px; clear:left; text-align:" ..
textalign .. "; font-size:85%; line-height:1.6em;"


local no_country_calendar={'ru'}
local no_country_calendar={'ru'}
Línia 111: Línia 117:
["Q65665708"] ="#FFC0CB" , -- Jersey polkadot.svg (Points)
["Q65665708"] ="#FFC0CB" , -- Jersey polkadot.svg (Points)
["Q25265958"] ="#FFC0CB" , -- Jersey polkadot.svg (Mountain)
["Q25265958"] ="#FFC0CB" , -- Jersey polkadot.svg (Mountain)
["Q11636369"] ="#FFC0CB" , -- Jersey polkadot.svg (Mountain)
["Q25265959"] ="#E0FFFF" , -- Jersey blue dotted.png (Mountain)
["Q25265959"] ="#E0FFFF" , -- Jersey blue dotted.png (Mountain)
["Q25265960"] ="#FFC0CB" , -- Jersey climbing Dauphine.png (Mountain)
["Q25265960"] ="#FFC0CB" , -- Jersey climbing Dauphine.png (Mountain)
Línia 247: Línia 252:
for _, q in qualifiers(element, property) do
for _, q in qualifiers(element, property) do
result = tonumber(q.value.amount)
result = tonumber(q.value.amount)
break
end
end
return result
return result
Línia 321: Línia 327:


--[[ Get start time of race as a timevalue ('+2016-01-01T00:00:00Z') or nil ]]
--[[ Get start time of race as a timevalue ('+2016-01-01T00:00:00Z') or nil ]]
local function getTimeOfRace (raceID)
local function gettimeOfRace (raceID)
local timeOfRace
local timeOfRace
local p580 = mw.wikibase.getBestStatements(raceID, "P580") -- P580 is start time
local p580 = mw.wikibase.getBestStatements(raceID, "P580") -- P580 is start time
Línia 352: Línia 358:
local y, m = string.match(sTime, "(%d+)-(%d+)-%d+")
local y, m = string.match(sTime, "(%d+)-(%d+)-%d+")
local y2, m2 = string.match(eTime, "(%d+)-(%d+)-%d+")
local y2, m2 = string.match(eTime, "(%d+)-(%d+)-%d+")
if y ~= y2 then
if mode=='long' then
if m=='00' then --manage the 30 November issue
if mode=='long' then
starttime = lang:formatDate( "j F Y", sTime )
starttime =lang:formatDate( "Y", sTime )
else
starttime = lang:formatDate( "j M Y", sTime )
end
elseif m ~= m2 then
if mode=='long' then
starttime = lang:formatDate( "j F", sTime )
else
else
starttime = lang:formatDate( "j M", sTime )
starttime ='-'
end
end
else
else
starttime = lang:formatDate( "j", sTime )
end

if wiki == "ar" then
if y ~= y2 then starttime = lang:formatDate( "d F Y", sTime )
elseif m ~= m2 then starttime = lang:formatDate( "d F", sTime )
else starttime = lang:formatDate( "d ", sTime ) end
elseif wiki == "br" then
if y ~= y2 then starttime = lang:formatDate( "j", sTime ) .." a viz ".. lang:formatDate( "F Y", sTime )
elseif m ~= m2 then starttime = lang:formatDate( "j", sTime ) .." a viz ".. lang:formatDate( "F", sTime )
else starttime = lang:formatDate( "j", sTime ) .." "
end
elseif wiki == "ca" or wiki == "es" or wiki == "ast" then
if y ~= y2 then
if y ~= y2 then
if mode=='long' then
starttime = lang:formatDate( "j", sTime ) .." de ".. lang:formatDate( "F", sTime ) .." de ".. lang:formatDate( "Y", sTime )
starttime = lang:formatDate( "j F Y", sTime )
else
starttime = lang:formatDate( "j M Y", sTime )
end
elseif m ~= m2 then
elseif m ~= m2 then
if mode=='long' then
starttime = lang:formatDate( "j", sTime ) .." de ".. lang:formatDate( "F", sTime )
else starttime = lang:formatDate( "j", sTime ) .." "
starttime = lang:formatDate( "j F", sTime )
else
starttime = lang:formatDate( "j M", sTime )
end
else
starttime = lang:formatDate( "j", sTime )
end
end
elseif wiki == "cs" then
if y ~= y2 then starttime = lang:formatDate( "j. xg Y", sTime )
if wiki == "ar" then
if y ~= y2 then starttime = lang:formatDate( "d F Y", sTime )
elseif m ~= m2 then starttime = lang:formatDate( "j. xg", sTime )
elseif m ~= m2 then starttime = lang:formatDate( "d F", sTime )
else starttime = lang:formatDate( "j", sTime )
else starttime = lang:formatDate( "d ", sTime ) end
elseif wiki == "br" then
end
if y ~= y2 then starttime = lang:formatDate( "j", sTime ) .." a viz ".. lang:formatDate( "F Y", sTime )
elseif wiki == "de" or wiki == "da" or wiki == "fo" or wiki == "no" then
if y ~= y2 then starttime = lang:formatDate( "j. F Y", sTime )
elseif m ~= m2 then starttime = lang:formatDate( "j", sTime ) .." a viz ".. lang:formatDate( "F", sTime )
elseif m ~= m2 then starttime = lang:formatDate( "j. F", sTime )
else starttime = lang:formatDate( "j", sTime ) .." "
end
else starttime = lang:formatDate( "j.", sTime )
elseif wiki == "ca" or wiki == "es" or wiki == "ast" then
end
elseif wiki == "fi" then
if y ~= y2 then
if y ~= y2 then starttime = lang:formatDate( 'j. F"ta" Y', sTime )
starttime = lang:formatDate( "j", sTime ) .." de ".. lang:formatDate( "F", sTime ) .." de ".. lang:formatDate( "Y", sTime )
elseif m ~= m2 then starttime = lang:formatDate( 'j. F"ta"', sTime )
elseif m ~= m2 then
else starttime = lang:formatDate( "j.", sTime )
starttime = lang:formatDate( "j", sTime ) .." de ".. lang:formatDate( "F", sTime )
else starttime = lang:formatDate( "j", sTime ) .." "
end
end
elseif wiki == "eo" then
elseif wiki == "cs" then
if y ~= y2 then starttime = lang:formatDate( "j", sTime ) .."-a de ".. lang:formatDate( "F Y", sTime )
elseif m ~= m2 then starttime = lang:formatDate( "j", sTime ) .."-a de ".. lang:formatDate( "F", sTime )
if y ~= y2 then starttime = lang:formatDate( "j. xg Y", sTime )
elseif m ~= m2 then starttime = lang:formatDate( "j. xg", sTime )
else starttime = lang:formatDate( "j", sTime ) .."-a "
else starttime = lang:formatDate( "j", sTime )
end
end
elseif wiki == "eu" then
elseif wiki == "de" or wiki == "da" or wiki == "fo" or wiki == "no" then
if y ~= y2 then starttime = lang:formatDate( "Y", sTime ) ..".eko ".. lang:formatDate( "F", sTime ) .."k ".. lang:formatDate( "j", sTime )
if y ~= y2 then starttime = lang:formatDate( "j. F Y", sTime )
elseif m ~= m2 then starttime = lang:formatDate( "j. F", sTime )
else starttime = lang:formatDate( "j.", sTime )
end
elseif m ~= m2 then starttime = lang:formatDate( "F", sTime ) .."k ".. lang:formatDate( "j", sTime )
elseif wiki == "fi" then
else starttime = lang:formatDate( "F", sTime ) .."k ".. lang:formatDate( "j", sTime )
if y ~= y2 then starttime = lang:formatDate( 'j. F"ta" Y', sTime )
end
elseif m ~= m2 then starttime = lang:formatDate( 'j. F"ta"', sTime )
elseif wiki == "hu" then
starttime = lang:formatDate( "Y. F j.", sTime)
else starttime = lang:formatDate( "j.", sTime )
end
elseif wiki == "ja" then
elseif wiki == "eo" then
if y ~= y2 then starttime = lang:formatDate( "Y年m月d日", sTime )
elseif m ~= m2 then starttime = lang:formatDate( "Y年m月d日", sTime )
if y ~= y2 then starttime = lang:formatDate( "j", sTime ) .."-a de ".. lang:formatDate( "F Y", sTime )
else starttime = lang:formatDate( "Y年m月d日", sTime )
elseif m ~= m2 then starttime = lang:formatDate( "j", sTime ) .."-a de ".. lang:formatDate( "F", sTime )
else starttime = lang:formatDate( "j", sTime ) .."-a "
end
end
elseif wiki == "lv" then
elseif wiki == "eu" then
if y ~= y2 then starttime = lang:formatDate( "Y. \\g\\a\\d\\a j. F", sTime )
elseif m ~= m2 then starttime = lang:formatDate( "Y. \\g\\a\\d\\a j. F", sTime )
if y ~= y2 then starttime = lang:formatDate( "Y", sTime ) ..".eko ".. lang:formatDate( "F", sTime ) .."k ".. lang:formatDate( "j", sTime )
else starttime = lang:formatDate( "Y. \\g\\a\\d\\a j.", sTime )
elseif m ~= m2 then starttime = lang:formatDate( "F", sTime ) .."k ".. lang:formatDate( "j", sTime )
else starttime = lang:formatDate( "F", sTime ) .."k ".. lang:formatDate( "j", sTime )
end
end
elseif wiki == "pl" then
elseif wiki == "hu" then
local date_pl = {"stycznia", "lutego", "marca", "kwietnia", "maja", "czerwca", "lipca", "sierpnia", "września", "października", "listopada", "grudnia"}
if y ~= y2 then starttime = lang:formatDate( "j ", sTime ) .. date_pl[tonumber(lang:formatDate( "n", sTime ))] .. lang:formatDate( " Y", sTime )
starttime = lang:formatDate( "Y. F j.", sTime)
elseif wiki == "ja" then
elseif m ~= m2 then starttime = lang:formatDate( "j ", sTime ) .. date_pl[tonumber(lang:formatDate( "n", sTime ))]
else starttime = lang:formatDate( "j", sTime )
if y ~= y2 then starttime = lang:formatDate( "Y年m月d日", sTime )
elseif m ~= m2 then starttime = lang:formatDate( "Y年m月d日", sTime )
else starttime = lang:formatDate( "Y年m月d日", sTime )
end
elseif wiki == "lv" then
if m ~= m2 then starttime = lang:formatDate( "Y. \\g\\a\\d\\a j. F", sTime )
else starttime = lang:formatDate( "Y. \\g\\a\\d\\a j.", sTime )
end
elseif wiki == "pl" then
local date_pl = {"stycznia", "lutego", "marca", "kwietnia", "maja", "czerwca", "lipca", "sierpnia", "września", "października", "listopada", "grudnia"}
if y ~= y2 then starttime = lang:formatDate( "j ", sTime ) .. date_pl[tonumber(lang:formatDate( "n", sTime ))] .. lang:formatDate( " Y", sTime )
elseif m ~= m2 then starttime = lang:formatDate( "j ", sTime ) .. date_pl[tonumber(lang:formatDate( "n", sTime ))]
else starttime = lang:formatDate( "j", sTime )
end
end
end
end
end

if mode=='long' or y ~= y2 then
if m2=='00' then --manage the 30 November issue
if mode=='long' then
endtime = lang:formatDate("j F Y", eTime)
endtime= lang:formatDate( "Y", eTime )
else
endtime = lang:formatDate("j M", eTime)
end
if wiki == "ar" then
if mode=='long' or y ~= y2 then endtime = lang:formatDate( "d F Y", eTime )
elseif m ~= m2 then endtime = lang:formatDate( "d F Y", eTime )
else endtime = lang:formatDate( "d F Y", eTime )
end
elseif wiki == "br" then endtime = lang:formatDate( "j", eTime ) .." a viz ".. lang:formatDate( "F Y", eTime )
elseif wiki == "ca" or wiki == "es" or wiki == "ast" then
if mode=='long' or y ~= y2 then
endtime = lang:formatDate( "j", eTime ) .." de "..
lang:formatDate( "F", eTime ) .." de ".. lang:formatDate( "Y", eTime )
else
else
endtime = lang:formatDate( "j", eTime ) .." de "..
endtime= '-'
lang:formatDate( "F", eTime )
end
end
else
elseif wiki == "cs" then endtime = lang:formatDate( "j. xg Y", eTime )

elseif wiki == "de" or wiki == "da" or wiki == "fi" or wiki == "fo" or wiki == "no" then
if mode=='long' or y ~= y2 then
if mode=='long' or y ~= y2 then
endtime = lang:formatDate( "j. F Y", eTime )
endtime = lang:formatDate("j F Y", eTime)
else
else
endtime = lang:formatDate( "j. M", eTime )
endtime = lang:formatDate("j M", eTime)
end
end
if wiki == "ar" then
elseif wiki == "eo" then endtime = lang:formatDate( "j", eTime ) .."-a de ".. lang:formatDate( "F Y", eTime )
elseif wiki == "eu" then endtime = lang:formatDate( "Y", eTime ) ..".eko ".. lang:formatDate( "F", eTime ) .."k "..
if mode=='long' or y ~= y2 then endtime = lang:formatDate( "d F Y", eTime )
lang:formatDate( "j", eTime )
elseif m ~= m2 then endtime = lang:formatDate( "d F Y", eTime )
elseif wiki == "fi" then endtime = lang:formatDate('j F"ta" Y', eTime)
else endtime = lang:formatDate( "d F Y", eTime )
end
elseif wiki == "hu" then
if y ~= y2 then endtime = lang:formatDate( "Y. F j.", eTime )
elseif wiki == "br" then endtime = lang:formatDate( "j", eTime ) .." a viz ".. lang:formatDate( "F Y", eTime )
elseif m ~= m2 then endtime = lang:formatDate( "F j.", eTime )
elseif wiki == "ca" or wiki == "es" or wiki == "ast" then
if mode=='long' or y ~= y2 then
else endtime = lang:formatDate( "j.", eTime )
endtime = lang:formatDate( "j", eTime ) .." de "..
end
--endtime = lang:formatDate( "Y", eTime ) ..". ".. lang:formatDate( "F j", eTime ) .."."
lang:formatDate( "F", eTime ) .." de ".. lang:formatDate( "Y", eTime )
else
elseif wiki == "ja" then
if y ~= y2 then endtime = lang:formatDate( "Y年m月d日", eTime )
endtime = lang:formatDate( "j", eTime ) .." de "..
elseif m ~= m2 then endtime = lang:formatDate( "m月d日", eTime )
lang:formatDate( "F", eTime )
end
else endtime = lang:formatDate( "d日", eTime )
elseif wiki == "cs" then endtime = lang:formatDate( "j. xg Y", eTime )
end
elseif wiki == "lv" then
elseif wiki == "de" or wiki == "da" or wiki == "fi" or wiki == "fo" or wiki == "no" then
if mode=='long' or y ~= y2 then endtime = lang:formatDate( "Y. \\g\\a\\d\\a j. F", eTime )
if mode=='long' or y ~= y2 then
endtime = lang:formatDate( "j. F Y", eTime )
else
elseif m ~= m2 then endtime = lang:formatDate( "j. F", eTime )
else endtime = lang:formatDate( "j. F", eTime )
endtime = lang:formatDate( "j. M", eTime )
end
elseif wiki == "eo" then endtime = lang:formatDate( "j", eTime ) .."-a de ".. lang:formatDate( "F Y", eTime )
elseif wiki == "eu" then endtime = lang:formatDate( "Y", eTime ) ..".eko ".. lang:formatDate( "F", eTime ) .."k "..
lang:formatDate( "j", eTime )
elseif wiki == "fi" then endtime = lang:formatDate('j F"ta" Y', eTime)
elseif wiki == "hu" then
if y ~= y2 then endtime = lang:formatDate( "Y. F j.", eTime )
elseif m ~= m2 then endtime = lang:formatDate( "F j.", eTime )
else endtime = lang:formatDate( "j.", eTime )
end
--endtime = lang:formatDate( "Y", eTime ) ..". ".. lang:formatDate( "F j", eTime ) .."."
elseif wiki == "ja" then
if y ~= y2 then endtime = lang:formatDate( "Y年m月d日", eTime )
elseif m ~= m2 then endtime = lang:formatDate( "m月d日", eTime )
else endtime = lang:formatDate( "d日", eTime )
end
elseif wiki == "lv" then
if y ~= y2 then endtime = lang:formatDate( "Y. \\g\\a\\d\\a j. F", eTime )
else endtime = lang:formatDate( "j. F", eTime )
end
elseif wiki == "pl" then
local date_pl = {"stycznia", "lutego", "marca", "kwietnia", "maja", "czerwca", "lipca", "sierpnia",
"września", "października", "listopada", "grudnia"}
endtime = lang:formatDate( "j ", eTime ) .. date_pl[tonumber(lang:formatDate( "n", eTime ))] ..
lang:formatDate( " Y", eTime )
end
end
elseif wiki == "pl" then
local date_pl = {"stycznia", "lutego", "marca", "kwietnia", "maja", "czerwca", "lipca", "sierpnia",
"września", "października", "listopada", "grudnia"}
endtime = lang:formatDate( "j ", eTime ) .. date_pl[tonumber(lang:formatDate( "n", eTime ))] ..
lang:formatDate( " Y", eTime )
end
end
return starttime, endtime
return starttime, endtime
Línia 505: Línia 527:
no = { long = 'j. F Y', small = 'j. M', onlyday = 'j.' }, -- copy of de
no = { long = 'j. F Y', small = 'j. M', onlyday = 'j.' }, -- copy of de
}
}

local function func_date(date, mode)
local function func_date(date, mode)
-- local date = '+2016-05-20'
-- local date = '+2016-05-20'
-- local mode = 'small'
-- local mode = 'small'
local format = formats[wiki] or formats['']
local format = formats[wiki] or formats['']
if string.sub(date,7,8)=='00' then --manage the 30 November issue
return contentLanguage:formatDate(format[mode], date)
if mode=='long' then
return lang:formatDate( "Y", date )
else
return '-'
end
else
return contentLanguage:formatDate(format[mode], date)
end
end
end


Línia 595: Línia 626:
local wikiisslavic = slavicWikis[wiki]
local wikiisslavic = slavicWikis[wiki]
local correctlanguage=true
local correctlanguage=true
local listOfProperty={'P1813','P1448'}


for _, p1813 in statements(riderID, 'P1813') do
for _, prop in ipairs(listOfProperty) do
for _, p1813 in statements(riderID, prop) do
if not officialname then
if not officialname then
language = p1813.mainsnak.datavalue.value.language
local languageisslavic = slavicWikis[language]
language = p1813.mainsnak.datavalue.value.language
if (languageisslavic==true and wikiisslavic==true) or (languageisslavic==nil and wikiisslavic==nil) then
local languageisslavic = slavicWikis[language]
if (languageisslavic==true and wikiisslavic==true) or (languageisslavic==nil and wikiisslavic==nil) then
officialnametemp = p1813.mainsnak.datavalue.value.text
officialnametemp = p1813.mainsnak.datavalue.value.text
if startOfSeason~= nil then
if startOfSeason~= nil then
local q = p1813.qualifiers
local q = p1813.qualifiers
if q then
if q then
local temp = checktime(officialnametemp,q,startOfSeason)
local temp = checktime(officialnametemp,q,startOfSeason)
if temp then officialname = officialnametemp end--if the time is correct than it is finished
if temp then officialname = officialnametemp end--if the time is correct than it is finished
else
else
officialname = officialnametemp
officialname = officialnametemp
end
end
end
end
end
end

for _, p1448 in statements(riderID, 'P1448') do
if not officialname then
language = p1448.mainsnak.datavalue.value.language
local languageisslavic = slavicWikis[language]
if (languageisslavic==true and wikiisslavic==true) or (languageisslavic==nil and wikiisslavic==nil) then
officialnametemp = p1448.mainsnak.datavalue.value.text
if startOfSeason~= nil then
local q = p1448.qualifiers
if q then
local temp = checktime(officialnametemp,q,startOfSeason)
if temp then officialname = officialnametemp end--if the time is correct than it is finished
else
officialname = officialnametemp
end
end
end
end
Línia 740: Línia 755:
Q20738667 = true, Q28492441 = true, Q20639848 = true, Q20639847 = true, Q20652655 = true,
Q20738667 = true, Q28492441 = true, Q20639848 = true, Q20639847 = true, Q20652655 = true,
Q20653563 = true, Q20653564 = true, Q20653566 = true, Q2466826 = true, Q26849121 = true,
Q20653563 = true, Q20653564 = true, Q20653566 = true, Q2466826 = true, Q26849121 = true,
Q78464255 = true, Q80425135=true
}
}
for _, p31 in statements(teamID, 'P31') do
for _, p31 in statements(teamID, 'P31') do
Línia 1.068: Línia 1.084:
end
end
return code
return code
end

--[[ Make a table row for infoboxes with links to previous and next ]]
local function getPreviousNextLine(raceID)
local previousID = firstValue(raceID, 'P155', 'id') -- P155 is 'follows'
local nextID = firstValue(raceID, 'P156', 'id') -- P156 is 'followed by'
if not nextID or not previousID then
for _, s in statements(raceID, 'P3450') do -- for items using P3450
local q = s.qualifiers
if q then
if not previousID and q.P155 and q.P155[1] and q.P155[1].snaktype == 'value' then
previousID = q.P155[1].datavalue.value.id
end
if not nextID and q.P156 and q.P156[1] and q.P156[1].snaktype == 'value' then
nextID = q.P156[1].datavalue.value.id
end
end
end
end
if not previousID and not nextID then
return ''
end
local previousText, nextText = '', ''
if previousID then
local year = getYear(previousID)
local link = wikibase.getSitelink(previousID)
if link then
previousText = '<span style="color:#3366CC">[[' .. link .. '|&#x25C0; ' .. year .. ']]</span>'
else
previousText = '<span style="color:#3366CC">&#x25C0;</span> ' .. year
end
end
if nextID then
local year = getYear(nextID)
local link = wikibase.getSitelink(nextID)
if link then
nextText = '<span style="color:#3366CC">[[' .. link .. '|' .. year .. ' &#x25B6;]]</span>'
else
nextText = year .. ' <span style="color:#3366CC">&#x25B6;</span>'
end
end
local direction = contentLanguage:getDir()
return "<tr><td style='text-align:" .. ((direction == 'ltr') and 'left' or 'right') ..
"'>" .. previousText .. "</td><td style='text-align:" .. ((direction == 'ltr') and 'right' or 'left') ..
"'>" .. nextText .. "</td></tr>"
end
end


Línia 1.134: Línia 1.105:


--=== C) Function for the output ===
--=== C) Function for the output ===
local function tableA(s, tableBody)
local function getcoutrybool (no_country_list)
local country = true
for _, value in pairs(no_country_list) do -- get data if country should be printed in this wiki
if value == wiki then country = false end
end
return country
end

local function tableA(s)
local error_message = ''
local error_message = ''
if wiki == "ar" and s.item == "" or not s.item then return "" end
if wiki == "ar" and s.item == "" or not s.item then return "" end
Línia 1.144: Línia 1.123:
error_message = ' [[File:Exclam icon.svg|12px|'.. error_message .. ']]'
error_message = ' [[File:Exclam icon.svg|12px|'.. error_message .. ']]'
end
end
local table = mw.html.create('table')
:addClass('sortable')
:attr('cellpadding', '0')
:attr('cellspacing', '0')
:css('border' , '1px solid rgb(200,200,200)')
:css('padding', '3px')
local title = s.header_function (wiki, s.header_1, s.title)
if s.header_1 == 19 and wiki == "ar" then title = title .. " " .. s.year end
local caption = table:tag('tr'):tag('th'):attr('colspan', tostring(#s.header_2 + 1)):cssText('padding:2px; text-align:center; background-color:#FFDF80; line-height: 1.8em;')
caption:tag('span'):cssText('float:left; margin: 0 5px'):wikitext('[[File:Wikidata-logo S.svg|12px|link=d:'.. s.item.. '#'.. s.property..']] '.. error_message)
caption:wikitext(title)


local tableHeader2_size = #s.header_2
local country=getcoutrybool (s.no_country)
local tableStart = '<table border="0" cellspacing="0" cellpadding="0" class="sortable"><tr><th colspan="' .. tostring(tableHeader2_size + 1) .. '"' ..
' style="padding:2px 2px; text-align:center; background-color:#FFDF80; line-height: 1.8em;">'
local Header1_lab = s.header_function (wiki, s.header_1, s.title)
if s.header_1 == 19 and wiki == "ar" then Header1_lab = Header1_lab .. " " .. s.year end
local tableHeader1 = '<span style="float:left">[[File:Wikidata-logo S.svg|12px|link=d:'.. s.item.. '#'.. s.property..']]'.. error_message .. '</span>'
.. Header1_lab .. '</th></tr>'
local tableHeader2 = '<tr>'

local country = true
for _, value in pairs(s.no_country) do -- get data if country should be printed in this wiki
if value == wiki then country = false end
end


local header = table:tag('tr')
for i,k in ipairs(s.header_2) do
for i,k in ipairs(s.header_2) do
if i == s.country_column then
if i == s.country_column then
if available_list and country == true then
if available_list and country == true then
header:tag('th')
tableHeader2 = tableHeader2.. '<th style="text-align:center;padding:2px 20px 2px 2px;white-space:nowrap">'.. s.header_function (wiki, k) .. '</th>' end
:cssText('text-align:center;padding:2px 20px 2px 2px;white-space:nowrap')
:wikitext(s.header_function (wiki, k))
end
end
end
if i ~= s.country_column then
if i ~= s.country_column then
local column = header:tag('th')
if s.data_sort_type[i] == 'unsortable' then tableHeader2 = tableHeader2.. '<th class="unsortable" style="text-align:center;padding:2px 20px 2px 2px;white-space:nowrap">' .. s.header_function (wiki, k) .. '</th>'
else tableHeader2 = tableHeader2.. '<th style="text-align:center;padding:2px 20px 2px 2px;white-space:nowrap">' .. s.header_function (wiki, k) .. '</th>'
:cssText('text-align:center;padding:2px 20px 2px 2px;white-space:nowrap')
:wikitext(s.header_function (wiki, k))
if s.data_sort_type[i] == 'unsortable' then
column:addClass('unsortable')
end
end
end
end
end
end


return table
tableHeader2 = tableHeader2 .. '</tr>'

local tableEnd = '</table>'

return '<table style="border:1px solid rgb(200,200,200)"><tr><td>' .. tableStart .. tableHeader1 .. tableHeader2 .. tableBody .. tableEnd .. '</td></tr></table>'
end
end


local function tableB(s, tableBody)
local function tableB(s) --for startlist
local error_message = ''
local error_message = ''
if wiki == "ar" and s.item == "" or not s.item then return "" end
if wiki == "ar" and s.item == "" or not s.item then return "" end
Línia 1.193: Línia 1.177:
if value == wiki then roll = false end
if value == wiki then roll = false end
end
end

local cssTable= "border: 1px solid rgb(200,200,200); margin: 0 0 0.5em 0;"..
"background-color: rgb(255, 255, 255); padding: 5px; float: left;"..
"clear: left; ; text-align: left; vertical-align: top; font-size: 85%; line-height: 1.8em;"
local wdLink = '[[File:Wikidata-logo S.svg|12px|link=d:'.. s.item.. '#'.. s.property..']] '.. error_message
--border-color:#AAA;
--border=0
local rollbegin='<div class="NavFrame" style="center = margin: 0 0.5em 0;clear:both; border: 1px solid rgb(200,200,200);' ..
'cellpadding="4" cellspacing="0" style="width:100%; background-color: rgb(255, 255, 255);padding: 5px;'..
'margin-bottom:1em; background-color:#FFDF80;" title="['..startlist_translate(14)..']/['..startlist_translate(15)..']" >'..
'<div class="NavHead" style="text-align:'.. textalign ..' =;height:1.8em;background-color:#FFDF80; color:black;font-weight:bold;">'..
'<span style="float:' .. floattable .. '">[[File:Wikidata-logo S.svg|12px|link=d:'.. s.item.. '#'.. s.property..']]'.. error_message .. '</span>' ..
startlist_translate(1)..
'</div>'..
'<div class="NavContent" style="margin:0; background:white; display:block; text-align:left;">'
local tableHeader1 = '<span style="float:left">[[File:Wikidata-logo S.svg|12px|link=d:'.. s.item.. '#'.. s.property..']]'.. error_message .. '</span>' ..
startlist_translate(1) .. '</th></tr><tr>'
local rollend='</div>'..
'<div class="NavEnd">&nbsp;</div>'..
'</div>'
local tableStart = '<table cellpadding="4" cellspacing="0" style="width:100%;" style="border: 1px solid rgb(200,200,200); color: black; margin: 0 0 0.5em 0; background-color: rgb(255, 255, 255); padding: 5px; float: left; clear: left; ; text-align: left; vertical-align: top; font-size: 85%; line-height: 1.8em;>'
if roll == false then tableStart =tableStart..'<tr><th style="background-color:#FFDF80;" align="center" colspan="3">' end
local tableEnd = '</table>'
if roll == true then
if roll == true then
local rollTable1 = mw.html.create('div'):addClass("NavFrame")
return rollbegin..'<table style="border:1px solid rgb(200,200,200)"><tr><td>' .. tableStart .. tableBody .. tableEnd .. '</td></tr></table>'..rollend
:cssText('center = margin: 0 0.5em 0;clear:both; border: 1px solid rgb(200,200,200);' ..
'cellpadding="4" cellspacing="0" style="width:100%; background-color: rgb(255, 255, 255);padding: 5px;'..
'margin-bottom:1em; background-color:#FFDF80;')
:attr('title','['..startlist_translate(14)..']/['..startlist_translate(15)..']')
local tDiv= rollTable1:tag('div'):addClass("NavHead")
:cssText('text-align:'.. textalign .." =;height:1.8em;background-color:#FFDF80; color:black;font-weight:bold;")
tDiv:tag('span')
local tSpan=tDiv:tag('span'):cssText('float:' .. floattable):wikitext(wdLink)
tSpan:wikitext(title)
tDiv:wikitext(startlist_translate(1))
tDiv = rollTable1:tag('div'):addClass("NavContent"):cssText("margin:0; background:white; display:block; text-align:left;")
local tTable= tDiv:tag('table'):cssText("border:1px solid rgb(200,200,200)")
local tCell = tTable:tag('tr'):tag('td')
local insideTable =tCell:tag('table'):attr('cellpadding','4') -- cellspacing="0" style="width:100%;" color: black;
:cssText(cssTable)

return rollTable1, insideTable
else
else
--otherwise problem of clear
return '<table style="border:1px solid rgb(200,200,200)"><tr><td>' .. tableStart .. tableHeader1 .. tableBody .. tableEnd .. '</td></tr></table>'
local tab = mw.html.create('table')
tCell=tab:tag('td')
local tTable =tCell:tag('table')
:attr('cellpadding','4')
:cssText(cssTable)
tCell = tTable:tag('tr'):tag('th'):cssText("background-color:#FFDF80;"):attr('colspan','3'):attr('align','center')
tCell:tag('span'):cssText('float:left'):wikitext(wdLink)
tCell:wikitext(startlist_translate(1))
local tRow=tCell:tag('tr')

return tab, tRow
end
end
end
end
Línia 1.227: Línia 1.226:
local flags = {
local flags = {
Q16 = {'CAN', {'Flag of Canada.svg', '+1965-02-15'}},
Q16 = {'CAN', {'Flag of Canada.svg', '+1965-02-15'}},
Q17 = {'JPN', {'Flag of Japan.svg', '+1999-08-13'}},
Q17 = {'JPN', {'Flag of Japan.svg', '+1999-08-13'},
{'Flag of Japan (1870–1999).svg', '+1870-02-27', '+1999-08-12'}},
Q20 = {'NOR', {'Flag of Norway.svg', '+1821-07-13'}},
Q20 = {'NOR', {'Flag of Norway.svg', '+1821-07-13'}},
Q27 = {'IRL', {'Flag of Ireland.svg', '+1937-12-29'}},
Q27 = {'IRL', {'Flag of Ireland.svg', '+1937-12-29'}},
Línia 1.250: Línia 1.250:
Q39 = {'SUI', {'Flag of Switzerland.svg', '+1889-12-12'},
Q39 = {'SUI', {'Flag of Switzerland.svg', '+1889-12-12'},
{'Flag of Switzerland.svg', '+1879-01-01'}},
{'Flag of Switzerland.svg', '+1879-01-01'}},
Q40 = {'AUT', {'Flag of Austria.svg', '+1945-05-01'}},
Q40 = {'AUT', {'Flag of Austria.svg', '+1945-05-01'},
{'Flag of Austria.svg', '+1919-10-21', '+1938-03-13'}},
Q41 = {'GRE', {'Flag of Greece.svg', '+1978'}},
Q41 = {'GRE', {'Flag of Greece.svg', '+1978'}},
Q43 = {'TUR', {'Flag of Turkey.svg'}},
Q43 = {'TUR', {'Flag of Turkey.svg'}},
Línia 1.260: Línia 1.261:
Q114 = {'KEN', {'Flag of Kenya.svg'}},
Q114 = {'KEN', {'Flag of Kenya.svg'}},
Q115 = {'ETH', {'Flag of Ethiopia.svg', '+1996-10-31'}},
Q115 = {'ETH', {'Flag of Ethiopia.svg', '+1996-10-31'}},
Q117 = {'GHA', {'Flag of Ghana.svg', '+1966-02-28'}},
Q142 = {'FRA', {'Flag of France.svg', '+1794-05-20'}},
Q142 = {'FRA', {'Flag of France.svg', '+1794-05-20'}},
Q145 = {'GBR', {'Flag of the United Kingdom.svg'}},
Q145 = {'GBR', {'Flag of the United Kingdom.svg'}},
Línia 1.275: Línia 1.277:
{'Flag of the German Empire.svg', '+1871-04-16', '+1919-04-11'}},
{'Flag of the German Empire.svg', '+1871-04-16', '+1919-04-11'}},
Q184 = {'BLR', {'Flag of Belarus.svg', '+2012-05-11'},
Q184 = {'BLR', {'Flag of Belarus.svg', '+2012-05-11'},
{'Flag of Belarus (1995–2012).svg', '+1995-06-07', '+2012-05-11'}},
{'Flag of Belarus (1995–2012).svg', '+1995-06-07', '+2012-05-11'},
{'Flag of Belarus (1918, 1991–1995).svg', '+1991-09-19', '1995-06-07'}},
Q189 = {'ISL', {'Flag of Iceland.svg', '+1944-06-17'}},
Q191 = {'EST', {'Flag of Estonia.svg'}},
Q191 = {'EST', {'Flag of Estonia.svg'}},
Q211 = {'LAT', {'Flag of Latvia.svg'}},
Q211 = {'LAT', {'Flag of Latvia.svg'}},
Línia 1.298: Línia 1.302:
{'Flag of Cyprus (1960-2006).svg', '+1960-08-16', '+2006-08-20'}},
{'Flag of Cyprus (1960-2006).svg', '+1960-08-16', '+2006-08-20'}},
Q232 = {'KAZ', {'Flag of Kazakhstan.svg'}},
Q232 = {'KAZ', {'Flag of Kazakhstan.svg'}},
Q235 = {'MON', {'Flag of Monaco.svg'}},
Q238 = {'SMR', {'Flag of San Marino.svg'}},
Q238 = {'SMR', {'Flag of San Marino.svg'}},
Q241 = {'CUB', {'Flag of Cuba.svg'}},
Q241 = {'CUB', {'Flag of Cuba.svg'}},
Línia 1.313: Línia 1.318:
Q408 = {'AUS', {'Flag of Australia.svg'}},
Q408 = {'AUS', {'Flag of Australia.svg'}},
Q414 = {'ARG', {'Flag of Argentina.svg'}},
Q414 = {'ARG', {'Flag of Argentina.svg'}},
Q419 = {'PER', {'Flag of Peru.svg', '+1950'},
{'Flag of Peru (1825-1950).svg', '+1825-02-25', '+1950'}},
Q664 = {'NZL', {'Flag of New Zealand.svg'}},
Q664 = {'NZL', {'Flag of New Zealand.svg'}},
Q711 = {'MGL', {'Flag of Mongolia.svg'}},
Q711 = {'MGL', {'Flag of Mongolia.svg'}},
Q717 = {'VEN', {'Flag of Venezuela.svg', '+2006'}},
Q717 = {'VEN', {'Flag of Venezuela.svg', '+2006-03-12'},
{'Flag of Venezuela (1930–2006).svg', '+1930','+2006-03-12'}},
Q733 = {'PAR', {'Flag of Paraguay.svg', '+2013-07-15'},
{'Flag of Paraguay (1990–2013).svg', '+1990', '+2013-07-14'}},
Q736 = {'ECU', {'Flag of Ecuador.svg'}},
Q736 = {'ECU', {'Flag of Ecuador.svg'}},
Q739 = {'COL', {'Flag of Colombia.svg'}},
Q739 = {'COL', {'Flag of Colombia.svg'}},
Q750 = {'BOL', {'Flag of Bolivia.svg', '+1851-10-31'}},
Q750 = {'BOL', {'Flag of Bolivia.svg', '+1851-10-31'}},
Q754 = {'TTO', {'Flag of Trinidad and Tobago.svg'}},
Q774 = {'GUA', {'Flag of Guatemala.svg'}},
Q778 = {'BAH', {'Flag of the Bahamas.svg'}, '+1973-07-10'},
Q783 = {'HON', {'Flag of Honduras.svg'}, '+1949'},
Q786 = {'DOM', {'Flag of the Dominican Republic.svg'}},
Q786 = {'DOM', {'Flag of the Dominican Republic.svg'}},
Q794 = {'IRI', {'Flag of Iran.svg', '+1980-07-29'},
Q794 = {'IRI', {'Flag of Iran.svg', '+1980-07-29'},
Línia 1.324: Línia 1.338:
Q800 = {'CRC', {'Flag of Costa Rica (state).svg', '+1906-11-27'}},
Q800 = {'CRC', {'Flag of Costa Rica (state).svg', '+1906-11-27'}},
Q801 = {'ISR', {'Flag of Israel.svg'}},
Q801 = {'ISR', {'Flag of Israel.svg'}},
Q804 = {'PAN', {'Flag of Panama.svg'}},
Q813 = {'KGZ', {'Flag of Kyrgyzstan.svg', '+1992-03-03'}},
Q817 = {'KUW', {'Flag of Kuwait.svg', '+1961-09-07'}},
Q817 = {'KUW', {'Flag of Kuwait.svg', '+1961-09-07'}},
Q833 = {'MAS', {'Flag of Malaysia.svg', '+1963-09-16'}},
Q833 = {'MAS', {'Flag of Malaysia.svg', '+1963-09-16'}},
Q842 = {'OMA', {'Flag of Oman.svg', '+1995'}},
Q842 = {'OMA', {'Flag of Oman.svg', '+1995'}},
Q846 = {'QAT', {'Flag of Qatar.svg'}},
Q846 = {'QAT', {'Flag of Qatar.svg'}},
Q858 = {'SYR', {'Flag of Syria.svg', '+1980-03-29'}},
Q865 = {'TPE', {'Flag of the Republic of China.svg', '+1928-12-17'}},
Q865 = {'TPE', {'Flag of the Republic of China.svg', '+1928-12-17'}},
Q869 = {'THA', {'Flag of Thailand.svg'}},
Q869 = {'THA', {'Flag of Thailand.svg'}},
Q878 = {'UAE', {'Flag of the United Arab Emirates.svg'}},
Q878 = {'UAE', {'Flag of the United Arab Emirates.svg'}},
Q881 = {'VIE', {'Flag of Vietnam.svg', '+1976-02-07'}},
Q884 = {'KOR', {'Flag of South Korea.svg', '+1997-10'}},
Q884 = {'KOR', {'Flag of South Korea.svg', '+1997-10'}},
Q916 = {'ANG', {'Flag of Angola.svg', '+1975-11-11'}},
Q921 = {'BRU', {'Flag of Brunei.svg', '+1959-09-29'}},
Q928 = {'PHI', {'Flag of the Philippines.svg', '+1998'}},
Q928 = {'PHI', {'Flag of the Philippines.svg', '+1998'}},
Q948 = {'TUN', {'Flag of Tunisia.svg', '+1999-07-03'}},
Q948 = {'TUN', {'Flag of Tunisia.svg', '+1999-07-03'}},
Q954 = {'ZIM', {'Flag of Zimbabwe.svg', '+1980-04-18'}},
Q965 = {'BUR', {'Flag of Burkina Faso.svg'}},
Q965 = {'BUR', {'Flag of Burkina Faso.svg'}},
Q983 = {'GEQ', {'Flag of Equatorial Guinea.svg', '+1979-08-21'},
{'Flag of Equatorial Guinea (1973–1979).svg', '+1973', '+1979-08-21'},
{'Flag of Equatorial Guinea (without coat of arms).svg', '+1968-10-12', '+1973'}},
Q986 = {'ERI', {'Flag of Eritrea.svg'}},
Q986 = {'ERI', {'Flag of Eritrea.svg'}},
Q1000 = {'GAB', {'Flag of Gabon.svg', '+1960-08-09'}},
Q1000 = {'GAB', {'Flag of Gabon.svg', '+1960-08-09'}},
Q1007 = {'GBS', {'Flag of Guinea-Bissau.svg', '+1973-09-24'}},
Q1008 = {'CIV', {"Flag of Côte d'Ivoire.svg"}},
Q1008 = {'CIV', {"Flag of Côte d'Ivoire.svg"}},
Q1009 = {'CMR', {'Flag of Cameroon.svg'}},
Q1009 = {'CMR', {'Flag of Cameroon.svg'}},
Q1027 = {'MRI', {'Flag of Mauritius.svg', '+1968-03-13'}},
Q1028 = {'MAR', {'Flag of Morocco.svg'}},
Q1028 = {'MAR', {'Flag of Morocco.svg'}},
Q1030 = {'NAM', {'Flag of Namibia.svg', '+1990-03-21'}},
Q1036 = {'UGA', {'Flag of Uganda.svg', '+1962-10-09'}},
Q1036 = {'UGA', {'Flag of Uganda.svg', '+1962-10-09'}},
Q1037 = {'RWA', {'Flag of Rwanda.svg', '+2001-10-25'},
Q1037 = {'RWA', {'Flag of Rwanda.svg', '+2001-10-25'},
Línia 1.345: Línia 1.372:
Q9676 = {'IMN', {'Flag of the Isle of Man.svg'}},
Q9676 = {'IMN', {'Flag of the Isle of Man.svg'}},
Q15180 = {'URS', {'Flag of the Soviet Union.svg', '+1980-08-15', '+1991-12-25'},
Q15180 = {'URS', {'Flag of the Soviet Union.svg', '+1980-08-15', '+1991-12-25'},
{'Flag of the Soviet Union (1955–1980).svg', '+1955-08-19', '+1980-08-14'}},
{'Flag of the Soviet Union (1955–1980).svg', '+1955-08-19', '+1980-08-14'},
{'Flag of the Soviet Union (1924–1955).svg', '+1923-11-13', '+1955-08-18'}},
Q16957 = {'GDR', {'Flag of East Germany.svg', '+1959-10-01'},
Q16957 = {'GDR', {'Flag of East Germany.svg', '+1959-10-01'},
{'Flag of Germany.svg', '+1949-10-07', '+1959-10-01'}}, --German Democratic Republic
{'Flag of Germany.svg', '+1949-10-07', '+1959-10-01'}}, --German Democratic Republic
Q8646 = {'HKG', {'Flag of Hong Kong.svg'}},
Q8646 = {'HKG', {'Flag of Hong Kong.svg'}},
Q25228 = {'AIA', {'Flag of Anguilla.svg'}},
Q29999 = {'NED', {'Flag of the Netherlands.svg', '+1690'}}, --Kingdom of the Netherlands
Q29999 = {'NED', {'Flag of the Netherlands.svg', '+1690'}}, --Kingdom of the Netherlands
Q33946 = {'TCH', {'Flag of the Czech Republic.svg', '+1920'}}, -- Czechoslovakia (1918–1992)
Q33946 = {'TCH', {'Flag of the Czech Republic.svg', '+1920'}}, -- Czechoslovakia (1918–1992)
Q36704 = {'YUG', {'Flag of Yugoslavia (1992–2003).svg', '+1992-04-27', '+2003-02-04'}, --Yugoslavia
Q36704 = {'YUG', {'Flag of Yugoslavia (1992–2003).svg', '+1992-04-27', '+2003-02-04'}, --Yugoslavia
{'Flag of Yugoslavia (1943–1992).svg', '+1946', '+1992-04-27'}},
{'Flag of Yugoslavia (1943–1992).svg', '+1946', '+1992-04-27'}},
Q41304 = {'GER', {'Flag of Germany (3-2 aspect ratio).svg', '+1918-11-09'}}, -- Weimar Republic
Q83286 = {'YUG', {'Flag of Yugoslavia (1943–1992).svg'}}, --Socialist Federal Republic of Yugoslavia
Q83286 = {'YUG', {'Flag of Yugoslavia (1943–1992).svg'}}, --Socialist Federal Republic of Yugoslavia
Q172579 = {'ITA', {'Flag of Italy (1861–1946).svg'}}, --Kingdom of Italy (1861-1946)
Q172579 = {'ITA', {'Flag of Italy (1861–1946).svg'}}, --Kingdom of Italy (1861-1946)
Q216923 = {'TPE', {'Flag of Chinese Taipei for Olympic games.svg'}}, -- Chinese Taipei
Q268970 = {'AUT', {'Flag of Austria.svg', '+1918-11-12', '+1919-09-10'}}, -- German-Austria (1918-1919)
Q713750 = {'FRG', {'Flag of Germany.svg'}}, --West Germany
Q713750 = {'FRG', {'Flag of Germany.svg'}}, --West Germany
Q853348 = {'TCH', {'Flag of the Czech Republic.svg'}, '+1960-07-11', '+1990-03-29'}, -- Czechoslovak Socialist Republic (1960-1990)
Q2415901 = {'GER', {'Merchant flag of Germany (1946–1949).svg', '+1945-05-09', '+1949-05-23'}}, -- Allied-occupied Germany
Q13474305 = {'ESP', {'Flag of Spain (1945–1977).svg', '+1945-10-11', '+1977-01-21'}, -- Francoist Spain (1935-1976)
Q13474305 = {'ESP', {'Flag of Spain (1945–1977).svg', '+1945-10-11', '+1977-01-21'}, -- Francoist Spain (1935-1976)
{'Flag of Spain (1938–1945).svg', '+1939', '+1945-10-11'},
{'Flag of Spain (1938–1945).svg', '+1939', '+1945-10-11'},
Línia 1.438: Línia 1.472:
end
end


local function jersey_infobox(wiki, winner_classification, item, timeofrace)
local function jersey_infobox(wiki, winner_classification, item, timeOfRace)
local jersey, jersey_name = '', ''
local jersey, jersey_name = '', ''
local jerseyWPID = ''
local jerseyWPID = ''
Línia 1.525: Línia 1.559:
{'Q17619325', 'winner_fighting', '+2016', '+2500', 'Q30035039', 'Q30020302'}, -- Jersey orange.svg
{'Q17619325', 'winner_fighting', '+2016', '+2500', 'Q30035039', 'Q30020302'}, -- Jersey orange.svg
}
}
--timeofrace = '+1968-07-01T00:00:00Z'
--timeOfRace = '+1968-07-01T00:00:00Z'
timeofrace = string.match(timeofrace, "+%d%d%d%d") or ''
timeOfRace = string.match(timeOfRace, "+%d%d%d%d") or ''
for _, v in pairs(item) do
for _, v in pairs(item) do
for _, value in pairs(data) do
for _, value in pairs(data) do
if v == value[1] then
if v == value[1] then
if winner_classification == value[2] then
if winner_classification == value[2] then
if (timeofrace >= value[3]) and (timeofrace <= value[4]) then
if (timeOfRace >= value[3]) and (timeOfRace <= value[4]) then
jersey = value[5]
jersey = value[5]
jerseyWPID = value[6]
jerseyWPID = value[6]
Línia 1.541: Línia 1.575:


-- local starttime, endtime = '', '+2500'
-- local starttime, endtime = '', '+2500'
if jersey ~= '' then --and (timeofrace > starttime) and (timeofrace < endtime) then
if jersey ~= '' then --and (timeOfRace > starttime) and (timeOfRace < endtime) then
local entity_jersey = mw.wikibase.getEntity(jersey)
local entity_jersey = mw.wikibase.getEntity(jersey)
jersey = entity_jersey.claims['P18'][1].mainsnak.datavalue.value
jersey = entity_jersey.claims['P18'][1].mainsnak.datavalue.value
Línia 1.636: Línia 1.670:
end
end


local function subwinner(riderId, timeofrace, q)
local function subwinner(riderId, timeOfRace, q)
local outputtable={}
local outputtable={}
local riderTeam, riderLink, countryID
local riderTeam, riderLink, countryID
Línia 1.642: Línia 1.676:
if riderId then
if riderId then
if isHuman(riderId) then
if isHuman(riderId) then
riderLink = getRiderLink(riderId, timeofrace)
riderLink = getRiderLink(riderId, timeOfRace)
local p27 = getStatementForTime(riderId, 'P27', timeofrace) --P27 is country of citizenship
local p27 = getStatementForTime(riderId, 'P27', timeOfRace) --P27 is country of citizenship
if p27 then
if p27 then
countryID = p27.mainsnak.datavalue.value.id
countryID = p27.mainsnak.datavalue.value.id
end
end
if countryID then
if countryID then
riderLink = flag(countryID, timeofrace) .. ' ' .. riderLink
riderLink = flag(countryID, timeOfRace) .. ' ' .. riderLink
end
end
riderTeam = getTeam(riderId, timeofrace, q) or ''
riderTeam = getTeam(riderId, timeOfRace, q) or ''
else
else
local _
local _
riderLink, _, countryID = getTeamLinkCat(riderId, timeofrace, true)
riderLink, _, countryID = getTeamLinkCat(riderId, timeOfRace, true)
if countryID then
if countryID then
riderLink = flag(countryID, timeofrace) .. ' ' .. riderLink
riderLink = flag(countryID, timeOfRace) .. ' ' .. riderLink
end
end
end
end
end
end
outputtable[1]=riderLink
return riderLink, riderTeam
outputtable[2]=riderTeam
return outputtable
end
end


Línia 1.757: Línia 1.789:
end
end
end
end
end

local function sortandconcat(t_Body, resulttable)
table.sort(t_Body, function(a, b) return a[1] < b[1] end)
for _, m in ipairs(t_Body) do resulttable:node(m[2]) end
return resulttable
end
end


--------- Definition sub-functions for calendar and victory ------
--------- Definition sub-functions for calendar and victory ------
local function fn_date(entityID, functionName) --to move as a general function
local function fn_date(entityID, functionName) --to move as a general function
local tempdate, dateOfRace, sortkey, sortkeyDate
local tempdate, timeOfRace, sortkey, sortkeyDate
local outputtable={}
local outputtable={}
local sTime = firstValue(entityID, 'P580', 'time') -- P580 is 'start time'
local sTime = firstValue(entityID, 'P580', 'time') -- P580 is 'start time'
Línia 1.774: Línia 1.812:
sortkeyDate =eTime
sortkeyDate =eTime
end
end
dateOfRace = eTime
timeOfRace = eTime
else
else
-- This function give a format to dates when P585 (date) is used in a single day race
-- This function give a format to dates when P585 (date) is used in a single day race
Línia 1.780: Línia 1.818:
if pTime then
if pTime then
tempdate = func_date(pTime, 'small')
tempdate = func_date(pTime, 'small')
dateOfRace = pTime
timeOfRace = pTime
sortkeyDate = pTime
sortkeyDate = pTime
end
end
Línia 1.794: Línia 1.832:
end
end


local tCell = mw.html.create('td'):attr('data-sort-value',sortkey)
outputtable[1]=dateOfRace
outputtable[2]='<td data-sort-value="'..sortkey.. '" style="text-align:right;padding:0 0.5em">'..tempdate.. '</td>'
:cssText("style=text-align:right;padding:0 0.5em")
:wikitext(tempdate)
outputtable[1]=timeOfRace
outputtable[2]=tostring(tCell)
outputtable[3]=sortkey
outputtable[3]=sortkey
return outputtable
return outputtable
end
end


local function fn_country(entityID, dateOfRace,countrybool, ParentID)
local function fn_country(entityID, timeOfRace,countrybool, fn_racetable)
-- This function gives countries where the race take place
-- This function gives countries where the race take place
-- ParentID taken from fn_race, optional
-- parentID taken from fn_race, optional
--outputtable[1] is the cell
--outputtable[2] is the name of the country
--outputtable[3] is the flag
local country, countryname, outputtable= {}, {}, {}
local country, countryname, outputtable= {}, {}, {}
local countryID, beginofstr
local countryID, parentID, raceSitelink

if fn_racetable~=nil then
for _, p1532 in statements(entityID, 'P1532') do -- P1512 is 'country for sport' to handle problems with Hong Kong etc.
raceSitelink = fn_racetable[1] --only for country false
countryID = p1532.mainsnak.datavalue.value.id
parentID=fn_racetable[3]
countryname[#countryname + 1] = getCountryName(countryID)
if countrybool==false or not countryname[#countryname] then
country[#country + 1]=flag(countryID, dateOfRace)
else
country[#country + 1]=flag(countryID, dateOfRace).." "..countryname[#countryname]
end
outputtable[3]=flag(countryID, dateOfRace)
end
end
local cssCell="text-align:" .. textalign .. ";padding:0 0.5em"
if countryID == nil then
local tCell= mw.html.create('td'):cssText(cssCell)
for _, p17 in statements(entityID, 'P17') do -- P17 is 'country' --we have to select the right one
countryID = p17.mainsnak.datavalue.value.id
local listOfProperty={'P1532','P17'} -- P1512 is 'country for sport' to handle problems with Hong Kong etc.
countryname[#countryname + 1] = getCountryName(countryID)
local listOfID = {entityID, parentID}
if countrybool==false or not countryname[#countryname] then
country[#country + 1]=flag(countryID, dateOfRace)
for _, thisID in ipairs(listOfID) do
else
if thisID~=nil then
country[#country + 1]=flag(countryID, dateOfRace).." "..countryname[#countryname]
for _, prop in ipairs(listOfProperty) do
end
outputtable[3]=flag(countryID, dateOfRace)
if countryID == nil then --like "break"
for _, p1532 in statements(thisID, prop) do
end
countryID = p1532.mainsnak.datavalue.value.id
end
countryname[#countryname + 1] = getCountryName(countryID)
--no country in entity, look by parent
if countrybool==false or not countryname[#countryname] then
if countryID == nil and ParentID ~= nil then
country[#country + 1]=flag(countryID, timeOfRace)
for _, p1532 in statements(ParentID, 'P1532') do
else
countryID = p1532.mainsnak.datavalue.value.id
countryname[#countryname + 1] = getCountryName(countryID)
country[#country + 1]=flag(countryID, timeOfRace).." "..countryname[#countryname]
end
if countrybool==false or not countryname[#countryname] then
country[#country + 1]=flag(countryID, dateOfRace)
outputtable[3]=flag(countryID, timeOfRace)
else
end
country[#country + 1]=flag(countryID, dateOfRace).." "..countryname[#countryname]
end
outputtable[3]=flag(countryID, dateOfRace)
end
if countryID == nil then
for _, p17 in statements(ParentID, 'P17') do -- P17 is 'country' --we have to select the right one
countryID = p17.mainsnak.datavalue.value.id
countryname[#countryname + 1] = getCountryName(countryID)
if countrybool==false or not countryname[#countryname] then
country[#country + 1]=flag(countryID, dateOfRace)
else
country[#country + 1]=flag(countryID, dateOfRace).." "..countryname[#countryname]
end
end
outputtable[3]=flag(countryID, dateOfRace)
end
end
end
end
end
end

if countryID == nil then outputtable[3]="no flag" end
if countryID == nil then outputtable[3]="no flag" end
if countryname[1] then
if countryname[1] then tCell:attr('data-sort-value',countryname[1]) end
beginofstr = '<td style="text-align:' .. textalign .. ';padding:0 0.5em data-sort-value="'..countryname[1].. '">'
else
beginofstr = '<td style="text-align:' .. textalign .. ';padding:0 0.5em">'
end
if countrybool==false then
if countrybool==false then
outputtable[1]=beginofstr..country[1].." "
tCell:wikitext(country[1].." "..(raceSitelink or ''))
outputtable[2]=''
outputtable[2]=''
else
else
if countryname[1] then
if countryname[1] then
outputtable[2]=countryname[1]
outputtable[2]=countryname[1]
if country[1] then tCell:wikitext(country[1]) end
if country[1] then
outputtable[1]=beginofstr..country[1]..'</td>'
else
outputtable[1]=beginofstr..'</td>'
end
else
else
outputtable[2]=''
outputtable[2]=''
outputtable[1]='<td></td>'
end
end
end
end
outputtable[1]=tCell
return outputtable
return outputtable
end
end
Línia 1.891: Línia 1.910:
local temp=firstValue(stageID, 'P1545')
local temp=firstValue(stageID, 'P1545')
if temp then stagenumber = temp end
if temp then stagenumber = temp end
--local p1545 = wikibase.getBestStatements(stageID, 'P1545') --name for championship
--if p1545[1] and p1545[1].mainsnak.snaktype == 'value' then stagenumber = p1545[1].mainsnak.datavalue.value end


if stagenumber=='0' then
if stagenumber=='0' then --prologue
stagenumber= victories_translate(wiki,9)
stagenumber= victories_translate(wiki,9)
else
else
Línia 1.957: Línia 1.974:
end
end


local function getmainraceLink(entityID,entity_type,stageID, functionName,dateOfRace) --the link to the edition but with a general name
local function getMainRaceLink(entityID,entity_type,stageID, functionName,timeOfRace) --the link to the edition but with a general name
local instanceOf, label, Sitelink, isclass, prefix, postfix
local instanceOf, label, Sitelink, isclass, prefix, postfix
Sitelink=wikibase.getSitelink(entityID)
Sitelink=wikibase.getSitelink(entityID)
prefix=''; postfix=''
prefix=''; postfix='' --general classification
listOfProperty={'P2561','P1448'}


for _, p31 in statements(entityID, 'P31') do
for _, p31 in statements(entityID, 'P31') do
instanceOf = p31.mainsnak.datavalue.value.id
instanceOf = p31.mainsnak.datavalue.value.id
isclass=0
isclass=false
for i=1,#class do--we don't want the class, but the main race
for _,thisClass in ipairs(class) do--we don't want the class, but the main race
if instanceOf == class[i] then isclass=1 end
if instanceOf == thisClass then isclass=true end
end
end
if isclass==0 then
if isclass==false then
for _, p2561 in statements(instanceOf, 'P2561') do --name for championship
for _, prop in ipairs(listOfProperty) do
for _, p2561 in statements(instanceOf, prop) do --name for championship
local lang_WD = p2561.mainsnak.datavalue.value.language
if wiki == lang_WD then
if label==nil then
local nametemp = p2561.mainsnak.datavalue.value.text
local lang_WD = p2561.mainsnak.datavalue.value.language
if dateOfRace~= nil then
if wiki == lang_WD then
local q = p2561.qualifiers
local nametemp = p2561.mainsnak.datavalue.value.text
if q then
if timeOfRace~= nil then
local temp = checktime(nametemp,q,dateOfRace)
local q = p2561.qualifiers
if q then
if temp then label = nametemp end--if the time is correct than it is finished
local temp = checktime(nametemp,q,timeOfRace)
else
label = nametemp
if temp then label = nametemp end--if the time is correct than it is finished
end
else
label = nametemp
end
end
end
end
if label==nil then
for _, p1448 in statements(instanceOf, 'P1448') do --name for championship
local lang_WD = p1448.mainsnak.datavalue.value.language
if wiki == lang_WD then
local nametemp = p1448.mainsnak.datavalue.value.text
if dateOfRace~= nil then
local q = p1448.qualifiers
if q then
local temp = checktime(nametemp,q,dateOfRace)
if temp then label = nametemp end--if the time is correct than it is finished
else
label = nametemp
end
end
end
end
Línia 2.047: Línia 2.053:
end
end


local function fn_getclassinfo(entityID,displayed_class) --get the class of the race
local function fn_getClassInfo(entityID,displayed_class) --get the class of the race
local display=false
local display=false
local outputtable={}
local outputtable={}
Línia 2.055: Línia 2.061:
display=true
display=true
else
else
for i=1,#displayed_class do
for _, thisClass in ipairs(displayed_class) do
if entityID ==displayed_class[i] then display=true break end
if entityID ==thisClass then display=true break end
end
end
end
end
listOfClassesList = {class_champ,class_2x, class_without2x}
--is it a championship?
listOfClassesName = {'champ', '2','1'}
for i=1,#class_champ do
if entityID == class_champ[i] then
for ii, thisClassesList in ipairs(listOfClassesList) do
entity_type = 'champ'
class_text = mw.wikibase.label(class_champ[i])
sortkey_class = class_sort[class_champ[i]]
end
end
if entity_type==nil then
for i=1,#class_2x do -- #class = number of elements in class
if entityID == class_2x[i] then
entity_type = '2'
class_text = mw.wikibase.label(class_2x[i])
sortkey_class = class_sort[class_2x[i]]
end
end
if entity_type==nil then
if entity_type==nil then
for i=1,#class_without2x do
for _, thisClass in ipairs(thisClassesList) do
if entityID == class_without2x[i] then
if entityID == thisClass then
entity_type = '1'
entity_type = listOfClassesName[ii]
class_text = mw.wikibase.label(class_without2x[i])
class_text = mw.wikibase.label(thisClass)
sortkey_class = class_sort[class_without2x[i]]
sortkey_class = class_sort[thisClass]
end
end
end
end
end
end
if entity_type==nil then entity_type = 'nada' end--to allow display of race without class...
end
end
if entity_type==nil then entity_type = 'nada' end--to allow display of race without class...


if display==false then
if display~=false then
else
outputtable[1]=entity_type
outputtable[1]=entity_type
outputtable[2]=class_text
outputtable[2]=class_text
Línia 2.097: Línia 2.090:
end
end


local function fn_race(entityID,displayed_class,displayclass,dateOfRace, functionName,country)--return link to the race and class
local function fn_race(entityID,displayed_class,displayclass,timeOfRace, functionName,country)--return link to the race and class
--first function read from victory main
--first function read from victory main
--outputtable[1] is the cell with the race, or sitelink if country is false
--outputtable[2] is the cell with the class
local Sitelink,instanceOf,circuitID,parentCircuitID, displayedCircuitID, Circuitlink
local Sitelink,instanceOf,circuitID,parentCircuitID, displayedCircuitID, Circuitlink
local Classlink, entity_type, classID, class_text
local Classlink, entity_type, classID, class_text
Línia 2.111: Línia 2.108:
if instanceOf == stages[i] then
if instanceOf == stages[i] then
entity_type = 'stage' --then the class is one stage above!
entity_type = 'stage' --then the class is one stage above!
local ParentID = getParentID(entityID)
local parentID = getParentID(entityID)
entityID = ParentID
entityID = parentID
outputtable[3] = ParentID --as we read it here, no need to read it afterwards
outputtable[3] = parentID --as we read it here, no need to read it afterwards
display = true
display = true
for _, p31bis in statements(ParentID, 'P31') do
for _, p31bis in statements(parentID, 'P31') do
local instanceOfbis = p31bis.mainsnak.datavalue.value.id
local instanceOfbis = p31bis.mainsnak.datavalue.value.id
inputtable=fn_getclassinfo(instanceOfbis,displayed_class)
inputtable=fn_getClassInfo(instanceOfbis,displayed_class)
if inputtable[1]==nil or inputtable[1]=='nada' then
if inputtable[1]~=nil and inputtable[1]~='nada' then
else
class_text =inputtable[2]
class_text =inputtable[2]
sortkey_class=inputtable[3]
sortkey_class=inputtable[3]
Línia 2.128: Línia 2.124:
end
end
if entity_type==nil then --bypass if stage
if entity_type==nil then --bypass if stage
inputtable=fn_getclassinfo(instanceOf,displayed_class)
inputtable=fn_getClassInfo(instanceOf,displayed_class)
if inputtable[1]==nil then
if inputtable[1]==nil then
elseif inputtable[1]=='nada' then --no display="inputtable[1]==nil" inputtable[1]=='nada'--> display but empty
elseif inputtable[1]=='nada' then --no display="inputtable[1]==nil" inputtable[1]=='nada'--> display but empty
Línia 2.147: Línia 2.143:
if display then
if display then
if entity_type == 'stage' then
if entity_type == 'stage' then
Sitelink=getmainraceLink(entityID,entity_type,stageID, functionName,dateOfRace)
Sitelink=getMainRaceLink(entityID,entity_type,stageID, functionName,timeOfRace)
else
else
Sitelink=getmainraceLink(entityID,entity_type,nil, functionName,dateOfRace)
Sitelink=getMainRaceLink(entityID,entity_type,nil, functionName,timeOfRace)
end
end
if country~=false then
if country~=false then
outputtable[1]='<td style="text-align:'.. textalign ..';padding:0 2.3em">'..Sitelink.. '</td>'
local tCell=mw.html.create('td'):cssText("text-align:".. textalign ..";padding:0 2.3em"):wikitext(Sitelink)
outputtable[1]=tostring(tCell)
else
else
outputtable[1]=Sitelink.. '</td>' --already opened
outputtable[1]=Sitelink --already opened
end
end
if displayclass == true then
if displayclass == true then
Línia 2.186: Línia 2.183:
end
end
-- class
-- class
local tCell=mw.html.create('td')
outputtable[2]='<td data-sort-value="'..sortkey_class.. '" style="text-align:center;padding:0 0.5em">'..Classlink.. '</td>'
:attr('data-sort-value',sortkey_class)
:cssText("text-align:center;padding:0 0.5em")
:wikitext(Classlink)
outputtable[2]=tCell
end
end
end
end
Línia 2.192: Línia 2.194:
end
end


local function fn_rider(entityID,dateOfRace,displayteam,only_winner,country)
local function fn_rider(entityID,timeOfRace,displayteam,only_winner,country)
local winners, bool, countrytemp
local winners, countrytemp, result
local WDlink_on = (wiki == "mk" or wiki == "ja")
local WDlink_on = (wiki == "mk" or wiki == "ja")
local thereisawinner=false
if only_winner == 1 then
if only_winner == 1 then
winners = {Q20882667 = '', Q20882747=''} -- first, general or stage
winners = {Q20882667 = '', Q20882747=''} -- first, general or stage
Línia 2.203: Línia 2.207:
end
end
if country==nil then countrytemp=false else countrytemp=country end
if country==nil then countrytemp=false else countrytemp=country end
winner(entityID, winners, dateOfRace, countrytemp, WDlink_on, displayteam, true)
winner(entityID, winners, timeOfRace, countrytemp, WDlink_on, displayteam, true)
local tCell=mw.html.create('td'):css("text-align:".. textalign ..";padding:0 0.5em")
if only_winner == 0 then
if only_winner == 0 then
tCell:wikitext(winners.Q20882667)
return
result=tostring(tCell)
'<td style="text-align:'.. textalign ..';padding:0 0.5em">'..winners.Q20882667.. '</td>' ..
'<td style="text-align:'.. textalign ..';padding:0 0.5em">'..winners.Q20882668.. '</td>' ..
tCell=mw.html.create('td'):css("text-align:".. textalign ..";padding:0 0.5em"):wikitext(winners.Q20882668)
result=result..tostring(tCell)
'<td style="text-align:'.. textalign ..';padding:0 0.5em">'..winners.Q20882669.. '</td>'
tCell=mw.html.create('td'):css("text-align:".. textalign ..";padding:0 0.5em"):wikitext(winners.Q20882669)
return result..tostring(tCell)
else
else
local tempwinner
local tempwinner
Línia 2.220: Línia 2.229:
tempwinner=winners.Q47640757
tempwinner=winners.Q47640757
end
end
if tempwinner=='' or tempwinner==nil then bool=0 else bool=1 end
if tempwinner~='' and tempwinner~=nil then thereisawinner=true end
return '<td style="text-align:'.. textalign ..';padding:0 0.5em">'..tempwinner.. '</td>', bool
return tCell:wikitext(tempwinner), thereisawinner
end
end
end
end
Línia 2.306: Línia 2.315:
end
end
end
end
return ""
return nil
end
end


local function getSpeed(raceID, addUnit,kmdistance, property)
local function getSpeed(raceID, addUnit,kmdistance, property)
local p = mw.wikibase.getBestStatements(raceID, 'P2052') -- P2052 is 'speed'
local p = mw.wikibase.getBestStatements(raceID, 'P2052') -- P2052 is 'speed'
local kmh, unit, text, found, timeofrace
local kmh, unit, text, found, timeOfRace
local lang = contentLanguage
local lang = contentLanguage
if p[1] and p[1].mainsnak.snaktype == 'value' then
if p[1] and p[1].mainsnak.snaktype == 'value' then
Línia 2.329: Línia 2.338:
end
end
if rank == 1 then
if rank == 1 then
timeofrace=qualifieramount(p2321[1], 'P2781') --get time
timeOfRace=qualifieramount(p2321[1], 'P2781') --get time
end
end
end
end

-- if true then return tostring( timeofrace) end
if timeofrace then
if timeOfRace then
found=true
found=true
kmh=math.modf(1000*kmdistance/(timeofrace/3600))/1000
kmh=math.modf(1000*kmdistance/(timeOfRace/3600))/1000
end
end
end
end
Línia 3.003: Línia 3.012:
["pt"] = {"Nome da equipe", "País", "Código", "Equipe WorldTeam", "Equipes WorldTeam", "Equipe ProTeam", "Equipes ProTeam", "Equipe profissional Continental", "Equipes profissionais Continentais", "Equipe Continental", "Equipes Continentais", "Equipe nacional", "Equipes nacionais", "Equipe regional e clube", "Equipes regionais e clubes", "Equipe profissional de ciclismo", "Equipes profissionais de ciclismo", "Equipe amadora de ciclismo", "Equipes amadoras de ciclismo", "Grupo esportivo I", "Grupos esportivos I", "Grupo esportivo II", "Grupos esportivos II", "Grupo esportivo III", "Grupos esportivos III", "Equipe mista", "Equipes mistas", "Equipe feminina profissional", "Equipes femininas profissionais", "Equipes femininas amadoras", "Equipes femininas amadoras"},
["pt"] = {"Nome da equipe", "País", "Código", "Equipe WorldTeam", "Equipes WorldTeam", "Equipe ProTeam", "Equipes ProTeam", "Equipe profissional Continental", "Equipes profissionais Continentais", "Equipe Continental", "Equipes Continentais", "Equipe nacional", "Equipes nacionais", "Equipe regional e clube", "Equipes regionais e clubes", "Equipe profissional de ciclismo", "Equipes profissionais de ciclismo", "Equipe amadora de ciclismo", "Equipes amadoras de ciclismo", "Grupo esportivo I", "Grupos esportivos I", "Grupo esportivo II", "Grupos esportivos II", "Grupo esportivo III", "Grupos esportivos III", "Equipe mista", "Equipes mistas", "Equipe feminina profissional", "Equipes femininas profissionais", "Equipes femininas amadoras", "Equipes femininas amadoras"},
["ro"] = {"Numele echipei", "Țară", "Cod", "WorldTeam", "WorldTeams", "ProTeam", "ProTeams", "Echipă continentală profesionistă", "Echipe continentale profesioniste", "Echipă continentală", "Echipe continentale", "Echipă națională", "Echipe naționale", "Echipă regională și de club", "Echipe regionale și de club", "Echipă ciclistă profesionistă", "Echipe cicliste profesioniste", "Echipă ciclistă de amatori", "Echipe cicliste de amatori", "Grup sportiv I", "Grupuri sportive I", "Grup sportiv II", "Grupuri sportive II", "Grup sportiv III", "Grupuri sportive III", "Echipă mixtă", "Echipe mixte", "Echipă feminină", "Echipe feminine", "Women's amateur cycling team", "Women's amateur cycling teams"},
["ro"] = {"Numele echipei", "Țară", "Cod", "WorldTeam", "WorldTeams", "ProTeam", "ProTeams", "Echipă continentală profesionistă", "Echipe continentale profesioniste", "Echipă continentală", "Echipe continentale", "Echipă națională", "Echipe naționale", "Echipă regională și de club", "Echipe regionale și de club", "Echipă ciclistă profesionistă", "Echipe cicliste profesioniste", "Echipă ciclistă de amatori", "Echipe cicliste de amatori", "Grup sportiv I", "Grupuri sportive I", "Grup sportiv II", "Grupuri sportive II", "Grup sportiv III", "Grupuri sportive III", "Echipă mixtă", "Echipe mixte", "Echipă feminină", "Echipe feminine", "Women's amateur cycling team", "Women's amateur cycling teams"},
["ru"] = {"Команда", "Страна", "Код", "[[UCI WorldTeam|WorldTeam]]", "[[UCI WorldTeam|WorldTeams]]", "[[UCI ProTeam|ProTeam]]", "[[UCI ProTeams|ProTeams]]", "[[UCI Professional Continental Team|Профессиональная континентальная команда]]", "[[UCI Professional Continental Team|Профессиональные континентальные команды]]", "[[UCI Continental Team|Континентальная команда]]", "[[UCI Continental Team|Континентальные команды]]", "Национальная команда", "Национальные команды", "Региональная команда или клуб", "Региональные команды и клубы", "Профессиональная велокоманда", "Профессиональные велокоманды", "Любительская велокоманда", "Любительские велокоманды", "Groupe sportif I", "Groupes sportifs I", "Groupe sportif II", "Groupes sportifs II", "Groupe sportif III", "Groupes sportifs III", "Смешанная велокоманда", "Смешанные велокоманды", "[[UCI Women’s Team|Женская профессиональная команда]]", "[[UCI Women’s Team|Женские профессиональные команды]]", "Женская любительская велокоманда", "Женские любительские велокоманды"},
["ru"] = {"Команда", "Страна", "Код", "WorldTeam", "WorldTeams", "ProTeam", "ProTeams", "Профессиональная континентальная команда", "Профессиональные континентальные команды", "Континентальная команда", "Континентальные команды", "Национальная команда", "Национальные команды", "Региональная команда или клуб", "Региональные команды и клубы", "Профессиональная велокоманда", "Профессиональные велокоманды", "Любительская велокоманда", "Любительские велокоманды", "Groupe sportif I", "Groupes sportifs I", "Groupe sportif II", "Groupes sportifs II", "Groupe sportif III", "Groupes sportifs III", "Смешанная велокоманда", "Смешанные велокоманды", "Женская профессиональная команда", "Женские профессиональные команды", "Женская любительская велокоманда", "Женские любительские велокоманды"},
["ast"] = {"Nome del equipu", "País", "Códigu", "WorldTeam", "WorldTeams", "ProTeam", "ProTeams", "Equipu continental profesional", "Equipos continentales profesionales", "Equipu continental", "Equipos continentales", "Equipu nacional", "Equipos nacionales", "Equipu rexonal y de club", "Equipos rexonales y de clubes", "Equipu ciclista profesional", "Equipos ciclistes profesionales", "Equipu ciclista aficionáu", "Equipos ciclistes aficionaos", "Grupu deportivu I", "Grupos deportivos I", "Grupu deportivu II", "Grupos deportivos II", "Grupu deportivu III", "Grupos deportivos III", "Equipu mestu", "Equipos mestos", "Equipu femenín", "Equipos femeninos", "Equipu femenín de ciclismu amateur", "Equipos femeninos de ciclismu amateur"},
["ast"] = {"Nome del equipu", "País", "Códigu", "WorldTeam", "WorldTeams", "ProTeam", "ProTeams", "Equipu continental profesional", "Equipos continentales profesionales", "Equipu continental", "Equipos continentales", "Equipu nacional", "Equipos nacionales", "Equipu rexonal y de club", "Equipos rexonales y de clubes", "Equipu ciclista profesional", "Equipos ciclistes profesionales", "Equipu ciclista aficionáu", "Equipos ciclistes aficionaos", "Grupu deportivu I", "Grupos deportivos I", "Grupu deportivu II", "Grupos deportivos II", "Grupu deportivu III", "Grupos deportivos III", "Equipu mestu", "Equipos mestos", "Equipu femenín", "Equipos femeninos", "Equipu femenín de ciclismu amateur", "Equipos femeninos de ciclismu amateur"},
}
}
Línia 3.101: Línia 3.110:
end
end


local function typeofstage(x, typ)
local function typeofstage(x, typ, noborder)
-- plain, hilly, inter, ... must be "" or "any text"
-- plain, hilly, inter, ... must be "" or "any text"
-- l10nDef[""] = {plain = "", hilly="", inter='', mount='', time_prologue='', time_team='', time_indiv='', uphill='', rest=''}
-- l10nDef[""] = {plain = "", hilly="", inter='', mount='', time_prologue='', time_team='', time_indiv='', uphill='', rest=''}
Línia 3.135: Línia 3.144:
if not l10n then l10n = l10nDef["en"] end -- default
if not l10n then l10n = l10nDef["en"] end -- default


local border
if x=='plain stage' then return "[[File:Plainstage.svg|border|right|20px|"..l10n.plain.."]]" end
if x=='hilly stage' then return "[[File:Hillystage.svg|border|right|20px|"..l10n.hilly.."]]" end
if noborder then border="" else border="|border|right" end
if x=='intermediate stage' then return "[[File:Mediummountainstage.svg|right|border|20px|"..l10n.inter.."]]" end
if x=='mountain stage' then return "[[File:Mountainstage.svg|border|right|20px|"..l10n.mount.."]]" end
if x=='plain stage' then return "[[File:Plainstage.svg"..border.."|20px|"..l10n.plain.."]]" end
if x=='uphill time trial stage' then return "[[File:Mountain Time Trial Stage.svg|border|right|20px|"..l10n.uphill.."]]" end
if x=='hilly stage' then return "[[File:Hillystage.svg"..border.."|20px|"..l10n.hilly.."]]" end
if x=='rest day' then return "[[File:Stage rest day.svg|border|right|20px|"..l10n.rest.."]]" end
if x=='intermediate stage' then return "[[File:Mediummountainstage.svg"..border.."|20px|"..l10n.inter.."]]" end
if x=='mountain stage' then return "[[File:Mountainstage.svg"..border.."|20px|"..l10n.mount.."]]" end
if x=='uphill time trial stage' then return "[[File:Mountain Time Trial Stage.svg"..border.."|20px|"..l10n.uphill.."]]" end
if x=='rest day' then return "[[File:Stage rest day.svg"..border.."|20px|"..l10n.rest.."]]" end
if x=='time trial stage' then
if x=='time trial stage' then
if typ==2348250 then return "[[File:Team Time Trial Stage.svg|right|20px|"..l10n.time_team.."]]" end
if noborder then border="" else border="|right" end
if typ==2266066 then return "[[File:Time Trial.svg|right|20px|"..l10n.time_indiv.."]]" end
if typ==2348250 then return "[[File:Team Time Trial Stage.svg"..border.."|20px|"..l10n.time_team.."]]" end
if typ==485321 then return "[[File:Time Trial.svg|right|20px|"..l10n.time_prologue.."]]" end
if typ==2266066 then return "[[File:Time Trial.svg"..border.."|20px|"..l10n.time_indiv.."]]" end
if typ==485321 then return "[[File:Time Trial.svg"..border.."|20px|"..l10n.time_prologue.."]]" end
end
end
end
end
Línia 3.208: Línia 3.221:
end
end


local function typeofstagelogo(stageID)
local function typeofstagelogo(stageID, noborder)
local sType
local sType
p = mw.wikibase.getBestStatements(stageID, 'P31') -- P31 is 'instance of'
p = mw.wikibase.getBestStatements(stageID, 'P31') -- P31 is 'instance of'
Línia 3.214: Línia 3.227:
if t.mainsnak.snaktype == 'value' then
if t.mainsnak.snaktype == 'value' then
local iOf = t.mainsnak.datavalue.value['numeric-id']
local iOf = t.mainsnak.datavalue.value['numeric-id']
if iOf == 20646667 then sType = typeofstage('plain stage') break end
if iOf == 20646667 then sType = typeofstage('plain stage', nil, noborder) break end
if iOf == 20646670 then sType = typeofstage('hilly stage') break end
if iOf == 20646670 then sType = typeofstage('hilly stage', nil,moborder) break end
if iOf == 20680270 then sType = typeofstage('intermediate stage') break end
if iOf == 20680270 then sType = typeofstage('intermediate stage', nil,noborder) break end
if iOf == 20646668 then sType = typeofstage('mountain stage') break end
if iOf == 20646668 then sType = typeofstage('mountain stage',nil, noborder) break end
if iOf == 485321 then sType = typeofstage('time trial stage', 485321) break end -- prologue
if iOf == 485321 then sType = typeofstage('time trial stage', 485321, noborder) break end -- prologue
if iOf == 2266066 then sType = typeofstage('time trial stage', 2266066) break end -- individual time trial
if iOf == 2266066 then sType = typeofstage('time trial stage', 2266066, noborder) break end -- individual time trial
if iOf == 2348250 then sType = typeofstage('time trial stage', 2348250) break end -- team time trial
if iOf == 2348250 then sType = typeofstage('time trial stage', 2348250, noborder) break end -- team time trial
if iOf == 20679712 then sType = typeofstage('uphill time trial stage') break end
if iOf == 20679712 then sType = typeofstage('uphill time trial stage', nil, noborder) break end
end
end
end
end
return sType or ''
return sType or ''
end

local function getStageLabel(inp)
local a
local b=''
local this_label=''
if inp then
a, _ = string.gsub(inp, "%a", "") -- 20, not 20a
if string.find(inp, "%a") then
b = string.sub(inp, string.find(inp, "%a"))
end
if inp == "0" then
this_label = func_prologue()
else
this_label = stageLink(inp, a, b)
end
end
return this_label
end

--[[ Make a table row for infoboxes with links to previous and next ]]
local function getPreviousNextLine(raceID, stage)
local previousID = firstValue(raceID, 'P155', 'id') -- P155 is 'follows'
local nextID = firstValue(raceID, 'P156', 'id') -- P156 is 'followed by'
if not nextID or not previousID then
for _, s in statements(raceID, 'P3450') do -- for items using P3450
local q = s.qualifiers
if q then
if not previousID and q.P155 and q.P155[1] and q.P155[1].snaktype == 'value' then
previousID = q.P155[1].datavalue.value.id
end
if not nextID and q.P156 and q.P156[1] and q.P156[1].snaktype == 'value' then
nextID = q.P156[1].datavalue.value.id
end
end
end
end
if not previousID and not nextID then
return ''
end

local previousText, nextText = '', ''
local this_label
if previousID then
if stage then
local series_ordinal= firstValue(previousID, 'P1545', 'value')
this_label=getStageLabel(series_ordinal)
else
this_label = getYear(previousID)
end
local link = wikibase.getSitelink(previousID)
if link then
previousText = '<span style="color:#3366CC">[[' .. link .. '|&#x25C0; ' .. this_label .. ']]</span>'
else
previousText = '<span style="color:#3366CC">&#x25C0;</span> ' .. this_label
end
end
if nextID then
if stage then
local series_ordinal= firstValue(nextID, 'P1545', 'value')
this_label=getStageLabel(series_ordinal)
else
this_label = getYear(nextID)
end
local link = wikibase.getSitelink(nextID)
if link then
nextText = '<span style="color:#3366CC">[[' .. link .. '|' .. this_label .. ' &#x25B6;]]</span>'
else
nextText = this_label .. ' <span style="color:#3366CC">&#x25B6;</span>'
end
end
local direction = contentLanguage:getDir()
local outputTable = mw.html.create('tr')
local tCell=outputTable:tag('td')
tCell:cssText("text-align:" .. ((direction == 'ltr') and 'left' or 'right')):wikitext(previousText)
if stage ~= nil and wiki=="ar" then
tCell:css('width','50%')
end
tCell=outputTable:tag('td')
:cssText("text-align:" .. ((direction == 'ltr') and 'right' or 'left')):wikitext( nextText)
if stage ~= nil and wiki=="ar" then
tCell:css('width','50%')
end
return outputTable
end
end


Línia 3.247: Línia 3.345:
return race_reference_translate(wiki, 1) .. table.concat(links)
return race_reference_translate(wiki, 1) .. table.concat(links)
elseif #links > 1 then
elseif #links > 1 then
return race_reference_translate(wiki, 1) .. table.concat(links)
return race_reference_translate(wiki, 2) .. table.concat(links)
else
else
return ''
return ''
Línia 3.255: Línia 3.353:
--=== B) Calendar ===
--=== B) Calendar ===
function p.calendarcustom(frame)
function p.calendarcustom(frame)
----- function to display calendar óf any competition -----
----- function to display calendar of any competition -----
local function getargs(frame, fieldname, headertemp, tempdic)
----- based on victories function -----
local argindex=tempdic[fieldname][1]
----- author: psemdel -----

local calendarID, countrycolumn, numberingtemp, displayclasstemp,onlywinnertemp, displayteamtemp, displayleadertemp
if frame.args[argindex] ~= nil and tonumber(frame.args[argindex]) ==1 then
local headertemp, data_typetemp={}, {}
tempdic[fieldname][3]= tempdic[fieldname][4]
local ll=1
table.insert(headertemp, tempdic[fieldname][2])
end
return headertemp, tempdic
end
-- position in args, header_column, default value,other value
local headertemp={2} --date
local tempdic = {
['numbering']={2, 3, false, true},
['displayclass']={4, 6, false, true},
['displayleader']={6, 10, false, true}
}

if wiki == "ar" and string.match(frame:getParent():getTitle(), '%P+') == mw.site.namespaces.Template.name
if wiki == "ar" and string.match(frame:getParent():getTitle(), '%P+') == mw.site.namespaces.Template.name
then frame = frame:getParent() end
then frame = frame:getParent() end


if frame.args[1] ~= nil then calendarID = string.gsub(frame.args[1], "%c", "") end
if frame.args[1] ~= nil then calendarID = string.gsub(frame.args[1], "%c", "") end
--date
headertemp[ll]=2
data_typetemp[ll] = ''
ll=ll+1


headertemp, tempdic= getargs(frame, 'numbering', headertemp, tempdic)
numberingtemp=false
countrycolumn=2
if tempdic['numbering'][3] then countrycolumn=3 else countrycolumn=2 end
if frame.args[2] ~= nil and tonumber(frame.args[2]) ==1 then
numberingtemp =true
headertemp[ll]=3
data_typetemp[ll] = ''
countrycolumn=3
ll=ll+1
end


local no_countrytemp={}
local no_countrytemp={}
if frame.args[3] ~= nil and tonumber(frame.args[3]) ==1 then no_countrytemp={wiki} end
if frame.args[3] ~= nil and tonumber(frame.args[3]) ==1 then no_countrytemp={wiki} end
-- country --
-- country --
headertemp[ll]=5
table.insert(headertemp, 5)
data_typetemp[ll] = ''
ll=ll+1

--race--
--race--
headertemp[ll]=4
table.insert(headertemp, 4)
data_typetemp[ll] = ''
ll=ll+1


headertemp, tempdic= getargs(frame, 'displayclass', headertemp, tempdic)
displayclasstemp =false
if frame.args[4] ~= nil and tonumber(frame.args[4]) ==1 then
local onlywinnertemp =1
displayclasstemp =true
if frame.args[5] ~= nil and tonumber(frame.args[5]) ==1 then
headertemp[ll]=6
onlywinnertemp =0
data_typetemp[ll] = ''
ll=ll+1
end
end
table.insert(headertemp, 7) --winner

if frame.args[5] ~= nil then
if onlywinnertemp==0 then
table.insert(headertemp, 8)
if tonumber(frame.args[5]) ==1 then
table.insert(headertemp, 9)
onlywinnertemp =0
headertemp[ll]=7 --winner
data_typetemp[ll] = ''
ll=ll+1
headertemp[ll]=8 --second
data_typetemp[ll] = ''
ll=ll+1
headertemp[ll]=9 --third
data_typetemp[ll] = ''
ll=ll+1
else
onlywinnertemp =1
headertemp[ll]=7
data_typetemp[ll] = ''
ll=ll+1
end
else
onlywinnertemp=1
headertemp[ll]=7
data_typetemp[ll] = ''
ll=ll+1
end
end
headertemp, tempdic= getargs(frame, 'displayleader', headertemp, tempdic)


displayleadertemp =false
local displayteamtemp =false
if frame.args[6] ~= nil and tonumber(frame.args[6]) ==1 then
displayleadertemp=true
headertemp[ll]=10
data_typetemp[ll] = ''
ll=ll+1
end

displayteamtemp =false
if frame.args[7] ~= nil and tonumber(frame.args[7]) ==1 then displayteamtemp =true end
if frame.args[7] ~= nil and tonumber(frame.args[7]) ==1 then displayteamtemp =true end

local titletemp=wikibase.getLabel(calendarID)
local data_typetemp={}
for ii=1,#headertemp do
table.insert(data_typetemp,'')
end


local s = {
local s = {
Línia 3.342: Línia 3.412:
header_1 = 1000, -- translation 1 in function Calendar_translate is printed in the upper part of the table header
header_1 = 1000, -- translation 1 in function Calendar_translate is printed in the upper part of the table header
header_2 = headertemp,-- translations 2, 3, 4, 5, 6 in function Calendar_translate are printed in this order
header_2 = headertemp,-- translations 2, 3, 4, 5, 6 in function Calendar_translate are printed in this order
title=titletemp, -- in the lower part of the table header. The second value 3 in {4, 3} tells where the icon will go.
title=wikibase.getLabel(calendarID), -- in the lower part of the table header. The second value 3 in {4, 3} tells where the icon will go.
country_column = countrycolumn,
country_column = countrycolumn,
data_sort_type = data_typetemp, -- see https://meta.wikimedia.org/wiki/Help:Sorting
data_sort_type = data_typetemp, -- see https://meta.wikimedia.org/wiki/Help:Sorting
Línia 3.349: Línia 3.419:
no_country = no_countrytemp,
no_country = no_countrytemp,
only_winner = onlywinnertemp,
only_winner = onlywinnertemp,
numbering = numberingtemp,
numbering = tempdic['numbering'][3],
error_message = 0,
error_message = 0,
displayed_class =nil,
displayed_class =nil,
displayteam=displayteamtemp,
displayteam=displayteamtemp,
displayclass=displayclasstemp,
displayclass= tempdic['displayclass'][3],
leadercolumn=displayleadertemp,
leadercolumn= tempdic['displayleader'][3],
frame=frame
frame=frame
}
}
return tableA(s, calendar_main(s))
return calendar_main(s, tableA(s))
end
end


Línia 3.364: Línia 3.434:
----- based on WWTcalendar function -----
----- based on WWTcalendar function -----
----- author: Mr. Ibrahem -----
----- author: Mr. Ibrahem -----
local calendarID = ""
local calendarID
if wiki == "ar" then frame = frame:getParent() end
if wiki == "ar" then frame = frame:getParent() end
local UCI = {}
local UCI = {}
Línia 3.429: Línia 3.499:
['2020'] = 'Q74279750',
['2020'] = 'Q74279750',
}
}

local header_1_tab = {["WT"]=13 ,["europe"]=14 ,["asia"]=15,["america"]=16 ,["africa"]=17 ,["oceania"]=18, ["WWT"]=11, ["women"]=1}
local header_1_tab = {["WT"]=13 ,["europe"]=14 ,["asia"]=15,["america"]=16 ,["africa"]=17 ,["oceania"]=18, ["WWT"]=11, ["women"]=1}
local display_code_tab= {["WT"]=1 ,["europe"]=2 ,["asia"]=2,["america"]=2 ,["africa"]=2 ,["oceania"]=2, ["WWT"]=1, ["women"]=2}
local header_1_number = 12
local header_1_number = 12
local display_code_tab = {["WT"]=1 ,["europe"]=2 ,["asia"]=2,["america"]=2 ,["africa"]=2 ,["oceania"]=2, ["WWT"]=1, ["women"]=2}
local tempdic
--Can depends on the wiki
local header_2_tab_code1 = {2, 3,5, 4, 7, 8, 9, 10}
local tempdic1 = {
local header_2_tab_code2 = {2, 5, 4, 6, 7}
header_2 = {2, 3,5, 4, 7, 8, 9, 10},
only_winner =0,
local only_winner_code1 = 0
numbering=true,
local only_winner_code2 = 1
displayteam=false,
local numbering_code1 = true
displayclass=false,
local numbering_code2 = false
leadercolumn=true
local displayteam_code1 = false
}
local displayteam_code2 = true
local displayclass_code1 = false
local tempdic2 = {
header_2 = {2, 5, 4, 6, 7},
local displayclass_code2 = true
only_winner =1,
local leadercolumn_code1 = true
numbering=false,
local leadercolumn_code2 = false
displayteam=true,
local display_code, displayclasstemp, displayteamtemp, header_2temp, leadercolumntemp, numberingtemp, only_winnertemp
displayclass=true,
leadercolumn=false
}


for key, v in pairs(UCI) do
for key, v in pairs(UCI) do
if calendarID == "" and frame.args[key] then
if not calendarID and frame.args[key] then
local year = frame.args[key]
local year = frame.args[key]
year = string.gsub(year , "%c", "")
year = string.gsub(year , "%c", "")
Línia 3.462: Línia 3.536:
end
end
end
end
if wiki == "ar" and calendarID == "" then
if not calendarID then return "" end
return ""
end
if display_code == 1 then
if display_code == 1 then
tempdic=tempdic1
header_2temp = header_2_tab_code1
only_winnertemp=only_winner_code1
numberingtemp=numbering_code1
displayteamtemp=displayteam_code1
displayclasstemp=displayclass_code1
leadercolumntemp=leadercolumn_code1
else
else
tempdic=tempdic2
header_2temp = header_2_tab_code2
only_winnertemp=only_winner_code2
numberingtemp=numbering_code2
displayteamtemp=displayteam_code2
displayclasstemp=displayclass_code2
leadercolumntemp=leadercolumn_code2
end
end


Línia 3.484: Línia 3.546:
header_function = calendar_translate, -- translations are in function Calendar_translate
header_function = calendar_translate, -- translations are in function Calendar_translate
header_1 = header_1_number, -- t
header_1 = header_1_number, -- t
header_2 = header_2temp,
header_2 = tempdic.header_2,
-- in the lower part of the table header. The second value 3 in {4, 3} tells where the icon will go.
-- in the lower part of the table header. The second value 3 in {4, 3} tells where the icon will go.
country_column = 3,
country_column = 3,
Línia 3.491: Línia 3.553:
property = 'P527',
property = 'P527',
no_country = no_country_calendar,
no_country = no_country_calendar,
only_winner = only_winnertemp,
only_winner = tempdic.only_winner,
numbering = numberingtemp,
numbering = tempdic.numbering,
error_message = 0,
error_message = 0,
displayed_class = {
displayed_class = {
Línia 3.510: Línia 3.572:
"Q22231118", -- CC
"Q22231118", -- CC
},
},
displayteam=displayteamtemp,
displayteam=tempdic.displayteam,
displayclass=displayclasstemp,
displayclass=tempdic.displayclass,
leadercolumn=leadercolumntemp,
leadercolumn=tempdic.leadercolumn,
frame=frame
frame=frame
}
}
return tableA(s, calendar_main(s))
return calendar_main(s, tableA(s))
end
end


function calendar_main(s)--Display the UCI women calendar of one year
function calendar_main(s, resulttable)--Display the UCI women calendar of one year
localframe=s.frame
localframe=s.frame
local calendarID=s.item
local calendarID=s.item
local sortkey, displayed_class
local sortkey
local t_Body, fn_racetable,fn_datetable, fn_countrytable = {}, {}, {},{}
local tBody = ''
local displayed_class=s.displayed_class
local tableBody, sortindex = {}, {}
if s.displayed_class then displayed_class=s.displayed_class end


local temp=firstValue(calendarID, s.property)
local temp=firstValue(calendarID, s.property)
if temp then else s.error_message = 2 return '' end
if not temp then s.error_message = 2 return '' end


local country=true
local country=getcoutrybool (s.no_country)
for _, value in pairs(s.no_country) do -- get data if country should be printed in this wiki
if value == wiki then country = false end
end
if available_list==false then country=false end --otherwise the display put no "country" column...
if available_list==false then country=false end --otherwise the display put no "country" column...


----- Begin of the main part of the code
----- Begin of the main part of the code
for kk, p527 in statements(calendarID, 'P527') do
if calendarID ~= nil then
local RaceID = p527.mainsnak.datavalue.value.id
local kk=0
---- Create a row ----
local fn_racetable,fn_datetable, fn_countrytable ={}, {},{}
fn_datetable = fn_date(RaceID)
local timeOfRace = fn_datetable[1]
fn_racetable=fn_race(RaceID,displayed_class,s.displayclass,timeOfRace,nil,country)


if fn_racetable[1]~=nil then --otherwise the class is not display
for _, p527 in statements(calendarID, 'P527') do
fn_countrytable=fn_country(RaceID,timeOfRace,country,fn_racetable)
local RaceID = p527.mainsnak.datavalue.value.id
---- Create a row ----
local tRow = mw.html.create('tr'):cssText( "line-height: 1.8em; padding: 5px;")
fn_datetable = fn_date(RaceID)
local dateOfRace = fn_datetable[1]
tRow:node(fn_datetable[2])
sortkey = fn_datetable[3]
fn_racetable=fn_race(RaceID,displayed_class,s.displayclass,dateOfRace,nil,country)
if s.numbering == true then
if fn_racetable[1]~=nil then --otherwise the class is not display
tBody = '<tr style= "line-height: 1.8em; padding: 5px;">'
tRow:tag('td'):cssText("text-align:center;padding:0 0.5em"):wikitext(tostring(kk))
end
tBody = tBody..fn_datetable[2]
sortkey = fn_datetable[3]
tRow:node(fn_countrytable[1])
kk=kk+1 --only if displayed
if s.numbering == true then
if country then
tRow:node(fn_racetable[1])
tBody = tBody..'<td style="text-align:center;padding:0 0.5em">'..tostring(kk).. '</td>'
end
end
fn_countrytable=fn_country(RaceID,dateOfRace,country,fn_racetable[3]) --fn_racetable[1] is parentID
if fn_racetable[2] then tRow:node(fn_racetable[2]) end --class
tRow:node(fn_rider(RaceID,timeOfRace,s.displayteam,s.only_winner))
tBody = tBody..fn_countrytable[1]..fn_racetable[1]
if s.leadercolumn==true then
if fn_racetable[2] then tBody = tBody..fn_racetable[2] end --class
tBody = tBody..fn_rider(RaceID,dateOfRace,s.displayteam,s.only_winner)
tRow:node(fn_rider(RaceID,timeOfRace,s.displayteam,3))
if s.leadercolumn==true then
tBody = tBody..fn_rider(RaceID,dateOfRace,s.displayteam,3)
end
tBody = tBody.. '</tr>'
---- Add the row to the table
local number = #tableBody
--Insertion sort
if number == 0 then
table.insert(sortindex, sortkey)
table.insert(tableBody, tBody)
elseif sortkey >= sortindex[number] then
table.insert(sortindex, sortkey)
table.insert(tableBody, tBody)
else
local done=0
for i=number,1,-1 do
if sortkey >= sortindex[i] then
table.insert(sortindex, i+1, sortkey)
table.insert(tableBody, i+1, tBody)
done=1
break
end
end
if done==0 then --case that the new one is the first
table.insert(sortindex, 1, sortkey)
table.insert(tableBody, 1, tBody)
end
end
end
end
---- Add the row to the table
end
t_Body[#t_Body + 1] = {sortkey, tRow}
return table.concat (tableBody)
end
end -- no calendar
end

return sortandconcat(t_Body, resulttable)
end
end


function p.nationalchampionships(frame)
function p.nationalchampionships(frame)
local calendarroadID, calendarITTID = "",""
local calendarroadID, calendarITTID, year
if wiki == "ar" then
if wiki == "ar" then
frame = frame:getParent()
frame = frame:getParent()
end
end
local UCI, UCIroad, UCIITT = {},{},{}
local UCIroad, UCIITT = {},{}

UCI["women"] = {
['2019'] = 'Q60015262',
['2018'] = 'Q43920899', ['2017'] = 'Q28005879', ['2016'] = 'Q22021840',
['2015'] = 'Q19296998', ['2014'] = 'Q15621925', ['2013'] = 'Q3339162',
['2012'] = 'Q1333003', ['2011'] = 'Q1143844', ['2010'] = 'Q1568490',
['2009'] = 'Q263224', ['2008'] = 'Q826505', ['2007'] = 'Q43286248',
['2006'] = 'Q43286261', ['2005'] = 'Q1335357', ['2004'] = 'Q43286272',
['2003'] = 'Q43286289', ['2002'] = 'Q43286297', ['2001'] = 'Q43286309'
}
UCIroad["women"] = {
UCIroad["women"] = {
['2019'] = 'Q66362617',
['2020']='Q78466304', ['2019'] = 'Q66362617',
['2018'] = 'Q66762475', ['2017'] = 'Q66762546', ['2016'] = 'Q66762540',
['2018'] = 'Q66762475', ['2017'] = 'Q66762546', ['2016'] = 'Q66762540',
['2015'] = 'Q66762534', ['2014'] = 'Q66762524', ['2013'] = 'Q66762521',
['2015'] = 'Q66762534', ['2014'] = 'Q66762524', ['2013'] = 'Q66762521',
Línia 3.616: Línia 3.643:
UCIITT["women"] = {
UCIITT["women"] = {
['2019'] = 'Q66736271',
['2020'] = 'Q78466572', ['2019'] = 'Q66736271',
['2018'] = 'Q66762631', ['2017'] = 'Q66762614', ['2016'] = 'Q66762604',
['2018'] = 'Q66762631', ['2017'] = 'Q66762614', ['2016'] = 'Q66762604',
['2015'] = 'Q66762597', ['2014'] = 'Q66762592', ['2013'] = 'Q66762584',
['2015'] = 'Q66762597', ['2014'] = 'Q66762592', ['2013'] = 'Q66762584',
Línia 3.622: Línia 3.649:
}
}
UCI["men"] = UCI["women"]
UCIroad["men"] = UCIroad["women"]
UCIroad["men"] = UCIroad["women"]
UCIITT["men"] = UCIITT["women"]
UCIITT["men"] = UCIITT["women"]
local year, modetemp
local listOfCalendar={UCIroad, UCIITT}

for key, v in pairs(UCIroad) do
for ii, thisCalendar in pairs(listOfCalendar) do --road/ITT
if calendarroadID == "" and frame.args[key] then
for key, v in pairs(thisCalendar) do --women/men
--mw.log("find arg " .. key)
year = frame.args[key]
if ((ii==1 and calendarroadID==nil) or (ii==2 and calendarITTID ==nil)) and frame.args[key] then
year = string.gsub( year , "%c", "")
year = frame.args[key]
year = string.gsub( year , "%c", "")
modetemp=key
if v[year] then
if v[year] then
calendarroadID = v[year]
if ii==1 then
calendarroadID = v[year]
else
calendarITTID = v[year]
end
end
end
end
end
end
end
end


for key, v in pairs(UCIITT) do
if calendarITTID == "" and frame.args[key] then
--mw.log("find arg " .. key)
year = frame.args[key]
year = string.gsub( year , "%c", "")
modetemp=key
if v[year] then
calendarITTID = v[year]
end
end
end
local s = {
local s = {
header_function = calendar_translate, -- translations are in function Calendar_translate
header_function = calendar_translate, -- translations are in function Calendar_translate
Línia 3.656: Línia 3.676:
country_column = 1,
country_column = 1,
data_sort_type = {'', '', ''}, -- -- see https://meta.wikimedia.org/wiki/Help:Sorting
data_sort_type = {'', '', ''}, -- -- see https://meta.wikimedia.org/wiki/Help:Sorting
item=calendarroadID,
item= calendarroadID,
calendarroadID = calendarroadID,
calendarroadID = calendarroadID,
calendarITTID = calendarITTID,
calendarITTID = calendarITTID,
property = 'P527',
property = 'P527',
year = year,
year = year,
mode = modetemp,
no_country = {}, --no sense here to hide the country
no_country = {}, --no sense here to hide the country
error_message = 0,
error_message = 0,
Línia 3.668: Línia 3.687:
frame = frame
frame = frame
}
}
return tableA(s, nationalchampionships_main(s))
return nationalchampionships_main(s,tableA(s))
end
end


function nationalchampionships_main(s)--Display the list of national champions for one year
function nationalchampionships_main(s, resulttable)--Display the list of national champions for one year
localframe=s.frame
localframe=s.frame
local tableChamp, fn_countrytable, t_Body = {}, {}, {}
local calendarroadID=s.calendarroadID
local timeOfRace ='+'..tostring(s.year).."-01-01T00:00:00Z"
local calendarITTID=s.calendarITTID
local tRace, thereisawinner, parentID, parentParentID, sitelink
local tBody = ''

local tableBody, sortindex, tableChamp, listofsortkey = {}, {}, {}, {}
local temp=firstValue(s.calendarroadID, s.property)
local dateOfRace ='+'..tostring(s.year).."-01-01T00:00:00Z"
local roadraceID,ITTID, tempbool
local ParentID, ParentParentID, sitelink
local temp=firstValue(calendarroadID, s.property)
if temp then else s.error_message = 2 return '' end
if temp then else s.error_message = 2 return '' end


local listOfCalendarID={s.calendarroadID, s.calendarITTID}
--road race
if calendarroadID ~= nil then
for _, p527 in statements(calendarroadID, 'P527') do
roadraceID = p527.mainsnak.datavalue.value.id
sitelink = nil
if s.displaycountrylink then --expensive
ParentID = firstValue(roadraceID, 'P361', 'id') --part of
if ParentID then
ParentParentID = firstValue(ParentID, 'P31', 'id')
if ParentParentID then sitelink = wikibase.getSitelink(ParentParentID) end
end
end
local fn_countrytable = {}
fn_countrytable=fn_country(roadraceID,dateOfRace,s.country)
sortkey=string.gsub(fn_countrytable[2], 'É', 'E') --case États Unis
tRoadrace, tempbool=fn_rider(roadraceID,dateOfRace,s.displayteam,1,true)
tableChamp[sortkey]={}
tableChamp[sortkey][1]=sortkey
tableChamp[sortkey][2]=sitelink
tableChamp[sortkey][3]=fn_countrytable[3]
tableChamp[sortkey][4]=tempbool --display only if there is a winner
tableChamp[sortkey][5]=tRoadrace
tableChamp[sortkey][6]='<td></td>'
table.insert(listofsortkey,sortkey)
end
end


--create the table with the information
--ITT
for ii, thisCalendarID in ipairs(listOfCalendarID) do
if calendarITTID ~= nil then
if thisCalendarID ~= nil then
for _, p527 in statements(calendarITTID, 'P527') do
for _, p527 in statements(thisCalendarID, 'P527') do
ITTID = p527.mainsnak.datavalue.value.id
thisID = p527.mainsnak.datavalue.value.id
local fn_countrytable = {}
fn_countrytable=fn_country(ITTID,dateOfRace,s.country)
fn_countrytable=fn_country(thisID,timeOfRace,s.country)
sortkey=string.gsub(fn_countrytable[2], 'É', 'E') --case États Unis
sortkey=string.gsub(fn_countrytable[2], 'É', 'E') --case États Unis

tITT, tempbool=fn_rider(ITTID,dateOfRace,s.displayteam,1,true)
--init the line
--create the table
if tableChamp[sortkey]==nil then
if tableChamp[sortkey]==nil then
tableChamp[sortkey]={}
tableChamp[sortkey]={}
tableChamp[sortkey][1]=sortkey
tableChamp[sortkey]['countryname']=fn_countrytable[2] --raw
tableChamp[sortkey]['roadwinner']='<td></td>'
if s.displaycountrylink then --expensive
tableChamp[sortkey]['ITTwinner']='<td></td>'
ParentID = firstValue(ITTID, 'P361', 'id') --part of
--look for sitelink to championship
if ParentID then
sitelink=nil --reinit
ParentParentID = firstValue(ParentID, 'P31', 'id')
if s.displaycountrylink then --expensive
if ParentParentID then sitelink = wikibase.getSitelink(ParentParentID) end
parentID = firstValue(thisID, 'P361', 'id') --part of
if parentID then
parentParentID = firstValue(parentID, 'P31', 'id')
if parentParentID then sitelink = wikibase.getSitelink(parentParentID) end
end
end
end
tableChamp[sortkey]['sitelink']=sitelink
tableChamp[sortkey]['flag']=fn_countrytable[3]
end
--fill the table
tRace, thereisawinner=fn_rider(thisID,timeOfRace,s.displayteam,1,true)
if tableChamp[sortkey]['thereisawinner']~=true then --all other cases
tableChamp[sortkey]['thereisawinner']=thereisawinner
end
if ii==1 then
tableChamp[sortkey]['roadwinner']=tRace
else
tableChamp[sortkey]['ITTwinner']=tRace
end
end
tableChamp[sortkey][2]=sitelink
tableChamp[sortkey][3]=fn_countrytable[3]
tableChamp[sortkey][4]=tempbool
tableChamp[sortkey][5]='<td></td>'
table.insert(listofsortkey,sortkey)
end
if not tableChamp[sortkey][4]==1 then
if tempbool==1 then tableChamp[sortkey][4]=1 end
end
end
tableChamp[sortkey][6]=tITT
end
end
end
end


-- structure the display
for ii=1,#listofsortkey,1 do
for key, thisRow in pairs(tableChamp) do
key=listofsortkey[ii]
if tableChamp[key][4]==1 then --there is a winner
if thisRow['thereisawinner'] then --there is a winner
tBody = '<tr style= "line-height: 1.8em; padding: 5px;">'
local tRow = mw.html.create('tr'):cssText( "line-height: 1.8em; padding: 5px;")
if tableChamp[key][2]==nil then
if thisRow['sitelink']~=nil then
tBody='<td>'..tableChamp[key][3]..' '..tableChamp[key][1]..'</td>'..tableChamp[key][5]..tableChamp[key][6]
tRow:tag('td'):wikitext(thisRow['flag']..' [['..thisRow['sitelink']..'|'..thisRow['countryname']..']]')
else
else
tRow:tag('td'):wikitext(thisRow['flag']..' '..thisRow['countryname'])
tBody='<td>'..tableChamp[key][3]..' [['..tableChamp[key][2]..'|'..tableChamp[key][1]..']]</td>'..tableChamp[key][5]..tableChamp[key][6]
end
end
tRow:node(thisRow['roadwinner'])
tBody = tBody.. '</tr>'
tRow:node(thisRow['ITTwinner'])
---- Add the row to the table
t_Body[#t_Body + 1] = {key, tRow}
local number = #tableBody
--Insertion sort
if number == 0 then
table.insert(sortindex, key)
table.insert(tableBody, tBody)
elseif key >= sortindex[number] then
table.insert(sortindex, key)
table.insert(tableBody, tBody)
else
local done=0
for i=number,1,-1 do
if key >= sortindex[i] then
table.insert(sortindex, i+1, key)
table.insert(tableBody, i+1, tBody)
done=1
break
end
end
if done==0 then --case that the new one is the first
table.insert(sortindex, 1, key)
table.insert(tableBody, 1, tBody)
end
end --end sorting
end --no winner
end --no winner
end --end list of key
end --end list of key

return table.concat (tableBody)
return sortandconcat(t_Body, resulttable)
end
end


Línia 3.797: Línia 3.777:
frame=frame
frame=frame
}
}
return tableA(s, victory_main(s))
return victory_main(s ,tableA(s))
end
end


function victory_main(s)
function victory_main(s, resulttable)
localframe=s.frame
localframe=s.frame
local _
local _
Línia 3.808: Línia 3.788:
if temp then else s.error_message = 2 return '' end
if temp then else s.error_message = 2 return '' end


local country = true
local country=getcoutrybool (s.no_country)
for _, value in pairs(s.no_country) do -- get data if country should be printed in this wiki
if value == wiki then country = false end
end
if available_list==false then country=false end
if available_list==false then country=false end


local sortkey
local sortkey
local t_Body, fn_countrytable, fn_datetable, fn_racetable = {}, {}, {}, {}
local tBody = ''
local tableBody, sortindex, fn_countrytable, fn_datetable, fn_racetable = {}, {}, {}, {}, {}


for _, p2522 in statements(s.item, 'P2522') do
for _, p2522 in statements(s.item, 'P2522') do
local RaceID = p2522.mainsnak.datavalue.value.id
local RaceID = p2522.mainsnak.datavalue.value.id
local tRow = mw.html.create('tr'):cssText( "line-height: 1.8em; padding: 5px;")


tBody = '<tr style= "line-height: 1.8em; padding: 5px;">' -- start the table row
fn_datetable = fn_date(RaceID, 'victory')
fn_datetable = fn_date(RaceID, 'victory')
local dateOfRace = fn_datetable[1]
local timeOfRace = fn_datetable[1]
sortkey=fn_datetable[2]
sortkey=fn_datetable[2]
fn_racetable=fn_race(RaceID,nil ,true,dateOfRace, 'victory',country)--displayed_class=nil
fn_racetable=fn_race(RaceID,nil ,true,timeOfRace, 'victory',country)--displayed_class=nil
if fn_racetable[1]~= nil then --otherwise class not to be displayed
if fn_racetable[1]~= nil then --otherwise class not to be displayed
fn_countrytable=fn_country(RaceID,timeOfRace,country,fn_racetable)
tBody = tBody..fn_datetable[2]
fn_countrytable=fn_country(RaceID,dateOfRace,country,fn_racetable[3])
tRow:node(fn_datetable[2])
if country==true then
if country==true then
tBody = tBody..fn_racetable[1]..fn_countrytable[1]
tRow:node(fn_racetable[1]) --race site link is in fn_countrytable
else
tBody = tBody..fn_countrytable[1]..fn_racetable[1]
end
end
tRow:node(fn_countrytable[1]) --country
tBody = tBody..fn_racetable[2]
tRow:node(fn_racetable[2]) --class
tBody = tBody..fn_rider(RaceID,dateOfRace,false,1)
tRow:node(fn_rider(RaceID,timeOfRace,false,1))
tBody = tBody.. '</tr>' -- end the table row
t_Body[#t_Body + 1] = {sortkey, tRow}
end --no winner
end --end list of key
return sortandconcat(t_Body, resulttable)
end


--== Cbis) Functions for infobox
local number = #tableBody
-- functions for both infoboxs
--Insertion sort
local function infoGetOthers(others, entityID)
if number == 0 then
if not others[1].content then --picture
table.insert(sortindex, sortkey)
others[1].content, others[2].content = getImage(entityID) -- picture, caption
table.insert(tableBody, tBody)
elseif sortkey >= sortindex[number] then
table.insert(sortindex, sortkey)
table.insert(tableBody, tBody)
else
local done=0
for i=number,1,-1 do
if sortkey >= sortindex[i] then
table.insert(sortindex, i+1, sortkey)
table.insert(tableBody, i+1, tBody)
done=1
break
end
end
if done==0 then --case that the new one is the first
table.insert(sortindex, 1, sortkey)
table.insert(tableBody, 1, tBody)
end
end
end
end
end

return table.concat (tableBody)
if not others[3].content then -- map
others[3].content = firstValue(entityID, 'P242') -- P242 is 'locator map image'
end
if not others[4].content then -- map
others[4].content = firstValue(entityID, 'P2713') -- sectional_view
end
end
end


local function infoGetCountry(details,index, entityID, timeOfRace)
--== D) Stage infobox
if not details[index].content then -- country
function p.stageinfobox(frame)
-- This function gives countries where the race take place
local tab, countryID
local entityId = frame.args[1]
local country = {}
for _, p17 in statements(entityID, 'P17') do -- P17 is 'country'
local lang = mw.language.getContentLanguage()
local countryID = p17.mainsnak.datavalue.value.id
local timeofrace
country[#country + 1] = flag(countryID, timeOfRace) .. ' ' .. getCountryName(countryID)
local jerseyWPID, jersey_name
end
local t_g = {show=true, name="", icon="", picture="", caption="", course= "", race={}, is_a="", startplace="", endplace="", time="",
if country[1] then
length="", length_unit="", speed="", speed_unit="", elevation="", nr_participants_start="", nr_participants_end="", country={},
if #country > 1 then
series_ordinal_previous="", series_ordinal_next="", map="", sectional_view="",previous="", next=""}
details[index].name = details[index].name_plural
local t_s = {order={'results', 'classement_gen', 'classement_annex'},
results={show=false, header=15, order = {'first','second','third','winner_fighting','winner_fighting2','cima_coppi','cima_pantani'},
-- name rider, stageinfobox_translate number, gender, jersey, team name, time, time gap, points, speed, rank
first={"", 16, "", "", "", "", "", "", "", ""},
second={"", 17, "", "", "", "", "", "", "", ""},
third={"", 18, "", "", "", "", "", "", "", ""},
winner_fighting={"", 19, "", "", "", "", "", "", "", ""},
winner_fighting2={"", 19, "", "", "", "", "", "", "", ""}, -- two winner_fighting possible
cima_coppi={"", 40, "", "", "", "", "", "", "", ""},
cima_pantani={"", 41, "", "", "", "", "", "", "", ""}},

classement_gen={show=false, header=20, order = {"leader", "deuxieme", "troisieme"},
-- name rider, stageinfobox_translate number, gender, jersey, team name, time, time gap, points, speed, rank
leader={"", 21, "", "", "", "", "", "", "", ""},
deuxieme={"", 22, "", "", "", "", "", "", "", ""},
troisieme={"", 23, "", "", "", "", "", "", "", ""}},

classement_annex={show=false, header=24, order={"points","montagne","sprints","jeune","super_combatif","combine",
"stage_volantes","regularite","azzurri_ditalia","breakaway","equipe","equipe_points"},
-- name rider, stageinfobox_translate number, gender, jersey, team name, time, time gap, points, speed, rank
points={"", 25, "", "", "", "", "", "", "", ""},
montagne={"", 26, "", "", "", "", "", "", "", ""},
sprints={"", 27, "", "", "", "", "", "", "", ""},
jeune={"", 28, "", "", "", "", "", "", "", ""},
super_combatif={"", 29, "", "", "", "", "", "", "", ""},
combine={"", 30, "", "", "", "", "", "", "", ""},
stage_volantes={"",31,"","","","","","", "", ""},
regularite={"",32,"","","","","","", "", ""},
azzurri_ditalia={"",42,"","","","","","", "", ""},
breakaway={"",43,"","","","","","", "", ""},
equipe={"", 33, "", "", "", "", "", "", "", ""},
equipe_points={"", 34, "", "", "", "", "", "", "", ""}}
}

if type(entityId) ~= 'string' then error( 'parameter must be a string') end
if not entityId:match( 'Q%d+' ) then error ( 'parameter must be a valid Wikidata item (ex: Q42)' ) end

t_g.name = getLabelFallback(entityId, {wikilang, 'en', 'fr'})
if wiki == 'fr' and t_g.name ~= "" then t_g.name= mw.ustring.gsub(t_g.name, "^(%d+)([re]+)", "%1<sup>%2</sup> ") end
t_g.name= mw.ustring.gsub(t_g.name, "^(%a)",function (x) return mw.ustring.upper(x) end)

local temp = firstValue(entityId, 'P31','id')
if temp and temp ~= 'Q18131152' then t_g.is_a = temp end

if t_g.is_a=='Q2266066' or t_g.is_a=='Q2348250' or t_g.is_a=='Q485321' then t_g.icon = " [[File:Cycling (track) pictogram.svg|35px]]"
else t_g.icon = " [[File:Cycling (road) pictogram.svg|35px]]" end

local p18 = wikibase.getAllStatements(entityId, 'P18')
if p18[1] and p18[1].mainsnak.snaktype == 'value' and t_g.picture == "" then
t_g.picture = p18[1].mainsnak.datavalue.value
local q = p18[1].qualifiers
if q and q.P2096 and q.P2096[1].snaktype == 'value' then
for _, q2096 in pairs(q.P2096) do
if q2096.datavalue.value.language == wikilang then t_g.caption = q2096.datavalue.value.text end
end
end
details[index].content = table.concat(country, '<br/>')
end
end
end
end
local function infoGetStartEnd(details,index, entityID)
if not details[index].content then -- start place
local place = firstValue(entityID, 'P1427', 'id') -- P1427 is 'start point'
details[index].content = place and getPlaceLink(place)
end
end


if not details[index+1].content then -- end place
-- Function that give the starting place of a race
local place = firstValue(entityId, 'P1427', 'id') -- P1427 is 'start point'
local place = firstValue(entityID, 'P1444', 'id') -- P1444 is 'destination point'
t_g.startplace = place or "" -- and getPlaceLink(place)
details[index+1].content = place and getPlaceLink(place)
place = firstValue(entityId, 'P1444', 'id')
t_g.endplace = place or "" -- and getPlaceLink(place)

-- This function give a format to dates when P585 (date) is used in a single day race
local pTime = firstValue(entityId, 'P585', 'time')
if pTime then
t_g.time = func_date(pTime, 'long')
timeofrace = pTime
end
end
end


local function infoGetParticipants(details,index, entityID)
-- Function that give the number of cyclists at the beginning and at the finishing of a race
-- Function that give the number of cyclists at the beginning and at the finishing of a race
for _, p1132 in statements(entityId, 'P1132') do -- P1132 is 'number of participants'
for _, p1132 in statements(entityID, 'P1132') do -- P1132 is 'number of participants'
local amount = tonumber(p1132.mainsnak.datavalue.value.amount) -- tonumber to remove starting '+'
local amount = tonumber(p1132.mainsnak.datavalue.value.amount) -- tonumber to remove starting '+'
for _, q in qualifiers(p1132, 'P276') do -- P276 is 'location'
for _, q in qualifiers(p1132, 'P276') do -- P276 is 'location'
local location = q.value['numeric-id']
local location = q.value['numeric-id']
if location == 529711 then -- Q529711 is 'beginning'
if location == 529711 then -- Q529711 is 'beginning'
if t_g.nr_participants_start=="" then t_g.nr_participants_start = amount end -- participants at start
if not details[index].content then details[index].content = amount end -- participants at start
elseif location == 12769393 then -- Q12769393 is 'end'
elseif location == 12769393 then -- Q12769393 is 'end'
if t_g.nr_participants_end=="" then t_g.nr_participants_end = amount end -- participants at end
if not details[index+1].content then details[index+1].content = amount end -- participants at end
end
end
end
end
end
end
end


local function infoInitTab(width, name, icon)
local kmdistance
if width==nil then width= '320px' end
t_g.length, kmdistance = getDistance(entityId, true)
t_g.length=t_g.length or ""
local tab = mw.html.create('table')
t_g.speed = getSpeed(entityId, true,kmdistance,'P2417') or ""
if wiki == "eo" then
t_g.elevation = getElevation(entityId)
tab:cssText(standardtablecss):css('width','23em')
:addClass('infobox')
else
tab:attr('cellpadding','4')
:attr('cellspacing','0')
:cssText(standardtablecss)
:cssText("float:"..floatinfobox.."; max-width:"..width)
end
local tCell=tab:tag('tr'):tag('td'):attr('colspan','2')
:cssText('border-bottom:5px solid white; font-size:175%; background:#FFDF80; text-align:center')
local topTable = tCell:tag('table')
:cssText('width:100%')
local tRow=topTable:tag('tr')
tRow:tag('td'):wikitext(name or '')
tRow:tag('td'):wikitext(icon or '')
return tab
end


local function infoFillOthersDetails(tab, others, details,title)
-- This function gives countries where the race take place
if others[1].content then -- picture
local countrytemp = {}
tab:tag('tr'):tag('td'):attr('colspan','2'):css('text-align','center')
for _, p17 in statements(entityId, 'P17') do -- P17 is 'country'
:wikitext("[[File:" .. others[1].content .."|center|300px]]")
countryID = p17.mainsnak.datavalue.value.id
if others[2].content then -- caption
countrytemp[#countrytemp + 1] = flag(countryID, timeofrace) .. ' ' .. getCountryName(countryID)
tab:tag('tr'):tag('td'):attr('colspan','2'):css('text-align','center'):css('font-size','80%')
:wikitext(others[2].content)
end
end
end
tab:tag('tr'):tag('td'):attr('colspan','2'):css('text-align','center'):css('background-color','#FFDF80')
t_g.country=countrytemp
:css('font-weight','bold')
:wikitext(title)
for _, row in ipairs(details) do
if row.content then
tRow= tab:tag('tr'):css('vertical-align','top')
tRow:tag('td'):css('width','40%'):css('font-weight','bold')
:wikitext(row.name)
tRow:tag('td'):wikitext(row.content)
end
end
end


local function infoFillOthersMap(tab, others)
temp = firstValue(entityId, 'P242', 'id')
if others[3].content then -- map
if temp ~= nil and t_g.map == "" then t_g.map = temp end
tab:tag('tr'):tag('td'):attr('colspan','2'):css('text-align','center')
temp = firstValue(entityId, 'P2713', 'id')
:wikitext("[[File:".. others[3].content .. "|center|300px]]")
if temp ~= nil and t_g.sectional_view == "" then t_g.sectional_view= temp end
end
if others[4].content then -- map
tab:tag('tr'):tag('td'):attr('colspan','2'):css('text-align','center')
:wikitext("[[File:".. others[4].content .. "|center|300px]]")
end
end


local function wdDoc(tab, s, translation, ID)
temp = firstValue(entityId, 'P155', 'id')
tab:tag('tr'):tag('td'):attr('colspan','2')
if temp ~= nil and t_g.previous == "" then
:cssText('text-align:right; border-top:3px solid #FFDF80; font-size:75%')
t_g.previous = temp
:wikitext("[[" .. s .. "|" .. translation .. "]] [[File:Wikidata-logo S.svg|12px|link=d:".. ID .."]]")
local temp2 = firstValue(temp, 'P1545', 'value')
end
if temp2 ~= nil then t_g.series_ordinal_previous =temp2 end

--== D) Stage infobox
function p.stageinfobox(frame)
local details = {
{ name = stageinfobox_translate(2)}, -- course / not used
{ name = stageinfobox_translate(2)}, -- competition
{ name = stageinfobox_translate(3), name_plural = infobox_translate(4)}, -- stage type
{ name = stageinfobox_translate(4), name_plural = infobox_translate(7)}, -- date
{ name = stageinfobox_translate(6)}, -- distance
{ name = stageinfobox_translate(7), name_plural = infobox_translate(10)}, -- country
{ name = stageinfobox_translate(9)}, -- start place
{ name = stageinfobox_translate(10)}, -- endplace
{ name = stageinfobox_translate(11)}, -- participants at start
{ name = stageinfobox_translate(12)}, -- participants at end
{ name = stageinfobox_translate(13)}, -- speed
{ name = stageinfobox_translate(44)}, -- elevation
{ name = infobox_translate(32), special = true}, -- special 1
{ name = infobox_translate(33), special = true}, -- special 2
}
local others = {
{ name = infobox_translate(29)}, -- picture
{ name = infobox_translate(30)}, -- caption
{ name = infobox_translate(31)}, -- map
{ name = 'sectional'}
}
--begin of the function
local t_P642 = {
[20882747]={'results', 'first'},
[20882748]={'results', 'second'},
[20882749]={'results', 'third'},
[21686770]={'results', 'winner_fighting'},
[2250962]={'results', 'cima_coppi'},
[10452933]={'results', 'cima_pantani'},
[20882763]={'gen', 'leader'},
[20882764]={'gen', 'deuxieme'},
[20882765]={'gen', 'troisieme'},
[20883213]={'annex', 'montagne'},
[20883140]={'annex', 'jeune'},
[20883008]={'annex', 'points'},
[20883329]={'annex', 'sprints'},
[20893984]={'annex', 'super_combatif'},
[20965880]={'annex', 'combine'},
[27104688]={'annex', 'stage_volantes'},
[27104684]={'annex', 'regularite'},
[20882922]={'annex', 'equipe'},
[27104271]={'annex', 'equipe_points'},
[20882667]={'gen', 'leader'},
[20882668]={'gen', 'deuxieme'},
[20882669]={'gen', 'troisieme'},
[20883212]={'annex', 'montagne'},
[20883139]={'annex', 'jeune'},
[20883007]={'annex', 'points'},
[20883328]={'annex', 'sprints'},
[20893983]={'annex', 'super_combatif'},
[20893979]={'annex', 'combine'},
[27067359]={'annex', 'stage_volantes'},
[27067170]={'annex', 'regularite'},
[27907747]={'annex', 'azzurri_ditalia'},
[27907748]={'annex', 'azzurri_ditalia'},
[27907714]={'annex', 'breakaway'},
[27907715]={'annex', 'breakaway'},
[20882921]={'annex', 'equipe'},
[27104269]={'annex', 'equipe_points'}
}
local entityID = mw.text.trim(frame.args[1])
local wikibase = mw.wikibase
if type(entityID) ~= 'string' then error('parameter must be a string') end
if not entityID:match('Q%d+') then error ('parameter must be a valid Wikidata item (ex: Q42)') end

local localframe
if string.match(frame:getParent():getTitle(), '%P+') == mw.site.namespaces.Template.name then
localframe = frame:getParent()
else
localframe = frame
end
end
temp = firstValue(entityId, 'P156', 'id')
getLocalContent(details, localframe.args)
if temp ~= nil and t_g.next == "" then
getLocalContent(others, localframe.args)
t_g.next = temp

local temp2 = firstValue(temp, 'P1545', 'value')
local timeOfRace
if temp2 ~= nil then t_g.series_ordinal_next =temp2 end
local temp = firstValue(entityID, 'P31','id')
icon = ''
if temp and temp ~= 'Q18131152' then
if temp=='Q2266066' or temp=='Q2348250' or temp=='Q485321' then
icon = " [[File:Cycling (track) pictogram.svg|35px]]"
else
icon = " [[File:Cycling (road) pictogram.svg|35px]]"
end
details[3].content = typeofstagelogo(entityID, true).." "..WPlinkpure(temp)
end
end
local name = getLabelFallback(entityID, {wikilang, 'en', 'fr', 'de'}) or ''
if wiki == 'fr' and name ~= nil then
name= mw.ustring.gsub(name, "^(%d+)([re]+)", "%1<sup>%2</sup> ")
end
name= mw.ustring.gsub(name, "^(%a)",function (x) return mw.ustring.upper(x) end)
infoGetOthers(others, entityID)


--name
local t_P642 = {[20882747]={'results', 'first'}, [20882748]={'results', 'second'}, [20882749]={'results', 'third'}, [21686770]={'results', 'winner_fighting'},
if course==nil then
[2250962]={'results', 'cima_coppi'}, [10452933]={'results', 'cima_pantani'},
temp = firstValue(entityID, 'P1545')
[20882763]={'classement_gen', 'leader'}, [20882764]={'classement_gen', 'deuxieme'}, [20882765]={'classement_gen', 'troisieme'},
if temp then
[20883213]={'classement_annex', 'montagne'}, [20883140]={'classement_annex', 'jeune'}, [20883008]={'classement_annex', 'points'},
details[2].content =getStageLabel(temp)
[20883329]={'classement_annex', 'sprints'}, [20893984]={'classement_annex', 'super_combatif'}, [20965880]={'classement_annex', 'combine'},
raceId = firstValue(entityID, 'P361','id')
[27104688]={'classement_annex', 'stage_volantes'}, [27104684]={'classement_annex', 'regularite'}, [20882922]={'classement_annex', 'equipe'},
if raceId then
[27104271]={'classement_annex', 'equipe_points'},
details[2].content = details[2].content or '' .. '، '.. WPlinkpure(raceId)
[20882667]={'classement_gen', 'leader'}, [20882668]={'classement_gen', 'deuxieme'}, [20882669]={'classement_gen', 'troisieme'},
for k, p31 in statements(raceId, 'P31') do
[20883212]={'classement_annex', 'montagne'}, [20883139]={'classement_annex', 'jeune'}, [20883007]={'classement_annex', 'points'},
if race==nil then race={} end
[20883328]={'classement_annex', 'sprints'}, [20893983]={'classement_annex', 'super_combatif'}, [20893979]={'classement_annex', 'combine'},
race[k] = p31.mainsnak.datavalue.value.id --for the jersey
[27067359]={'classement_annex', 'stage_volantes'}, [27067170]={'classement_annex', 'regularite'},
end
[27907747]={'classement_annex', 'azzurri_ditalia'}, [27907748]={'classement_annex', 'azzurri_ditalia'},
end
[27907714]={'classement_annex', 'breakaway'}, [27907715]={'classement_annex', 'breakaway'},
end
[20882921]={'classement_annex', 'equipe'}, [27104269]={'classement_annex', 'equipe_points'}
end

-- This function give a format to dates when P585 (date) is used in a single day race
local pTime = firstValue(entityID, 'P585', 'time') -- P585 is 'point in time'
if pTime then
details[4].content = func_date(pTime, 'long')
timeOfRace = pTime
end
local kmdistance
if not details[5].content then details[5].content, kmdistance = getDistance(entityID, true) end -- distance
infoGetCountry(details,6, entityID, timeOfRace)
infoGetStartEnd(details,7, entityID)
infoGetParticipants(details,9, entityID)
if not details[11].content then details[11].content = getSpeed(entityID, true, kmdistance, 'P2417') end --speed
if not details[12].content then
local elevation=getElevation(entityID)
if elevation ~= nil then details[12].content =elevation else details[12].content = nil end
end --Elevation

local jerseyWPID, jersey_name
local t_s = {
order={'results', 'gen', 'annex'},
results={show=false,
header=15,
order = {'first','second','third','winner_fighting','winner_fighting2','cima_coppi','cima_pantani'},
first={translation=16},
second={translation=17},
third={translation=18},
winner_fighting={translation=19},
winner_fighting2={translation=19}, -- two winner_fighting possible
cima_coppi={translation=40},
cima_pantani={translation=41}
},
gen={show=false,
header=20,
order = {"leader", "deuxieme", "troisieme"},
leader={translation=21},
deuxieme={translation=22},
troisieme={translation=23}
},
annex={show=false,
header=24,
order={"points","montagne","sprints","jeune","super_combatif","combine",
"stage_volantes","regularite","azzurri_ditalia","breakaway","equipe","equipe_points"},
points={translation=25},
montagne={translation=26},
sprints={translation=27},
jeune={translation=28},
super_combatif={translation=29},
combine={translation=30},
stage_volantes={translation=31},
regularite={translation=32},
azzurri_ditalia={translation=42},
breakaway={translation=43},
equipe={translation=33},
equipe_points={translation=34}
}
}
}


--Winner
--Winner
for _, p1346 in statements(entityId, 'P1346') do
for _, p1346 in statements(entityID, 'P1346') do
local id_speed, id_time, id_time_gap, id_points_a, id_points_b
local id_speed, id_time, id_time_gap, id_points_a, id_points_b, type_ofclas, name_ofclas
local subwinnertable={}
local q = p1346.qualifiers
local q = p1346.qualifiers
local riderId = p1346.mainsnak.datavalue.value.id
local riderId = p1346.mainsnak.datavalue.value.id
Línia 4.022: Línia 4.131:


if riderId ~= nil then
if riderId ~= nil then
subwinnertable = subwinner(riderId, timeofrace, q) --sub function to avoid code in double
local riderLink,riderTeam = subwinner(riderId, timeOfRace, q) --sub function to avoid code in double
local riderLink = subwinnertable[1]
local riderTeam = subwinnertable[2]
-- looks into race item if the winner has a P642 statement for showing the type of winner (points, mountain, ..)
-- looks into race item if the winner has a P642 statement for showing the type of winner (points, mountain, ..)
if q.P642 and q.P642[1].snaktype == 'value' then
if q.P642 and q.P642[1].snaktype == 'value' then
for _, vv in pairs(q.P642) do
for _, vv in pairs(q.P642) do
local qual = vv.datavalue.value['numeric-id']
local qual = vv.datavalue.value['numeric-id']
if riderId~=nil and qual~=nil and deprecated~='deprecated' and t_P642[qual] then
if qual~=nil and deprecated~='deprecated' and t_P642[qual] then
if qual==21686770 and t_s['results']['winner_fighting'][1] ~= "" then t_P642[qual][2] = 'winner_fighting2' end
if qual==21686770 and t_s['results']['winner_fighting'][1] ~= "" then
t_P642[qual][2] = 'winner_fighting2'
end
t_s[t_P642[qual][1]][t_P642[qual][2]][1]=riderLink
t_s[t_P642[qual][1]][t_P642[qual][2]][5]=riderTeam or ""
type_ofclas=t_P642[qual][1] --annex or gen
t_s[t_P642[qual][1]][t_P642[qual][2]][10]=isdisqualified(p1346,q)
name_ofclas=t_P642[qual][2] --name of ranking
local v=t_s[type_ofclas][name_ofclas]
if id_time then t_s[t_P642[qual][1]][t_P642[qual][2]][6]=id_time end
if id_time_gap then t_s[t_P642[qual][1]][t_P642[qual][2]][7]=id_time_gap end
if id_points_a then t_s[t_P642[qual][1]][t_P642[qual][2]][8]=id_points_a end
if id_points_b then t_s[t_P642[qual][1]][t_P642[qual][2]][8]=id_points_b end
if id_speed then t_s[t_P642[qual][1]][t_P642[qual][2]][9]=id_speed end
if qual==27104271 and t_s.classement_annex.equipe_points[1]=="" then t_s.classement_annex.equipe_points[1]=riderId end
if qual==20882922 and t_s.classement_annex.equipe[1]=="" then t_s.classement_annex.equipe[1]=riderId end
t_s[t_P642[qual][1]][t_P642[qual][2]][3] = getgendercode(riderId,'f')
end
end
end
end
end
local rank, deprecated
local order = {'first', 'second', 'third'}


v['link']=riderLink
-- look into P2417, stage classification
v['team']=riderTeam
for _, p2417 in statements(entityId, 'P2417') do
v['rank']=isdisqualified(p1346,q)
local q = p2417.qualifiers
v['time']=id_time
if q.P1352 and q.P1352[1].snaktype == 'value' then
v['gap']=id_time_gap
for _, q1352 in pairs(q.P1352) do
if id_points_a then v['points']=id_points_a end
rank = tonumber(q1352.datavalue.value.amount)
if id_points_b then v['points']=id_points_b end
end
v['speed']=id_speed
if rank == 1 or rank == 2 or rank == 3 then
if qual==27104271 and t_s.annex.equipe_points['link']==nil then
t_s.results[order[rank]][10] = isdisqualified(p2417, q)
t_s.annex.equipe_points['link']=riderId
local thisid= p2417.mainsnak.datavalue.value.id
if isHuman(thisid) then
t_s.results[order[rank]][1] = getRiderLink( thisid, timeofrace)
local p27 = getStatementForTime(thisid, 'P27', timeofrace) --P27 is country of citizenship
if p27 then
countryID = p27.mainsnak.datavalue.value.id
else countryID=nil
end
else
t_s.results[order[rank]][1] = getTeamLinkCat(thisid, timeofrace)
local p1532 = getStatementForTime(thisid, 'P1532', timeofrace) --P1532 is country for sport
if p1532 then
countryID = p1532.mainsnak.datavalue.value.id
else
local p17 = getStatementForTime(thisid, 'P17', timeofrace) --P27 is country of citizenship
if p17 then
countryID = p17.mainsnak.datavalue.value.id
else countryID=nil
end
end
if qual==20882922 and t_s.annex.equipe['link']==nil then
t_s.annex.equipe['link']=riderId
end
v['genre'] = getgendercode(riderId,'f')
end
end
end
end
if countryID then
t_s.results[order[rank]][1] = flag(countryID, timeofrace) .. ' ' .. t_s.results[order[rank]][1]
end
if t_s.results[order[rank]][7] == "" and t_s.results[order[rank]][6] == "" then
t_s.results[order[rank]][7] = qualifieramount(p2417, 'P2911') or ""
end
if t_s.results[order[rank]][7] == "" and t_s.results[order[rank]][6] == "" then
t_s.results[order[rank]][6] = qualifieramount(p2417, 'P2781') or ""
end
if t_s.results[order[rank]][9] == "" then
t_s.results[order[rank]][9] = qualifieramount(p2417, 'P2052') or ""
end
t_s.results[order[rank]][3] = getgendercode(thisid, 'f')
end
end
end
end
end
end
local rank, deprecated, prop, order, thisorder
local listoftable = {'results','gen'}


-- look into P2417, stage classification, then p2321 gen classification
order = {'leader', 'deuxieme', 'troisieme'}
for _, p2321 in statements(entityId, 'P2321') do
for ii, thistable in ipairs(listoftable) do
if ii==1 then
local q = p2321.qualifiers
prop='P2417'
if q.P1352 and q.P1352[1].snaktype == 'value' then
order = {'first', 'second', 'third'}
for _, q1352 in pairs(q.P1352) do
rank = tonumber(q1352.datavalue.value.amount)
end
if rank == 1 or rank == 2 or rank == 3 then
t_s.classement_gen[order[rank]][10] = isdisqualified(p2417, q1352)
local thisid=p2321.mainsnak.datavalue.value.id
t_s.classement_gen[order[rank]][1] = getRiderLink( thisid, timeofrace)
local p27 = getStatementForTime(thisid, 'P27', timeofrace) --P27 is country of citizenship
if p27 then
countryID = p27.mainsnak.datavalue.value.id
end
if countryID then
t_s.classement_gen[order[rank]][1] = flag(countryID, timeofrace) .. ' ' .. t_s.classement_gen[order[rank]][1]
end
if t_s.classement_gen[order[rank]][7] == "" and t_s.classement_gen[order[rank]][6] == "" then
t_s.classement_gen[order[rank]][7] = qualifieramount(p2321, 'P2911') or ""
end
if t_s.classement_gen[order[rank]][7] == "" and t_s.classement_gen[order[rank]][6] == "" then
t_s.classement_gen[order[rank]][6] =qualifieramount(p2321, 'P2781') or ""
end
if t_s.classement_gen[order[rank]][9] == "" then
t_s.classement_gen[order[rank]][9] = qualifieramount(p2321, 'P2052') or ""
end
t_s.classement_gen[order[rank]][3] = getgendercode(thisid, 'f')
end
end
end

local a, b, _
local span1, span2 = "<span style='color:#3366CC'>&#x25C0; </span>", "<span style='color:#3366CC'> &#x25B6;</span>"

if t_g.series_ordinal_previous ~= "" then
a, _ = string.gsub(t_g.series_ordinal_previous, "%a", "") -- 20, not 20a
if string.find(t_g.series_ordinal_previous, "%a") then b = string.sub(t_g.series_ordinal_previous, string.find(t_g.series_ordinal_previous, "%a"))
else b = "" end
local label_previous = stageLink(t_g.series_ordinal_previous, a, b)
if t_g.series_ordinal_previous == "0" then label_previous = func_prologue() end
if mw.wikibase.sitelink( t_g.previous ) ~= nil then
local k = WPlinkpure(t_g.previous)
local i, _ = string.find(k, "|")
local j, _ = string.find(k, "]")
if i ~= nil and j ~= nil then
t_g.previous = string.sub(k, 1, i) .. span1 .. label_previous .. string.sub(k, j)
if wiki == "ar" then t_g.previous = string.sub(k, 1, i) .. span2 .. label_previous .. string.sub(k, j) end
else
t_g.previous = span1 .. label_previous
if wiki == "ar" then t_g.previous = span2 .. label_previous end
end
else
else
prop='P2321'
t_g.previous = span1 .. label_previous
order = {'leader', 'deuxieme', 'troisieme'}
if wiki == "ar" then t_g.previous = span2 .. label_previous end
end
end
else t_g.previous = ''
for _, p2417 in statements(entityID, prop) do
end
local q = p2417.qualifiers
if q.P1352 and q.P1352[1].snaktype == 'value' then
for _, q1352 in pairs(q.P1352) do
rank = tonumber(q1352.datavalue.value.amount)
end
if rank == 1 or rank == 2 or rank == 3 then
thisorder=order[rank]
local v=t_s[thistable][thisorder]
v['rank'] = isdisqualified(p2417, q)
local thisid= p2417.mainsnak.datavalue.value.id
v['link'],_ = subwinner(thisid, timeOfRace, q)


if v['gap'] == nil and v['time'] == nil then
if t_g.series_ordinal_next~= '' then
v['gap'] = qualifieramount(p2417, 'P2911')
a, _ = string.gsub(t_g.series_ordinal_next, "%a", "") -- 20, not 20a
end
if string.find(t_g.series_ordinal_next, "%a") then b = string.sub(t_g.series_ordinal_next, string.find(t_g.series_ordinal_next, "%a"))
if v['gap'] == nil and v['time'] == nil then
else b = "" end
v['time'] = qualifieramount(p2417, 'P2781')
local label_next = stageLink(t_g.series_ordinal_next, a, b)
end
if t_g.series_ordinal_next == "0" then label_next = func_prologue() end
v['speed'] = qualifieramount(p2417, 'P2052')
if mw.wikibase.sitelink( t_g.next ) ~= nil then
v['genre'] = getgendercode(thisid, 'f')
local k = WPlinkpure(t_g.next)
end
local i, _ = string.find(k, "|")
local j, _ = string.find(k, "]")
if i ~= nil and j ~= nil then
t_g.next = string.sub(k, 1, i) .. label_next.. span2 .. string.sub(k, j)
if wiki == "ar" then t_g.next = string.sub(k, 1, i) .. label_next.. span1 .. string.sub(k, j) end
else
t_g.next = label_next.. span2
if wiki == "ar" then t_g.next = label_next .. span1 end
end
end
else
t_g.next = label_next.. span2
if wiki == "ar" then t_g.next = label_next .. span1 end
end
end
else t_g.next = ''
end
end


listoftable={t_s.results,t_s.gen,t_s.annex}
if t_g.course== '' then
temp = firstValue(entityId, 'P1545')
for _, thistable in ipairs(listoftable) do
if temp then
for _, v in ipairs(thistable.order) do --order is the list of all classification names
a, _ = string.gsub(temp, "%a", "") -- 20, not 20a
if thistable[v]['link'] then
if string.find(temp, "%a") then b = string.sub(temp, string.find(temp, "%a")) else b = "" end
thistable.show = true
local label = stageLink(temp, a, b)
if temp == "0" then label = func_prologue() end
t_g.course = label
temp = firstValue(entityId, 'P361','id')
if temp then
local raceId = temp
local comma = ', '
--if wiki == "ar" then comma = " ، " end
if wiki == "ar" then
t_g.course = t_g.course .. '، '.. WPlinkpure(raceId)
else
t_g.course = t_g.course .. comma.. WPlinkpure(raceId)
end
for k, p31 in statements(raceId, 'P31') do
t_g.race[k] = p31.mainsnak.datavalue.value.id
end
end
end
end
end
end
end

if t_s.results.first[1]~='' or t_s.results.second[1]~='' or t_s.results.third[1]~='' or t_s.results.winner_fighting[1]
then t_s.results.show = true end
if t_s.classement_gen.leader[1]~='' or t_s.classement_gen.deuxieme[1]~='' or t_s.classement_gen.troisieme[1]~=''
then t_s.classement_gen.show = true end
if t_s.classement_annex.points[1]~='' or t_s.classement_annex.montagne[1]~='' or t_s.classement_annex.sprints[1]~='' or t_s.classement_annex.jeune[1]~='' or
t_s.classement_annex.super_combatif[1]~='' or t_s.classement_annex.combine[1]~='' or t_s.classement_annex.stage_volantes[1]~='' or
t_s.classement_annex.regularite[1]~='' or t_s.classement_annex.azzurri_ditalia[1]~='' or t_s.classement_annex.breakaway[1]~='' or
t_s.classement_annex.equipe[1]~='' or t_s.classement_annex.equipe_points[1]~='' then t_s.classement_annex.show = true end

local function stage_icon(x)
if x=='Q20646667' then return "[[File:Plainstage.svg|20px]] " end
if x=='Q20646670' then return "[[File:Hillystage.svg|20px]] " end
if x=='Q20680270' then return "[[File:Mediummountainstage.svg|20px]] " end
if x=='Q20646668' then return "[[File:Mountainstage.svg|20px]] " end
if x=='Q20679712' then return "[[File:Mountain Time Trial Stage.svg|20px]] " end
if x=='Q2348250' then return "[[File:Team Time Trial Stage.svg|20px]] " end
if x=='Q2266066' then return "[[File:Time Trial.svg|20px]] " end
if x=='Q485321' then return "[[File:Time Trial.svg|20px]] " end
return ''
end

---General table
---General table
local temp
local width= '320px' -- size standard 320px, special 340px
local width= '320px' -- size standard 320px, special 340px
if t_s.classement_annex.show == true and (wiki == 'no' or wiki == '..') then width= '340px' end
if t_s.annex.show == true and (wiki == 'no' or wiki == '..') then width= '340px' end
tab= infoInitTab(width, name, icon)
infoFillOthersDetails(tab, others, details,stageinfobox_translate(1))


tab = "<table border='0' cellpadding='4' cellspacing='0' style='float:"..floatinfobox.."; max-width:"..width.."; border:1px solid rgb(200,200,200);"
tab = tab .. "margin:0 0 0.5em 0.5em; background-color:rgb(255, 255, 255); color:black; padding:5px; clear:left; "
tab = tab .. "text-align:" .. textalign .. "; font-size:85%; line-height:1.6em;'>"
tab = tab .. "<tr><td colspan='2' style='border-bottom:5px solid white; font-size:175%; background:#FFE7A0; text-align:center'>"
tab = tab .. "<table style='width:100%'><tr><td>" .. t_g.name .."</td><td>" .. t_g.icon .. "</td></tr></table></td></tr>"

if t_g.picture ~= "" then tab = tab .. "<tr><td colspan='2' style='text-align:center'>".." [[File:".. t_g.picture .."|center|300px]]</td></tr>" end
if t_g.picture ~= "" and t_g.caption ~= "" then tab = tab .. "<tr><td colspan='2' style='text-align:center; font-size:80%'>"..t_g.caption.."</td></tr>" end
if t_g.course~="" or t_g.is_a~="" or t_g.time~="" or t_g.length~="" or t_g.startplace~="" or t_g.endplace~="" then
tab=tab.."<tr><td colspan='2' style='background-color:#FFE7A0; text-align:center'>'''"..stageinfobox_translate(1).."'''</td></tr>" end
if t_g.course ~= "" then tab = tab.."<tr><td>'''"..stageinfobox_translate(2).."'''</td><td>" .. t_g.course .. "</td></tr>" end
if t_g.is_a ~= "" then tab = tab.."<tr><td>'''"..stageinfobox_translate(3).."'''</td><td>" ..stage_icon(t_g.is_a).. WPlinkpure(t_g.is_a).. "</td></tr>" end
if t_g.time~="" then tab = tab.."<tr><td>'''"..stageinfobox_translate(4).."'''</td><td>" .. t_g.time.."</td></tr>" end
if t_g.length ~= "" then
tab = tab .. "<tr><td>'''" .. stageinfobox_translate(6) .. "'''</td><td>" .. t_g.length .. "</td></tr>"
end
if t_g.startplace ~= "" then tab = tab.."<tr><td>'''"..stageinfobox_translate(9).."'''</td><td>" .. WPlinkpure(t_g.startplace).. "</td></tr>" end
if t_g.endplace ~= "" then tab = tab.."<tr><td>'''"..stageinfobox_translate(10).."'''</td><td>" .. WPlinkpure(t_g.endplace).. "</td></tr>" end
if t_g.country[1] ~= nil then tab = tab.."<tr><td style= 'vertical-align:top'>'''"
if #t_g.country == 1 then tab = tab..stageinfobox_translate(7).."'''</td><td>" else tab = tab..stageinfobox_translate(8).."'''</td><td>" end
for i=1,#t_g.country-1 do tab = tab .. t_g.country[i].."<br>" end tab = tab .. t_g.country[#t_g.country].."</td></tr>" end
if t_g.nr_participants_start ~= "" then tab = tab.."<tr><td>'''"..stageinfobox_translate(11).."'''</td><td>" .. t_g.nr_participants_start .. "</td></tr>" end
if t_g.nr_participants_end ~= "" then tab = tab.."<tr><td>'''"..stageinfobox_translate(12).."'''</td><td>" .. t_g.nr_participants_end .. "</td></tr>" end
if t_g.speed ~= "" then
tab = tab .. "<tr><td>'''" .. stageinfobox_translate(13) .. "'''</td><td>" .. t_g.speed .. "</td></tr>"
end
if t_g.elevation ~= "" then
tab = tab .. "<tr><td>'''" .. stageinfobox_translate(44) .. "'''</td><td>" .. t_g.elevation .. "</td></tr>"
end
-- ranking table, general and stage
-- ranking table, general and stage
for _, value_order in ipairs(t_s.order) do
for _, value_order in ipairs(t_s.order) do
if t_s[value_order].show == true then -- if a section of the stageinfobox should be shown
local thistable =t_s[value_order] --results or gen or annex
tab=tab.."<tr><td colspan='2'>"
if thistable.show then -- if a section of the stageinfobox should be shown
tab=tab.."<table border='0' cellpadding='0' cellspacing='0' style='width:100%'>"
tCell=tab:tag('tr'):tag('td'):attr('colspan','2')
tab=tab.."<tr><td colspan='3' style='border-bottom:5px solid #fff2cc; background-color:#FFE7A0; text-align:center'>'''"..
tTab=tCell:tag('table'):attr('cellpadding','0'):attr('cellspacing','0'):css('width','100%')
stageinfobox_translate(t_s[value_order].header).."'''</td></tr>"
tCell=tTab:tag('tr'):tag('td'):attr('colspan','3')
:cssText('border-bottom:5px solid #fff2cc; background-color:#FFE7A0; text-align:center')
:css('font-weight','bold')
:wikitext(stageinfobox_translate(thistable.header))


for key, value in ipairs(t_s[value_order].order) do
for key, value in ipairs(thistable.order) do --value is the name of the class
if t_s[value_order][value][1]~="" then
local v=thistable[value]
if v['link'] then
local a1
local a1
a1, jersey_name, jerseyWPID = jersey_infobox(wiki, value, t_g.race, timeofrace)
a1, jersey_name, jerseyWPID = jersey_infobox(wiki, value, race, timeOfRace)
if a1~='' then t_s[value_order][value][4] = a1 end
if a1~='' then v['jersey'] = a1 end
if t_s[value_order][value][9] ~= '' then
if v['speed'] then
if wiki == 'fo' then
t_s[value_order][value][9] = '('.. lang:formatNum(t_s[value_order][value][9])..unit(5)..')'
if wiki == 'fo' then t_s[value_order][value][9] = string.gsub(t_s[value_order][value][9], "%.", ",") end
v['speed'] = string.gsub(v['speed'], "%.", ",")
else
local lang = mw.language.getContentLanguage()
v['speed'] = '('.. lang:formatNum(v['speed'])..unit(5)..')'
end
end
end
if t_s[value_order][value][8] ~= '' then
if v['points'] then
if v['points'] > 1 then
if t_s[value_order][value][8] > 1 then t_s[value_order][value][8] = t_s[value_order][value][8]..unit(7)
temp=unit(7)
else t_s[value_order][value][8] = t_s[value_order][value][8]..unit(6) end end
else
local title, k = string.gsub(stageinfobox_translate(t_s[value_order][value][2]), " ", "&nbsp;")
temp=unit(6)
end
v['points'] = v['points']..temp
end
local title, k = string.gsub(stageinfobox_translate(v['translation']), " ", "&nbsp;")
if k > 0 then title = string.gsub(title, "&nbsp;", "<br>", 1) end --&#32;
if k > 0 then title = string.gsub(title, "&nbsp;", "<br>", 1) end --&#32;
--Create an empty column on the left
--Create an empty column on the left
tRow=tTab:tag('tr'):css('vertical-align','top')
if t_s[value_order][value][5]=="" and t_s[value_order][value][9] =="" then
tCell=tRow:tag('td')
tab=tab.."<tr style='vertical-align:top;'><td style='width:1%;background-color:#fff2cc;text-align:" .. textalign .. ";padding:0 2px 0 2px;white-space:nowrap'>'''"
:css('font-weight','bold')
else tab=tab.."<tr style='vertical-align:top;'><td rowspan='2' style='width:1%;background-color:#fff2cc;text-align:" .. textalign .. ";padding:0 2px 0 2px;white-space:nowrap'>'''"
if v['team']~=nil or v['speed'] ~=nil then
tCell:attr('rowspan','2')
end
end
tCell:cssText("width:1%;background-color:#fff2cc;text-align:" ..
if value_order~='classement_annex' and t_s[value_order][value][2]~=40 and t_s[value_order][value][2]~=41 then -- Cima Coppi, Cima Pantani with a line break
textalign .. ";padding:0 2px 0 2px;white-space:nowrap")
if t_s[value_order][value][4] == "" then
if value_order~='annex' and v['translation']~=40 and v['translation']~=41 then -- Cima Coppi, Cima Pantani with a line break
if v['jersey'] == nil then
if (value_order=='results') and (value=='winner_fighting' or value=='winner_fighting2' or value=='cima_coppi' or value=='cima_pantanii') then
if (value_order=='results') and (value=='winner_fighting' or value=='winner_fighting2' or value=='cima_coppi' or value=='cima_pantanii') then
tab=tab..stageinfobox_translate(t_s[value_order][value][2])
tCell:wikitext(stageinfobox_translate(v['translation']))
else
else tab=tab..number(t_s[value_order][value][3], key, wiki) end
tCell:wikitext(number(v['genre'], key, wiki))
end
else
else
if jerseyWPID=='' then tab=tab.."[[File:"..t_s[value_order][value][4].."|20px|"..title.."]]"
if jerseyWPID=='' then
temp=''
else tab=tab.."[[File:"..t_s[value_order][value][4].."|20px|"..title.."|link="..jerseyWPID.."]]" end
else
temp="|link="..jerseyWPID
end
tCell:wikitext("[[File:"..v['jersey'].."|20px|"..title..temp.."]]")
end
end
else
else
if t_s[value_order][value][4] == "" then tab=tab..title
if v['jersey'] == nil then
tCell:wikitext(title)
else
else
if jerseyWPID=='' then
if jerseyWPID=='' then
if jersey_name ~= '' then tab=tab.."[[File:"..t_s[value_order][value][4].."|20px|"..jersey_name.."]]" .. title
if jersey_name ~= '' then
temp = "|"..jersey_name
else tab=tab.."[[File:"..t_s[value_order][value][4].."|20px]]" .. title end
else
else tab=tab.."[[File:"..t_s[value_order][value][4].."|20px|link="..jerseyWPID.."]]" .. title end end
temp=''
end
else
temp= "|link="..jerseyWPID
end
tCell:wikitext("[[File:"..v['jersey'].."|20px"..temp.."]]" .. title)
end
end
tRow:tag('td'):cssText("padding:0 0.5em 0 0.5em;"..v['rank'])
:wikitext( v['link'])
tCell=tRow:tag('td'):cssText('text-align:right;font-size:85%;white-space:nowrap')

if v['time'] then
tCell:wikitext(calculate_time(v['time']))
end
if v['gap'] then
tCell:wikitext('+ '.. calculate_time(v['gap']))
end
end
tCell:wikitext(v['points'])
tab=tab.. "'''</td><td style='padding:0 0.5em 0 0.5em;"..t_s[value_order][value][10].."'>".. t_s[value_order][value][1] --the rider
tab=tab.."</td><td style='text-align:right;font-size:85%;white-space:nowrap'>"
if t_s[value_order][value][6]~="" then tab=tab..calculate_time(t_s[value_order][value][6]) end
if t_s[value_order][value][7]~="" then tab=tab..'+ '.. calculate_time(t_s[value_order][value][7]) end
tab= tab.. t_s[value_order][value][8].. "</td></tr>"
end
end

tCell=tTab:tag('tr'):tag('td'):attr('colspan','2')
if t_s[value_order][value][5]~="" and t_s[value_order][value][9] ~="" then -- team row
if v['team']~=nil and v['speed'] ~=nil then -- team row
tab=tab.."<tr><td colspan='2'>"
tab = tab.. "<table border='0' cellpadding='0' cellspacing='0' style='width:100%'>"
tTab2=tCell:tag('table'):attr('cellpadding','0'):attr('cellspacing','0'):css('width','100%')
tRow = tTab2:tag('tr')
tab = tab.. "<tr><td style='width:100%;text-align:" .. textalign .. ";padding-left:2px'>("..t_s[value_order][value][5].. --add the team
tRow:tag('td'):cssText('width:100%;text-align:" .. textalign .. ";padding-left:2px')
")</td><td style='font-size:85%;vertical-align:top;white-space:nowrap'>"..t_s[value_order][value][9] .. "</td></tr></table></td></tr>"
:wikitext("("..v['team']..")") --add the team
tRow:tag('td'):cssText('font-size:85%;vertical-align:top;white-space:nowrap')
:wikitext(v['speed'])
else
else
if t_s[value_order][value][5]~="" or t_s[value_order][value][9] ~="" then
if v['team']~=nil or v['speed'] ~=nil then
tab=tab.."<tr><td colspan='2' style='text-align:" .. textalign .. ";padding-left:2px'>"
tCell:cssText("text-align:" .. textalign .. ";padding-left:2px")
if v['team'] ~= nil then
if t_s[value_order][value][5] ~= "" then tab=tab..'('..t_s[value_order][value][5]..')' end --add the team
tCell:wikitext("("..v['team']..")") --add the team
tab = tab.. '<span style="float:right;font-size:85%;">'.. t_s[value_order][value][9].."</span></td></tr>"
end
tCell:tag('span'):cssText("float:right;font-size:85%;"):wikitext(v['speed'])
end
end
end
end
end
end
tab=tab.. "</table></td></tr>"
end
end
end
end

infoFillOthersMap(tab, others)
if t_g.map ~= "" then tab = tab .. "<tr><td colspan='2' style='text-align:center'>".." [[File:".. t_g.map .."|center|300px]]".."</td></tr>" end
tab:node(getPreviousNextLine(entityID,true))
if t_g.sectional_view ~= "" then tab = tab .. "<tr><td colspan='2' style='text-align:center'>".." [[File:".. t_g.sectional_view .."|center|300px]]".."</td></tr>" end
wdDoc(tab, "d:Wikidata:WikiProject Cycling/Documentation/stageinfobox", stageinfobox_translate(39), frame.args[1])

local prevNextLine = "<tr><td>"..t_g.previous.."</td><td style='text-align:right'>" .. t_g.next .. "</td></tr>"
if wiki == "ar" then prevNextLine = "<tr><td width='50%' style='text-align:right'>"..t_g.previous.."</td><td width='50%' style='text-align:left'>" .. t_g.next .. "</td></tr>" end
tab = tab .. prevNextLine

local s = "d:Wikidata:WikiProject Cycling/Documentation/stageinfobox"
tab = tab .. "<tr><td colspan='2' style='text-align:right; border-top:3px solid #FFDF80; font-size:75%'>".. --infobox_bottom(1)
"[[" .. s .. "|" .. stageinfobox_translate(39).. "]] [[File:Wikidata-logo S.svg|12px|link=d:".. frame.args[1] .. "]]"
tab = tab .. "</td></tr>"
tab= tab.."</table>"
return tab
return tab
end
end
Línia 4.346: Línia 4.343:
local raceID = frame.args[1]
local raceID = frame.args[1]
local teams = {} -- values will be {teamLink, teamCat, sortkey, index}
local teams = {} -- values will be {teamLink, teamCat, sortkey, index}
local text = ''


local timeOfRace, errorMessage = getTimeOfRace(raceID)
local timeOfRace, errorMessage = gettimeOfRace(raceID)
if not timeOfRace then return errorMessage end
if not timeOfRace then return errorMessage end


local teamCats = { -- {c,d,e} c = singular team type, d = plural team type, e = print order of the team types
local teamCats = { -- {c,d,e} c = singular team type, d = plural team type, e = print order of the team types
["Q6154783"] = {4,5,1}, -- WorldTeam
["Q6154783"] = {4,5,1}, -- WorldTeam
["Q20638319"] = {6,7,2}, -- ProTeam
["Q20638319"] = {6,7,2}, -- ProTeam (2005-2014)
["Q382927"] = {8,9,3}, -- UCI Professional Continental Team
["Q382927"] = {8,9,4}, -- UCI Professional Continental Team (2005-2019)
["Q1756006"] = {10,11,4}, -- UCI Continental Team
["Q78464255"] = {6,7,3},-- ProTeam (2020-)
["Q1756006"] = {10,11,5}, -- UCI Continental Team
["Q23726798"] = {12,13,6}, -- national cycling team
["Q23726798"] = {12,13,6}, -- national cycling team
["Q20738667"] = {12,13,6}, -- national cycling team U23
["Q20738667"] = {12,13,7}, -- national cycling team U23
["Q28492441"] = {12,13,6}, -- équipe cycliste nationale de marque
["Q28492441"] = {12,13,8}, -- équipe cycliste nationale de marque
["Q20639848"] = {14,15,7}, -- club cycling team
["Q20639848"] = {14,15,9}, -- club cycling team
["Q20639847"] = {16,17,8}, -- professional cycling team
["Q20639847"] = {16,17,10}, -- professional cycling team
["Q20652655"] = {18,19,9}, -- amateur cycling team
["Q20652655"] = {18,19,11}, -- amateur cycling team
["Q20653563"] = {20,21,10}, -- Groupe Sportif I
["Q20653563"] = {20,21,12}, -- Groupe Sportif I
["Q20653564"] = {22,23,11}, -- Groupe Sportif II
["Q20653564"] = {22,23,13}, -- Groupe Sportif II
["Q20653566"] = {24,25,12}, -- Groupe Sportif III
["Q20653566"] = {24,25,14}, -- Groupe Sportif III
["Q2466826"] = {28,29,5}, -- UCI Women’s Team
["Q80425135"] = {4,5,5}, -- UCI Women’s WorldTeam
["Q26849121"] = {30,31,13} -- Women's amateur cycling team
["Q2466826"] = {28,29,13}, -- UCI Women’s Team
["Q26849121"] = {30,31,14} -- Women's amateur cycling team
}
}


Línia 4.388: Línia 4.386:


local function getHeader(CatID, count)
local function getHeader(CatID, count)
local header
local header, sitelink
if teamCats[CatID] then
if teamCats[CatID] then
if count == 1 then
if count == 1 then
header = headoftableIII(teamCats[CatID][1]) -- singular name
header_label = headoftableIII(teamCats[CatID][1]) -- singular name
else
else
header = headoftableIII(teamCats[CatID][2]) -- plural name
header_label = headoftableIII(teamCats[CatID][2]) -- plural name
end
if CatID=='Q78464255' then
sitelink=wikibase.getSitelink('Q382927') --continental
else
sitelink=wikibase.getSitelink(CatID)
end

if sitelink ~= nil then
header = '[['..sitelink..'|'..header_label..']]'
else
header= header_label
end
end
end
end

local text
local tHeader= mw.html.create('span'):css('font-size','1.2em'):css('font-weight','bold')
if not header then
if not header then
-- Unknown team category. Get the label for the entity to display if possible
-- Unknown team category. Get the label for the entity to display if possible
header = (CatID and getLabelFallback(CatID, {wikilang, 'en', 'fr', 'de'})) or 'Unknown team category'
header = (CatID and getLabelFallback(CatID, {wikilang, 'en', 'fr', 'de'})) or 'Unknown team category'
tHeader:css('text-transform','capitalize')
text = '<span style="font-size:1.2em;font-weight:bold;text-transform: capitalize;>' .. header .. '</span>'
else
text = '<span style="font-size:1.2em;font-weight:bold">' .. header .. '</span>'
end
end
tHeader:wikitext(header)
-- Set parameter to show team count in front of each category
-- Set parameter to show team count in front of each category
local tTag=''
local showcounter = 2
local showcounter = 2
if count >= showcounter then
if count >= showcounter then
text = text .. ' <small>(' .. count ..')</small>'
tTag=mw.html.create('small'):wikitext(' (' .. count ..')')
end
end
return text
return tostring(tHeader)..tostring(tTag)
end
end


Línia 4.416: Línia 4.427:
local count = 0
local count = 0
local list = ''
local list = ''
local header
local resulttable = mw.html.create('table')
:cssText("max-width:95%; padding:0.5em; margin-right:1em; border:1px solid rgb(200,200,200)")
local tCell = resulttable:tag('tr'):tag('td')

for _, team in ipairs(teams) do
for _, team in ipairs(teams) do
local order = team[3]
local order = team[3]
if order ~= oldOrder then
if order ~= oldOrder then --new cat
if oldOrder > 0 then
if oldOrder > 0 then
text = text .. getHeader(oldCatID, count) .. '<ol>' .. list .. '</ol>'
header = getHeader(oldCatID, count)
tCell:wikitext(header)
tCell:node(tOl)
end
end
count = 1
count = 1
oldOrder = order
oldOrder = order
list = ''
tOl = mw.html.create('ol') --reinit
else
else
count = count + 1
count = count + 1
end
end
oldCatID = team[2]
oldCatID = team[2]
tOl:tag('li')
list = list .. '<li style="text-indent:0em;width:20em;display:inline-block;vertical-align:text-top">' .. team[1] .. '</li>'
:cssText("text-indent:0em;width:20em;display:inline-block;vertical-align:text-top")
:wikitext(team[1])
end
end
--add last row
header = getHeader(oldCatID, count)
tCell:wikitext(header)
tCell:node(tOl)


local tableFooter1=mw.html.create('tr')
return '<table style="max-width:95%; padding:0.5em; margin-right:1em; border:1px solid rgb(200,200,200)"><tr><td>' ..
tCell=tableFooter1:tag('td')
text .. getHeader(oldCatID, count) .. '<ol>' .. list ..
:addClass('navigation-only')
'</ol><table border="0" cellspacing="0" cellpadding="0" style="line-height:0em;width:20em;margin:0.5em 0em;border-top:2px solid #FFDF80;"><tr><th><span style="float:'..floattable..'">[[File:Wikidata-logo S.svg|12px|link=d:' ..
:attr('colspan',2)
raceID .. '#P1923]]</span></th></tr></table></td></tr></table>'
:cssText('border-top: 2px #FFDF80 solid; font-size: 80%;')
tCell:tag('span'):css("float",floattable)
:wikitext('[[File:Wikidata-logo S.svg|12px|link=d:' ..raceID .. '#P1923]]')
resulttable:node(tableFooter1)
return resulttable
end
end


Línia 4.688: Línia 4.719:
]=]
]=]


local timeOfRace, errorMessage = getTimeOfRace(raceID)
local timeOfRace, errorMessage = gettimeOfRace(raceID)
if not timeOfRace then return errorMessage end
if not timeOfRace then return errorMessage end


Línia 4.704: Línia 4.735:
if s.header_1_text ==nil then s.header_1_text=s.header_function(s.header_1) end --for custom title
if s.header_1_text ==nil then s.header_1_text=s.header_function(s.header_1) end --for custom title


local tableBody = mw.html.create('table')
local tableStart = '<table border="0" cellspacing="0" cellpadding="0"><tr><th colspan="' ..
:addClass('sortable')
tostring(tableHeader2_size + 1) ..
:attr('cellpadding', '0')
'" style="padding:2px 2px; text-align:center; background-color:#FFDF80">'
:attr('cellspacing', '0')
local tableHeader1 = '<span style="float:left">[[File:Wikidata-logo S.svg|12px|link=d:' ..
:css('border' , '0')
raceID .. '#' .. s.property..']]</span>'.. s.header_1_text .. '</th></tr>'

local tableHeader2 = '<tr style="text-align:center;padding:2px 2px;white-space:nowrap">'
local thisspan= mw.html.create('span'):cssText('float:left;'):wikitext('[[File:Wikidata-logo S.svg|12px|link=d:'.. raceID .. '#' .. s.property..']]')
tableBody:tag('tr'):tag('th')
:attr('colspan', tostring(tableHeader2_size + 1)):cssText("padding:2px 2px; text-align:center; background-color:#FFDF80")
:wikitext(tostring(thisspan)..s.header_1_text)

header= tableBody:tag('tr'):cssText("text-align:center;padding:2px 2px;white-space:nowrap")
for i, k in ipairs(s.header_2) do
for i, k in ipairs(s.header_2) do
if i==1 then
if i ~= 2 or (country and available_list) then
tableHeader2 = tableHeader2.. '<th colspan="2">'.. s.header_function(k) .. '</th>'
local head=header:tag('th'):wikitext(s.header_function(k))
elseif i==2 and available_list and country or i>=3 then
if i == 1 then
head:attr('colspan','2')
tableHeader2 = tableHeader2.. '<th>'.. s.header_function(k) .. '</th>'
end
end
end
end
end
tableHeader2 = tableHeader2.. '</tr>'


local tableBody = ''
local t_Body = {} --contains all rows
local t_Body = {}
local tCell, bg_color, tStyle, temp, temp2
local bg_color
local claims = mw.wikibase.getAllStatements(raceID, s.property)
local claims = mw.wikibase.getAllStatements(raceID, s.property)
for l, m in pairs(claims) do -- look into all statements
for l, m in pairs(claims) do -- look into all statements
Línia 4.733: Línia 4.769:
value = {'', '', '', ''} -- points, time, time_gap, speed
value = {'', '', '', ''} -- points, time, time_gap, speed
}
}

if q.P1352 and q.P1352[1].snaktype == 'value' then -- P1352 is ranking
if q.P1352 and q.P1352[1].snaktype == 'value' then -- P1352 is ranking
rank = tonumber(q.P1352[1].datavalue.value.amount)
rank = tonumber(q.P1352[1].datavalue.value.amount)
Línia 4.791: Línia 4.827:
end
end


local tBody = '<tr'
-- find the right background color if a rider has more then one jersey
-- find the right background color if a rider has more then one jersey
-- see Wikidata:WikiProject Cycling/Kit to translate/Jerseys
-- see Wikidata:WikiProject Cycling/Kit to translate/Jerseys
bg_color=nil
if h.jersey[1] then
if h.jersey[1] then
if wiki == "ca" then bg_color_table["Q24257763"] = "lightpink" end
if wiki == "ca" then bg_color_table["Q24257763"] = "lightpink" end
Línia 4.803: Línia 4.839:
end
end
end
end
tStyle=''
if rank == 1 then
if rank == 1 then
if s.background then -- values are 'strong' or 'color'
if s.background then -- values are 'strong' or 'color'
tBody = tBody ..' style="font-weight:bold;' -- winner is formated bold
tStyle = tStyle ..'font-weight:bold;' -- winner is formated bold
if s.background == 'color' then
if s.background == 'color' then
if h.jersey[1] and bg_color then -- background color of winner depending on jersey
if h.jersey[1] and bg_color then -- background color of winner depending on jersey
tBody = tBody .. 'background-color:' ..bg_color
tStyle = tStyle .. 'background-color:' ..bg_color
end
end
end
end
tBody = tBody .. '"'
end
end
end
end

tBody = tBody .. '><td style="text-align:center;padding:2px 0.5em 2px 0.5em;white-space:nowrap;'..cancelled..'">'..
local tBody = mw.html.create('tr'):cssText(tStyle) -- a row
number(gender, rank, wiki).. '</td><td style="text-align:' .. textalign .. ';padding:0 0.2em 0 0.2em;'..cancelled..'">'
tBody:tag('td'):cssText("text-align:center;padding:2px 0.5em 2px 0.5em;white-space:nowrap;"..cancelled)
:wikitext(number(gender, rank, wiki))
tCell= tBody:tag('td'):cssText("text-align:" .. textalign .. ";padding:0 0.2em 0 0.2em;"..cancelled)


if not s.team_classification then
if not s.team_classification then
if not teamLink then teamLink = '' end
if not teamLink then teamLink = '' end
if not available_list then
if not available_list then
tCell:wikitext(flagLink .. ' '.. riderLink .. jersey(h.jersey))
if s.displayteam==false then
if s.displayteam~=false then
tBody = tBody .. flagLink .. ' '.. riderLink .. jersey(h.jersey)
tBody:tag('td'):wikitext(teamLink)
else
tBody = tBody .. flagLink .. ' '.. riderLink .. jersey(h.jersey) .. '</td><td>'.. teamLink
end
end
else
else
if country == true then
if country == true then
tCell:wikitext(riderLink .. jersey(h.jersey) )
if s.displayteam==false then
tBody = tBody .. riderLink .. jersey(h.jersey) ..'</td><td>' .. flagLink ..
tBody:tag('td'):wikitext( flagLink ..' '.. countryName)
' '.. countryName
else
tBody = tBody .. riderLink .. jersey(h.jersey) ..'</td><td>' .. flagLink ..
' '.. countryName .. '</td><td style="text-align:' .. textalign ..
';padding:0 0.2em 0 0.2em">'.. teamLink
end
else
else
tCell:wikitext(flagLink .. ' ' .. riderLink .. jersey(h.jersey))
if s.displayteam==false then
end
tBody = tBody .. flagLink .. ' ' .. riderLink .. jersey(h.jersey)
if s.displayteam~=false then
else
tBody = tBody .. flagLink .. ' ' .. riderLink .. jersey(h.jersey) ..
tBody:tag('td'):cssText("text-align:".. textalign ..";padding:0 0.2em 0 0.2em")
:wikitext(teamLink)
'</td><td style="text-align:' .. textalign .. ';padding:0 0.2em 0 0.2em">'.. teamLink
end
end
end
end
end
else
else --team
if not available_list then
if available_list==true and country then
tBody = tBody .. flagLink .. ' ' .. teamLink .. jersey(h.jersey)
tCell:wikitext(teamLink .. jersey(h.jersey))
tBody:tag('td'):wikitext(flagLink .. ' ' .. countryName)
else
else
tCell:wikitext(flagLink .. ' ' .. teamLink .. jersey(h.jersey))
if country then
tBody = tBody .. teamLink .. jersey(h.jersey) .. '</td><td>'.. flagLink .. ' ' .. countryName
else
tBody = tBody .. flagLink .. ' ' .. teamLink .. jersey(h.jersey)
end
end
end
end
end
tBody = tBody.. '</td>'


if s.header_2[4] == 4 then -- for table stageclassification, generalclassification, adds time and time gap
if s.header_2[4] == 4 then -- for table stageclassification, generalclassification, adds time and time gap
if rank == 1 and h.value[2] then
if rank == 1 and h.value[2] then
temp=calculate_time(h.value[2])
tBody = tBody.. '<td style="text-align:right;padding:0 0.2em 0 0.2em">'..
calculate_time(h.value[2]) .. '</td>'
elseif rank == 1 and h.value[3]==nil then --avoid a plus with nothing
elseif rank == 1 and h.value[3]==nil then --avoid a plus with nothing
temp=''
tBody = tBody.. '<td style="text-align:right;padding:0 0.2em 0 0.2em">'..
'' .. '</td>'
else
else
temp=plus .. calculate_time(h.value[3])
tBody = tBody.. '<td style="text-align:right;padding:0 0.2em 0 0.2em">'..
plus .. calculate_time(h.value[3]) .. '</td>'
end
end
tBody:tag('td'):cssText("text-align:right;padding:0 0.2em 0 0.2em"):wikitext(temp)
end
end


if s.header_2[4] == 7 or (s.header_2[3] == 7 and s.header_2[1] == 1) then -- for table pointsclassification, adds points
if s.header_2[4] == 7 or (s.header_2[3] == 7 and s.header_2[1] == 1) then -- for table pointsclassification, adds points
--trick for UCI classification
--trick for UCI classification
local temp
if h.value[1] then temp=h.value[1] else temp='' end
if h.value[1] then temp=h.value[1] else temp='' end
tBody = tBody.. '<td style="text-align:right;padding:0 0.2em 0 0.2em">'..temp
tCell=tBody:tag('td'):cssText("text-align:right;padding:0 0.2em 0 0.2em")
:wikitext(temp)
.. '<span style="font-size:80%">'
if type(h.value[1]) == "number" then
if type(h.value[1]) == "number" then
if h.value[1] > 1 then
if h.value[1] > 1 then
tBody = tBody..unit(7)
temp2=unit(7)
else
else
tBody = tBody..unit(6)
temp2=unit(6)
end
end
tCell:tag('span'):cssText("font-size:80%"):wikitext(temp2)
end
end
tBody = tBody.. '</span>' .. '</td>'
end
end


Línia 4.889: Línia 4.914:
if s.property == 'P2417' or s.property == 'P2321' then
if s.property == 'P2417' or s.property == 'P2321' then
-- for tables teamtimetrialclassification or generaltttclassification, adds time
-- for tables teamtimetrialclassification or generaltttclassification, adds time
tBody = tBody.. '<td style="text-align:right;padding:0 0.2em 0 0.2em">'..
tBody:tag('td'):cssText("text-align:right;padding:0 0.2em 0 0.2em")
calculate_time(h.value[2]) .. '</td>'
:wikitext(calculate_time(h.value[2]))
end
end
end
end


if s.property == 'P3497' then -- for table teambytimeclassification, adds time and time gap
if s.property == 'P3497' then -- for table teambytimeclassification, adds time and time gap
if rank == 1 then tBody = tBody.. '<td style="text-align:right;padding:0 0.2em 0 0.2em">'..
if rank == 1 then
calculate_time(h.value[2]) .. '</td>'
temp=calculate_time(h.value[2])
else
else
temp=calculate_time(h.value[3])
tBody = tBody.. '<td style="text-align:right;padding:0 0.2em 0 0.2em">'..
plus.. calculate_time(h.value[3]) .. '</td>'
end
end
tBody:tag('td'):cssText("text-align:right;padding:0 0.2em 0 0.2em"):wikitext(temp)
end
end


if s.property == 'P3496' then -- for table teambypointsclassification, adds points
if s.property == 'P3496' then -- for table teambypointsclassification, adds points
tBody = tBody.. '<td style="text-align:right;padding:0 0.2em 0 0.2em">'.. h.value[1]..
tCell=tBody:tag('td'):cssText("text-align:right;padding:0 0.2em 0 0.2em")
:wikitext(h.value[1])
'<span style="font-size:80%">'
if type(h.value[1]) == "number" then
if type(h.value[1]) == "number" then
if h.value[1] > 1 then
if h.value[1] > 1 then
tBody = tBody..unit(7)
temp2=unit(7)
else
else
tBody = tBody..unit(6)
temp2=unit(6)
end
end
tCell:tag('span'):cssText("font-size:80%"):wikitext(temp2)
end
end
tBody = tBody.. '</span>' .. '</td>'
end
end


if s.header_2[4] == 5 then -- for table teamtimetrialclassification, adds time gap
if s.header_2[4] == 5 then -- for table teamtimetrialclassification, adds time gap
if l > 1 then temp= plus else temp='' end
tBody = tBody.. '<td style="text-align:right;padding:0 0.2em 0 0.2em">'
tBody:tag('td'):cssText("text-align:right;padding:0 0.2em 0 0.2em"):wikitext(temp..calculate_time(h.value[3]))
if l > 1 then tBody = tBody.. plus end
tBody = tBody.. calculate_time(h.value[3]) .. '</td>'
end
end


if s.header_2[5] == 6 then -- for table teamtimetrialclassification, adds speed
if s.header_2[5] == 6 then -- for table teamtimetrialclassification, adds speed
tBody = tBody.. '<td style="text-align:right;padding:0 0.2em 0 0.2em">'
tCell=tBody:tag('td'):cssText("text-align:right;padding:0 0.2em 0 0.2em")
if type(h.value[4]) == "number" then tBody = tBody.. mw.ustring.format('%.3f', h.value[4])..
if type(h.value[4]) == "number" then
tCell:wikitext(mw.ustring.format('%.3f', h.value[4]))
'<span style="font-size:80%">'.. unit(5).. '</span>'
:tag('span'):cssText("font-size:80%"):wikitext(unit(5))
end
end
tBody = tBody.. '</td>'
end
end
t_Body[#t_Body + 1] = {(type(rank) == 'number') and rank or 999, tostring(tBody)}
tBody = tBody.. '</tr>'
t_Body[#t_Body + 1] = {(type(rank) == 'number') and rank or 999, tBody}
end
end
end
end
table.sort(t_Body, function(a, b) return a[1] < b[1] end)
for _, m in ipairs(t_Body) do tableBody = tableBody .. m[2] end
tableBody=sortandconcat(t_Body, tableBody)
local tableFooter1,tableFooter2

local tableFooter = ''
if s.display_ref == 1 then
if s.display_ref == 1 then
tableFooter1=mw.html.create('tr')
tableFooter = '<tr><td class="navigation-only" colspan=' .. tostring(tableHeader2_size + 1) ..
tCell=tableFooter1:tag('td')
' style="border-top: 2px #FFDF80 solid; font-size: 80%; "></td></tr><tr><td colspan=' ..
:addClass('navigation-only')
tostring(tableHeader2_size + 1) .. ' style="text-align:right"><small>' ..
:attr('colspan',tostring(tableHeader2_size + 1))
race_reference(raceID) ..' </small></td></tr>'
:cssText('border-top: 2px #FFDF80 solid; font-size: 80%;')
tableFooter2=mw.html.create('tr')
tCell=tableFooter2:tag('td')
:attr('colspan',tostring(tableHeader2_size + 1))
:cssText("text-align:right")
tCell:tag('small')
:wikitext(race_reference(raceID))
end
end

--general table style and last line
local tableEnd = '</table>'

local tableStyle, tableNewline
local tableStyle, tableNewline
if localframe.args.newline == 'false' then -- parameter newline in WP article is 'false'
if localframe.args.newline == 'false' then -- parameter newline in WP article is 'false'
Línia 4.965: Línia 4.993:
end
end


local finalTable= mw.html.create('table'):cssText(tableStyle)
return '<table style="'.. tableStyle.. '"><tr><td>' .. tableStart .. tableHeader1 ..
finalTable:tag('tr'):tag('td')
tableHeader2 .. tableBody .. tableFooter..tableEnd .. '</td></tr></table>' .. tableNewline
:node(tableBody)
if tableFooter1 then
finalTable:node(tableFooter1)
finalTable:node(tableFooter2)
end

return tostring(finalTable)..tableNewline
end
end


Línia 5.000: Línia 5.035:
{ name = infobox_translate(30)}, -- caption
{ name = infobox_translate(30)}, -- caption
{ name = infobox_translate(31)}, -- map
{ name = infobox_translate(31)}, -- map
{ name = 'sectional_view '}
}
}
local winners = {
local winners = {
Línia 5.037: Línia 5.073:
getLocalContent(winners, localframe.args)
getLocalContent(winners, localframe.args)


local dateOfRace, class
local timeOfRace, class
local icon = (firstValue(entityID, 'P641', 'numeric-id') == 3609) and -- P641 is 'sport', Q3609 is 'road bicycle racing'
local icon = (firstValue(entityID, 'P641', 'numeric-id') == 3609) and -- P641 is 'sport', Q3609 is 'road bicycle racing'
' [[File:Cycling (road) pictogram.svg|35px]]' or ''
' [[File:Cycling (road) pictogram.svg|35px]]' or ''


local name = wikibase.getLabel(entityID)
local name = getLabelFallback(entityID, {wikilang, 'en', 'fr', 'de'}) or ''
infoGetOthers(others, entityID)
if not name then
name = getLabelFallback(entityID, {'en', 'fr', 'de'}) or ''
end
if not others[1].content then --picture
others[1].content, others[2].content = getImage(entityID) -- picture, caption
end

if not others[3].content then -- map
others[3].content = firstValue(entityID, 'P242') -- P242 is 'locator map image'
end


if not details[1].content then -- course
if not details[1].content then -- course
Línia 5.119: Línia 5.146:
details[4].content = startTime .. ' – ' .. endTime
details[4].content = startTime .. ' – ' .. endTime
details[4].name = details[4].name_plural
details[4].name = details[4].name_plural
dateOfRace = eTime
timeOfRace = eTime
else
else
-- This function give a format to dates when P585 (date) is used in a single day race
-- This function give a format to dates when P585 (date) is used in a single day race
Línia 5.125: Línia 5.152:
if pTime then
if pTime then
details[4].content = func_date(pTime, 'long')
details[4].content = func_date(pTime, 'long')
dateOfRace = pTime
timeOfRace = pTime
end
end
end
end
Línia 5.133: Línia 5.160:
if not details[5].content then details[5].content, kmdistance = getDistance(entityID, true) end -- distance
if not details[5].content then details[5].content, kmdistance = getDistance(entityID, true) end -- distance


infoGetCountry(details,6, entityID, timeOfRace)
if not details[6].content then -- country
infoGetStartEnd(details,7, entityID)
-- This function gives countries where the race take place
local country = {}
for _, p17 in statements(entityID, 'P17') do -- P17 is 'country'
local countryID = p17.mainsnak.datavalue.value.id
country[#country + 1] = flag(countryID, dateOfRace) .. ' ' .. getCountryName(countryID)
end
if country[1] then
if #country > 1 then
details[6].name = details[6].name_plural
end
details[6].content = table.concat(country, '<br/>')
end
end

if not details[7].content then -- start place
local place = firstValue(entityID, 'P1427', 'id') -- P1427 is 'start point'
details[7].content = place and getPlaceLink(place)
end

if not details[8].content then -- end place
local place = firstValue(entityID, 'P1444', 'id') -- P1444 is 'destination point'
details[8].content = place and getPlaceLink(place)
end


if not details[9].content then -- teams
if not details[9].content then -- teams
Línia 5.165: Línia 5.170:
end
end


infoGetParticipants(details,10, entityID)
-- Function that give the number of cyclists at the beginning and at the finishing of a race
for _, p1132 in statements(entityID, 'P1132') do -- P1132 is 'number of participants'
local amount = tonumber(p1132.mainsnak.datavalue.value.amount) -- tonumber to remove starting '+'
for _, q in qualifiers(p1132, 'P276') do -- P276 is 'location'
local location = q.value['numeric-id']
if location == 529711 then -- Q529711 is 'beginning'
if not details[10].content then details[10].content = amount end -- participants at start
elseif location == 12769393 then -- Q12769393 is 'end'
if not details[11].content then details[11].content = amount end -- participants at end
end
end
end
if not details[10].content or not details[11].content then
if not details[10].content or not details[11].content then
local Allp710= wikibase.getAllStatements(entityID, 'P710')
local Allp710= wikibase.getAllStatements(entityID, 'P710')
Línia 5.190: Línia 5.184:
end
end
end
end
details[11].content=maxrank
if maxrank~=1 then details[11].content=maxrank end
end
end
end
end
Línia 5.198: Línia 5.192:
if not details[13].content then
if not details[13].content then
local elevation=getElevation(entityID)
local elevation=getElevation(entityID)
if elevation ~= '' then details[13].content =elevation else details[13].content = nil end
if elevation then details[13].content =elevation else details[13].content = nil end
end --Elevation
end --Elevation
Línia 5.214: Línia 5.208:
end
end


tab = infoInitTab("300px", name, icon)
local tab
infoFillOthersDetails(tab, others, details,infobox_translate(1))
if wiki == "eo" then
tab = "<table style='width:23em; border:1px solid rgb(200,200,200);" ..
local winRows=''
"margin:0 0 0.5em 0.5em; background-color:rgb(255, 255, 255); color:black; padding:5px;" ..
"text-align:" .. textalign .. "; font-size:85%; line-height:1.6em;' class='infobox' >"
else
tab = "<table cellpadding='4' cellspacing='0' style='float:" .. floatinfobox ..
"; width:300px; border:1px solid rgb(200,200,200);" ..
"margin:0 0 0.5em 0.5em; background-color:rgb(255, 255, 255); color:black; padding:5px; clear:left; " ..
"text-align:" .. textalign .. "; font-size:85%; line-height:1.6em;'>"
end
tab = tab ..
"<tr><td colspan='2' style='border-bottom:5px solid white; font-size:175%; background:#FFDF80; text-align:center'>" ..
"<table style='width:100%'><tr><td>" .. name .."</td><td>" .. icon .. "</td></tr></table></td></tr>"

if others[1].content then -- picture
tab = tab .. "<tr><td colspan='2' style='text-align:center'>[[File:" .. others[1].content ..
"|center|300px]]</td></tr>"
if others[2].content then -- caption
tab = tab .. "<tr><td colspan='2' style='text-align:center; font-size:80%'>" ..
others[2].content .. "</td></tr>"
end
end
tab = tab .. "<tr><td colspan='2' style='background-color:#FFDF80; text-align:center'>'''" ..
infobox_translate(1) .. "'''</td></tr>"
for _, row in ipairs(details) do
if row.content then
tab = tab .. "<tr style= 'vertical-align:top'><td style='width:40%'>'''" .. row.name ..
"'''</td><td>" .. row.content .. "</td></tr>"
end
end

local winRows = ''
local win = {}
local win = {}
for _, v in pairs(winners) do
for _, v in pairs(winners) do
Línia 5.253: Línia 5.218:
end
end
end
end
winner(entityID, win, dateOfRace, false, WDlink_on, team, true)
winner(entityID, win, timeOfRace, false, WDlink_on, team, true)
for _, v in pairs(winners) do
for _, v in pairs(winners) do
if not v.content then
if not v.content then
Línia 5.261: Línia 5.226:
end
end
if v.content then
if v.content then
winRows = winRows .. "<tr style= 'vertical-align:top'><td>'''" .. v.name ..
tRow= mw.html.create('tr') :css('vertical-align','top')
tRow:tag('td'):css('font-weight','bold'):wikitext(v.name)
"'''</td><td>" .. v.content .. "</td></tr>"
tRow:tag('td'):wikitext(v.content)
winRows=winRows..tostring(tRow) --not elegant
end
end
end
end
if winRows ~= '' then
if winRows~= '' then
tab = tab .. "<tr><td colspan='2' style='border-bottom:5px solid white; background-color:#FFDF80; text-align:center'>'''"
tab:tag('tr'):tag('td'):attr('colspan','2')
:cssText('border-bottom:5px solid white; background-color:#FFDF80; text-align:center')
:css('font-weight','bold')
.. infobox_translate(18) .. "'''</td></tr>" .. winRows
:wikitext(infobox_translate(18))
tab:wikitext(winRows)
end
end


if others[3].content then -- map
if others[3].content then -- map
tab = tab .. "<tr><td colspan='2' style='text-align:center'>[[File:".. others[3].content .. "|center|300px]]</td></tr>"
tab:tag('tr'):tag('td'):attr('colspan','2'):css('text-align','center')
:wikitext("[[File:".. others[3].content .. "|center|300px]]")
end
end
tab = tab .. getPreviousNextLine(entityID)
tab:node(getPreviousNextLine(entityID))
local s = "d:Wikidata:WikiProject Cycling/Documentation/infobox"
wdDoc(tab, "d:Wikidata:WikiProject Cycling/Documentation/infobox", infobox_translate(34), entityID)
tab = tab .. "<tr><td colspan='2' style='text-align:right; border-top:3px solid #FFDF80; font-size:75%'>" ..
"[[" .. s .. "|" .. infobox_translate(34) .. "]] [[File:Wikidata-logo S.svg|12px|link=d:".. entityID ..
"]]</td></tr></table>"
return tab
return tab
end
end
Línia 5.313: Línia 5.282:
end
end
end
end
outputTable[1]= riderReason
return riderReason, riderRef
outputTable[2]= riderRef
return outputTable
end
end


Línia 5.322: Línia 5.289:
if riderPosition == nil then -- find the 'position' (P39) of a rider
if riderPosition == nil then -- find the 'position' (P39) of a rider
for _, q in qualifiers(v, 'P39') do
for _, q in qualifiers(v, 'P39') do
stagiaire = q.value.id
stagiaire = q.value.id
local label = string.gsub(wikibase.label(stagiaire), "%b()", "") or getLabelFallback(stagiaire,{'en', 'fr', 'de'})
local label = string.gsub(wikibase.label(stagiaire), "%b()", "") or getLabelFallback(stagiaire,{'en', 'fr', 'de'})
riderPosition = ', ' .. label
riderPosition = ', ' .. label
end
end
end
end
Línia 5.342: Línia 5.309:


local function findlastname(label,wiki)
local function findlastname(label,wiki)
if not label then label = '' end
local _, count = string.gsub(label, " ", " ")
local _, count = string.gsub(label, " ", " ")
local names
local names
Línia 5.388: Línia 5.356:
end
end
end
end
return names
return names or ''
end
end


Línia 5.396: Línia 5.364:
local label = wikibase.getLabelByLang(riderID, wiki)
local label = wikibase.getLabelByLang(riderID, wiki)
if not label then
if not label then
label = getLabelFallback(riderID, {'en', 'fr', 'de'})
label = getLabelFallback(riderID, {'en', 'fr', 'de', 'es'})
return findlastname(label,wiki)
return findlastname(label,wiki)
else
else
Línia 5.403: Línia 5.371:
return nametable[1]..nametable[2]
return nametable[1]..nametable[2]
else --no coma
else --no coma
return findlastname(label,wiki)
return findlastname(label,wiki)
end
end
end
end
else
else
local label = getLabelFallback(riderID, {'en', 'fr', 'de'})
local label = getLabelFallback(riderID, {'en', 'fr', 'de', 'es'})
return findlastname(label,wiki)
return findlastname(label,wiki)
end
end
Línia 5.451: Línia 5.419:
riderName, correctlanguage =getRiderLink(riderID, startOfSeason) --label
riderName, correctlanguage =getRiderLink(riderID, startOfSeason) --label
if WDlink_on==true then riderName=riderName..wdLink(riderID) end
if WDlink_on==true then riderName=riderName..wdLink(riderID) end
local timeofrace = startOfSeason
local timeOfRace = startOfSeason


local temp=firstValue(riderID, 'P569','time')
riderBirthday=firstValue(riderID, 'P569','time')
if temp then riderBirthday= temp end


if not wikiisslavic then correctlanguage=true end --actually we never take a cyrillic name if no latin is found
if not wikiisslavic then correctlanguage=true end --actually we never take a cyrillic name if no latin is found
local sortkey = findsortkey(riderID, correctlanguage, wiki, wikiisslavic)
local sortkey = findsortkey(riderID, correctlanguage, wiki, wikiisslavic)


riderReasonTable=getreason(riderReason,riderRef,p527)
riderReason, iderRef=getreason(riderReason,riderRef,p527)
riderReason=riderReasonTable[1]
riderRef=riderReasonTable[2]


for _, q in qualifiers(p527, 'P580') do
for _, q in qualifiers(p527, 'P580') do
local startdate = q.value['time']
local startdate = q.value['time']
timeofrace = startdate
timeOfRace = startdate
riderStart = func_date(trans(startdate,'01', '01'), 'small')
riderStart = func_date(trans(startdate,'01', '01'), 'small')
end
end
Línia 5.478: Línia 5.443:


if teamID == nil then
if teamID == nil then
local p54 = getStatementForTime(riderID, 'P54', timeofrace)
local p54 = getStatementForTime(riderID, 'P54', timeOfRace)
if p54 then teamID = p54.mainsnak.datavalue.value.id end
if p54 then teamID = p54.mainsnak.datavalue.value.id end
else
else
Línia 5.485: Línia 5.450:
local thisteamID = v.mainsnak.datavalue.value.id
local thisteamID = v.mainsnak.datavalue.value.id
if thisteamID == teamID then
if thisteamID == teamID then
riderReasonTable=getreason(riderReason,riderRef,v)
riderReason, riderRef=getreason(riderReason,riderRef,v)
riderReason=riderReasonTable[1]
riderRef=riderReasonTable[2]
if v.qualifiers and v.qualifiers["P580"] and v.qualifiers["P580"][1].snaktype == 'value' then
if v.qualifiers and v.qualifiers["P580"] and v.qualifiers["P580"][1].snaktype == 'value' then
date1=v.qualifiers["P580"][1].datavalue.value.time
date1=v.qualifiers["P580"][1].datavalue.value.time
Línia 5.561: Línia 5.524:
--get the country
--get the country
local countryID
local countryID
local p27 = getStatementForTime(riderID, 'P27', timeofrace) --P27 is country of citizenship
local p27 = getStatementForTime(riderID, 'P27', timeOfRace) --P27 is country of citizenship
if p27 then
if p27 then
countryID = p27.mainsnak.datavalue.value.id
countryID = p27.mainsnak.datavalue.value.id
Línia 5.567: Línia 5.530:
if countryID then
if countryID then
pays = getCountryName(countryID)
pays = getCountryName(countryID)
flags = flag(countryID, timeofrace)
flags = flag(countryID, timeOfRace)
end
end
--save
--save
Línia 5.590: Línia 5.553:
end
end


local tableBody= ''
local outputTable = mw.html.create('table')
:addClass('sortable')
local tableHeader = '<table border="0" cellspacing="0" cellpadding="2" class="sortable">'
:attr('cellpadding', '2')
..'<tr style="background-color:#FFDF80;line-height:1.8em;"><th colspan = "4" style="text-align:center;white-space:nowrap">'
:attr('cellspacing', '0')
if WDlink_on == false then tableHeader = tableHeader..'<span style="float:left">[[File:Wikidata-logo S.svg|12px|link=d:'.. frame.args[1].. '#P527]]</span>' end
:css('border' , '1px solid rgb(200,200,200)')
tableHeader = tableHeader..getSquadTableColumn(7) .. '</th></tr>'
:css('padding', '3px')
tableHeader = tableHeader..'<th style="text-align:center;padding:2px 20px 2px 2px;white-space:nowrap">'..getSquadTableColumn(1) ..
outputTable:tag('tr'):cssText('background-color:#FFDF80;line-height:1.8em;')
'</th><th style="text-align:center;padding:2px 20px 2px 2px;white-space:nowrap">'..getSquadTableColumn(2)
if available_list and wiki ~= 'lv' then tableHeader = tableHeader.. '</th><th style="text-align:center;padding:2px 20px 2px 2px;white-space:nowrap">'..getSquadTableColumn(6) end
:tag('th'):attr('colspan', 4):cssText('text-align:center;white-space:nowrap')
:wikitext('<span style="float:left">[[File:Wikidata-logo S.svg|12px|link=d:'.. frame.args[1].. '#P527]]</span>')
tableHeader = tableHeader.. '</th><th style="text-align:center;padding:2px 20px 2px 2px;white-space:nowrap">'..getSquadTableColumn(3) .. '</th></tr>'
:wikitext(getSquadTableColumn(7))
local tableFoot = '</table>'
local tableEndText = ''
local header = outputTable:tag('tr')
header:tag('th'):cssText('text-align:center;padding:2px 20px 2px 2px;white-space:nowrap'):wikitext(getSquadTableColumn(1))
header:tag('th'):cssText('text-align:center;padding:2px 20px 2px 2px;white-space:nowrap'):wikitext(getSquadTableColumn(2))
if available_list and wiki ~= 'lv' then
header:tag('th'):cssText('text-align:center;padding:2px 20px 2px 2px;white-space:nowrap'):wikitext(getSquadTableColumn(6))
end
header:tag('th'):cssText('text-align:center;padding:2px 20px 2px 2px;white-space:nowrap'):wikitext(getSquadTableColumn(3))

local temp
local iii = 1
local iii = 1
local i = 1
local i = 1
for _, v in pairs (riderTable) do
for _, v in pairs (riderTable) do
sortkey=v[1]
riderName=v[2]
riderName=v[2]
riderBirthday=v[3]
riderBirthday=v[3]
Línia 5.617: Línia 5.589:
pays=v[13]
pays=v[13]
flags=v[14]
flags=v[14]
local tRow=outputTable:tag('tr'):css('line-height','1.8em')
local tCell= tRow:tag('td'):cssText("padding:0 1em 0 0;white-space:nowrap")

if not available_list or wiki == 'lv' then temp=flags..' ' else temp='' end
tCell:wikitext(temp..riderName):attr('data-sort-value',sortkey)


tableBody = tableBody.. '<tr style="line-height:1.8em"><td style="padding:0 1em 0 0;white-space:nowrap">'
if not available_list or wiki == 'lv' then tableBody=tableBody.. flags..' '..riderName else tableBody = tableBody.. riderName end
if riderStart~=nil or riderEnd~=nil then
if riderStart~=nil or riderEnd~=nil then
tableBody=tableBody..'<span style="font-size:80%; color:#686868"> ('..riderStart..'–'..riderEnd.. (riderPosition or '')
tCell:tag('span'):cssText("font-size:80%; color:#686868")
local note=''
if riderReason ~= nil then
if riderReason ~= nil then
local note = ', [[#tr_'..i..frame.args[1]..'|'..getSquadTableColumn(4)..']]'
note = ', [[#tr_'..i..frame.args[1]..'|'..getSquadTableColumn(4)..']]'
if wiki == "ar" then note = '، [[#tr_'..i..frame.args[1]..'|'..getSquadTableColumn(4)..']]' end
if wiki == "ar" then note = '، [[#tr_'..i..frame.args[1]..'|'..getSquadTableColumn(4)..']]' end
tableBody = tableBody .. note
end
end
tCell:wikitext( ' ('..riderStart..'–'..riderEnd.. (riderPosition or '')..note..')')
tableBody=tableBody .. ')</span>'
elseif riderReason then
elseif riderReason then
tableBody=tableBody.. '<span style="font-size:80%; color:#686868"> ([[#tr_'..i..frame.args[1]..'|'..getSquadTableColumn(4)..']]'.. ')</span>'
tCell:tag('span'):cssText("font-size:80%; color:#686868")
:wikitext('([[#tr_'..i..frame.args[1]..'|'..getSquadTableColumn(4)..']]'.. ')')
end
end
tableBody = tableBody.. '</td><td style="text-align:right;white-space:nowrap">'
tCell=tRow:tag('td'):cssText("text-align:right;white-space:nowrap")
if wiki == 'lv' then
if wiki == 'lv' then
local _, _, y1, m1, d1 = string.find(startOfSeason,"(%d+)-(%d+)-0*(%d+)")
local _, _, y1, m1, d1 = string.find(startOfSeason,"(%d+)-(%d+)-0*(%d+)")
local _, _, y2, m2, d2 = string.find(riderBirthday or '',"(%d+)-(%d+)-0*(%d+)")
local _, _, y2, m2, d2 = string.find(riderBirthday or '',"(%d+)-(%d+)-0*(%d+)")
tableBody = tableBody.. frame:expandTemplate{ title = 'Template:Birth date and age2', args = { y1, m1, d1, y2, m2, d2 } }.. '</td>'
tCell:wikitext(frame:expandTemplate{ title = 'Template:Birth date and age2', args = { y1, m1, d1, y2, m2, d2 } })
else
else
tableBody = tableBody.. func_date(riderBirthday or '', 'long')
tCell:wikitext(func_date(riderBirthday or '', 'long'))
if available_list then
if not available_list then tableBody=tableBody..'</td>' else tableBody=tableBody..'</td><td>'.. flags.. ' '..pays.. '</td>' end
tRow:tag('td'):wikitext(flags.. ' '..pays)
end
end
end


Línia 5.644: Línia 5.623:
local isRtl = (mw.ustring.find(riderTeam, '|.*[א-ת]') or (not mw.ustring.find(riderTeam, '|') and mw.ustring.find(riderTeam, '[א-ת]')))
local isRtl = (mw.ustring.find(riderTeam, '|.*[א-ת]') or (not mw.ustring.find(riderTeam, '|') and mw.ustring.find(riderTeam, '[א-ת]')))
if isRtl then
if isRtl then
tableBody = tableBody.. '<td style="padding:0 0.5em; text-align:right">'
tCell=tRow:tag('td'):cssText("padding:0 0.5em; text-align:right")
else
else
labelMissing = true -- FIXME: labelMissing is not functional in most languages. once we have infra support for it, move it there
labelMissing = true -- FIXME: labelMissing is not functional in most languages. once we have infra support for it, move it there
tableBody = tableBody.. '<td style="padding:0 0.5em; text-align:left">'
tCell=tRow:tag('td'):cssText("padding:0 0.5em; text-align:left")
end
end
else
else
tableBody = tableBody.. '<td style="padding:0 0.5em; text-align:left">'
tCell=tRow:tag('td'):cssText("padding:0 0.5em; text-align:left")
end
if riderTeam then
tCell:wikitext(riderTeam.. timeTeam..errortext)
end
end

if riderTeam then tableBody = tableBody.. riderTeam.. timeTeam..errortext end
tableBody = tableBody..'</td></tr>'


if riderReason ~= nil or errortext ~= '' then
if riderReason ~= nil or errortext ~= '' then
Línia 5.664: Línia 5.643:
end
end
if iii == 1 then
if iii == 1 then
tableEndText = tableEndText.. getSquadTableColumn(5)..': '.. riderName.. temp
outputTable:wikitext(getSquadTableColumn(5)..': '.. riderName.. temp)
else
else
outputTable:tag('span'):css('color','white')
tableEndText = tableEndText.. '<span style="color:white">'.. getSquadTableColumn(5)..': </span>'.. riderName.. temp
:wikitext(getSquadTableColumn(5))
outputTable:wikitext(riderName.. temp)
end
end
iii = iii + 1
iii = iii + 1
if riderRef ~= nil then tableEndText = tableEndText..
if riderRef ~= nil then
frame:extensionTag{name='ref', content=riderRef, args = {name='tr_'..i..frame.args[1]}} end
local tRef=frame:extensionTag{name='ref', content=riderRef, args = {name='tr_'..i..frame.args[1]}}
outputTable:node(tRef)
tableEndText = tableEndText.. '<br>'
end
outputTable:wikitext('<br>')
end
end
end
end
if labelMissing then outputTable:wikitext(getMissingLabelTrackingCategory()) end

local borderStyle = 'border:1px solid rgb(200,200,200); padding: 4px'
local UCIlink
if wiki == 'lv' then
if wiki=="fr" then
borderStyle = 'border:0'
UCIlink="https://www.uci.org/fr/route/%C3%A9quipe"
else
UCIlink="https://www.uci.org/road/teams"
end
end
local tableStart = '<table style="' .. borderStyle .. '"><tr><td style="vertical-align:top;">'
local tableEnd = '</td></tr></table>'


outputTable:tag('tr'):tag('td'):addClass("navigation-only")
if labelMissing then tableEnd = tableEnd .. getMissingLabelTrackingCategory() end
:attr('data-sort-value','zz')

:attr('colspan',4)
return tableStart .. tableHeader .. tableBody .. tableFoot .. tableEnd .. tableEndText
:cssText("border-top: 2px #FFDF80 solid; font-size: 80%;")
:tag('tr')
:tag('td'):attr('colspan',4)
:attr('data-sort-value','zzz')
:cssText("text-align:right")
:tag('small'):wikitext(race_reference_translate(wiki, 1).."["..UCIlink..' UCI]')
return outputTable
end
end


Línia 5.921: Línia 5.913:


local titletable={
local titletable={
['Q20882667']=listofwinners_translate(2), --winner
['Q20882667']=listofwinners_translate(2), --winner
['Q20882668']=listofwinners_translate(3), --second
[ 'Q27104269' ]=listofwinners_translate(2), --winner team
['Q20882669']=listofwinners_translate(4), --third
[ 'Q20883139' ]=listofwinners_translate(2), --winner young
['Q20883007']=listofwinners_translate(5), --points
[ 'Q72068715' ]=listofwinners_translate(2), --winner country
['Q20883212' ]=listofwinners_translate(6), -- mountains
[ 'Q72068724' ]=listofwinners_translate(2), --winner countryU23
['Q20883328' ]=listofwinners_translate(7), -- sprints
['Q20882668']=listofwinners_translate(3), --second

[ 'Q20883139']=listofwinners_translate(8) , -- youth
['Q20882669']=listofwinners_translate(4), --third
[ 'Q20883007' ]=listofwinners_translate(5), -- points
[ 'Q20883212' ]=listofwinners_translate(6), -- mountains
[ 'Q20883328' ]=listofwinners_translate(7), -- sprints
[ 'Q20883139' ]=listofwinners_translate(8), -- youth
[ 'Q20893983' ]=listofwinners_translate(9), -- combativity
[ 'Q20893983' ]=listofwinners_translate(9), -- combativity
[ 'Q20893979' ]=listofwinners_translate(10), -- combination
[ 'Q20893979' ]=listofwinners_translate(10), -- combination
[ 'Q20882921' ]=listofwinners_translate(11), -- teams
[ 'Q20882921' ]=listofwinners_translate(11), -- teams
[ 'Q27067359' ]=listofwinners_translate(12), -- volantes
[ 'Q27067359' ]=listofwinners_translate(12), -- volantes
[ 'Q27067170' ]=listofwinners_translate(13), -- regularity
[ 'Q27067170' ]=listofwinners_translate(13), -- regularity
Línia 5.937: Línia 5.935:
[ 'Q27907747' ]=listofwinners_translate(16), -- azzurri
[ 'Q27907747' ]=listofwinners_translate(16), -- azzurri
[ 'Q28092831' ]=listofwinners_translate(17), -- rookie
[ 'Q28092831' ]=listofwinners_translate(17), -- rookie
[ 'Q61976850' ]=listofwinners_translate(18), -- amateur
[ 'Q61976850' ]=listofwinners_translate(18), -- amateur
[ 'Q61976872' ]=listofwinners_translate(19) --nationality
[ 'Q61976872' ]=listofwinners_translate(19), -- nationality
-- 1, 2 and 3 place of team, young, country, countryU23 :
[ 'Q72065970' ]=listofwinners_translate(3), --second team
[ 'Q72099969' ]=listofwinners_translate(3), --second young
[ 'Q72068718' ]=listofwinners_translate(3), --second country
[ 'Q72068725' ]=listofwinners_translate(3), --second countryU23
[ 'Q72065977' ]=listofwinners_translate(4), --third team
[ 'Q72099972' ]=listofwinners_translate(4), --third young
[ 'Q72068721' ]=listofwinners_translate(4), --third country
[ 'Q72068729' ]=listofwinners_translate(4), --third countryU23
}
}


Línia 6.002: Línia 6.010:
local winners = {}
local winners = {}
for _, property in ipairs(s.winnersProperty) do winners[property]='' end
for _, property in ipairs(s.winnersProperty) do winners[property]='' end
local tCell

local temprow = "<tr><td style='text-align:left'>" .. sitelink
local tCellstr=''
local temp=firstValue(partID, 'P1346','id')
local temp=firstValue(partID, 'P1346','id')
if temp and temp=='Q30108381' then --race cancelled
if temp and temp=='Q30108381' then --race cancelled
local cancelledlabel = getLabelFallback('Q30108381', {wikilang, 'en', 'fr', 'de'})
local cancelledlabel = getLabelFallback('Q30108381', {wikilang, 'en', 'fr', 'de'})
tCell=mw.html.create('td'):attr('colspan','4')
temprow=temprow.."<td colspan='4' style='text-align:center; font-style: italic'>" ..cancelledlabel
:cssText('text-align:center; font-style: italic')
.. "</td>"
:wikitext(cancelledlabel)
tCellstr=tostring(tCell)
else
else
winner(partID, winners, timeOfRace, not s.countryflag, WDlink_on,s.displayteam,true)
winner(partID, winners, timeOfRace, not s.countryflag, WDlink_on,s.displayteam,true)
for _, property in ipairs(s.winnersProperty) do
for _, property in ipairs(s.winnersProperty) do
temprow=temprow.."</td><td>" ..winners[property]
tCell=mw.html.create('td'):wikitext(winners[property])
if winners[property]~='' then
if winners[property]~='' then
thereisawinner=true
thereisawinner=true
if tonumber(year)<firstyeartodisplay then firstyeartodisplay=tonumber(year) end
if tonumber(year)<firstyeartodisplay then firstyeartodisplay=tonumber(year) end
end
end
tCellstr= tCellstr..tostring(tCell)
end
end
end
end
if firstyeartodisplay<=tonumber(year) then
if firstyeartodisplay<=tonumber(year) then
rows[#rows+1]={year..month, temprow .. "</td></tr>"}
rows[#rows+1]={year..month, sitelink, tCellstr}
end
end
end
end
Línia 6.027: Línia 6.039:
end
end
table.sort(rows, function(a, b) return a[1] < b[1] end) -- Sort by year
table.sort(rows, function(a, b) return a[1] < b[1] end) -- Sort by year
local clear = "left"
local clear = "left"
if wiki == "ar" then clear = "right" end
if wiki == "ar" then clear = "right" end
local table_first = "<table cellpadding='4' cellspacing='0' style='border:1px solid rgb(200,200,200); color:black;margin:0 0 0.5em 0; background-color:rgb(255, 255, 255); padding:5px; clear:".. clear .. "; text-align:" .. textalign .. "; vertical-align:top; font-size:85%; line-height:1.6em;'>"
--do not use hw.html here otherwise the begin and end year won't work
local table_proto = "<tr style='background:#FFDF80; text-align:center'><th>"
local table_first = "<table cellpadding='4' cellspacing='0' style='"..standardtablecss.."'>"

local tTitleRow=mw.html.create('tr')
:cssText('background:#FFDF80; text-align:center')
local tCell=tTitleRow:tag('th')
if WDlink_on == false then
if WDlink_on == false then
tCell:tag('span'):css("float","left")
table_proto = table_proto .. '<span style="float:left">[[File:Wikidata-logo S.svg|12px|link=d:' ..
raceID .. '#P527]]</span>'
:wikitext("[[File:Wikidata-logo S.svg|12px|link=d:"..raceID .. "#P527]]")
end
end
table_proto = table_proto .. listofwinners_translate(1).. "</th>" --year
tCell:wikitext(listofwinners_translate(1)) --year
for kk, pp in ipairs(s.winnersProperty) do
for _, pp in ipairs(s.winnersProperty) do
table_proto = table_proto.."<th>".. titletable[pp] .. "</th>"
tTitleRow:tag('th'):wikitext(titletable[pp])
end
end
table_proto =table_proto .."</tr>"
local table_center, table_last = "", "</table>"
local table_center=''
local nb_year_inrow=1

local lastyear
for i, row in ipairs(rows) do
for i, row in ipairs(rows) do
sitelink=row[2]

local tRowWD=mw.html.create('tr')
local tCell=tRowWD:tag('td'):css('text-align','left')
if lastyear and mw.ustring.sub(row[1],1,4)==lastyear then
nb_year_inrow=nb_year_inrow+1
tCell:wikitext(sitelink..' ('..tostring(nb_year_inrow)..')')
else
tCell:wikitext(sitelink)
nb_year_inrow=1
end
lastyear=mw.ustring.sub(row[1],1,4)
tRowWD:node(row[3]) --add the end of the row
if WPcontent.row[i] then
if WPcontent.row[i] then
tRow=mw.html.create('tr'):tag('td'):attr('colspan','4')
:css('text-align','center')
tRow:wikitext(WPcontent.row[i])

if WPcontent.code[i]==0 then --above
if WPcontent.code[i]==0 then --above
table_center = table_center .. "<tr><td colspan='4' style='text-align:center'>" ..
table_center=table_center..tostring(tRow)
table_center=table_center..tostring(tRowWD)
WPcontent.row[i] .. "</td></tr>"
table_center = table_center .. row[2]
else --below
else --below
table_center = table_center .. row[2]
table_center=table_center..tostring(tRowWD)
table_center = table_center .. "<tr><td colspan='4' style='text-align:center'>" ..
table_center=table_center..tostring(tRow)
WPcontent.row[i] .. "</td></tr>"
end
end
else
else
table_center = table_center .. row[2]
table_center=table_center..tostring(tRowWD)
end
end
end
end
--firstpart with header no foot
--firstpart with header no foot
if endyear > 0 then
if endyear > 0 then
return table_first .. table_proto .. table_center
return table_first .. tostring(tTitleRow) .. table_center
elseif beginyear > 0 then
elseif beginyear > 0 then
return table_center .. table_last
return table_center .. table_last
else
else
return table_first .. table_proto .. table_center .. table_last
return table_first .. tostring(tTitleRow) .. table_center .. "</table>"
end
end
end
end
Línia 6.203: Línia 6.240:
local sDistance = getDistance(stageID, false) or ''
local sDistance = getDistance(stageID, false) or ''
local sElevation = getElevation(stageID)
local sElevation = getElevation(stageID)
if sElevation ~= "" then thereiselevation=true end
if sElevation then thereiselevation=true end
local winners = {
local winners = {
Línia 6.238: Línia 6.275:
return a[2] < b[2]
return a[2] < b[2]
end)
end)
tab=mw.html.create('table')
:attr('cellpadding','4' )
:attr('cellspacing','0')
:cssText(standardtablecss)

local tRow=tab:tag('tr'):cssText('background:#FFDF80; text-align:center;')
tRow:tag('th'):css('white-space','nowrap')
:wikitext(((not WDlink_on and wdLink(string.gsub(raceID, '%s', '') .. "#P527")) or "")..
headoftable(1))
tRow:tag('th'):wikitext(headoftable(2))
tRow:tag('th'):wikitext(headoftable(3))
tRow:tag('th'):css('color','#FFDF80'):wikitext("type")
tRow:tag('th'):wikitext(headoftable(4))
if thereiselevation then
tRow:tag('th'):wikitext(headoftable(7))
end
tRow:tag('th'):wikitext(headoftable(5))
tRow:tag('th'):wikitext(headoftable(6))


for num, row in pairs(rows) do
for num, row in pairs(rows) do
Línia 6.252: Línia 6.308:
end
end


local tRow = tab:tag('tr')
local t = "<tr><td style='text-align:center; white-space:nowrap'>" .. sLink ..
"<span style='white-space:nowrap'>&nbsp;".. WDLink ..
local tCell= tRow:tag('td'):cssText('text-align:center; white-space:nowrap'):wikitext(sLink)
"</span></td><td style='white-space:nowrap; text-align:right; padding-right:0px'>" .. sDate ..
tCell:tag('span'):css('white-space','nowrap'):wikitext("&nbsp;".. WDLink )
"</td><td style='padding-right:0px'>" .. sPoint
tRow:tag('td'):css('white-space','nowrap'):cssText("text-align:right; padding-right:0px")
:wikitext(sDate)
if dPoint ~= '' then t = t .. " – " .. dPoint end
tCell=tRow:tag('td'):cssText("padding-right:0px"):wikitext( sPoint)
t = t .. "</td><td style='padding-top:10px'>" .. sType ..
if dPoint ~= '' then
"</td><td style='text-align:center'>" .. sDistance .. "</td>"
tCell:wikitext(" – " .. dPoint)
end
tRow:tag('td'):cssText("padding-right:0px"):wikitext(sType)
tRow:tag('td'):css('text-align','center'):wikitext( sDistance)
if thereiselevation then
if thereiselevation then
t = t.."<td style='text-align:center'>" .. sElevation .. "</td>"
tRow:tag('td'):css('text-align','center'):wikitext(sElevation)
end
end


if WPc and WPc['stage winner'] then
if WPc and WPc['stage winner'] then
t = t .. "<td style='text-align:" .. textalign .. "'>" .. WPc['stage winner'] .. "</td>"
tRow:tag('td'):css('text-align',textalign):wikitext( WPc['stage winner'])
else
else
t = t .. "<td>" .. sSWin .. "</td>"
tRow:tag('td'):wikitext(sSWin)
end
end
if WPc and WPc['general winner'] then
if WPc and WPc['general winner'] then
t = t .. "<td style='text-align:" .. textalign .. "'>" .. WPc['general winner'] .. "</td></tr>"
tRow:tag('td'):css('text-align',textalign):wikitext( WPc['general winner'])
else
else
t = t .. "<td>" .. sGWin .. "</td></tr>"
tRow:tag('td'):wikitext(sGWin)
end
end
if WPc and (WPc['date'] or WPc['text'] or WPc['icon (new row)']) then
if WPc and (WPc['date'] or WPc['text'] or WPc['icon (new row)']) then
t = t .. "<tr><td></td>"
tRow = tab:tag('tr')
tRow:tag('td') --empty

if WPc['icon (new row)'] == '' then
if WPc['icon (new row)'] == '' then
t = t .. "<td style='text-align:right; padding:3px 0px 10px 0px;white-space:nowrap'>" .. WPc['date'] ..
tRow:tag('td'):cssText('text-align:right; padding:3px 0px 10px 0px;white-space:nowrap')
:wikitext(WPc['date'])
"</td><td style='text-align:" .. textalign .. "; padding:3px 4px 10px'>" .. WPc['text']
tRow:tag('td'):cssText("text-align:" .. textalign .. "; padding:3px 4px 10px")
:wikitext(WPc['text'])
else
else
t = t .. "<td style='text-align:right; padding-right:0px'>" .. WPc['date'] ..
tRow:tag('td'):cssText('text-align:right; padding-right:0px')
:wikitext(WPc['date'])
"</td><td style='text-align:" .. textalign .. "'>" .. WPc['text']
tRow:tag('td'):cssText("text-align:" .. textalign)
:wikitext(WPc['text'])
end
end
t = t .. "</td><td style='padding-top:10px'>" .. WPc['icon (new row)'] .. "</td><td colspan='3' ></td></tr>"
tRow:tag('td'):css('padding-top','10px'):wikitext(WPc['icon (new row)'])
tRow:tag('td'):attr('colspan','3')
end
end
rows[num] = t
end
end
return tab
tableBody=table.concat(rows)

result= "<table border='0' cellpadding='4' cellspacing='0' style='border:1px solid rgb(200,200,200); color:black; margin:0 0 0.5em 0; background-color:rgb(255, 255, 255); padding:5px; clear:left; text-align:" ..
textalign .. "; font-size:85%; line-height:1.6em;'>" ..
"<tr style='background:#FFDF80; text-align:center;'><th style='white-space:nowrap'>" ..
((not WDlink_on and wdLink(string.gsub(raceID, '%s', '') .. "#P527")) or "")..
headoftable(1) .. "</th><th>" .. headoftable(2) .. "</th><th>".. headoftable(3) ..
"</th><th style='color:#FFDF80'>type</th><th>".. headoftable(4)
if thereiselevation then result=result.. "</th><th>".. headoftable(7) end
result=result.."</th><th>".. headoftable(5) ..
"</th><th>" .. headoftable(6) .. "</th></tr>"..tableBody.."</table>"
return result
end
end


Línia 6.315: Línia 6.369:
-- find the type of stage
-- find the type of stage
local sType = typeofstagelogo(stageID)
local sType = typeofstagelogo(stageID)
return "<table><th>"..sPoint.." - "..dPoint .."</th><td>"..sType.."</td><td>'''("..sDistance..")'''</td></table>"
tab=mw.html.create('table')
tab:tag('th'):wikitext(sPoint.." - "..dPoint)
tab:tag('td'):wikitext(sType)
tab:tag('td'):css('font-weight','bold'):wikitext("("..sDistance..")")
return tab
end
end


Línia 6.328: Línia 6.387:
local road, ITT, result
local road, ITT, result
local hcountry, hnotcountry = {},{}
local hcountry, hnotcountry = {},{}
--the jersey for a stage race and the jersey from national championship should be differentiated
--to avoid to look every time, below is a list of all national championships
local womenRoadtable= {Q934877=true, Q50064341=true,Q50061750=true,Q31271454=true,Q54315111=true,Q30894544=true,
local womenRoadtable= {Q934877=true, Q50064341=true,Q50061750=true,Q31271454=true,Q54315111=true,Q30894544=true,
Q66082905=true,Q65965631=true,Q45083914=true,Q31271492=true,Q43286073=true,Q55185740=true,Q65371835=true,
Q66082905=true,Q65965631=true,Q45083914=true,Q31271492=true,Q43286073=true,Q55185740=true,Q65371835=true,
Línia 6.607: Línia 6.669:
end
end


local dateOfRace
local timeOfRace
for ii, v in pairs(stages) do
for ii, v in pairs(stages) do
if v.mainsnak.snaktype == 'value' then
if v.mainsnak.snaktype == 'value' then
Línia 6.636: Línia 6.698:
local eTime = firstValue(stageID, 'P582', 'time') -- P582 is 'end time'
local eTime = firstValue(stageID, 'P582', 'time') -- P582 is 'end time'
if sTime and eTime then
if sTime and eTime then
dateOfRace = eTime
timeOfRace = eTime
else
else
-- This function give a format to dates when P585 (date) is used in a single day race.
-- This function give a format to dates when P585 (date) is used in a single day race.
local pTime = firstValue(stageID, 'P585', 'time') -- P585 is 'point in time'
local pTime = firstValue(stageID, 'P585', 'time') -- P585 is 'point in time'
if pTime then
if pTime then
dateOfRace = pTime
timeOfRace = pTime
end
end
end
end
Línia 6.650: Línia 6.712:
if ii==1 then jerseytable[v.QID]='' end
if ii==1 then jerseytable[v.QID]='' end
end
end
winner(stageID, win, dateOfRace, false, WDlink_on, false, false)
winner(stageID, win, timeOfRace, false, WDlink_on, false, false)
if ii==1 then --only first stage
if ii==1 then --only first stage
jerseytable, bgcolortable=winnerjersey(stageID, jerseytable)
jerseytable, bgcolortable=winnerjersey(stageID, jerseytable)
Línia 6.690: Línia 6.752:
end
end
end
end
local thiskey
somewinner = false
somewinner = false
jerseytable, bgcolortable=winnerjersey(raceID, jerseytable)
jerseytable, bgcolortable=winnerjersey(raceID, jerseytable)
winner(raceID, win, dateOfRace, false, WDlink_on, false, false)
winner(raceID, win, timeOfRace, false, WDlink_on, false, false)
for _, v in pairs(winnersgen) do
for _, v in pairs(winnersgen) do
if win[v.QID] and win[v.QID] ~= '' then
if win[v.QID] and win[v.QID] ~= '' then
somewinner=true
somewinner=true
thiskey=generaltoleader[v.QID]
columntable[generaltoleader[v.QID]][#stages+1][1]=win[v.QID]
columntable[generaltoleader[v.QID]][#stages+1][2]=#stages+1
columntable[thiskey][#stages+1][1]=win[v.QID]
columntable[generaltoleader[v.QID]][#stages+1][3]=1
columntable[thiskey][#stages+1][2]=#stages+1
if type(columntable[generaltoleader[v.QID]][#stages][1])~="string" then --check nil actually, but it is a table..
columntable[thiskey][#stages+1][3]=1
if type(columntable[thiskey][#stages][1])~="string" then --check nil actually, but it is a table..
columntable[generaltoleader[v.QID]][#stages][1]=win[v.QID] --no need to fill last stage of a stage race
columntable[thiskey][#stages][1]=win[v.QID] --no need to fill last stage of a stage race
if type(columntable[generaltoleader[v.QID]][#stages-1][1])=="string" and win[v.QID]==columntable[generaltoleader[v.QID]][#stages-1][1] then
if type(columntable[thiskey][#stages-1][1])=="string" and win[v.QID]==columntable[thiskey][#stages-1][1] then
local initialstage=columntable[generaltoleader[v.QID]][#stages-1][2]
local initialstage=columntable[thiskey][#stages-1][2]
columntable[generaltoleader[v.QID]][#stages][2]=initialstage
columntable[thiskey][#stages][2]=initialstage
columntable[generaltoleader[v.QID]][initialstage][3]=columntable[generaltoleader[v.QID]][initialstage][3]+1
columntable[thiskey][initialstage][3]=columntable[thiskey][initialstage][3]+1
columntable[generaltoleader[v.QID]][#stages][3]=0
columntable[thiskey][#stages][3]=0
else
else
columntable[generaltoleader[v.QID]][#stages][2]=#stages
columntable[thiskey][#stages][2]=#stages
columntable[generaltoleader[v.QID]][#stages][3]=1
columntable[thiskey][#stages][3]=1
end
end
end
end
columntable[generaltoleader[v.QID]].used=true
columntable[thiskey].used=true
if jerseytable[v.QID] and jerseytable[v.QID]~='' then
if jerseytable[v.QID] and jerseytable[v.QID]~='' then
columntable[generaltoleader[v.QID]].jersey=jerseytable[v.QID]
columntable[thiskey].jersey=jerseytable[v.QID]
columntable[generaltoleader[v.QID]].bg_color=bgcolortable[v.QID]
columntable[thiskey].bg_color=bgcolortable[v.QID]
end
end
end
end
Línia 6.721: Línia 6.785:


--build the table
--build the table
local tab=mw.html.create('table')
local tablebegin="<table border='0' cellpadding='4' cellspacing='0' style='border:1px solid rgb(200,200,200); color:black; margin:0 0 0.5em 0; background-color:rgb(255, 255, 255); padding:5px; clear:left; text-align:" ..
:attr('cellpadding','4' )
textalign .. "; font-size:85%; line-height:1.6em;'>" ..
:attr('cellspacing','0')
"<tr style='background:#FFDF80; text-align:center;'><th style='white-space:nowrap'>" ..
:cssText(standardtablecss)
((not WDlink_on and wdLink(mw.ustring.gsub(raceID, '%s', '') .. "#P527")) or "")..
local tRow=tab:tag('tr'):cssText('background:#FFDF80; text-align:center;')
headoftable(1) .. "</th>"
tRow:tag('th'):css('white-space','nowrap')
:wikitext(((not WDlink_on and wdLink(string.gsub(raceID, '%s', '') .. "#P527")) or "")..
if displaytypeofstage==true then tablebegin=tablebegin.."<th></th>" end
headoftable(1))
if displaytypeofstage==true then tRow:tag('th') end


local tableheader=''
for v in itercolumns(columntable) do
for v in itercolumns(columntable) do
if v.used == true then
if v.used == true then
if v.jersey == '' then v.jersey = "_" end
if v.jersey == '' then v.jersey = "_" end
tableheader=tableheader.."<th>"..v.name.."<br />"..v.jersey.."</th>"
tRow:tag('th'):wikitext(v.name.."<br />"..v.jersey)
end
end
end
end
tableheader=tableheader.."</tr>"

local row, tablebody='',''
local style, tdtemp


local style
--then fill the table
--then fill the table
for ii, v in pairs(stageinfotable) do --one stage=one row
for ii, v in pairs(stageinfotable) do --one stage=one row
--stages link
--stages link
tRow=tab:tag('tr')
local tCell=tRow:tag('td')
if ii==#stageinfotable then
if ii==#stageinfotable then
tdtemp="<td colspan=2 style='font-weight:bold; border-top: 2px black solid;'>"
tCell:attr('colspan','2'):cssText('font-weight:bold; border-top: 2px black solid;')
tdtemp2="<td style='font-weight:bold; border-top: 2px black solid;'>"
else
tdtemp="<td>"
tdtemp2=tdtemp
end
end
row=tdtemp..v.sLink.."</td>"
tCell:wikitext(v.sLink)
tCell=tRow:tag('td')
if ii==#stageinfotable then
tCell:cssText('font-weight:bold; border-top: 2px black solid;')
end
if displaytypeofstage == true then
if displaytypeofstage == true then
if v.sType then
if v.sType then
row=row..tdtemp2..v.sType.."</td>"
tCell:wikitext(v.sType)
else
row=row..tdtemp2.."</td>"
end
end
end
end
Línia 6.765: Línia 6.828:
if y.used==true and not (ii==#stageinfotable and columntable['Q20882747']==y) then --only display used QID
if y.used==true and not (ii==#stageinfotable and columntable['Q20882747']==y) then --only display used QID
if type(y[ii][1])=="string" and type(y[ii][3])=="number" then --actually check nil but it is a table
if type(y[ii][1])=="string" and type(y[ii][3])=="number" then --actually check nil but it is a table
style=" style='"
style=""
if y[ii][3]~=0 and (columntable['Q20882747']==y)==false then
if y[ii][3]~=0 and (columntable['Q20882747']==y)==false then
if ii~=1 and ii~=#stageinfotable then style=style.." border-top:1px gray solid;" end
if ii~=1 and ii~=#stageinfotable then style=style.." border-top:1px gray solid;" end
if y.bg_color then style=style.." background-color:"..y.bg_color..";" end
if y.bg_color then style=style.." background-color:"..y.bg_color..";" end
if ii==#stageinfotable then style=style.."font-weight:bold; border-top: 2px black solid;" end
if ii==#stageinfotable then style=style.."font-weight:bold; border-top: 2px black solid;" end
tRow:tag('td'):attr('rowspan',tostring(y[ii][3])):cssText(style):wikitext(y[ii][1])
style=style.."'>"
row=row.."<td rowspan="..tostring(y[ii][3])..style..y[ii][1].."</td>"
elseif (columntable['Q20882747']==y) then --no rowspan for stages
elseif (columntable['Q20882747']==y) then --no rowspan for stages
row=row.."<td>"..y[ii][1].."</td>"
tRow:tag('td'):wikitext(y[ii][1])
end
end
else
else
tCell=tRow:tag('td')
if ii~=#stageinfotable and v.somewinner==true then
if ii~=#stageinfotable and v.somewinner==true then
row=row.."<td>"..listofstagesclassification_translate(1).."</td>" --not attributed
tCell:wikitext(listofstagesclassification_translate(1)) --not attributed
elseif ii~=#stageinfotable then
elseif ii~=#stageinfotable then
row=row.."<td>".."</td>" --empty
--empty
elseif v.somewinner==true then
elseif v.somewinner==true then
row=row.."<td style='border-top: 2px black solid'>"..listofstagesclassification_translate(1).."</td>"
tCell:cssText('border-top: 2px black solid')
:wikitext(listofstagesclassification_translate(1))
else
else
row=row.."<td style='border-top: 2px black solid'>".."</td>"
tCell:cssText('border-top: 2px black solid') --empty
end
end
end
end
end
end
end
end
tablebody=tablebody.."<tr>"..row.."</tr>"
end
end
return tab
return tablebegin..tableheader..tablebody.."</table>"
end
end


Línia 6.803: Línia 6.866:
header_function = startlist_translate,
header_function = startlist_translate,
header_1 = 1, -- translation 1 in function victories_translate is printed in the upper part of the table header
header_1 = 1, -- translation 1 in function victories_translate is printed in the upper part of the table header
header_2 = {2, 3,4,5},-- translations 2, 3, 4, 5, 6 in function victories_translate are printed in this order
header_2 = {2, 3,4,5},
item=IDtemp,
item=IDtemp,
title="Start list",
title="Start list", -- in the lower part of the table header. The second value 3 in {4, 3} tells where the icon will go.
data_sort_type={'unsortable', 'unsortable', 'unsortable'},
data_sort_type={'unsortable', 'unsortable', 'unsortable'},
property ='P710',
property ='P710',
no_roll_startlist=no_roll_startlist
no_roll_startlist=no_roll_startlist
}
}

--return frame:extensionTag{ name = 'nowiki', content =
local resulttable, tag = tableB(s)
return tableB(s, startlist_main(s)) --}
return startlist_main(s, resulttable, tag)
end
end


Línia 6.826: Línia 6.890:
item=IDtemp,
item=IDtemp,
title="Start list", -- in the lower part of the table header. The second value 3 in {4, 3} tells where the icon will go.
title="Start list", -- in the lower part of the table header. The second value 3 in {4, 3} tells where the icon will go.
-- data_type = {'date', 'race', 'country', 'class', 'rider'},
-- country_column = 3,
no_country ={'fr'},
no_country ={'fr'},
data_sort_type={'', '', ''},
data_sort_type={'', '', ''},
Línia 6.833: Línia 6.895:
no_roll_startlist=no_roll_startlist
no_roll_startlist=no_roll_startlist
}
}
return startlisttable_main(s, tableA(s))
--return frame:extensionTag{ name = 'nowiki', content =
return tableA(s, startlisttable_main(s)) --}
end
end


Línia 6.911: Línia 6.972:
riderTeam = getTeam(riderID, timeOfRace, q)
riderTeam = getTeam(riderID, timeOfRace, q)
riderTeamCode= getTeamCode(riderID, timeOfRace, q)
if riderTeam == nil then riderTeam ="" end
if riderTeam == nil then riderTeam ="" end
local sortkey = riderDossard == "" and 0 or tonumber(riderDossard)
local sortkey = riderDossard == "" and 0 or tonumber(riderDossard)


tBody = '<tr style= "line-height: 1.8em; padding: 5px;">'
tBody = mw.html.create('tr'):cssText("line-height: 1.8em; padding: 5px;")
tBody=tBody..'<td style="text-align:right;padding:0 0.5em">'..riderDossard..'</td>'
tBody:tag('td'):cssText("text-align:right;padding:0 0.5em"):wikitext(riderDossard)
tBody = tBody..'<td style="text-align:'..textalign.. ';padding:0 0.5em;'..DSQ..'>'..riderLink..'</td>'
tBody:tag('td'):cssText('text-align:'..textalign.. ';padding:0 0.5em;'..DSQ):wikitext(riderLink)
if istable then
if istable then
tBody = tBody..'<td style="text-align:'..textalign.. ';padding:0 0.5em">'..riderTeam..' </td>'
tBody:tag('td'):cssText("text-align:right;padding:0 0.5em"):wikitext(riderTeam)
end
end
tBody = tBody..'<td style="text-align:right;padding:0 0.5em;'..DSQ..'>'..number(gender,riderRank,wiki)..riderDNF..'</td>'
tBody:tag('td'):cssText('text-align:'..textalign.. ';padding:0 0.5em;'..DSQ):wikitext(number(gender,riderRank,wiki)..riderDNF)
tBody = tBody.. '</tr>'


table.insert(resulttable, {sortkey=sortkey, riderTeam=riderTeam,riderTeamCode=riderTeamCode, tBody=tBody})
table.insert(resulttable, {sortkey=sortkey, riderTeam=riderTeam,riderTeamCode=riderTeamCode, tBody=tBody})
Línia 6.927: Línia 6.989:
end
end


function startlist_main(s)
function startlist_main(s, resulttable, tag)
local tableBody, sortindex, fn_datetable, ridertable, DStable, subtable = {}, {}, {}, {}, {}, {}
local ridertable, DStable, subtable = {}, {}, {}, {}
local DSID, DSLink, DSteamID, DSteam
local DSID, DSLink, DSteamID, DSteam
local numberoflines
local WDlink_on = (wiki == "mk" or wiki == "ja" or wiki == "ru")
local WDlink_on = (wiki == "mk" or wiki == "ja" or wiki == "ru")


fn_datetable=fn_date(s.item)
local fn_datetable=fn_date(s.item)
local timeOfRace=fn_datetable[1]
local timeOfRace=fn_datetable[1]


Línia 6.949: Línia 7.010:
for _, p710 in statements(s.item, 'P710') do -- P710 is participants
for _, p710 in statements(s.item, 'P710') do -- P710 is participants
subtable=startlist_sub(p710, timeOfRace, WDlink_on, false)
subtable=startlist_sub(p710, timeOfRace, WDlink_on, false)
ridertable[#ridertable + 1] = {subtable[1].sortkey, riderTeam=subtable[1].riderTeam,riderTeamCode=subtable[1].riderTeamCode, tBody=subtable[1].tBody}
numberoflines = #ridertable
end
--sort by dossard
if numberoflines == 0 then
--sort
table.insert(sortindex, subtable[1].sortkey)
table.sort(ridertable, function(a, b) return a[1] < b[1] end)
table.insert(ridertable, {sortkey=subtable[1].sortkey, riderTeam=subtable[1].riderTeam,riderTeamCode=subtable[1].riderTeamCode, tBody=subtable[1].tBody})

elseif subtable[1].sortkey >= sortindex[numberoflines] then
local thisTableRow, thisTeamTable, thisDS, insideTable, test
table.insert(sortindex, subtable[1].sortkey)
local tSubtitle, tTitle
table.insert(ridertable, {sortkey=subtable[1].sortkey, riderTeam=subtable[1].riderTeam,riderTeamCode=subtable[1].riderTeamCode,tBody=subtable[1].tBody})
else
if wiki == "ar" then
local done=0
tSubtitle=mw.html.create('tr')
for i=numberoflines,1,-1 do
tSubtitle:tag('td'):attr('width','30px')
if subtable[1].sortkey >= sortindex[i] then
:css("align:right;text-align:right")
table.insert(sortindex, i+1, subtable[1].sortkey)
:wikitext(startlist_translate(2))
table.insert(ridertable, i+1, {sortkey=subtable[1].sortkey, riderTeam=subtable[1].riderTeam,riderTeamCode=subtable[1].riderTeamCode,tBody=subtable[1].tBody})
tSubtitle:tag('td'):attr('width','200px')
done=1
:css("align:right;text-align:right")
break
:wikitext(startlist_translate(3))
end
tSubtitle:tag('td'):attr('width','85px')
end
:css("align:right;text-align:right")
if done==0 then
:wikitext(startlist_translate(4))
table.insert(sortindex, 1, subtable[1].sortkey)
else
table.insert(ridertable, 1, {sortkey=subtable[1].sortkey, riderTeam=subtable[1].riderTeam,riderTeamCode=subtable[1].riderTeamCode,tBody=subtable[1].tBody})
tSubtitle=mw.html.create('tr')
end
tSubtitle:tag('td'):attr('width','30px'):wikitext(startlist_translate(2))
end
tSubtitle:tag('td'):attr('width','250px'):wikitext(startlist_translate(3))
tSubtitle:tag('td'):attr('width','35px'):wikitext(startlist_translate(4))
end
end

--look for transition between teams
--look for transition between teams
local test
local numberofteam=0
local numberofteam=0
local beginRow="<tr>"
local endRow="</tr>"
local tSubtitle, tTitle, beginTable, endTable
local tDS=''


if #ridertable==0 then--empty table
beginTable= '<td style="width:33%;" valign=top ><table border="0" cellpadding="4" cellspacing="0" solid rgb(200,200,200); color: black; margin: 0 0 0.5em 0; background-color: rgb(255, 255, 255); padding: 5px; float: left; clear:'..floattable..'; ; text-align:"' .. textalign .. '"; vertical-align: top; font-size: 100%; line-height: 1.8em;">'
return nil
endTable='</table></td>'
if numberoflines==nil then--empty table
table.insert(tableBody, beginTable)
table.insert(tableBody, endTable)
return table.concat (tableBody)
else
else
for ii=1,numberoflines+1 do
for ii=1,#ridertable do
if ridertable[ii].riderTeam==nil then ridertable[ii].riderTeam=startlist_translate(13) end
if ridertable[ii].riderTeam==nil then ridertable[ii].riderTeam=startlist_translate(13) end
tTitle = '<tr style="background-color:#FFDF80;" align="center"><th colspan="3"><big>'..ridertable[ii].riderTeam.."<br/>"
tTitle =tTitle..(ridertable[ii].riderTeamCode or "___")..'</big></th></tr>'
tSubtitle='<tr><td width="30px">'..startlist_translate(2)..'</td><td width="250px">'..startlist_translate(3)..'</td><td width="35px">'..startlist_translate(4)..'</td></tr>'
if wiki == "ar" then
tSubtitle='<tr><td width="30px" style="align:right;text-align:right">'..startlist_translate(2)..'</td><td width="200px" style="align:right;text-align:right">'..startlist_translate(3)..'</td><td width="85px" style="align:right;text-align:right">'..startlist_translate(4)..'</td></tr>'
end
if ii~=1 and ridertable[ii].riderTeam and ridertable[ii].riderTeam==ridertable[ii-1].riderTeam then test=0 else test=1 end--team change
if ii~=1 and ridertable[ii].riderTeam and ridertable[ii].riderTeam==ridertable[ii-1].riderTeam then test=0 else test=1 end--team change
--new team
if test==1 then
if ii~=1 then
if test==1 or ii==1 then
if thisDS and ii~=1 then
table.insert(tableBody,tDS)
tDS=insideTable:tag('tr')
table.insert(tableBody, endTable)
tDS:tag('td'):attr('colspan','3'):attr('align','center')
:wikitext(startlist_translate(5).." "..thisDS)
thisDS=nil
end
end
numberofteam=numberofteam+1
numberofteam=numberofteam+1
if math.fmod(numberofteam, 3 )==1 then
if math.fmod(numberofteam, 3 )==1 then
if ii~=1 then
if ii~=1 then
tag:node(thisTableRow) --a row with 3 tables inside, save and re-init
table.insert(tableBody, endRow)
end
end
thisTableRow=mw.html.create('tr')
table.insert(tableBody, beginRow)
end
end
thisTeamTable= thisTableRow:tag('td'):cssText("width:33%;"):attr('valign','top')
table.insert(tableBody, beginTable)
insideTable=thisTeamTable:tag('table') --reinit
table.insert(tableBody, tTitle)
:attr('cellpadding','4') --solid rgb(200,200,200)
table.insert(tableBody,tSubtitle)
:attr('background-color','rgb(255, 255, 255)')
end
:attr('margin', '0 0 0.5em 0')
table.insert(tableBody, ridertable[ii].tBody)
:attr('padding','5px')
if test==1 then
:attr('float','left')
local thisDS
:attr('text-align',textalign)
tDS=''
:attr('line-height','1.8em')
:attr('clear',floattable)

tTitle = mw.html.create('tr'):cssText("background-color:#FFDF80"):attr('align','center')
local tCell=tTitle:tag('th'):attr('colspan','3')
tCell:tag('big'):wikitext(ridertable[ii].riderTeam.."<br/>"..(ridertable[ii].riderTeamCode or "___"))
insideTable:node(tTitle)
insideTable:node(tSubtitle)
tDS=nil
--look for the DS of this team
--look for the DS of this team
for _,v in pairs(DStable) do
for _,v in pairs(DStable) do
if v.DSteam==ridertable[ii].riderTeam then thisDS=v.DSLink break end
if v.DSteam==ridertable[ii].riderTeam then thisDS=v.DSLink break end
end
if thisDS then
tDS='<tr><td colspan=3 align="center">'..startlist_translate(5).." "..thisDS.."</td></tr>"
end
end
end
end
insideTable:node(ridertable[ii].tBody)
end
end
--last DS
table.insert(tableBody,tDS)
if tDS then thisTeamTable:node(tDS) end
table.insert(tableBody, endTable)
tag:node(thisTableRow)
table.insert(tableBody, endRow)

return table.concat (tableBody)
return resulttable
end
end
end
end


function startlisttable_main(s)
function startlisttable_main(s, resulttable)
local tableBody, sortindex, fn_datetable, subtable = {}, {}, {}, {}
local t_Body, fn_datetable, subtable = {}, {}, {}, {}
local tBody = '' --row in our case
local sortkey
local WDlink_on = (wiki == "mk" or wiki == "ja" or wiki == "ru")
local WDlink_on = (wiki == "mk" or wiki == "ja" or wiki == "ru")


Línia 7.044: Línia 7.105:
for _, p710 in statements(s.item, 'P710') do -- P710 is participants
for _, p710 in statements(s.item, 'P710') do -- P710 is participants
subtable=startlist_sub(p710, timeOfRace, WDlink_on, true)
subtable=startlist_sub(p710, timeOfRace, WDlink_on, true)
sortkey=subtable[1].sortkey
t_Body[#t_Body + 1] = {subtable[1].sortkey, tostring(subtable[1].tBody)}
tBody=subtable[1].tBody

local number = #tableBody
--sort by dossard
if number == 0 then
table.insert(sortindex, sortkey)
table.insert(tableBody, tBody)
elseif sortkey >= sortindex[number] then
table.insert(sortindex, sortkey)
table.insert(tableBody, tBody)
else
local done=0
for i=number,1,-1 do
if sortkey >= sortindex[i] then
table.insert(sortindex, i+1, sortkey)
table.insert(tableBody, i+1, tBody)
done=1
break
end
end
if done==0 then --case that the new one is the first
table.insert(sortindex, 1, sortkey)
table.insert(tableBody, 1, tBody )
end
end
end
end
return table.concat (tableBody)
return sortandconcat(t_Body, resulttable)
end
end


Línia 7.095: Línia 7.130:


function riderranking_main(frame,s)
function riderranking_main(frame,s)
local thisCompetition, rank, thisyear, sitelink, cell, q, gender
local thisCompetition, rank, thisyear, sitelink, q, gender
local Resulttable, listofcalendar, UCI, UCImaster={},{},{}, {}
local Resulttable, listofcalendar, UCI, UCImaster={},{},{}, {}
local minmaxyear= {
local minmaxyear= {
Línia 7.163: Línia 7.198:
Resulttable[thisyear][calendar]["rank"]=tostring(rank)
Resulttable[thisyear][calendar]["rank"]=tostring(rank)
calendarlistpresent[calendar]=true
calendarlistpresent[calendar]=true
sitelink=mw.wikibase.getSitelink(thisCompetition) or "Jean"
sitelink=mw.wikibase.getSitelink(thisCompetition)
Resulttable[thisyear][calendar]["sitelink"]=sitelink
Resulttable[thisyear][calendar]["sitelink"]=sitelink
end
end
Línia 7.172: Línia 7.207:
--display result
--display result
if minmaxyear.minimum~=0 then
if minmaxyear.minimum~=0 then
local finalTable =mw.html.create('table'):attr('cellspacing','0')
local tablebegin='<table align="center" style="text-align:center; border: 1px solid #999; line-height: 1.8em; ">' --style="border=0; cellspacing=0; cellpadding=0; border="0"
:attr("align","center"):cssText("text-align:center; border: 1px solid #999; line-height: 1.8em;")
local wdLin = wdLink(string.gsub(s.item, '%s', '') .. "#P1344")
tablebegin=tablebegin..'<tr><th style="background-color:#FFDF80">'..wdLin..' '..riderranking_translate(1)..'</th>'
local wdLin = wdLink(string.gsub(s.item, '%s', '') .. "#P1344")
local tableyear=''
local tRow= finalTable:tag('tr'):tag('th'):cssText("background-color:#FFDF80"):wikitext(wdLin..' '..riderranking_translate(1))

for ii=minmaxyear.minimum,minmaxyear.maximum,1 do
for ii=minmaxyear.minimum,minmaxyear.maximum,1 do
tableyear=tableyear..'<th width="50px" style="text-align:center; background-color:#FFDF80;padding:1px 1px;"> '..tostring(ii)..' </th>'--
tRow:tag('th'):attr("width","50px"):cssText("text-align:center; background-color:#FFDF80;padding:1px 1px;")
:wikitext(tostring(ii))
end
end

tableyear=tableyear..'</tr>'
local tablebody=''
for _, calendar in pairs(listofcalendar) do
for _, calendar in pairs(listofcalendar) do
if calendarlistpresent[calendar] then
if calendarlistpresent[calendar] then
sitelink=mw.wikibase.getSitelink(UCImaster[calendar])
sitelink=mw.wikibase.getSitelink(UCImaster[calendar])
local tRow=finalTable:tag('tr')
tablebody=tablebody..'<tr><th style="text-align:left;">[['..sitelink..'|'..UCImastername[calendar]..']]</th>'
local tCell = tRow:tag('th'):cssText("text-align:left;")

if sitelink then
tCell:wikitext('[['..sitelink..'|'..UCImastername[calendar]..']]')
else
tCell:wikitext(UCImastername[calendar])
end
for ii=minmaxyear.minimum,minmaxyear.maximum,1 do
for ii=minmaxyear.minimum,minmaxyear.maximum,1 do
thisyear=tostring(ii)
thisyear=tostring(ii)
Línia 7.199: Línia 7.240:
color="silver"
color="silver"
end
end
tCell=tRow:tag('td'):attr("bgcolor",color)
if Resulttable[thisyear][calendar]["sitelink"] then
if Resulttable[thisyear][calendar]["sitelink"] then
cell='<td bgcolor='..color..'>[['..Resulttable[thisyear][calendar]["sitelink"]..'|'..
tCell:wikitext('[['..Resulttable[thisyear][calendar]["sitelink"]..'|'..
number(gender,Resulttable[thisyear][calendar]["rank"],wiki)..']]'..'</td>'
number(gender,Resulttable[thisyear][calendar]["rank"],wiki)..']]')
else
else
cell='<td bgcolor='..color..'>'..number(gender,Resulttable[thisyear][calendar]["rank"],wiki)..'</td>'
tCell:wikitext(number(gender,Resulttable[thisyear][calendar]["rank"],wiki))
end
end
else
else
cell='<td > - </td>'
tRow:tag('td'):wikitext(' - ')
end
end
tablebody=tablebody..cell
end
end
tablebody=tablebody..'</tr>'
end
end
end
end
Línia 7.224: Línia 7.264:
local tableyearsize=minmaxyear.maximum-minmaxyear.minimum+2
local tableyearsize=minmaxyear.maximum-minmaxyear.minimum+2
local tableFooter = '<tr><td class="navigation-only" colspan=' .. tostring(tableyearsize) ..
finalTable:tag('tr'):tag('td'):addClass("navigation-only")
:attr('colspan',tostring(tableyearsize))
' style="border-top: 2px #FFDF80 solid; font-size: 80%; "></td></tr><tr><td colspan=' ..
:cssText("border-top: 2px #FFDF80 solid; font-size: 80%;")
tostring(tableyearsize) .. ' style="text-align:right"><small>'..
:tag('tr')
race_reference_translate(wiki, 1).."["..UCIlink..' UCI]</small></td></tr>'
:tag('td'):attr('colspan',tostring(tableyearsize))

:cssText("text-align:right")
return tablebegin..tableyear..tablebody..tableFooter ..'</table>'
:tag('small'):wikitext(race_reference_translate(wiki, 1).."["..UCIlink..' UCI]')


return finalTable
end
end
end
end

Revisió del 12:49, 5 feb 2020

local p = {}
local wiki = string.match(mw.site.server, "%a+")
if wiki == "www" then
	wiki = "fr"
end

local contentLanguage = mw.getContentLanguage()
local wikilang = contentLanguage:getCode()
local wikibase = mw.wikibase
local localframe  -- Value may be given by functions which use frame functions like getReference

-- == Structure of the code ==
-- I) Constant
-- II) Basic functions
-- III) Functions less basic called from other functions
-----A) Time functions
-----B) Link functions
-----C) Functions for the output, like table
-----D) Jersey, flag functions
-----E) Other (winner)
-- IV) Translation
-- V) Main functions
----- A) Function race reference
----- B) Calendar
----- C) Victory
----- Cbis) Function for infobox
----- D) Stage infobox
----- E) List of teams
----- F) Classifications
----- G) Infobox
----- H) Team roster
----- I) Function list of winners (palmarès)
----- J) List of stages
----- K) List of stages classification
----- I) Start list
----- J) Rider ranking
--Tip: search "--==" to navigate between the sections

--== I) Classes declared as global ==
-- Class of a cycling race. Class is: 1.UWT, 2.UWT, 1.HC, ... add new classes, no problem
local class = { "Q22231106", "Q22231107", "Q22231108", "Q22231109", "Q22231110", "Q22231111", "Q22231112",
	"Q22231113", "Q22231114", "Q22231115", "Q22231116", "Q22231117", "Q22231118", "Q22231119", "Q23015458",
	"Q23005601", "Q23005603", "Q74275170", "Q74275176" } 
local classes = {
	Q22231106 = true, Q22231107 = true, Q22231108 = true, Q22231109 = true, Q22231110 = true, Q22231111 = true,
	Q22231112 = true, Q22231113 = true, Q22231114 = true, Q22231115 = true, Q22231116 = true, Q22231117 = true,
	Q22231118 = true, Q22231119 = true, Q23015458 = true, Q23005601 = true, Q23005603 = true, Q74275170 = true,
	Q74275176 = true
}

local class_2x = {"Q22231107", "Q23005603", "Q22231115", "Q22231109", "Q22231112", "Q22231113", "Q22231117", "Q74275176"} --multi stage races
local class_without2x = { "Q22231106", "Q22231108", "Q22231110", "Q22231111", "Q22231114", "Q22231116",
	"Q22231118", "Q22231119", "Q23015458", "Q23005601", "Q74275170" }
local class_champ = { "Q22231118", "Q22231119", "Q23015458"}

local class_sort={["Q22231106"]='01', ["Q22231107"]='01', ["Q23005601"]='01', ["Q23005603"]='01', ["Q22231115"]='01', -- 1.UWT, 2.UWT, 1.WWT, 2.WWT, 2.Ncup
		["Q22231114"]='02', ["Q22231109"]='03', ["Q22231108"]='04', ["Q22231112"]='05', ["Q22231110"]='06', -- 1.Ncup, 2.HC, 1.HC, 2.1, 1.1
		["Q22231113"]='07', ["Q22231117"]='07', ["Q22231111"]='08', ["Q22231116"]='08', ["Q22231119"]='09', --2.2, 2.2U, 1.2, 1.2U, CN
		["Q22231118"]='13', ["Q23015458"]='15', ["Q74275176"]='03', ["Q74275170"]='04' }
local stages = {'Q18131152', 'Q20646667', 'Q20646670', 'Q20680270', 'Q20646668', 'Q20679712', 'Q2348250', 'Q2266066', 'Q485321'}
	-- UCI Europe Tour,..., UCI ProTour, UCI World Calendar, UCI WorldTour, UCI Women’s WorldTour, UCI Women's Road World Rankings
local UCI_Circuits = {'Q1194340', 'Q1063423', 'Q1063430', 'Q268357', 'Q1039648', 'Q1329578', 'Q12270097', 'Q635366', 'Q21075974', 'Q1693153', "Q71580493"}

local available, translations = pcall(require, "Module:Cycling race/lang")
local available_list = available and type(translations.list) == "function"
local available_lang_priority = available == true and type(translations.lang_priority) == "table"

local textalign = "left"
local floattable = "left"
local floatinfobox = "right"
if wiki == "ar" or wiki == "fa" or wiki == "ur" or wiki == "he" then
	textalign = "right"
	floattable = "right"
	floatinfobox = "left"
end

local standardtablecss="border:1px solid rgb(200,200,200); color:black; margin:0 0 0.5em 0;"..
		"background-color:rgb(255, 255, 255); padding:5px; clear:left; text-align:" ..
		textalign .. "; font-size:85%; line-height:1.6em;"

local no_country_calendar={'ru'}
local no_country_victories={'ru'}
local no_country_classification={'es','da','no','ru'}
local no_roll_startlist={'fr','no','ar'}

local bg_color_table = {
	["Q24257871"] ="#FFFF99" , -- Jersey yellow.svg (General)
	["Q24257763"] ="#FFC0CB" , -- Jersey pink.svg (General)
	["Q24257872"] ="#FF8666" , -- Jersey red.svg (General)
	["Q24687408"] ="#99CBFF" , -- Jersey blue.svg (General)
	["Q24258056"] ="#FFD030" , -- Jersey orange.svg (General)
	["Q26696171"] ="#FFFFFF" , -- Jersey white.svg (General)
	["Q24258125"] ="#BFFF80" , -- Jersey green 2.svg (General)
	["Q24257991"] ="#FFD030" , -- Jersey gold.svg (General)
	["Q24645208"] ="#90EE90" , -- Jersey green.svg (General)
	["Q26945271"] ="#90EE90" , -- MaillotVolta.png (General)
	["Q26945272"] ="#BF80FF" , -- Jersey violet.svg (General)
	["Q29982321"] ="#FFFF99" , -- Jersey combined.svg (General)
	["Q29594434"] ="#87CEEB" , -- Jersey green lines volta.svg (General)
	["Q30132459"] ="#FFFF99" , -- Jersey yellow-bluebar.svg (General)
	["Q24645209"] ="#90EE90" , -- Jersey green.svg (Points)
	["Q25831179"] ="#FFFFFF" , -- Jersey white.svg (Points)
	["Q26919974"] ="#FF8666" , -- Jersey red.svg (Points)
	["Q24687409"] ="#99CBFF" , -- Jersey blue.svg (Points)
	["Q25265938"] ="#BF80FF" , -- Jersey violet.svg (Points)
	["Q641083"] ="#BF80FF" , -- Jersey violet.svg (Points), Giro
	["Q27114205"] ="#C0C0C0" , -- Jersey black.svg (Points)
	["Q28546656"] ="#FFFF99" , -- Jersey yellow.svg (Points)
	["Q28820618"] ="#87CEEB" , -- MaillotCyan.PNG (Points)
	["Q29982764"] ="#FFD030" , -- Jersey orange.svg (Points)
	["Q43276992"] ="#FFC0CB" , -- Jersey pink.svg (Points)
	["Q47945989"] ="#6495ED" , -- Jersey dark blue.svg (Points)
	["Q56449834"] ="#E0FFFF" , -- Jersey blue dotted.png (Points)
	["Q56449834"] ="#DDDDDD" , -- Jersey silver.svg (Points)
	["Q65557843"] ="#FF8666" , -- Jersey red-blackdots.svg (Points)
	["Q62471242"] ="#99CBFF" , -- Jersey blue lines volta.svg (Points)
	["Q65665708"] ="#FFC0CB" , -- Jersey polkadot.svg (Points)	
	["Q25265958"] ="#FFC0CB" , -- Jersey polkadot.svg (Mountain)
	["Q25265959"] ="#E0FFFF" , -- Jersey blue dotted.png (Mountain)
	["Q25265960"] ="#FFC0CB" , -- Jersey climbing Dauphine.png (Mountain)
	["Q27670178"] ="#FF8666" , -- Jersey red.svg (Mountain)
	["Q27670182"] ="#90EE90" , -- Jersey green.svg (Mountain)
	["Q27670174"] ="#FFD030" , -- Jersey orange.svg (Mountain)
	["Q24790519"] ="#C0C0C0" , -- Jersey grey.svg (Mountain)
	["Q27670105"] ="#C0C0C0" , -- Jersey blackdots.png (Mountain)
	["Q28604413"] ="#99CBFF" , -- Jersey blue.svg (Mountain)
	["Q25266023"] ="#F5DEB3" , -- Jersey brown.svg (Mountain)
	["Q27670126"] ="#FF8666" , -- Jersey granate.svg (Mountain)
	["Q25831602"] ="#FF69B4" , -- Jersey rosa.svg (Mountain)
	["Q29168665"] ="#FFC0CB" , -- Jersey pink.svg (Mountain)
	["Q29823248"] ="#FFFFFF" , -- Jersey white.svg (Mountain)
	["Q28820591"] ="#F5DEB3" , -- Jersey red green.svg (Mountain)
	["Q36859499"] ="#CCFFCC" , -- Jersey greendots.svg (Mountain)
	["Q33060977"] ="#C0C0C0" , -- Jersey black.svg (Mountain)
	["Q47537141"] ="#87CEEB" , -- MaillotCyan.PNG (Mountain)
	["Q50822370"] ="#FFC0CB" , -- Jersey red lines volta.svg (Mountain)
	["Q56246573"] ="#C0C0C0" , -- Jersey black white dotted.svg (Mountain)
	["Q26858731"] ="#FFFFFF" , -- Jersey white.svg (Combinated)
	["Q28823004"] ="#FFFF99" , -- Jersey combined.svg (Combinated)
	["Q28604421"] ="#FFD030" , -- Jersey orange.svg (Combinated)
	["Q43098388"] ="#99CBFF" , -- Jersey blue.svg (Combinated)
	["Q24790627"] ="#FF8666" , -- Jersey red.svg (Sprints)
	["Q25831754"] ="#99CBFF" , -- Jersey blue.svg (Sprints)
	["Q26806427"] ="#90EE90" , -- Jersey green.svg (Sprints)
	["Q27478100"] ="#C0C0C0" , -- Jersey black.svg (Sprints)
	["Q28060932"] ="#BF80FF" , -- Jersey violet.svg (Sprints)
	["Q28483869"] ="#FFFF99" , -- Jersey yellow.svg (Sprints)
	["Q33134180"] ="#FF69B4" , -- Jersey rosa.svg (Sprints)
	["Q42532690"] ="#E0FFFF" , -- Jersey light blue.svg (Sprints)
	["Q43278032"] ="#FFC0CB" , -- Jersey polkadot.svg (Sprints)
	["Q47513277"] ="#FFFFFF" , -- Jersey white.svg (Sprints)
	["Q64814800"] ="#C0C0C0" , -- Jersey grey.svg (Sprints)
	["Q65614883"] ="#FFFFFF" , -- Jersey white-black strip.png (Sprints)	
	["Q50822390"] ="#FFD030" , -- Jersey orange lines volta.svg (Sprints)
	["Q62471233"] ="#FFD030" , -- Jersey orange lines volta.svg (Best young)
	["Q24645383"] ="#FFFFFF" , -- Jersey white.svg (Best young)
	["Q26919967"] ="#90EE90" , -- Jersey green.svg (Best young)
	["Q26209148"] ="#99CBFF" , -- Jersey blue.svg (Best young)
	["Q26696523"] ="#FFD030" , -- Jersey orange.svg (Best young)
	["Q29229790"] ="#BF80FF" , -- Jersey violet.svg (Best young)
	["Q29982765"] ="#FFC0CB" , -- Jersey pink.svg (Best young)
	["Q33134078"] ="#FF8666" , -- Jersey red.svg (Best young)
	["Q38929482"] ="#FFFF99" , -- Jersey yellow.svg (Best young)
	["Q33026698"] ="#FF8666" , -- Jersey red.svg (Best young)
	["Q56002706"] ="#87CEEB" , -- MaillotCyan.PNG (Best young)
	["Q50822410"] ="#99CBFF" , -- Jersey blue lines volta.svg (Best young)
	["Q26953919"] ="#8FBC8F" , -- Jersey dark green.svg (Combativity)
	["Q29957114"] ="#87CEEB" , -- MaillotCyan.PNG (Combativity)
	["Q25265995"] ="#F5DEB3" , -- Jersey red green.svg (Combativity)
	["Q29594765"] ="#C0C0C0" , -- Jersey black.svg (Combativity)
	["Q30035039"] ="#FFD030" , -- Jersey orange.svg (Combativity)
	["Q30035038"] ="#90EE90" , -- Jersey green.svg (Combativity)
	["Q48691401"] ="#F2BC38" , -- Jersey Goldenrod.svg (Combativity)
	["Q61710200"] ="#FF8666" , -- Jersey Red.svg (Combativity)
	["Q31474628"] ="#99CBFF" , -- Jersey blue.svg (Nationality)	
	["Q27117411"] ="#FF8666" , -- Jersey red.svg (Best suisse)	
	["Q65935870"] ="#FFFFFF" , -- Jersey white.svg (Best suisse)
}

--== II) basic functions
--[[ Get any value for a property which is not deprecated ]]
local function firstValue(QID, PID, field)
	local ss = wikibase.getAllStatements(QID, PID)
	for _, s in pairs(ss) do
		if s.rank ~= 'deprecated' and s.mainsnak.snaktype == 'value' then
			return field and s.mainsnak.datavalue.value[field] or s.mainsnak.datavalue.value
		end
	end
end

--[[ Go from season of a team to the team ]]
local function getParentID(teamID)
	return firstValue(teamID, 'P361', 'id') -- P361 is 'part of'
		or firstValue(teamID, 'P5138', 'id') -- P5138 is 'season of club or team'
end

--[[ Get a label in any of the languages in the fallback list of language codes ]]
local function getLabelFallback(itemID, fallback)
	local label
	for _, lang in ipairs(fallback) do
		label = mw.wikibase.getLabelByLang(itemID, lang)
		if label then break end
	end
	return label
end

--[[ Get a sitelink from the local wiki or from the fallback list of language codes ]]
local function getSitelinkFallback(itemID, fallback)
	local link = mw.wikibase.getSitelink(itemID)
	if link then return link end
	for _, lang in ipairs(fallback) do
		link = mw.wikibase.getSitelink(itemID, lang .. 'wiki')
		if link then return link end
	end
	return nil
end

local function make_IllWD2_link(q, label)
	return mw.getCurrentFrame():expandTemplate{ title = 'Ill-WD2', args = {id= q ,target='en',label = label } }
end

--[[ Iterator to get all statements for an entity and property which are not deprecated and have a value]]
local function nextStatement(state, i)
	repeat
		i = i + 1
		local s = state[i]
		if s and s.rank ~= 'deprecated' and s.mainsnak.snaktype == 'value' then
			return i, s
		end
	until s == nil
end
local function statements(QID, PID)
	return nextStatement, wikibase.getAllStatements(QID, PID), 0
end

--[[ Iterator to get all qualifier values for a property for a statement]]
local function nextQualifier(state, i)
	repeat
		i = i + 1
		local q = state[i]
		if q and q.snaktype == 'value' then
			return i, q.datavalue
		end
	until q == nil
end
local function qualifiers(statement, PID)
	return nextQualifier, statement.qualifiers and statement.qualifiers[PID] or {}, 0
end

local function qualifieramount(element, property)
	local result
	for _, q in qualifiers(element, property) do
		result = tonumber(q.value.amount)
		break
	end
	return result
end

--== III) Functions less basic called from other functions ==
--=== A) Time functions ===
--[[ Get a Wikidata statement for an entity and property valid at the given timevalue ]]
local function checktime(s,q, time)
	local start, startPrecision, END, endPrecision
	if q.P580 and q.P580[1] and q.P580[1].snaktype == 'value' then -- P580 is start time
		start = q.P580[1].datavalue.value.time
		startPrecision = q.P580[1].datavalue.value.precision
		if startPrecision == 9 then -- precision is years
			start = string.sub(start, 1, 5) -- Cut of everything after year
		elseif startPrecision == 10 then -- precision is months
			start = string.sub(start, 1, 8) -- Cut of everything after month
		end
	end
	if q.P582 and q.P582[1] and q.P582[1].snaktype == 'value' then -- P582 is end time
		END = q.P582[1].datavalue.value.time
		endPrecision = q.P582[1].datavalue.value.precision
	end
	if not start or start <= time then
		if not END then
			return s
		end
		if endPrecision == 9 then -- precision 9 is 'years'
			END = string.sub(END, 1, 6) .. '13' -- Set month to 13
		elseif endPrecision == 10 then -- precision 10 is 'months'
			END = string.sub(END, 1, 9) .. '32' -- Set day to 32
		end
		if END > time then
			return s
		end
	end
	return nil
end

local function getStatementForTime(ID, property, time)
	for _, s in statements(ID, property) do
		local start, startPrecision, END, endPrecision
		local q = s.qualifiers
		if q then
			if q.P580 and q.P580[1] and q.P580[1].snaktype == 'value' then -- P580 is start time
				start = q.P580[1].datavalue.value.time
				startPrecision = q.P580[1].datavalue.value.precision
				if startPrecision == 9 then -- precision is years
					start = string.sub(start, 1, 5) -- Cut of everything after year
				elseif startPrecision == 10 then -- precision is months
					start = string.sub(start, 1, 8) -- Cut of everything after month
				end
			end
			if q.P582 and q.P582[1] and q.P582[1].snaktype == 'value' then -- P582 is end time
				END = q.P582[1].datavalue.value.time
				endPrecision = q.P582[1].datavalue.value.precision
			end
		end
		if not start or start <= time then
			if not END then
				return s
			end
			if endPrecision == 9 then -- precision 9 is 'years'
				END = string.sub(END, 1, 6) .. '13' -- Set month to 13
			elseif endPrecision == 10 then -- precision 10 is 'months'
				END = string.sub(END, 1, 9) .. '32' -- Set day to 32
			end
			if END > time then
				return s
			end
		end
	end
end

--[[ Get start time of race as a timevalue ('+2016-01-01T00:00:00Z') or nil ]]
local function gettimeOfRace (raceID)
	local timeOfRace
	local p580 = mw.wikibase.getBestStatements(raceID, "P580") -- P580 is start time
	if p580[1] and p580[1].mainsnak.snaktype == 'value' then
		timeOfRace = p580[1].mainsnak.datavalue.value.time
	else
		local p585 = mw.wikibase.getBestStatements(raceID, "P585") -- P585 is point in time
		if p585[1] and p585[1].mainsnak.snaktype == 'value' then
			timeOfRace = p585[1].mainsnak.datavalue.value.time
		else
			local link = getSitelinkFallback(raceID, {'en', 'fr', 'de'})
			if link then
				local year = string.match(link, '%d%d%d%d')
				if year then
					timeOfRace = year .. '-01-01T00:00:00Z'
				end
			end
		end
	end
	return timeOfRace, '> Wikidata is missing data about start time (P580) or point in time (P582)'
end

local function getStartEndTime(sTime, eTime, mode)
	-- Note: Add the formats to "formats" and use func_date
	local lang = contentLanguage
	local starttime, endtime
	--local format = formats[wiki] or formats['']
	if mode==nil then mode='long' end
	-- Timevalues is like "+2015-07-04T00:00:00Z"
	local y, m = string.match(sTime, "(%d+)-(%d+)-%d+")
	local y2, m2 = string.match(eTime, "(%d+)-(%d+)-%d+")
	
	if m=='00' then --manage the 30 November issue
		if  mode=='long' then
			starttime =lang:formatDate( "Y", sTime )
		else
			starttime ='-'
		end
	else
		if y ~= y2 then
			if mode=='long' then
				starttime = lang:formatDate( "j F Y", sTime )
			else
				starttime = lang:formatDate( "j M Y", sTime )
			end
		elseif m ~= m2 then
			if mode=='long' then
				starttime = lang:formatDate( "j F", sTime )
			else
				starttime = lang:formatDate( "j M", sTime )
			end
		else
			starttime = lang:formatDate( "j", sTime )
		end
	
		if wiki == "ar" then
			if y ~= y2 then starttime = lang:formatDate( "d F Y", sTime )
			elseif m ~= m2 then starttime = lang:formatDate( "d F", sTime )
			else starttime = lang:formatDate( "d ", sTime ) end
		elseif wiki == "br" then
			if y ~= y2 then starttime = lang:formatDate( "j", sTime ) .." a viz ".. lang:formatDate( "F Y", sTime )
			elseif m ~= m2 then starttime = lang:formatDate( "j", sTime ) .." a viz ".. lang:formatDate( "F", sTime )
			else starttime = lang:formatDate( "j", sTime ) .." "
			end
		elseif wiki == "ca" or wiki == "es" or wiki == "ast" then
			if y ~= y2 then
				starttime = lang:formatDate( "j", sTime ) .." de ".. lang:formatDate( "F", sTime ) .." de ".. lang:formatDate( "Y", sTime )
			elseif m ~= m2 then
				starttime = lang:formatDate( "j", sTime ) .." de ".. lang:formatDate( "F", sTime )
			else starttime = lang:formatDate( "j", sTime ) .." "
			end
		elseif wiki == "cs" then
			if y ~= y2 then starttime = lang:formatDate( "j. xg Y", sTime )
			elseif m ~= m2 then starttime = lang:formatDate( "j. xg", sTime )
			else starttime = lang:formatDate( "j", sTime )
			end
		elseif wiki == "de" or wiki == "da" or wiki == "fo" or wiki == "no" then
			if y ~= y2 then starttime = lang:formatDate( "j. F Y", sTime )
			elseif m ~= m2 then starttime = lang:formatDate( "j. F", sTime )
			else starttime = lang:formatDate( "j.", sTime )
			end
		elseif wiki == "fi" then
			if y ~= y2 then starttime = lang:formatDate( 'j. F"ta" Y', sTime )
			elseif m ~= m2 then starttime = lang:formatDate( 'j. F"ta"', sTime )
			else starttime = lang:formatDate( "j.", sTime )
			end
		elseif wiki == "eo" then
			if y ~= y2 then starttime = lang:formatDate( "j", sTime ) .."-a de ".. lang:formatDate( "F Y", sTime )
			elseif m ~= m2 then starttime = lang:formatDate( "j", sTime ) .."-a de ".. lang:formatDate( "F", sTime )
			else starttime = lang:formatDate( "j", sTime ) .."-a "
			end
		elseif wiki == "eu" then
			if y ~= y2 then starttime = lang:formatDate( "Y", sTime ) ..".eko ".. lang:formatDate( "F", sTime ) .."k ".. lang:formatDate( "j", sTime )
			elseif m ~= m2 then starttime = lang:formatDate( "F", sTime ) .."k ".. lang:formatDate( "j", sTime )
			else starttime = lang:formatDate( "F", sTime ) .."k ".. lang:formatDate( "j", sTime )
			end
		elseif wiki == "hu" then
			starttime = lang:formatDate( "Y. F j.", sTime)
		elseif wiki == "ja" then
			if y ~= y2 then starttime = lang:formatDate( "Y年m月d日", sTime )
			elseif m ~= m2 then starttime = lang:formatDate( "Y年m月d日", sTime )
			else starttime = lang:formatDate( "Y年m月d日", sTime )
			end
		elseif wiki == "lv" then
			if m ~= m2 then starttime = lang:formatDate( "Y. \\g\\a\\d\\a j. F", sTime )
			else starttime = lang:formatDate( "Y. \\g\\a\\d\\a j.", sTime )
			end
		elseif wiki == "pl" then
			local date_pl = {"stycznia", "lutego", "marca", "kwietnia", "maja", "czerwca", "lipca", "sierpnia", "września", "października", "listopada", "grudnia"}
			if y ~= y2 then starttime = lang:formatDate( "j ", sTime ) .. date_pl[tonumber(lang:formatDate( "n", sTime ))] .. lang:formatDate( " Y", sTime )
			elseif m ~= m2 then starttime = lang:formatDate( "j ", sTime ) .. date_pl[tonumber(lang:formatDate( "n", sTime ))]
			else starttime = lang:formatDate( "j", sTime )
			end
		end
	end
	
	if m2=='00' then --manage the 30 November issue
		if  mode=='long' then
			endtime= lang:formatDate( "Y", eTime )
		else
			endtime= '-'
		end
	else

		if mode=='long' or y ~= y2 then
			endtime = lang:formatDate("j F Y", eTime)
		else
			endtime = lang:formatDate("j M", eTime)
		end
		if wiki == "ar" then
			if mode=='long' or y ~= y2 then endtime = lang:formatDate( "d F Y", eTime )
			elseif m ~= m2 then endtime = lang:formatDate( "d F Y", eTime )
			else endtime = lang:formatDate( "d F Y", eTime )
			end
		elseif wiki == "br" then endtime = lang:formatDate( "j", eTime ) .." a viz ".. lang:formatDate( "F Y", eTime )
		elseif wiki == "ca" or wiki == "es" or wiki == "ast" then
			if mode=='long' or y ~= y2 then
				endtime = lang:formatDate( "j", eTime ) .." de "..
				lang:formatDate( "F", eTime ) .." de ".. lang:formatDate( "Y", eTime )
			else
				endtime = lang:formatDate( "j", eTime ) .." de "..
				lang:formatDate( "F", eTime )
			end
		elseif wiki == "cs" then endtime = lang:formatDate( "j. xg Y", eTime )
		elseif wiki == "de" or wiki == "da" or wiki == "fi" or wiki == "fo" or wiki == "no" then
			if mode=='long' or y ~= y2 then
				endtime = lang:formatDate( "j. F Y", eTime )
			else
				endtime = lang:formatDate( "j. M", eTime )
			end
		elseif wiki == "eo" then endtime = lang:formatDate( "j", eTime ) .."-a de ".. lang:formatDate( "F Y", eTime )
		elseif wiki == "eu" then endtime = lang:formatDate( "Y", eTime ) ..".eko ".. lang:formatDate( "F", eTime ) .."k "..
			lang:formatDate( "j", eTime )
		elseif wiki == "fi" then endtime = lang:formatDate('j F"ta" Y', eTime)
		elseif wiki == "hu" then
			if y ~= y2 then endtime = lang:formatDate( "Y. F j.", eTime )
			elseif m ~= m2 then endtime = lang:formatDate( "F j.", eTime )
			else endtime = lang:formatDate( "j.", eTime )
			end
			--endtime = lang:formatDate( "Y", eTime ) ..". ".. lang:formatDate( "F j", eTime ) .."."
		elseif wiki == "ja" then
			if y ~= y2 then endtime = lang:formatDate( "Y年m月d日", eTime )
			elseif m ~= m2 then endtime = lang:formatDate( "m月d日", eTime )
			else endtime = lang:formatDate( "d日", eTime )
			end
		elseif wiki == "lv" then
			if y ~= y2 then endtime = lang:formatDate( "Y. \\g\\a\\d\\a j. F", eTime )
			else endtime = lang:formatDate( "j. F", eTime )
			end
		elseif wiki == "pl" then
			local date_pl = {"stycznia", "lutego", "marca", "kwietnia", "maja", "czerwca", "lipca", "sierpnia",
				"września", "października", "listopada", "grudnia"}
			endtime = lang:formatDate( "j ", eTime ) .. date_pl[tonumber(lang:formatDate( "n", eTime ))] ..
			lang:formatDate( " Y", eTime )
		end
	end
	return starttime, endtime
end

local formats = {
	[''] = { long = 'j F Y', small = 'j M', onlyday = 'j' },
	ar = { long = 'j F Y', small = 'j F', onlyday = 'j' },
	br = { long = 'j "a viz" F Y', small = 'j "a viz" M', onlyday = 'j' },
	ca = { long = 'j "de" F "de" Y', small = 'j "de" M', onlyday = 'j' },
	cs = { long = 'j. xg Y', small = 'j. M', onlyday = 'j' },
	da = { long = 'j. F Y', small = 'j. M', onlyday = 'j.' }, -- copy of de
	de = { long = 'j. F Y', small = 'j. M', onlyday = 'j.' },
	eo = { long = 'j"-a de" F Y', small = 'j"-a de" M', onlyday = 'j' },
	en = { long = 'F d, Y', small = 'M d', onlyday = 'd' },
	es = { long = 'j "de" F "de" Y', small = 'j "de" M', onlyday = 'j' }, -- copy of ca
	eu = { long = 'Y".eko" F"k" j', small = 'M"k" j', onlyday = 'j' },
	fi = { long = 'j. F"ta" Y', small = 'j. M', onlyday = 'j.' },
	fo = { long = 'j. F Y', small = 'j. M', onlyday = 'j.' }, -- copy of de
	he = { long = 'j xg Y', small = 'j F', onlyday = 'j' },
	hu = { long = 'Y. F j.', small = 'M. j.', onlyday = 'j.' },
	ja = { long = 'Y年m月d日', small = 'm月d日', onlyday = 'd日' },
	lv = { long = 'Y. "gada" j. F', small = 'j. M', onlyday = 'j.' },
	ru = { long = 'j xg Y', small = 'j M', onlyday = 'j' },
	no = { long = 'j. F Y', small = 'j. M', onlyday = 'j.' }, -- copy of de
}

local function func_date(date, mode)
	-- local date = '+2016-05-20'
	-- local mode = 'small'
	local format = formats[wiki] or formats['']
	if string.sub(date,7,8)=='00' then --manage the 30 November issue
		if  mode=='long' then
			return lang:formatDate( "Y", date )
		else
			return '-'
		end
	else
		return contentLanguage:formatDate(format[mode], date)
	end
end

--[[ get the year for a race as a string, or an empty string]]
local function getYear(raceID)
	local year = firstValue(raceID, 'P580', 'time') or -- P580 is 'start time'
		firstValue(raceID, 'P585', 'time') -- P585 is 'point in time'
	if year then
		return string.sub(year, 2, 5)
	end
	return ''
end

function isdisqualified(p,q) --disqualification can use deprecated or P1534
	local cancelled=""
	local disqualified=false
	
	if p and p.rank=='deprecated' then
		cancelled='text-decoration:line-through;'
		disqualified=true
	else
		if q and q.P1534 and q.P1534[1].snaktype == 'value' then
			local tempdsq=q.P1534[1].datavalue.value.id
			if tempdsq=='Q1229261' then 
				cancelled='text-decoration:line-through;'
				disqualified=true
			end --disqualified
		end
	end
	return cancelled, disqualified
end

--=== B) Link functions ===
local function getOfficialName(teamID, timeOfRace,season) -- for team
	local p1448 = getStatementForTime(teamID, 'P1448', timeOfRace) -- P1448 is official name
	if p1448 then
		if available_lang_priority and p1448.qualifiers and p1448.qualifiers.P1448 then
			local q = p1448.qualifiers.P1448
			local wantedLanguages = {}
			local best = 999
			local name
			for i, lang in ipairs(translations.lang_priority) do
				wantedLanguages[lang] = i
			end
			for _, l in pairs(q) do
				if l.snaktype == 'value' then
					local lang = l.datavalue.value.language
					if wantedLanguages[lang] and wantedLanguages[lang] < best then
						best = wantedLanguages[lang]
						name = l.datavalue.value.text
					end
				end
			end
			if name then return name, true end
		end
		return p1448.mainsnak.datavalue.value.text, false
	end
	local label=wikibase.getLabel(teamID)
	if season and season==true then
		if label then return string.sub(label,1,label:len()-5) end -- 
	else
		return label -- No official name, try label
	end
end

local function revertfirstlast(name)
	local nametable = mw.text.split(name, ",")
	if nametable[2] then --there is a coma
		return nametable[2].." "..nametable[1]
	else
		return nametable[1]
	end
end

local function getRiderLink(riderID, startOfSeason) --startOfSeason optional
	--Priority order
	--#1 P1813, short name, in correct alphabet, correct time
	--#2 P1448, official name, in correct alphabet, correct time
	--#3 sitelink (so label from wikipedia) in correct language
	--#4 label from wikidata in correct language
	--#5 label from wikidata in another language
	local slavicWikis = {mk = true, ru = true}
	local sitelink = wikibase.getSitelink(riderID)
	local officialname,officialnametemp, language
	local wikiisslavic = slavicWikis[wiki]
	local correctlanguage=true
	local listOfProperty={'P1813','P1448'}

	for _, prop in ipairs(listOfProperty) do
		for _, p1813 in statements(riderID, prop) do
			if not officialname then
				language = p1813.mainsnak.datavalue.value.language
				local languageisslavic = slavicWikis[language]
				if (languageisslavic==true and wikiisslavic==true) or (languageisslavic==nil and wikiisslavic==nil) then
					officialnametemp = p1813.mainsnak.datavalue.value.text
					if startOfSeason~= nil then
						local q = p1813.qualifiers
						if q then
							local temp = checktime(officialnametemp,q,startOfSeason)
							if temp then officialname = officialnametemp end--if the time is correct than it is finished
						else
							officialname = officialnametemp
						end
					end
				end
			end
		end
	end

	if sitelink and officialname then --if there is an official name, then use it
		return "[[" .. sitelink .. "|" ..officialname.."]]", correctlanguage
	else
		if officialname then return officialname end
		if sitelink then
			if wiki == "de" then
				local label = wikibase.getLabelByLang(riderID, wiki)
				if label then
					local p27 = wikibase.getBestStatements(riderID, 'P27') -- P27 is country of citizenship
					if p27[1] and p27[1].mainsnak.snaktype == 'value' then
						local c = p27[1].mainsnak.datavalue.value['numeric-id']
						if c==159 or c==184 or c==212 or c==232 then -- Q159, Q184, Q212, Q232 is Russia, Belarus, Ukraine, Kazakhstan
							return "[[" .. sitelink .. "|" .. label .. "]]", correctlanguage
						end
					end
				end
			end
			if wiki == 'ru' then
				local label = revertfirstlast(mw.text.trim(string.gsub(sitelink, "%b()", "")))
				return "[[" .. sitelink .. "|" .. label.. "]]", correctlanguage
			else
				return "[[" .. sitelink .. "|" .. mw.text.trim(string.gsub(sitelink, "%b()", "")) .. "]]", correctlanguage
			end
		end

		-- No WP article. Display label, and make it a red link if no other article uses the title
		local link
		local label = wikibase.getLabelByLang(riderID, wiki)
		if label then
			if wiki == 'ar' then
				link = make_IllWD2_link(riderID)
			else
				if wiki=='ru' then
					label=revertfirstlast(label)
				end

				if black_list(wiki, label) then
					link = label
				else
					local title = mw.title.new(label)
					if title and title.exists then
						link = label
					else
						link = "[[" .. label.. "]]"
					end
				end
			end
			return link, correctlanguage
		end

		-- No label in the local language. Try other languages, but don't link.
		correctlanguage=false
		if wiki == 'ar' then
			link = make_IllWD2_link(riderID)
		else
			link = getLabelFallback(riderID, {'en', 'de', 'fr','es'})
			if link then
				link = string.gsub(link, "%b()", "")
			else
				link = "(label missing)"
			end
		end
		return link, correctlanguage
	end
end

--[[ Get the name of a country ]]
local function getCountryName(countryID)
	local name = ''
	if available_list then
		name = translations.list(countryID)
	end
	if name == '' then
		local label, lang = wikibase.getLabelWithLang(countryID)
		--[[ Uses standard language fallback. Should not return nil, nil, as all countries have English labels. ]]
		if lang == wikilang then
			name = label
		elseif lang then
			name = label .. ' (' .. lang .. ')'
		end
	end
	return name
end

--[[ Get sitelink with no wiki no formating ]]
local function getRawTeamLink(teamID)
	local sitelink
	local parentID = getParentID(teamID)
	if parentID then -- try parent team first
		sitelink = mw.wikibase.getSitelink(parentID)
	end
	if not sitelink then
		sitelink = mw.wikibase.getSitelink(teamID)
	end
	return sitelink
end

--[[ Get sitelink, categoryID and maybe country for a team.
	Returns sitelink, team category ID, countryID (only countryID if country arg is true ]]
local function getTeamLinkCat(teamID, timeOfRace, country, season)
	local name, sitelink, parentID, catID
	-- Find team category
	local teamCats = {
		Q6154783 = true, Q20638319 = true, Q382927 = true, Q1756006 = true, Q23726798 = true,
		Q20738667 = true, Q28492441 = true, Q20639848 = true, Q20639847 = true, Q20652655 = true,
		Q20653563 = true, Q20653564 = true, Q20653566 = true, Q2466826 = true, Q26849121 = true,
		Q78464255 = true, Q80425135=true
	}
	for _, p31 in statements(teamID, 'P31') do
		local natureID = p31.mainsnak.datavalue.value.id
		if teamCats[natureID] then
			catID = natureID
			break
		end
	end
	if not catID then
		parentID = getParentID(teamID)
		if parentID then
			local p31 = getStatementForTime(parentID, 'P31',timeOfRace)
			if p31 then catID = p31.mainsnak.datavalue.value.id end
		end
		catID = catID or 'Q53534649'
	end
	-- Find country if needed
	local countryID
	if country or catID == 'Q23726798' or catID == 'Q20738667' then
		countryID = firstValue(teamID, 'P1532', 'id') -- P17 is country for sport
		if countryID == nil then
			countryID = firstValue(teamID, 'P17', 'id') -- P17 is country
		end
	end
	if countryID and (catID == 'Q23726798' or catID == 'Q20738667') then
		-- It is a national cycling team
		name = getCountryName(countryID)
		if catID == 'Q20738667' then -- national cycling team U23
			local s
			if wiki == 'fr' then s = ' espoirs'
			elseif wiki == 'mk' then s = ' под 23 години'
			elseif wiki == 'ar' then s = ' تحت 23'
			elseif wiki == 'es' then s = ' sub-23'
			else s = ' U23'
			end
			name = name .. s
		end
		sitelink = getRawTeamLink(teamID)
	else
		-- It is not a national cycling team
		local isLocal
		if season and season == true then
			sitelink = wikibase.getSitelink(teamID)
			name, isLocal = getOfficialName(teamID, timeOfRace,true)
			if not sitelink then
				parentID = getParentID(teamID)
				if parentID then sitelink = wikibase.getSitelink(parentID) end
			end
		else
			parentID = getParentID(teamID)
			if parentID then -- try parent team first
				sitelink = wikibase.getSitelink(parentID)
				name, isLocal = getOfficialName(parentID, timeOfRace)
			end
			if not sitelink then
				sitelink = wikibase.getSitelink(teamID)
			end
		end

		if not name or (not isLocal and available_lang_priority) then
			local partName, partIsLocal = getOfficialName(teamID, timeOfRace)
			if partName and (not name or partIsLocal) then
				name = partName
			end
		end
	end
	if sitelink then
		if name then
			sitelink = '[[' .. sitelink .. '|' .. name .. ']]'
		else
			sitelink = '[[' .. sitelink .. ']]'
		end
	else
		if name then
			sitelink = name
		else
			sitelink = (parentID and wikibase.getLabel(parentID)) or
				wikibase.getLabel(teamID) or 'No name'
		end
	end
	return sitelink, catID, countryID
end

local function getTeamCodeCat(teamID, timeOfRace)
	-- Find team category
	local codeUCI
	local p1998 =getStatementForTime(teamID, 'P1998', timeOfRace)
	if p1998 then
		codeUCI = p1998.mainsnak.datavalue.value
	else
		local parentID = getParentID(teamID)
		if parentID then
			p1998 =getStatementForTime(parentID, 'P1998', timeOfRace)
			if p1998 then
				codeUCI = p1998.mainsnak.datavalue.value
			end
		end
	end
	return codeUCI
end

local function getReference(statement, outputLocal)
	local function formatRefDate(date, precision)
		if precision == 9 then -- Precision is year
			return string.sub(date, 2, 5)
		elseif precision == 10 then -- Precision is month
			return contentLanguage:formatDate("F Y", string.sub(date, 2, 8))
		elseif precision >= 11 then -- Precision is day (or less)
			return func_date(date, 'long')
		end
	end

	local ref = statement.references
	if not ref or not ref[1] then
		return nil
	end
	ref = ref[1].snaks
	if ref.P854 and ref.P854[1] and ref.P854[1].snaktype == 'value' then -- P854 is 'reference URL'
		local refURL = ref.P854[1].datavalue.value
		local refTitle = ''
		local refDate = ''
		local refRetrieved = ''
		local refLang = ''
		if ref.P1476 and ref.P1476[1] and ref.P1476[1].snaktype == 'value' then -- P1476 is 'title URL'
			refTitle = ref.P1476[1].datavalue.value.text
			local lang = ref.P1476[1].datavalue.value.language
			if lang ~= wikilang then
				refLang = '(' .. lang .. ')'
			end
		end
		if ref.P577 and ref.P577[1] and ref.P577[1].snaktype == 'value' then -- P577 is 'publication date'
			local value = ref.P577[1].datavalue.value
			refDate = formatRefDate(value.time, value.precision)
			if (wiki == 'ar') then refDate = '، ' .. refDate
			else refDate = ', ' .. refDate
			end
		end
		if ref.P813 and ref.P813[1] and ref.P813[1].snaktype == 'value' then -- P813 is 'retrieved'
			local value = ref.P813[1].datavalue.value
			refRetrieved = formatRefDate(value.time, value.precision)
			if wiki == "de" then
				refRetrieved = ", (abgerufen am " .. refRetrieved .. ')'
			elseif wiki == "ar" then
				refRetrieved = " تاريخ الوصول " .. refRetrieved .. '.'
			elseif wiki == "fr" then
				refRetrieved = " (consulté le " .. refRetrieved .. ')'
			elseif wiki == "da" then
				refRetrieved = " Hentet " .. refRetrieved .. '.'
			else
				refRetrieved = " Retrieved " .. refRetrieved .. '.'
			end
		end
		local domain = string.match(refURL, '//([^/]+)')
		if string.sub(domain, 1, 4) == 'www.' then
			domain = string.sub(domain, 5)
		end
		local refText
		if wiki == "fr" then
			-- fr: "(en) « Lloyd Mondory ... EPO », sur velonews.competitor.com (consulté le 30 april 2016), 30 octobre 2015."
			local sur = ', sur <span style="font-style:italic;"> ' .. domain .. '</span>'
			refText = refLang .. ' « ['.. refURL .. ' '.. refTitle .. '] »' .. sur .. refRetrieved .. refDate .. '.'
		elseif wiki == "de" then
			local In = ' In: <span style="font-style:italic;">' .. domain .. '</span>'
			refText = '<span style="font-style:italic;">['.. refURL.. ' '.. refTitle.. '.]</span> ' ..
				In .. refDate .. refRetrieved ..'.'
		else
			local at = ', <span style="font-style:italic;"> ' .. domain .. '</span>'
			refText = refLang .. ' [' .. refURL .. ' ' .. refTitle .. ']' .. at .. refDate .. '.' .. refRetrieved
		end
		if outputLocal==1 then
			return refText
		else
			return localframe:extensionTag('ref', refText, {name=refText})
		end
	end
end

function black_list(wiki, Label)
	--[[ List of Wikipedia articles with the same lemma as the non existing rider article. Those lemmas are printed
		as text "black" in the tables, not "blue" or "red". This way there will be no false wikilinks at the WhatLinksHere entry.
		List should be updated maybe once a year. ]]
	local black_list
	if wiki == 'de' then black_list = {
		["Ryan Anderson"]=true, ["Chris Butler"]=true, ["Josef Černý"]=true, ["Brad Evans"]=true, ["Robert Fontaine"]=true,
		["Carlos Giménez"]=true, ["George Harper"]=true, ["Mathias Jørgensen"]=true, ["Luis Lemus"]=true, ["David Lozano"]=true, ["Jan Maas"]=true,
		["James McLaughlin"]=true, ["Nikolaj Michajlow"]=true, ["Antonio Molina"]=true, ["Ben O'Connor"]=true, ["Andrea Peron"]=true, ["Cristian Rodríguez"]=true,
		["Nick Schultz"]=true, ["Adam Stachowiak"]=true, ["Michel Vermote"]=true, ["Johannes Weber"]=true, ["Martin Weiss"]=true, ["Christopher Williams"]=true,
		["Samuel Williams"]=true, ["Peter Williams"]=true, ['Stephen Williams']=true, ["Michael Woods"]=true, ["Michael Wright"] = true, ["Edoardo Zardini"]=true,
		["Georg Zimmermann"]=true,
	}
	elseif wiki == 'fr' then black_list = {
		['Pierre Barbier']=true, ['Jessica Cutler']=true, ['Fernanda da Silva']=true, ['Guillaume Delvaux']=true, ['Willy De Waele']=true,
		['Jules Dubois']=true, ['Jean Dupont']=true, ['Robert Fontaine']=true, ['René Fournier']=true, ['Pierre Gauthier']=true, ['Marc Goossens']=true,
		['Claude Guyot']=true, ['Amy Hill']=true, ['Liang Hongyu']=true, ['Marcus Johansson']=true, ['Mathias Jørgensen']=true, ['José Mendoza']=true,
		['Daniel Müller']=true, ['Henri Parmentier']=true, ['Jean Raynal']=true, ['Pascal Robert']=true, ['Jean-Yves Roy']=true, ['Michael Shermer']=true,
		['Juris Silovs']=true, ['Jacques Simon']=true, ['Guy Thomas']=true, ['Ryan Thomas']=true, ['Hans Vonk']=true, ['Jan Wijnants']=true,
	}
	else
		black_list = {}
	end
	return black_list[Label]
end

local function getImage(QID)
	local p18 = wikibase.getBestStatements(QID, 'P18') -- P18 is 'image'
	local first
	for _, image in pairs(p18) do
		if image.mainsnak.snaktype == 'value' then
			if not first then
				first = image.mainsnak.datavalue.value
			end
			local q = image.qualifiers
			if q and q.P2096 then
				for _, caption in pairs(q.P2096) do -- P2096 is 'caption'
					if caption.snaktype == 'value' and caption.datavalue.value.language == wikilang then
						return image.mainsnak.datavalue.value, caption.datavalue.value.text
					end
				end
			end
		end
	end
	return first
end

--[[ Get link for race or competition]]
local function raceLink(QID)
	local sitelink = wikibase.getSitelink(QID)
	local instanceOf = firstValue(QID, 'P31', 'id') -- P31 is 'instance of'
	if instanceOf == 'Q1137352' then -- Q1137352 is 'French Road Cycling Cup'
		local label2 = wikibase.getLabel(instanceOf)
		if sitelink then
			if label2 then return '[[' .. sitelink .. '|' .. label2 .. ']]' end
			return '[[' .. sitelink .. ']]'
		end
		local sitelink2 = wikibase.getSitelink(instanceOf)
		if sitelink2 then return '[[' .. sitelink2 ..'|' .. string.gsub(sitelink2, " %b()", "") .. ']]' end
		if label2 then return label2 end
	end
	if sitelink then return "[[".. sitelink.. "]]" end
	return wikibase.getLabel(QID) or ''
end

local function getPlaceLink(placeID)
	local sitelink = wikibase.getSitelink(placeID)
	if sitelink then
		-- Delete " (...)" form e.g. "Unley (South Australia)"
		return '[[' .. sitelink .. '|' .. string.gsub(sitelink, ' %b()', '') .. ']]'
	end
	local label = wikibase.getLabel(placeID) or ''
	if wiki == 'ar' then
		return make_IllWD2_link( placeID,label)
			-- '[[' .. label.. ']]'
	end
	return contentLanguage:ucfirst(label)
end

local function classLink(class)
	local link = wikibase.getSitelink('Q22348500') -- Q22348500 is 'cycling race class'
	local label = getLabelFallback(class, {wikilang, 'en', 'fr', 'de'})
	if label and link then
		link = '[[' .. link .. '|' .. label .. ']]'
	elseif link then
		link = '[[' .. link .. ']]'
	elseif label then
		link = label
	else
		link=''
	end
	if wiki == "ar" then-- right now Q22348500 has no link in "ar"
		link = make_IllWD2_link(class , "")
	end
	return link
end
--[[ Get local content to a infoboxe from template args ]]
local function getLocalContent(contents, args)

	for _, content in pairs(contents) do
		local name = content.name
		local nameNoShy = string.gsub(name, '&#173;', '')  -- filter soft hyphen out
		local name_plural = content.name_plural
		local name_pluralNoShy = name_plural and string.gsub(name_plural, '&#173;', '')  -- filter soft hyphen out
		if args[nameNoShy] and args[nameNoShy] ~= '' then
			if content.special then
				local newname, value = string.match(args[nameNoShy], '([^:]+):(.*)')
				if value and mw.text.trim(value) ~= '' then
					content.name = mw.text.trim(newname)
					content.content = mw.text.trim(value)
				end
			else
				content.content = mw.text.trim(args[nameNoShy])
			end
		elseif args[name_pluralNoShy] and args[name_pluralNoShy] ~= '' then
			content.name = content.name_plural
			content.content = mw.text.trim(args[name_pluralNoShy])
		end
	end
end

local function getTeam(riderID, timeOfRace, q)
	-- q: qualifiers of statement in race entity where the rider is the value
	local teamID, link
	if q and q.P54 and q.P54[1].snaktype == 'value' then -- P54 is member of sports team
		teamID = q.P54[1].datavalue.value.id
		link = getTeamLinkCat(teamID, timeOfRace)
	else
		local p54 = getStatementForTime(riderID, 'P54', timeOfRace)
		if p54 then
			teamID = p54.mainsnak.datavalue.value.id
			link = getTeamLinkCat(teamID, timeOfRace)
		end
	end
	return link
end

local function getTeamCode(riderID, timeOfRace, q)
	-- q: qualifiers of statement in race entity where the rider is the value
	local teamID, code
	if q and q.P54 and q.P54[1].snaktype == 'value' then -- P54 is member of sports team
		teamID = q.P54[1].datavalue.value.id
		code = getTeamCodeCat(teamID, timeOfRace)
	else
		local p54 = getStatementForTime(riderID, 'P54', timeOfRace)
		if p54 then
			teamID = p54.mainsnak.datavalue.value.id
			code= getTeamCodeCat(teamID, timeOfRace)
		end
	end
	return code
end

local function wdLink(id)
	return "[[File:Wikidata-logo S.svg|12px|link=d:" .. id .. "]]"
end

local function WPlinkpure(Qnumber)
	local link=''
	local Sitelink = wikibase.getSitelink(Qnumber) -- link to WParticle
	local Label = getLabelFallback(Qnumber, {wikilang, 'en', 'fr', 'de'}) or ''

	if Sitelink ~= nil then link = "[[" .. Sitelink .. "|" .. mw.text.trim(string.gsub(Sitelink, "%b()", "")..' ') .. "]]"
	elseif wiki == 'ar' then
		link = make_IllWD2_link(Qnumber , Label)
	else link = mw.ustring.gsub(Label, "^(%a)", function (x) return mw.ustring.upper(x) end)
	end

	return link
end

--=== C) Function for the output ===
local function getcoutrybool (no_country_list)
	local country = true
	for _, value in pairs(no_country_list) do -- get data if country should be printed in this wiki
		if value == wiki then country = false end
	end
	return country
end

local function tableA(s)
	local error_message = ''
	if wiki == "ar" and s.item == "" or not s.item then return "" end
	if s.error_message == 1 then
		error_message = func_error_message(wiki, 1)
		error_message = mw.ustring.gsub(error_message, "<1>", s.property)
		error_message = mw.ustring.gsub(error_message, "<2>", mw.wikibase.label( s.item ))
		error_message = mw.ustring.gsub(error_message, "<3>", s.item)
		error_message = ' [[File:Exclam icon.svg|12px|'.. error_message .. ']]'
	end
	
	local table = mw.html.create('table')
		:addClass('sortable')
		:attr('cellpadding', '0')
		:attr('cellspacing', '0')
		:css('border' , '1px solid rgb(200,200,200)')
		:css('padding', '3px')
	
	local title = s.header_function (wiki, s.header_1, s.title)
	if s.header_1 == 19 and wiki == "ar" then title = title .. " " .. s.year end	
		
	local caption = table:tag('tr'):tag('th'):attr('colspan', tostring(#s.header_2 + 1)):cssText('padding:2px; text-align:center; background-color:#FFDF80; line-height: 1.8em;')
	caption:tag('span'):cssText('float:left; margin: 0 5px'):wikitext('[[File:Wikidata-logo S.svg|12px|link=d:'.. s.item.. '#'.. s.property..']] '.. error_message)
	caption:wikitext(title)

	local country=getcoutrybool (s.no_country)

	local header = table:tag('tr')
	for i,k in ipairs(s.header_2) do
		if i == s.country_column then
			if available_list and country == true then
				header:tag('th')
					:cssText('text-align:center;padding:2px 20px 2px 2px;white-space:nowrap')
					:wikitext(s.header_function (wiki, k))
			end
		end
		if i ~= s.country_column then
			local column = header:tag('th')
					:cssText('text-align:center;padding:2px 20px 2px 2px;white-space:nowrap')
					:wikitext(s.header_function (wiki, k))
			if s.data_sort_type[i] == 'unsortable' then
				column:addClass('unsortable')
			end
		end
	end

	return table
end

local function tableB(s) --for startlist
	local error_message = ''
	if wiki == "ar" and s.item == "" or not s.item then return "" end
	if s.error_message == 1 then
		error_message = func_error_message(wiki, 1)
		error_message = mw.ustring.gsub(error_message, "<1>", s.property)
		error_message = mw.ustring.gsub(error_message, "<2>", mw.wikibase.label( s.item ))
		error_message = mw.ustring.gsub(error_message, "<3>", s.item)
		error_message = ' [[File:Exclam icon.svg|12px|'.. error_message .. ']]'
	end
	
	local roll = true
	for _, value in pairs(s.no_roll_startlist) do -- get data if country should be printed in this wiki
		if value == wiki then roll = false end
	end

	local cssTable= "border: 1px solid rgb(200,200,200); margin: 0 0 0.5em 0;"..
				"background-color: rgb(255, 255, 255); padding: 5px; float: left;"..
				"clear: left; ; text-align: left; vertical-align: top; font-size: 85%; line-height: 1.8em;"
	local wdLink = '[[File:Wikidata-logo S.svg|12px|link=d:'.. s.item.. '#'.. s.property..']] '.. error_message
	
	if roll == true then
		local rollTable1 = mw.html.create('div'):addClass("NavFrame")
		:cssText('center = margin: 0 0.5em 0;clear:both; border: 1px solid rgb(200,200,200);' ..
		'cellpadding="4" cellspacing="0" style="width:100%; background-color: rgb(255, 255, 255);padding: 5px;'..
		'margin-bottom:1em; background-color:#FFDF80;')
		:attr('title','['..startlist_translate(14)..']/['..startlist_translate(15)..']')
		local tDiv= rollTable1:tag('div'):addClass("NavHead")
		:cssText('text-align:'.. textalign .." =;height:1.8em;background-color:#FFDF80; color:black;font-weight:bold;")
		tDiv:tag('span')
		
		local tSpan=tDiv:tag('span'):cssText('float:' .. floattable):wikitext(wdLink)
		tSpan:wikitext(title)
		tDiv:wikitext(startlist_translate(1))
		
		tDiv = rollTable1:tag('div'):addClass("NavContent"):cssText("margin:0; background:white; display:block; text-align:left;")
	
		local tTable= tDiv:tag('table'):cssText("border:1px solid rgb(200,200,200)")
		local tCell = tTable:tag('tr'):tag('td')
		local insideTable =tCell:tag('table'):attr('cellpadding','4')  -- cellspacing="0" style="width:100%;"  color: black;
		:cssText(cssTable)

		return rollTable1, insideTable
	else
		--otherwise problem of clear
		local tab = mw.html.create('table')
		tCell=tab:tag('td')
		
		local tTable =tCell:tag('table')
		:attr('cellpadding','4')
		:cssText(cssTable)
		tCell = tTable:tag('tr'):tag('th'):cssText("background-color:#FFDF80;"):attr('colspan','3'):attr('align','center')
		tCell:tag('span'):cssText('float:left'):wikitext(wdLink)
		tCell:wikitext(startlist_translate(1))
	    local tRow=tCell:tag('tr')

		return tab, tRow
	end
end

--=== D) Jersey, flag functions ===
--used from 2 functions
local flags = {
		Q16 = {'CAN', {'Flag of Canada.svg', '+1965-02-15'}},
		Q17 = {'JPN', {'Flag of Japan.svg', '+1999-08-13'},
			{'Flag of Japan (1870–1999).svg', '+1870-02-27', '+1999-08-12'}},
		Q20 = {'NOR', {'Flag of Norway.svg', '+1821-07-13'}},
		Q27 = {'IRL', {'Flag of Ireland.svg', '+1937-12-29'}},
		Q28 = {'HUN', {'Flag of Hungary.svg', '+1957-05-23'}},
		Q29 = {'ESP', {'Flag of Spain.svg', '+1981-12-06'},
			{'Flag of Spain (1977–1981).svg', '+1977-01-21', '+1981-12-06'},
			{'Flag of Spain (1945–1977).svg', '+1945-10-11', '+1977-01-21'},
			{'Flag of Spain (1938–1945).svg', '+1939', '+1945-10-11'},
			{'Flag of the Second Spanish Republic.svg', '+1931-04-14', '+1939'},
			{'Flag of Spain (1785–1873, 1875–1931).svg', '+1874', '+1931-04-13'}},
		Q30 = {'USA', {'Flag of the United States.svg', '+1960-07-04'}},
		Q31 = {'BEL', {'Flag of Belgium (civil).svg'}},
		Q32 = {'LUX', {'Flag of Luxembourg.svg'}},
		Q33 = {'FIN', {'Flag of Finland.svg', '+1918-05-29'}},
		Q34 = {'SWE', {'Flag of Sweden.svg'}},
		Q35 = {'DEN', {'Flag of Denmark.svg'}},
		Q36 = {'POL', {'Flag of Poland.svg'}},
		Q37 = {'LTU', {'Flag of Lithuania.svg', '+2004-09-01'},
			{'Flag of Lithuania (1988-2004).svg', '+1990-03-11', '+2004-09-01'}},
		Q38 = {'ITA', {'Flag of Italy.svg', '+1946-06-19'},
			{'Flag of Italy (1861–1946).svg', '+1861', '+1946-06-19'}},
		Q39 = {'SUI', {'Flag of Switzerland.svg', '+1889-12-12'},
			{'Flag of Switzerland.svg', '+1879-01-01'}},
		Q40 = {'AUT', {'Flag of Austria.svg', '+1945-05-01'},
			{'Flag of Austria.svg', '+1919-10-21', '+1938-03-13'}},
		Q41 = {'GRE', {'Flag of Greece.svg', '+1978'}},
		Q43 = {'TUR', {'Flag of Turkey.svg'}},
		Q45 = {'POR', {'Flag of Portugal.svg', '+1911-06-30'}},
		Q55 = {'NED', {'Flag of the Netherlands.svg', '+1806'}},
		Q77 = {'URU', {'Flag of Uruguay.svg'}},
		Q96 = {'MEX', {'Flag of Mexico.svg', '+1968-09-16'},
			{'Flag of Mexico (1934-1968).svg', '+1934', '+1968-09-16'}},
		Q114 = {'KEN', {'Flag of Kenya.svg'}},
		Q115 = {'ETH', {'Flag of Ethiopia.svg', '+1996-10-31'}},
		Q117 = {'GHA', {'Flag of Ghana.svg', '+1966-02-28'}},
		Q142 = {'FRA', {'Flag of France.svg', '+1794-05-20'}},
		Q145 = {'GBR', {'Flag of the United Kingdom.svg'}},
		Q148 = {'CHN', {"Flag of the People's Republic of China.svg", '+1985'}},
		Q155 = {'BRA', {'Flag of Brazil.svg', '+1992-05-11'},
			{'Flag of Brazil (1968–1992).svg', '+1968-05-28', '+1992-05-11'}},
		Q159 = {'RUS', {'Flag of Russia.svg', '+1993-12-11'},
			{'Flag of Russia (1991–1993).svg', '+1991-08-22', '+1993-12-11'},
			{'Flag of the Russian Soviet Federative Socialist Republic.svg', '+1954', '+1991-08-22'},
			{'Flag of the Russian Soviet Federative Socialist Republic (1937–1954).svg', '+1937', '+1954'}},
		Q183 = {'GER', {'Flag of Germany.svg', '+1949-05-23'},
			{'Flag of the German Reich (1935–1945).svg', '+1935-09-15', '+1945-05-23'},
			{'Flag of the German Reich (1933–1935).svg', '+1933-03-12', '+1935-09-15'},
			{'Flag of Germany (3-2 aspect ratio).svg', '+1919-04-11', '+1933-03-12'},
			{'Flag of the German Empire.svg', '+1871-04-16', '+1919-04-11'}},
		Q184 = {'BLR', {'Flag of Belarus.svg', '+2012-05-11'},
			{'Flag of Belarus (1995–2012).svg', '+1995-06-07', '+2012-05-11'},
			{'Flag of Belarus (1918, 1991–1995).svg', '+1991-09-19', '1995-06-07'}},
		Q189 = {'ISL', {'Flag of Iceland.svg', '+1944-06-17'}},
		Q191 = {'EST', {'Flag of Estonia.svg'}},
		Q211 = {'LAT', {'Flag of Latvia.svg'}},
		Q212 = {'UKR', {'Flag of Ukraine.svg', '+1992-01-28'}},
		Q213 = {'CZE', {'Flag of the Czech Republic.svg', '+1920-03-30'}},
		Q214 = {'SVK', {'Flag of Slovakia.svg'}},
		Q215 = {'SLO', {'Flag of Slovenia.svg'}},
		Q217 = {'MDA', {'Flag of Moldova.svg'}},
		Q218 = {'ROU', {'Flag of Romania.svg', '+1989-12-27'},
			{'Flag of Romania (1965-1989).svg', '+1989-12-27', '+1965'},
			{'Flag of Romania (1952-1965).svg', '+1952', '+1965'},
			{'Flag of Romania (1948-1952).svg', '+1948-01-08', '+1952'},
			{'Flag of Romania.svg', '12. april 1867-04-12', '+1948-01-08'}},
		Q219 = {'BUL', {'Flag of Bulgaria.svg', '+1990-11-22'},
			{'Flag of Bulgaria (1971 – 1990).svg', '+1971-05-18', '+1990-11-22'}},
		Q222 = {'ALB', {'Flag of Albania.svg', '+1992'}},
		Q224 = {'CRO', {'Flag of Croatia.svg', '+1990-12-21'},
			{'Flag of Croatia (white chequy).svg', '+1990-06-27', '+1990-12-21'}},
		Q227 = {'AZE', {'Flag of Azerbaijan.svg'}},
		Q228 = {'AND', {'Flag of Andorra.svg'}},
		Q229 = {'CYP', {'Flag of Cyprus.svg', '+2006-08-20'},
			{'Flag of Cyprus (1960-2006).svg', '+1960-08-16', '+2006-08-20'}},
		Q232 = {'KAZ', {'Flag of Kazakhstan.svg'}},
		Q235 = {'MON', {'Flag of Monaco.svg'}},
		Q238 = {'SMR', {'Flag of San Marino.svg'}},
		Q241 = {'CUB', {'Flag of Cuba.svg'}},
		Q252 = {'INA', {'Flag of Indonesia.svg'}},
		Q258 = {'RSA', {'Flag of South Africa.svg', '+1994-04-27'},
			{'Flag of South Africa (1928–1994).svg', '+1928-05-31', '+1994-04-27'}},
		Q262 = {'ALG', {'Flag of Algeria.svg'}},
		Q265 = {'UZB', {'Flag of Uzbekistan.svg'}},
		Q298 = {'CHI', {'Flag of Chile.svg'}},
		Q334 = {'SGP', {'Flag of Singapore.svg'}},
		Q347 = {'LIE', {'Flag of Liechtenstein.svg'}},
		Q398 = {'BRN', {'Flag of Bahrain.svg', '+2002-02-14'}},
		Q403 = {'SRB', {'Flag of Serbia.svg', '+2004-08-18'},
			{'Flag of Serbia (1992–2004).svg', '+1992-04-27', '+2004-08-17'}},
		Q408 = {'AUS', {'Flag of Australia.svg'}},
		Q414 = {'ARG', {'Flag of Argentina.svg'}},
		Q419 = {'PER', {'Flag of Peru.svg', '+1950'},
			{'Flag of Peru (1825-1950).svg', '+1825-02-25', '+1950'}},
		Q664 = {'NZL', {'Flag of New Zealand.svg'}},
		Q711 = {'MGL', {'Flag of Mongolia.svg'}},
		Q717 = {'VEN', {'Flag of Venezuela.svg', '+2006-03-12'},
			{'Flag of Venezuela (1930–2006).svg', '+1930','+2006-03-12'}},
		Q733 = {'PAR', {'Flag of Paraguay.svg', '+2013-07-15'},
			{'Flag of Paraguay (1990–2013).svg', '+1990', '+2013-07-14'}},
		Q736 = {'ECU', {'Flag of Ecuador.svg'}},
		Q739 = {'COL', {'Flag of Colombia.svg'}},
		Q750 = {'BOL', {'Flag of Bolivia.svg', '+1851-10-31'}},
		Q754 = {'TTO', {'Flag of Trinidad and Tobago.svg'}},
		Q774 = {'GUA', {'Flag of Guatemala.svg'}},
		Q778 = {'BAH', {'Flag of the Bahamas.svg'}, '+1973-07-10'},
		Q783 = {'HON', {'Flag of Honduras.svg'}, '+1949'},
		Q786 = {'DOM', {'Flag of the Dominican Republic.svg'}},
		Q794 = {'IRI', {'Flag of Iran.svg', '+1980-07-29'},
			{'Flag of Iran (1964–1980).svg', '+1964', '+1980-07-29'}},
		Q800 = {'CRC', {'Flag of Costa Rica (state).svg', '+1906-11-27'}},
		Q801 = {'ISR', {'Flag of Israel.svg'}},
		Q804 = {'PAN', {'Flag of Panama.svg'}},
		Q813 = {'KGZ', {'Flag of Kyrgyzstan.svg', '+1992-03-03'}},
		Q817 = {'KUW', {'Flag of Kuwait.svg', '+1961-09-07'}},
		Q833 = {'MAS', {'Flag of Malaysia.svg', '+1963-09-16'}},
		Q842 = {'OMA', {'Flag of Oman.svg', '+1995'}},
		Q846 = {'QAT', {'Flag of Qatar.svg'}},
		Q858 = {'SYR', {'Flag of Syria.svg', '+1980-03-29'}},
		Q865 = {'TPE', {'Flag of the Republic of China.svg', '+1928-12-17'}},
		Q869 = {'THA', {'Flag of Thailand.svg'}},
		Q878 = {'UAE', {'Flag of the United Arab Emirates.svg'}},
		Q881 = {'VIE', {'Flag of Vietnam.svg', '+1976-02-07'}},
		Q884 = {'KOR', {'Flag of South Korea.svg', '+1997-10'}},
		Q916 = {'ANG', {'Flag of Angola.svg', '+1975-11-11'}},
		Q921 = {'BRU', {'Flag of Brunei.svg', '+1959-09-29'}},
		Q928 = {'PHI', {'Flag of the Philippines.svg', '+1998'}},
		Q948 = {'TUN', {'Flag of Tunisia.svg', '+1999-07-03'}},
		Q954 = {'ZIM', {'Flag of Zimbabwe.svg', '+1980-04-18'}},
		Q965 = {'BUR', {'Flag of Burkina Faso.svg'}},
		Q983 = {'GEQ', {'Flag of Equatorial Guinea.svg', '+1979-08-21'},
			{'Flag of Equatorial Guinea (1973–1979).svg', '+1973', '+1979-08-21'},
			{'Flag of Equatorial Guinea (without coat of arms).svg', '+1968-10-12', '+1973'}},
		Q986 = {'ERI', {'Flag of Eritrea.svg'}},
		Q1000 = {'GAB', {'Flag of Gabon.svg', '+1960-08-09'}},
		Q1007 = {'GBS', {'Flag of Guinea-Bissau.svg', '+1973-09-24'}},
		Q1008 = {'CIV', {"Flag of Côte d'Ivoire.svg"}},
		Q1009 = {'CMR', {'Flag of Cameroon.svg'}},
		Q1027 = {'MRI', {'Flag of Mauritius.svg', '+1968-03-13'}},
		Q1028 = {'MAR', {'Flag of Morocco.svg'}},
		Q1030 = {'NAM', {'Flag of Namibia.svg', '+1990-03-21'}},
		Q1036 = {'UGA', {'Flag of Uganda.svg', '+1962-10-09'}},
		Q1037 = {'RWA', {'Flag of Rwanda.svg', '+2001-10-25'},
			{'Flag of Rwanda (1962–2001).svg', '+1962', '+2001-10-25'}},
		Q9676 = {'IMN', {'Flag of the Isle of Man.svg'}},
		Q15180 = {'URS', {'Flag of the Soviet Union.svg', '+1980-08-15', '+1991-12-25'},
			{'Flag of the Soviet Union (1955–1980).svg', '+1955-08-19', '+1980-08-14'},
			{'Flag of the Soviet Union (1924–1955).svg', '+1923-11-13', '+1955-08-18'}},
		Q16957 = {'GDR', {'Flag of East Germany.svg', '+1959-10-01'},
			{'Flag of Germany.svg', '+1949-10-07', '+1959-10-01'}}, --German Democratic Republic
		Q8646 = {'HKG', {'Flag of Hong Kong.svg'}},
		Q25228 = {'AIA', {'Flag of Anguilla.svg'}},
		Q29999 = {'NED', {'Flag of the Netherlands.svg', '+1690'}}, --Kingdom of the Netherlands
		Q33946 = {'TCH', {'Flag of the Czech Republic.svg', '+1920'}}, -- Czechoslovakia (1918–1992)
		Q36704 = {'YUG', {'Flag of Yugoslavia (1992–2003).svg', '+1992-04-27', '+2003-02-04'}, --Yugoslavia
			{'Flag of Yugoslavia (1943–1992).svg', '+1946', '+1992-04-27'}},
		Q41304 = {'GER', {'Flag of Germany (3-2 aspect ratio).svg', '+1918-11-09'}}, -- Weimar Republic
		Q83286 = {'YUG', {'Flag of Yugoslavia (1943–1992).svg'}}, --Socialist Federal Republic of Yugoslavia
		Q172579 = {'ITA', {'Flag of Italy (1861–1946).svg'}}, --Kingdom of Italy (1861-1946)
		Q216923 = {'TPE', {'Flag of Chinese Taipei for Olympic games.svg'}}, -- Chinese Taipei
		Q268970 = {'AUT', {'Flag of Austria.svg', '+1918-11-12', '+1919-09-10'}}, -- German-Austria (1918-1919)
		Q713750 = {'FRG', {'Flag of Germany.svg'}}, --West Germany
		Q853348 = {'TCH', {'Flag of the Czech Republic.svg'}, '+1960-07-11', '+1990-03-29'}, -- Czechoslovak Socialist Republic (1960-1990)
		Q2415901 = {'GER', {'Merchant flag of Germany (1946–1949).svg', '+1945-05-09', '+1949-05-23'}}, -- Allied-occupied Germany
		Q13474305 = {'ESP', {'Flag of Spain (1945–1977).svg', '+1945-10-11', '+1977-01-21'}, -- Francoist Spain (1935-1976)
			{'Flag of Spain (1938–1945).svg', '+1939', '+1945-10-11'},
			{'Flag of the Second Spanish Republic.svg', '+1931-04-14', '+1939'}},
	}

local function flag(countryID, date)
	local trackingCategory = ''
	--[[ If you uncomment the line under this comment, all pages with look-up misses in
	the flag table will be placed in a tracking category. You can use this to find more flags
	to add to the table. ]]
	-- trackingCategory = '[[Category:Missing flag in Module:Cycling race]]'

	
	local entry = flags[countryID]
	local IOC
	local file
	if entry then
		for i, v in ipairs(entry) do
			if i == 1 then
				IOC = v
			else
				if not date then
					file = v[1]
					break
				else
					local from = v[2]
					local to = v[3]
					if (not from or from <= date) and (not to or to > date) then
						file = v[1]
						break
					end
				end
			end
		end
	end
	local flagpxSize = '20px'
	if countryID == 'Q39' then flagpxSize = '16px'end -- Small size for an square flag as Switzerland
	if file then
		return '[[File:' .. file .. '|border|' .. flagpxSize ..'|' .. IOC .. ']]'
	elseif not date then
		local p41 = mw.wikibase.getBestStatements(countryID, "P41") -- P41 is flag image
		if p41[1] and p41[1].mainsnak.snaktype == 'value' then
			return '[[File:' .. p41[1].mainsnak.datavalue.value .. '|border|' .. flagpxSize ..'|(Wikidata:' .. countryID .. ')]]' .. trackingCategory
		end
	else
		-- Search flag for specific date
		local p41 = getStatementForTime(countryID, "P41", date) -- P41 is flag image
		if p41 then
			return '[[File:' .. p41.mainsnak.datavalue.value .. '|border|' .. flagpxSize ..'|(Wikidata:' .. countryID .. ')]]' .. trackingCategory
		end
	end
	return trackingCategory
end

local function ucicodeCountry(countryID)
    local ucicode, countryName 
    local blacklist={Q736=true}
	if countryID then
		--get UCI code
		if flags[countryID] then
			ucicode=flags[countryID][1]
		end
		--get link, assumed for a country the label is equal to the link, where not correct in the blacklist
		--if the black list becomes too long, we could create a second list for the sitelinks
		if available_list then
			if type(translations.list) == "function" then
				countryName = translations.list(countryID)
			end
		end
		if countryName == nil or countryName=='' or blacklist[countryID] then
			countryName = mw.wikibase.getSitelink(countryID)
		end
		if ucicode and countryName then
			return ' <small>([['..countryName..'|'..ucicode..']])</small> '
		else
			return ''
		end
	else
		return ''
	end
end

local function jersey_infobox(wiki, winner_classification, item, timeOfRace)
	local jersey, jersey_name = '', ''
	local jerseyWPID = ''

	-- 1. Item of race, e.g. Tour de France = 'Q33881'
	-- 2. type of winner, names are the ones in variable t_s
	-- 3. and 4. start and end time. '+2500' means year 2500. Always beginning with a '+'
	-- 5. item of the jersey
	-- 6. item of the Wikipedia article of that jersey

	local data = {
		{'Q33881', 'montagne', '+1975', '+2500', 'Q25265958', 'Q927157'}, -- Tour de France
		{'Q33881', 'leader', '+1919', '+2500', 'Q24257871', 'Q738903'},
		{'Q33881', 'points', '+1953', '+1967', 'Q24645209', 'Q175399'}, -- Jersey green.svg
		{'Q33881', 'points', '+1968', '+1968', 'Q26919974', 'Q175399'}, -- Jersey red.svg
		{'Q33881', 'points', '+1969', '+2500', 'Q24645209', 'Q175399'}, -- Jersey green.svg
		{'Q33881', 'jeune', '+1975', '+2500', 'Q24645383', 'Q2254180'}, -- Jersey white.svg
		{'Q33881', 'winner_fighting', '+2003', '+2500', 'Q27644113', 'Q2094179'}, -- Jersey red number.svg
		{'Q33881', 'winner_fighting2', '+2003', '+2500', 'Q27644113', 'Q2094179'}, -- Jersey red number.svg
		{'Q33881', 'equipe', '+2006', '+2500', 'Q27644112', 'Q1436680'}, -- Jersey yellow number.svg

		{'Q33861', 'leader', '+1931', '+2500', 'Q24257763', 'Q1164275'}, -- Giro d'Italia, Jersey pink.svg
		{'Q33861', 'points', '+1967', '+1968', 'Q26919974', 'Q641083'}, -- Jersey red.svg
		{'Q33861', 'points', '+1969', '+2009', 'Q26945272', 'Q641083'}, -- Jersey violet.svg
		{'Q33861', 'points', '+2010', '+2016', 'Q26919974', 'Q641083'}, -- Jersey red.svg
		{'Q33861', 'points', '+2017', '+2500', 'Q26945272', 'Q641083'}, -- Jersey violet.svg
		{'Q33861', 'montagne', '+1974', '+2011', 'Q24645209', 'Q641060'}, -- Jersey green.svg
		{'Q33861', 'montagne', '+2012', '+2500', 'Q24687409', 'Q641060'}, -- Jersey blue.svg
		{'Q33861', 'jeune', '+1976', '+2500', 'Q24645383', 'Q641662'}, -- Jersey white.svg

		{'Q33937', 'leader', '+1935', '+1936', 'Q24258056', 'Q3278226'}, -- Vuelta a España, Jersey orange.svg
		{'Q33937', 'leader', '+1941', '+1941', 'Q26696171', 'Q640430'}, -- Jersey white.svg
		{'Q33937', 'leader', '+1942', '+1942', 'Q24258056', 'Q3278226'}, -- Jersey orange.svg
		{'Q33937', 'leader', '+1945', '+1945', 'Q24257872', 'Q2534046'}, -- Jersey red.svg
		{'Q33937', 'leader', '+1946', '+1950', 'Q26696171', 'Q640430'}, -- Jersey white.svg
		{'Q33937', 'leader', '+1955', '+1976', 'Q24257871', 'Q738903'}, -- Jersey yellow.svg
		{'Q33937', 'leader', '+1977', '+1977', 'Q24258056', 'Q3278226'}, -- Jersey orange.svg
		{'Q33937', 'leader', '+1978', '+1998', 'Q24257871', 'Q738903'}, -- Jersey yellow.svg
		{'Q33937', 'leader', '+1999', '+2009', 'Q24257991', 'Q27665179'}, -- Jersey gold.svg
		{'Q33937', 'leader', '+2010', '+2500', 'Q24257872', 'Q2534046'}, -- Jersey red.svg
		{'Q33937', 'points', '+1945', '+1986', 'Q24687409', 'Q2746711'}, -- Jersey blue.svg
		{'Q33937', 'points', '+1987', '+1989', 'Q24645209', 'Q11638007'}, -- Jersey green.svg
		{'Q33937', 'points', '+1990', '+2009', 'Q24687409', 'Q2746711'}, -- Jersey blue.svg
		{'Q33937', 'points', '+2010', '+2500', 'Q24645209', 'Q11638007'}, -- Jersey green.svg
		{'Q33937', 'montagne', '+1935', '+1985', 'Q27670182', 'Q11638007'}, -- Jersey green.svg
		{'Q33937', 'montagne', '+1986', '+1986', 'Q27670174', 'Q3278226'}, -- Jersey orange.svg
		{'Q33937', 'montagne', '+1987', '+1987', 'Q27670178', 'Q2534046'}, -- Jersey red.svg
		{'Q33937', 'montagne', '+1988', '+1989', 'Q27670105', 'Q27670115'}, -- Jersey blackdots.png
		{'Q33937', 'montagne', '+1990', '+2005', 'Q27670182', 'Q11638007'}, -- Jersey green.svg
		{'Q33937', 'montagne', '+2006', '+2008', 'Q27670174', 'Q3278226'}, -- Jersey orange.svg
		{'Q33937', 'montagne', '+2009', '+2009', 'Q27670126', 'Q27670163'}, -- Jersey granate.svg
		{'Q33937', 'montagne', '+2010', '+2500', 'Q25265959', 'Q27670167'}, -- Jersey bluedots.svg
		{'Q33937', 'jeune', '+2019', '+2500', 'Q24645383', 'Q60233927'}, -- Jersey white.svg

		{'Q2091354', 'leader', '+2011', '+2500', 'Q24257871', 'Q30020298'}, -- Tour of Norway, Jersey yellow.svg
		{'Q2091354', 'sprints', '+2011', '+2011', 'Q26806427', 'Q30020298'}, -- Jersey green.svg
		{'Q2091354', 'points', '+2012', '+2017', 'Q24645209', 'Q30020298'}, -- Jersey green.svg
		{'Q2091354', 'points', '+2018', '+2018', 'Q28820618', 'Q30020298'}, -- MaillotCyan.PNG
		{'Q2091354', 'points', '+2019', '+2500', 'Q47945989', 'Q30020298'}, -- Jersey dark blue.svg
		{'Q2091354', 'montagne', '+2011', '+2015', 'Q25265958', 'Q30020298'}, -- Jersey polkadot.svg
		{'Q2091354', 'montagne', '+2016', '+2017', 'Q27670174', 'Q30020298'}, -- Jersey orange.svg
		{'Q2091354', 'montagne', '+2018', '+2500', 'Q25265958', 'Q30020298'}, -- Jersey polkadot.svg
		{'Q2091354', 'jeune', '+2011', '+2500', 'Q24645383', 'Q30020298'}, -- Jersey white.svg
		{'Q2091354', 'winner_fighting', '+2017', '+2017', 'Q29957114', 'Q30020298'}, -- MaillotCyan.PNG
		{'Q128713', 'leader', '+2013', '+2017', 'Q24257871', 'Q30020299'}, -- Tour des Fjords, Jersey yellow.svg
		{'Q128713', 'leader', '+2018', '+2018', 'Q29594434', 'Q30020299'}, -- MaillotCyan.PNG
		{'Q128713', 'points', '+2013', '+2014', 'Q24645209', 'Q30020299'}, -- Jersey green.svg
		{'Q128713', 'points', '+2015', '+2017', 'Q24687409', 'Q30020299'}, -- Jersey blue.svg
		{'Q128713', 'points', '+2018', '+2018', 'Q25265938', 'Q30020299'}, -- Jersey violet.svg
		{'Q128713', 'montagne', '+2013', '+2018', 'Q25265958', 'Q30020299'}, -- Jersey polkadot.svg
		{'Q128713', 'jeune', '+2013', '+2018', 'Q24645383', 'Q30020299'}, -- Jersey white.svg
		{'Q128713', 'winner_fighting', '+2015', '+2015', 'Q30035038', 'Q30020299'}, -- Jersey green.svg
		{'Q128713', 'winner_fighting', '+2016', '+2017', 'Q30035039', 'Q30020299'}, -- Jersey orange.svg
		{'Q128961', 'leader', '+2013', '+2500', 'Q24687408', 'Q30020300'}, -- Arctic Race of Norway, Jersey blue.svg
		{'Q128961', 'points', '+2013', '+2500', 'Q24645209', 'Q30020300'}, -- Jersey green.svg
		{'Q128961', 'montagne', '+2013', '+2014', 'Q27670178', 'Q30020300'}, -- Jersey red.svg
		{'Q128961', 'montagne', '+2015', '+2500', 'Q27670174', 'Q30020300'}, -- Jersey orange.svg
		{'Q128961', 'jeune', '+2013', '+2500', 'Q24645383', 'Q30020300'}, -- Jersey white.svg
		{'Q128961', 'winner_fighting', '+2014', '+2500', 'Q27644113', 'Q30020300'}, -- Jersey red number.svg
		{'Q17619325', 'leader', '+2014', '+2014', 'Q24257871', 'Q30020302'}, -- Ladies Tour of Norway, Jersey yellow.svg
		{'Q17619325', 'leader', '+2015', '+2016', 'Q26945272', 'Q30020302'}, -- Jersey violet.svg
		{'Q17619325', 'leader', '+2017', '+2500', 'Q24257871', 'Q30020302'}, -- Jersey yellow.svg
		{'Q17619325', 'points', '+2014', '+2500', 'Q24645209', 'Q30020302'}, -- Jersey green.svg
		{'Q17619325', 'montagne', '+2014', '+2500', 'Q25265958', 'Q30020302'}, -- Jersey polkadot.svg
		{'Q17619325', 'jeune', '+2014', '+2500', 'Q24645383', 'Q30020302'}, -- Jersey white.svg
		{'Q17619325', 'winner_fighting', '+2016', '+2500', 'Q30035039', 'Q30020302'}, -- Jersey orange.svg
	}
	--timeOfRace = '+1968-07-01T00:00:00Z'
	timeOfRace = string.match(timeOfRace, "+%d%d%d%d") or ''
	for _, v in pairs(item) do
		for _, value in pairs(data) do
			if v == value[1] then
				if winner_classification == value[2] then
					if (timeOfRace >= value[3]) and (timeOfRace <= value[4]) then
						jersey = value[5]
						jerseyWPID = value[6]
					end
				end
			end
		end
	end

	-- local starttime, endtime = '', '+2500'
	if jersey ~= '' then --and (timeOfRace > starttime) and (timeOfRace < endtime) then
		local entity_jersey = mw.wikibase.getEntity(jersey)
			jersey = entity_jersey.claims['P18'][1].mainsnak.datavalue.value
			jersey_name = entity_jersey:getLabel(wikilang) or ''
		if jerseyWPID ~= '' then
			local entity = mw.wikibase.getEntity( jerseyWPID )
			local Sitelink = entity:getSitelink(wiki..'wiki') -- link to WParticle
			if Sitelink ~= nil then jerseyWPID = wiki..':'..Sitelink else jerseyWPID = '' end
		end
		return jersey, jersey_name, jerseyWPID
	else return '', '', ''
	end
end

local function jersey(h)
	local jersey_string = ' '
	local jerseys = {
	['Q24257871'] = {file = 'Jersey yellow.svg',
		name_ar = 'قميص أصفر لمتصدر الترتيب العام',
		name_fr = 'maillot jaune de leader du classement général',
		name_es = 'maillot amarillo de líder de la clasificación general',
		name_ru = 'жёлтая майка лидера генеральной классификации'
		},
	['Q24645209'] = {file = 'Jersey green.svg',
		name_ar = 'قميص أخضر لمتصدر ترتيب النقاط',
		name_fr = 'maillot vert de leader du classement par points',
		name_es = 'maillot verde de líder de la clasificación por puntos',
		name_ca = 'mallot verd del líder de la classificació per punts',
		name_ru = 'зелёная майка лидера очковой классификации'
		},
	['Q24645383'] = {file = 'Jersey white.svg',
		name_ar = 'قميص أبيض لمتصدر ترتيب الشباب',
		name_fr = 'maillot blanc de leader du classement du meilleur jeune',
		name_es = 'maillot blanco de líder de la clasificación de los jóvenes',
		name_ru = 'белая майка лидера молодёжной классификации',
		name_de = 'weißes Trikot des Führenden der Nachwuchswertung'
		},
	}

	if type(h) == 'table' and h[1] then
		for _, v in ipairs(h) do
			local jersey_name
			if jerseys[v] then
				jersey_string = jersey_string .. '[[File:' .. jerseys[v].file .. '|20px'
				jersey_name = jerseys[v]['name_' .. wiki] or mw.wikibase.getLabel(v) or jerseys[v]['name_fr']
				if jersey_name then
					jersey_string = jersey_string .. '|' .. jersey_name
				end
				jersey_string = jersey_string .. ']]'
			else
				local p18 = mw.wikibase.getBestStatements(v, 'P18')
				if p18[1] and p18[1].mainsnak.snaktype == 'value' then
					jersey_string = jersey_string .. '[[File:' .. p18[1].mainsnak.datavalue.value .. '|20px'
					jersey_name = getLabelFallback(v, {wikilang, 'en', 'fr'})
					if jersey_name then
						jersey_string = jersey_string .. '|' .. jersey_name
					end
					jersey_string = jersey_string .. ']]'
				end
			end
		end
	end
	return jersey_string
end -- function end

--=== E) Other (winner, getkm) ===
local function isHuman(riderId)
	local isHuman = false
	if riderId then
		local p31 = wikibase.getBestStatements(riderId, 'P31')
		for _, iOf in pairs (p31) do
			if iOf.mainsnak.snaktype == 'value' and iOf.mainsnak.datavalue.value['numeric-id'] == 5 then
				isHuman = true
				break
			end
		end
	end
	return isHuman
end

local function isCountry(riderId)
	local isCountry = false
	if riderId then
		local p31 = wikibase.getBestStatements(riderId, 'P31')
		for _, iOf in pairs (p31) do
			-- exception Hong-Kong and Taiwan
			if iOf.mainsnak.snaktype == 'value' and (iOf.mainsnak.datavalue.value['numeric-id'] == 6256 or iOf.mainsnak.datavalue.value['numeric-id'] ==15634554 or iOf.mainsnak.datavalue.value['numeric-id'] ==779415) then
				isCountry = true
				break
			end
		end
	end
	return isCountry
end

local function subwinner(riderId, timeOfRace, q)
	local outputtable={}
	local riderTeam, riderLink, countryID

	if riderId then
		if isHuman(riderId) then
			riderLink = getRiderLink(riderId, timeOfRace)
			local p27 = getStatementForTime(riderId, 'P27', timeOfRace) --P27 is country of citizenship
			if p27 then
				countryID = p27.mainsnak.datavalue.value.id
			end
			if countryID then
				riderLink = flag(countryID, timeOfRace) .. ' ' .. riderLink
			end
			riderTeam = getTeam(riderId, timeOfRace, q) or ''
		else
			local _
			riderLink, _, countryID = getTeamLinkCat(riderId, timeOfRace, true)
			if countryID then
				riderLink = flag(countryID, timeOfRace) .. ' ' .. riderLink
			end
		end
	end
	return riderLink, riderTeam
end

local function winner(raceID, winners, timeOfRace, country, WDlink_on, team, ref)
	local p1346 = wikibase.getAllStatements(raceID, 'P1346') -- P1346 is 'winner'
	for _, winner in pairs(p1346) do
		local wID = winner.mainsnak.snaktype == 'value' and winner.mainsnak.datavalue.value.id
		local wOf, wCause, wCriterion, riderLink
		local q = winner.qualifiers
		if q then
			local _, disqualified =isdisqualified(winner,q)
			
			if q.P642 and q.P642[1].snaktype == 'value' then
				for _, q642 in pairs(q.P642) do
					wOf = q642.datavalue.value.id -- P642 is 'of'
					if not wOf then
						-- Try P1346 (winner) instead
						-- Assume Q20882667 ('overall winner general classification') if neither are found
						wOf = q.P1346 and q.P1346[1].snaktype == 'value' and q.P1346[1].datavalue.value.id or 'Q20882667'
					end
					wCause = q.P828 and q.P828[1].snaktype == 'value' and q.P828[1].datavalue.value.id
						-- P828 is 'has cause'
					wCriterion = q.P1013 and q.P1013[1].snaktype == 'value' and q.P1013[1].datavalue.value.id
						-- P1013 is 'criterion used'

					if winners[wOf] then
						if wID then
							local reference = ref and getReference(winner)
							local _, countryID
							if isHuman(wID) then
								riderLink = getRiderLink(wID, timeOfRace)
								if reference then
									riderLink = riderLink .. reference
								end
								if team then
									local riderTeam = getTeam(wID, timeOfRace, q)
									if riderTeam then
										riderLink = riderLink .. ' (' .. riderTeam .. ')'
									end
								end
							elseif isCountry(wID) then
								riderLink = flag(wID, timeOfRace).." "..getCountryName(wID) 
								if reference then
									riderLink = riderLink .. reference
								end
								country=true	
							else --team
								local _
								riderLink, _, countryID = getTeamLinkCat(wID, timeOfRace, country)
								if reference then
									riderLink = riderLink .. reference
								end
							end
							if not country then
								if not countryID then
									if isHuman(wID) then
										local p27 = getStatementForTime(wID, 'P27', timeOfRace) --P27 is country of citizenship
										if p27 then
											countryID = p27.mainsnak.datavalue.value.id
										end
									else
										local p17 = getStatementForTime(wID, 'P17', timeOfRace) --P27 is country of citizenship
										if p17 then
											countryID = p17.mainsnak.datavalue.value.id
										end
									end
								end
								if countryID then
									riderLink = flag(countryID, timeOfRace) .. ' ' .. riderLink
								end
							end
							if WDlink_on then
								riderLink = riderLink .. ' ' .. wdLink(wID)
							end
						else
							riderLink = wCriterion and contentLanguage:ucfirst(wikibase.getLabel(wCriterion) or '') or ''
							if wCause then
								local cause = wikibase.getLabel(wCause)
								if cause then
									riderLink = riderLink .. ' (' .. cause .. ')'
								end
							end
						end
						if disqualified==true then
							riderLink='<s>'..riderLink..'</s>'
						end
						if winners[wOf] == '' then
							winners[wOf] = riderLink
						else
							winners[wOf] = winners[wOf] .. '<br/>' .. riderLink
						end
					end
				end
			end
		end
	end
end

local function sortandconcat(t_Body, resulttable)
	table.sort(t_Body, function(a, b) return a[1] < b[1] end)
	for _, m in ipairs(t_Body) do resulttable:node(m[2]) end
	return resulttable
end

--------- Definition sub-functions for calendar and victory ------
local function fn_date(entityID, functionName)  --to move as a general function
	local tempdate, timeOfRace, sortkey, sortkeyDate
	local outputtable={}
	local sTime = firstValue(entityID, 'P580', 'time') -- P580 is 'start time'
	local eTime = firstValue(entityID, 'P582', 'time') -- P582 is 'end time'
	if sTime and eTime then
		local startTime, endTime = getStartEndTime(sTime, eTime, 'small')
		if functionName==nil then --calendar
			tempdate = startTime .. ' – ' .. endTime  --mettre year en option!
			sortkeyDate = sTime
		else  --victory, general classification
			tempdate =endTime
			sortkeyDate =eTime
		end
		timeOfRace = eTime
	else
		-- This function give a format to dates when P585 (date) is used in a single day race
		local pTime = firstValue(entityID, 'P585', 'time') -- P585 is 'point in time'
		if pTime then
			tempdate = func_date(pTime, 'small')
			timeOfRace = pTime
			sortkeyDate = pTime
		end
	end
	local _, _, y, m, d = string.find(sortkeyDate, "(%d+)-(%d+)-(%d+)")
	if y~= nil and m~= nil and d~=nil then
		sortkey = y..m..d
	elseif y~= nil and m~= nil then
		sortkey = y..m
	elseif y~= nil then
		sortkey = y
	else sortkey = '0000'
	end

	local tCell = mw.html.create('td'):attr('data-sort-value',sortkey)
	:cssText("style=text-align:right;padding:0 0.5em")
	:wikitext(tempdate)
	
	outputtable[1]=timeOfRace
	outputtable[2]=tostring(tCell)
	outputtable[3]=sortkey
	return outputtable
end

local function fn_country(entityID, timeOfRace,countrybool, fn_racetable)
	-- This function gives countries where the race take place
	-- parentID taken from fn_race, optional
	
	--outputtable[1] is the cell
	--outputtable[2] is the name of the country
	--outputtable[3] is the flag
	local country, countryname, outputtable= {}, {}, {}
	local countryID, parentID, raceSitelink
	
	if fn_racetable~=nil then
		raceSitelink = fn_racetable[1] --only for country false
		parentID=fn_racetable[3]
	end
	
	local cssCell="text-align:" .. textalign .. ";padding:0 0.5em"
	local tCell= mw.html.create('td'):cssText(cssCell)
	
	local listOfProperty={'P1532','P17'} -- P1512 is 'country for sport' to handle problems with Hong Kong etc.
	local listOfID = {entityID, parentID}
	
	for _, thisID in ipairs(listOfID) do
		if thisID~=nil then
			for _, prop in ipairs(listOfProperty) do
				if countryID == nil then --like "break"
					for _, p1532 in statements(thisID, prop) do 
						countryID = p1532.mainsnak.datavalue.value.id
						countryname[#countryname + 1] = getCountryName(countryID)
						if countrybool==false or not countryname[#countryname] then
							country[#country + 1]=flag(countryID, timeOfRace)
						else
							country[#country + 1]=flag(countryID, timeOfRace).." "..countryname[#countryname]
						end
						outputtable[3]=flag(countryID, timeOfRace)
					end
				end
			end
		end
	end

	if countryID == nil then outputtable[3]="no flag" end
	if countryname[1] then tCell:attr('data-sort-value',countryname[1]) end
	if countrybool==false then
		tCell:wikitext(country[1].." "..(raceSitelink or ''))
		outputtable[2]=''
	else
		if countryname[1] then
			outputtable[2]=countryname[1]
			if country[1] then tCell:wikitext(country[1]) end
		else
			outputtable[2]=''
		end
		
	end
	outputtable[1]=tCell
	return outputtable
end

local function commastage(stageID,racelabel) --how to write "stage, "
	local outputtable={}
	local stagenumber=''
	local substage = ''
	local stagenumberonly, stageletter
	outputtable[1]=''
	outputtable[2]=''

	local temp=firstValue(stageID, 'P1545')
	if temp then stagenumber = temp end

	if stagenumber=='0' then --prologue
		stagenumber= victories_translate(wiki,9)
	else
		if stagenumber==nil then
			stagenumber= victories_translate(wiki,8)
		else
			--look for substage
			local i,j = string.find(stagenumber, "%a+") --if letter in the stage number
			if i ~= nil then --we have to do something
				local k,l = string.find(stagenumber, "%d+") --select the number in the stage number
				stagenumberonly = string.sub(stagenumber, k, l)--cut the string in 2
				stageletter = string.sub(stagenumber, i, j)
				stagenumber=stagenumberonly
				if stageletter ~= nil then substage=stageletter end
			end
			if wiki == 'ar' then
				stagenumber= victories_translate(wiki,8)..' '..number('f', stagenumber, wiki)
			else
				stagenumber= number('f', stagenumber, wiki)..substage..' '..victories_translate(wiki,8)
			end
		end
	end

	local comma = ", "
	if wiki == 'ar' then comma = " ، " end
	if wiki == 'fr' then
		local correpondance={
		{name="^Trois", article= " des "},
		{name="^Quatre", article= " des "},
		{name="^Boucles", article= " des "},
		{name="^Triptyque", article= " du "},
		{name="^Tour", article= " du "},
		{name="^Grand Prix", article= " du "},
		{name="^Circuit", article= " du "},
		{name="^Mémorial", article= " du "},
		{name="^Trophée", article= " du "},
		{name="^Ronde", article= " de la "},
		{name="^Semaine", article= " de la "},
		{name="^Classica", article= " de la "},
		{name="^Flèche", article= " de la "},
		{name="^Course", article= " de la "},
		{name="^Classique", article= " de la "},
		{name="Race", article= " de la "},
		{name="^Étoile", article= " de l'"},
		{name="^La", article= " de "}
		}

		for _, v in ipairs(correpondance) do
			if string.find(racelabel, v.name) then
				comma = v.article
				break
			end
		end
	end

	if wiki == 'fr' or wiki == "lb" or wiki=="ca" or wiki=="es" or wiki=="ast" then
		outputtable[1]=stagenumber..comma
	elseif wiki=="de" or wiki=="da" or wiki=="fo" or wiki=="no" or wiki=="ru" or wiki=="ar" or wiki=="lv" then
		outputtable[2]=comma..stagenumber
	end
	return outputtable
end

local function getMainRaceLink(entityID,entity_type,stageID, functionName,timeOfRace) --the link to the edition but with a general name
	local instanceOf, label, Sitelink, isclass, prefix, postfix
	
	Sitelink=wikibase.getSitelink(entityID)
	prefix=''; postfix='' --general classification
	listOfProperty={'P2561','P1448'}

	for _, p31 in statements(entityID, 'P31') do
		instanceOf = p31.mainsnak.datavalue.value.id
		isclass=false
		for _,thisClass in ipairs(class) do--we don't want the class, but the main race
			if instanceOf == thisClass then isclass=true end
		end
		if isclass==false then
			for _, prop in ipairs(listOfProperty) do
				for _, p2561 in statements(instanceOf, prop) do --name for championship
					if label==nil then
						local lang_WD = p2561.mainsnak.datavalue.value.language
						if wiki == lang_WD then
							local nametemp = p2561.mainsnak.datavalue.value.text
							if timeOfRace~= nil then
								local q = p2561.qualifiers
								if q then
									local temp = checktime(nametemp,q,timeOfRace)
									if temp then label = nametemp end--if the time is correct than it is finished
								else
									label = nametemp
								end
							end
						end
					end
				end
			end

			if label==nil then
				label=wikibase.label(instanceOf)
				if not label then
					label = getLabelFallback(entityID, {'en', 'fr', 'de'}) or ''
				end
			end
			if Sitelink==nil then --only if no link to the race direct
				Sitelink=wikibase.getSitelink(instanceOf)
			end
			if Sitelink==nil and entity_type=='champ' then --only for champ
				local temp=firstValue(instanceOf, 'P361','id')
				if temp then Sitelink= wikibase.getSitelink(temp) end
			end
		end
	end
	--affect the label
	if label==nil then
		label=wikibase.label(entityID)
		if not label then
			label = getLabelFallback(entityID, {'en', 'fr', 'de'}) or ''
		end
	end
	--look for link to the race if nothing
	--if different languages have to be added, a language table can be created
	if entity_type=='2' then
		if functionName~=nil then --calendar=nil
			if wiki == 'fr' then prefix= victories_translate(wiki,1)..', ' --general classification
			elseif wiki == 'ar' then postfix ='، '..victories_translate(wiki,1)
			else postfix = ', '..victories_translate(wiki,1)
			end
		end
	elseif entity_type=='stage' then
		--how to write "stage, " is concentrated in one function
		local commatable=commastage(stageID, label)
		prefix= commatable[1]
		postfix=commatable[2]
	end

	if Sitelink == nil then
		return prefix..label..postfix
	else
		return prefix..'[['..Sitelink..'|'..label..']]'..postfix
	end
end

local function fn_getClassInfo(entityID,displayed_class) --get the class of the race
	local display=false
	local outputtable={}
	local entity_type, class_text, sortkey_class

	if displayed_class==nil then
		display=true
	else
		for _, thisClass in ipairs(displayed_class) do
			if entityID ==thisClass then display=true break end
		end
	end
	listOfClassesList = {class_champ,class_2x, class_without2x}
	listOfClassesName = {'champ', '2','1'}
	
	for ii, thisClassesList in ipairs(listOfClassesList) do
		if entity_type==nil then
			for _, thisClass in ipairs(thisClassesList) do
				if entityID == thisClass then
					entity_type = listOfClassesName[ii]
					class_text = mw.wikibase.label(thisClass)
					sortkey_class = class_sort[thisClass]
				end
			end
		end
	end
	if entity_type==nil then entity_type = 'nada' end--to allow display of race without class...

	if display~=false then
		outputtable[1]=entity_type
		outputtable[2]=class_text
		outputtable[3]=sortkey_class
		outputtable[4]=entityID --save the class
	end
	return outputtable
end

local function fn_race(entityID,displayed_class,displayclass,timeOfRace, functionName,country)--return link to the race and class
	--first function read from victory main
	
	--outputtable[1] is the cell with the race, or sitelink if country is false
	--outputtable[2] is the cell with the class
	
	local Sitelink,instanceOf,circuitID,parentCircuitID, displayedCircuitID, Circuitlink
	local Classlink, entity_type, classID, class_text
	local inputtable, outputtable={}, {}
	local display=true -- should be true to work, bypassed
	local sortkey_class = ''
	local stageID=entityID

	for _, p31 in statements(entityID, 'P31') do
		instanceOf = p31.mainsnak.datavalue.value.id
		for i=1,#stages do --is it a stage?
			if instanceOf == stages[i] then
				entity_type = 'stage'  --then the class is one stage above!
				local parentID = getParentID(entityID)
				entityID = parentID
				outputtable[3] = parentID --as we read it here, no need to read it afterwards
				display = true
				for _, p31bis in statements(parentID, 'P31') do
					local instanceOfbis = p31bis.mainsnak.datavalue.value.id
					inputtable=fn_getClassInfo(instanceOfbis,displayed_class)
					if inputtable[1]~=nil and inputtable[1]~='nada' then
						class_text =inputtable[2]
						sortkey_class=inputtable[3]
						classID=inputtable[4]
					end
				end
			end
		end
		if entity_type==nil then  --bypass if stage
			inputtable=fn_getClassInfo(instanceOf,displayed_class)
			if inputtable[1]==nil then
			elseif inputtable[1]=='nada' then --no display="inputtable[1]==nil" inputtable[1]=='nada'--> display but empty
				display=true
			else
				display=true
				entity_type=inputtable[1]
				class_text =inputtable[2]
				sortkey_class=inputtable[3]
				classID=inputtable[4]
			end
		end
	end
	--Now we have the class and know the type of race it is
	--Get the circuit, if we display it only
	if class_text ~=nil then Classlink = class_text else Classlink ='' sortkey_class='' end

	if display then
		if entity_type == 'stage' then
			Sitelink=getMainRaceLink(entityID,entity_type,stageID, functionName,timeOfRace)
		else
			Sitelink=getMainRaceLink(entityID,entity_type,nil, functionName,timeOfRace)
		end
		if country~=false then
			local tCell=mw.html.create('td'):cssText("text-align:".. textalign ..";padding:0 2.3em"):wikitext(Sitelink)
			outputtable[1]=tostring(tCell)
		else
			outputtable[1]=Sitelink --already opened
		end
		if displayclass == true then
			if classID=='Q23005601' or classID=='Q23005603' then --1WWT 2WWT clear
				displayedCircuitID = 'Q21075974'
			elseif classID=='Q22231106' or classID=='Q22231107' then --1UWT 2UWT clear
				displayedCircuitID = 'Q635366'
			else --we have to look in the item
				for _, p361 in statements(entityID, 'P361') do
					circuitID = p361.mainsnak.datavalue.value.id
					for _, p31 in statements(circuitID, 'P31') do --is it a UCI circuit?
						parentCircuitID = p31.mainsnak.datavalue.value.id
						for i=1,#UCI_Circuits do
							if parentCircuitID == UCI_Circuits[i] then  --Yes it is
								displayedCircuitID=circuitID
								break
							end
						end
					end
				end
			end
			if displayedCircuitID~=nil then
				Circuitlink = wikibase.getSitelink(displayedCircuitID) --we display the circuit of the year
				if Circuitlink ~= nil then 
					if class_text ~= nil then 
						Classlink = '[['..Circuitlink..'|'..class_text..']]' 
						else
						Classlink = '[['..Circuitlink .. ']]' 
					end
				end
			end
			-- class
			local tCell=mw.html.create('td')
			:attr('data-sort-value',sortkey_class)
			:cssText("text-align:center;padding:0 0.5em")
			:wikitext(Classlink)
			
			outputtable[2]=tCell
		end
	end
	return outputtable
end

local function fn_rider(entityID,timeOfRace,displayteam,only_winner,country)
	local winners, countrytemp, result
	local WDlink_on = (wiki == "mk" or wiki == "ja")
	local thereisawinner=false
	
	if only_winner == 1 then
		winners = {Q20882667 = '', Q20882747=''} -- first, general or stage
	elseif only_winner == 0 then
		winners = { Q20882667 = '', Q20882668 = '',Q20882669 = ''} -- Q20882668 is 'second overall'
	else --3
		winners = { Q47640757='' } -- World Tour -- name not used here
	end
	if country==nil then countrytemp=false else countrytemp=country end
	winner(entityID, winners, timeOfRace, countrytemp, WDlink_on, displayteam, true)
	
	local tCell=mw.html.create('td'):css("text-align:".. textalign ..";padding:0 0.5em")
	
	if only_winner == 0 then
		tCell:wikitext(winners.Q20882667)
		result=tostring(tCell)
		tCell=mw.html.create('td'):css("text-align:".. textalign ..";padding:0 0.5em"):wikitext(winners.Q20882668)
		result=result..tostring(tCell)
		tCell=mw.html.create('td'):css("text-align:".. textalign ..";padding:0 0.5em"):wikitext(winners.Q20882669)
		return result..tostring(tCell)
	else
		local tempwinner
		if only_winner == 1 then
			if winners.Q20882667~=nil and winners.Q20882667~='' then
				tempwinner=winners.Q20882667
			else
				tempwinner=winners.Q20882747
			end
		else
			tempwinner=winners.Q47640757
		end
		if tempwinner~='' and tempwinner~=nil then thereisawinner=true end
		return tCell:wikitext(tempwinner), thereisawinner
	end
end

local function getKm(wiki)
	local km
	if wiki == "ar" then km = 'كم'
	elseif wiki == "mk" then km = 'км'
	elseif wiki == "ru" then km = 'км'
	elseif wiki == "ja" then km = 'キロメートル'
	else km = 'km' end
	return km
end

local function checkkm(p)
	local km, unit
	if p[1] and p[1].mainsnak.snaktype == 'value' then
		km = tonumber(p[1].mainsnak.datavalue.value.amount)
		unit = p[1].mainsnak.datavalue.value.unit
		if unit == 'http://www.wikidata.org/entity/Q828224' then
			return km
		end
	end
	return nil
end

local function getDistance(raceID, addUnit)
	local km
	local p = mw.wikibase.getBestStatements(raceID, 'P3157') -- P3157 is 'event distance'
	if not p[1] then
		p = mw.wikibase.getBestStatements(raceID, 'P2043') -- P2043 is 'length'
	end
	km =checkkm(p)
	if not km then --for stage race we can sum the distances from each stage
		local stagep, tempkm
		for _, p527 in statements(raceID,'P527') do
			stageID = p527.mainsnak.datavalue.value.id
			stagep=mw.wikibase.getBestStatements(stageID, 'P3157')
			tempkm=checkkm(stagep)
			if tempkm then
				if not km then
					km=tempkm
				else
					km=km+tempkm
				end
			end
		end
	end
	local text
	local lang = contentLanguage
	if km then
		-- The unit should always be km. Skip if it isn't.
		text = lang:formatNum(km)
		if wiki == 'fo' then
			text = string.gsub(text, "%.", ",")
		end
		if addUnit then
			text = text .. ' ' .. getKm(wiki)
		end
	end
	return text, km
end

local function getKmh(wiki)
	local kmh
	if wiki == "ar" then kmh = 'كم/س'
	elseif wiki == "da" then kmh = 'km/t'
	elseif wiki == "fo" then kmh = 'km/t'
	elseif wiki == "nl" then kmh = 'km/u'
	elseif wiki == "no" then kmh = 'km/t'
	elseif wiki == "mk" then kmh = 'км/ч'
	elseif wiki == "ru" then kmh = 'км/ч'
	elseif wiki == "ja" then kmh = 'キロメートル毎時'
	else kmh = 'km/h' end
	return kmh
end

local function getElevation(raceID)
	local temp = mw.wikibase.getBestStatements(raceID, 'P7297')
	if temp[1] and temp[1].mainsnak.snaktype == 'value' then
		local unit = temp[1].mainsnak.datavalue.value.unit
		if unit == 'http://www.wikidata.org/entity/Q11573' then
			return tonumber(temp[1].mainsnak.datavalue.value.amount)..' m'
		end
	end
    return nil
end

local function getSpeed(raceID, addUnit,kmdistance, property)
	local p = mw.wikibase.getBestStatements(raceID, 'P2052') -- P2052 is 'speed'
	local kmh, unit, text, found, timeOfRace
	local lang = contentLanguage
	if p[1] and p[1].mainsnak.snaktype == 'value' then
		kmh = tonumber(p[1].mainsnak.datavalue.value.amount)
		unit = p[1].mainsnak.datavalue.value.unit
		if unit == 'http://www.wikidata.org/entity/Q180154' then -- Q180154 is 'kilometre per hour'
			found=true
		end
	end
	if not found and kmdistance then --calculate speed
		local p2321= wikibase.getBestStatements(raceID, property) --winner supposed to be first of overall classification
		if p2321 and p2321[1] and p2321[1].mainsnak.snaktype == 'value' then
			local q = p2321[1].qualifiers
			if q and q.P1352 and q.P1352[1].snaktype == 'value' then --rank
				for _, q1352 in pairs(q.P1352) do
					rank = tonumber(q1352.datavalue.value.amount)
				end
				if rank == 1 then
					timeOfRace=qualifieramount(p2321[1], 'P2781') --get time
				end
			end

			if timeOfRace then
				found=true
				kmh=math.modf(1000*kmdistance/(timeOfRace/3600))/1000
			end
		end
	end
	if found then	
		-- The unit should always be km/h. Skip if it isn't.
		text = lang:formatNum(kmh)
		if wiki == 'fo' then
			text = string.gsub(text, "%.", ",")
		end
		if addUnit then
			text = text .. ' ' .. getKmh(wiki)
		end
	end
	return text
end

local function getgendercode(riderID, default)
	local gender
	local p21 = mw.wikibase.getBestStatements(riderID, 'P21') -- P21 is gender
	if p21[1] and p21[1].mainsnak.snaktype == 'value' then
		local g = p21[1].mainsnak.datavalue.value.id
		if g == 'Q6581097' then gender = 'm' -- Male
		elseif g == 'Q6581072' then gender = 'f' -- Female
		elseif g == 'Q1052281' then gender = 't' -- Transgenre
		end
	end
	return gender or default -- default is for teams, n or f
end

function number(gender, b, wiki)
	local str
	if b=="" then return "" end
	if wiki=="ar" then
		str = b
	elseif wiki == "ca" then
	if b==1 then str = b.."r"
		elseif b==2 then str = b.."n"
		elseif b==3 then str = b.."r"
		elseif b==4 then str = b.."t"
		else str = b.."è"
		end
	elseif wiki=="es" then
		if gender == 'm' or gender == 'n' then str = b..".º"
		elseif gender == 'f' then str = b..".ª"
		else str = b.."."
		end
	elseif wiki=="fr" then
		if b==1 then
			if gender == 'm' then str="1<sup>er</sup>"
			elseif gender == 'f' or gender == 'n' then str="1<sup>re</sup>"
			else str="1<sup>e</sup>"
			end
		else str=b.."<sup>e</sup>"
		end
	elseif wiki=="nl" then str=b.."e"
	elseif wiki=="ru" then str=b.."-й"
	elseif wiki=="eo" then str=b.."-a"
	elseif wiki=="ast" then
		if gender == 'm' or gender == 'n' then str = b.."ᵘ"
		elseif gender == 'f' then str = b.."ª"
		else str = b.."."
		end
	else str = b .. ". "
	end
	return str
end

local function calculate_time(t)
	local time = tonumber(t)
	local h, m, s = 0, 0, 0
	local str = ''

	if time == nil then return '' end
	if time < 60 then s = time
	elseif time < 3600 then m = math.modf(time/60) s = time - m*60
	else h = math.modf(time/3600) m = math.modf((time - h*3600)/60) s = time - h*3600 - m*60
	end

	if h>0 then str = str..mw.ustring.format ('%i'..unit(2), h) end
	if m>=0 and h>0 then str = str.. mw.ustring.format('%02i'..unit(3), m) end
	if m>0 and h==0 then str = str.. mw.ustring.format('%i'..unit(3), m) end
	if s>=0 and (h>0 or m>0) then str = str.. mw.ustring.format('%02i'..unit(4), s) end
	if s>=0 and h==0 and m==0 then str = str.. mw.ustring.format('%i'..unit(4), s) end
	return str --time..': '..h..' '..m..' '..s
end

function func_error_message(wiki,x)
	local l10nDef = {
		["en"] = {'Property <1> is missing in item "<2>" (<3>)'},
		["ar"] = {'الخاصية <1> غير موجودة في العنصر "<2>" (<3>)'},
	}
	local l10n = l10nDef[wiki]
	if not l10n then l10n = l10nDef["en"] end  -- default
	return l10n[x]
end

local function getMissingLabelTrackingCategory()
	local l10nDef = {
		["//cs.wikipedia.org"] = '[[Kategorie:Údržba:Doplnit štítek na Wikidatech]]',
		["//lv.wikipedia.org"] = '[[Category:Vikidatos trūkst nosaukuma latviešu valodā]]',
		["//he.wikipedia.org"] = '[[קטגוריה:ויקינתונים:ערכים חסרי תווית בעברית: קבוצת אופניים]]',
	}
	local l10n = l10nDef[mw.site.server]
	if not l10n then
		l10n = ''
	end
	return l10n
end

--== IV) Translation ==
function startlist_translate(x)
	local l10nDef = {
		["ar"] = {"المشاركين","م","عداء","مرتبة","مدير الرياضة:","لم يكمل السباق","HD","لم يبدأ","تم إقصائه","طريق","فردي ضد الساعة","و","بدون فريق","عرض","إخفاء"},
		["ast"] = {"Llista de participantes", "Númberu", "Ciclista","Posición","Direutor deportivu:","AB","FLT","NTS","DES","ruta","CRI","y", "ensin equipo","amosar","anubrir"},
		["br"] = {"Roll ar berzidi", "Niv.", "Reder","Pos","Rener sport :","AB","HD","NP","DQ","hent","chrono","ha", "hep skipailh","diskouez","kuzhat"},
		["ca"] = {"Llista de participants", "#", "Rider","Rank","Directeur sportif:","DNF","HD","NP","DQ","road","ITT","and", "no team","show","hide"},
		["da"] = {"Startliste", "Nr.", "Rytter","Placering","Sportsdirektør:","DNF","HD","DNS","DQ","landevej","enkeltstart","og", "intet hold","vis","skjul"},
		["de"] = {"Startliste", "Nr.", "Fahrer","Platz","Sportlicher Leiter:","DNF","HD","NP","DQ","Straße","Zeitfahrt","und", "no team","Öffnen","Schließen"},
		["en"] = {"Startlist", "#", "Rider","Rank","Directeur sportif :","DNF","OTL","DNS","DSQ","road","ITT","and", "no team","show","hide"},
		["es"] = {"Lista de participantes", "Dorsal", "Ciclista","Posición","Director deportivo:","AB","FLT","NTS","DES","ruta","CRI","y", "sin equipo","show","hide"},
		["fr"] = {"Liste des participants", "Num", "Coureur","Pos","Directeur sportif :","AB","HD","NP","DQ","route","chrono","et", "sans équipe","afficher","masquer"},
		["lv"] = {"Starta saraksts", "#", "Braucējs","Rangs","Sporta direktors:","DNF","HD","NP","DQ","šoseja","ITT","un", "nav komandas","show","hide"},
		["mk"] = {"Почетен состав", "Бр.", "Возач","Место","Спортски директор:","НЗ","HD","NP","DQ","друмска","ITT","и", "нема екипа","show","hide"},
		["nl"] = {"Deelnemerslijst", "Nummer", "Wielrenner","Ranglijst", "Ploegleider :","AB","HD","NP","DQ","weg","chrono","en", "zonder ploeg","show","hide"},
		["pt"] = {"Lista de Participantes", "Dorsal", "Ciclista","Posição","Director desportivo:","DNF","HD","NP","DQ","estrada","CRI","e", "sem equipe","show","hide"},
		["ru"] = {"Составы команд", "№", "Гонщик","Место","Спортивный директор:","DNF","OTL","DNS","DSQ","RR","ITT","и", "без команды","показать","скрыть"},
		["no"] = {"Startliste", "Nr.", "Rytter","Plassering","Sportsdirektør:","DNF","OTL","DNS","DSQ","landevei","tempo","og", "ingen lag","vis","skjul"},
	}
	local l10n = l10nDef[wiki]
	if not l10n then l10n = l10nDef["en"] end  -- default
	return l10n[x]
end

function startlisttable_translate(wiki,x)
	local l10nDef ={
		["ar"] = {"المشاركين", "#", "الدراج","الفريق","المرتبة"},
		["ca"] = {"Llista de participants", "#", "Rider",'Equip',"Rank"},
		["da"] = {"Startliste", "Nr.", "Rytter","Holdnavn","Placering"},
		["de"] = {"Startliste", "Nr.", "Fahrer","Team","Platz"},
		["en"] = {"Startlist", "#", "Rider","Team","Rank"},
		["es"] = {"Lista de participantes", "Dorsal", "Ciclista","Equipo","Posición"},
		["fr"] = {"Liste des participants", "Num", "Coureur","Équipe","Pos"},
		["lv"] = {"Starta saraksts", "#", "Braucējs","Komandas nosaukums","Rangs"},
		["mk"] = {"Почетен состав", "Бр.", "Возач","Име на екипата", "Место"},
		["nl"] = {"Deelnemerslijst", "Nummer", "Wielrenner","Ploegnaam","Ranglijst"},
		["pt"] = {"Lista de Participantes", "Dorsal", "Ciclista","Equipe","Posição"},
		["ru"] = {"Составы команд", "№", "Гонщик","Команда","Место"},
		["no"] = {"Startliste", "Nr.", "Rytter","Lagnavn","Plassering"},
	}
	local l10n = l10nDef[wiki]
	if not l10n then l10n = l10nDef["en"] end  -- default
	return l10n[x]
end

local function race_reference_translate(wiki, x)
	local l10nDef = {
		["ar"] = {"مصدر: ", "مصادر: "},
		["ast"] = {"Fonte: ","Fontes: "},
		["br"] = {"Dave : ", "Daveoù : "},
		["da"] = {"Kilde: ","Kilder: "},
		["de"] = {"Quelle: ","Quellen: "},
		["en"] = {"Source: ", "Sources: "},
		["es"] = {"Fuente: ","Fuentes: "},
		["fr"] = {"Source : ", "Sources : "},
		["he"] = {"מקור : ", "מקורות : "},
		["hu"] = {"Forrás: ", "Források: "},
		["lv"] = {"Avots: ", "Avoti: "},
		["mk"] = {"Извор: ", "Извори: "},
		["no"] = {"Kilde: ","Kilder: "},
		["pt"] = {"Fonte: ","Fontes: "},
		["ru"] = {"Источник: ", "Источники: "},
	}
	local l10n = l10nDef[wiki] or l10nDef["en"] -- default
	return l10n[x]
end

local function calendar_translate(wiki, x, title)
	local l10nDef = {
		["ar"] = { "تقويم الاتحاد الدولي للدراجات", "التاريخ", "#", "السباق", "البلد", "الصنف", "الفائز", "الثاني", "الثالث", "متصدر الترتيب العام", "طواف العالم للدراجات للنساء", "", "طواف العالم للدراجات" , "طواف أوروبا للدراجات" , "طواف آسيا للدراجات" , "طواف أمريكا للدراجات" , "طواف أفريقيا للدراجات" , "طواف أوقيانوسيا للدراجات", "بطولات وطنية", "سباق الطريق", "سباق فردي ضد الساعة" },
		["ast"] = {"Calendariu UCI", "Data", "#","Carrera", "País", "Clas", "Ganador","Segundu", "Terceru", "Líder","UCI WorldTour Femenín","","UCI WorldTour","UCI Europe Tour","UCI Asia Tour","UCI America Tour","UCI Africa Tour","UCI Oceania Tour","Campeonatu nacional","Carrera de ruta","Contrarreló individual"},
		["br"] = {"Deiziadur UCI", "Deiziad", "niv.","Redadeg", "Bro", "Klas", "Gounezer", "Eil", "Trede", "E penn ar renkamant hollek","UCI Women's World Tour","","UCI World Tour","UCI Europe Tour","UCI Asia Tour","UCI America Tour","UCI Africa Tour","UCI Oceania Tour","Kampionadoù broadel","Redadeg a-renk","A-benn d'an eur hiniennel"},
		["fr"] = {"Calendrier UCI", "Date", "n°","Course", "Pays", "Classe", "Vainqueur", "Deuxième", "Troisième", "Leader du classement général","UCI Women's World Tour","","UCI World Tour","UCI Europe Tour","UCI Asia Tour","UCI America Tour","UCI Africa Tour","UCI Oceania Tour","Championnats nationaux","Course en ligne","Contre-la-montre"},
		["en"] = {"UCI Calendar", "Date", "#","Race", "Country", "Class", "Winner", "Second", "Third", "Overall leader","UCI Women's World Tour","","UCI World Tour","UCI Europe Tour","UCI Asia Tour","UCI America Tour","UCI Africa Tour","UCI Oceania Tour","National championship","Road race","Individual time trial"},
		["de"] = {"UCI Kalender", "Datum", "Nr.","Rennen", "Staat", "Klasse", "Sieger", "Zweiter", "Dritter", "Gesamt&shy;führender","UCI Women's World Tour","","UCI World Tour","UCI Europe Tour","UCI Asia Tour","UCI America Tour","UCI Africa Tour","UCI Oceania Tour","Nationale Straßen-Radsportmeister","Straßenrennen","Einzelzeitfahren"},
		["da"] = {"","Dato", "#","Løb", "Land", "Klasse", "Vinder","Toer", "Treer", "Førende rytter","UCI Women's World Tour","","UCI World Tour","UCI Europe Tour","UCI Asia Tour","UCI America Tour","UCI Africa Tour","UCI Oceania Tour","Nationalt mesterskab","Landevej","Enkeltstart"},
		["es"] = {"Calendario UCI", "Fecha", "#","Carrera", "País", "Clase", "Ganador","Segundo", "Tercero", "Líder","UCI Women's World Tour","","UCI World Tour","UCI Europe Tour","UCI Asia Tour","UCI America Tour","UCI Africa Tour","UCI Oceania Tour","Campeonato nacional","Carrera de ruta","Contrarreloj individual"},
		["he"] = {"UCI Calendar", "תאריך", "#","מרוץ", "מדינה", "Class", "מנצח", "שני", "שלישי", "Overall leader","UCI Women's World Tour","","UCI World Tour","UCI Europe Tour","UCI Asia Tour","UCI America Tour","UCI Africa Tour","UCI Oceania Tour","אלוף לאומי","Road race","Individual time trial"},
		["ja"] = {"", "開催日", "#","レース", "国", "国", "勝者","準優勝", "3位", "全体リーダー","UCI Women's World Tour","","UCI World Tour","UCI Europe Tour","UCI Asia Tour","UCI America Tour","UCI Africa Tour","UCI Oceania Tour","National championship","Road race","Individual time trial"},
		["lv"] = {"", "Datums", "#","Sacensības", "Valsts", "Kategorija", "Uzvarētājs","Otrais", "Trešais", "Kopvērtējuma līderis","UCI Women's World Tour","","UCI World Tour","UCI Europe Tour","UCI Asia Tour","UCI America Tour","UCI Africa Tour","UCI Oceania Tour","National championship","Road race","Individual time trial"},
		["mk"] = {"", "Датум","#", "Трка", "Земја", "Класа", "Победник", "Второпласиран", "Третопласиран", "Cевкупен лидер","UCI Women's World Tour","","UCI World Tour","UCI Europe Tour","UCI Asia Tour","UCI America Tour","UCI Africa Tour","UCI Oceania Tour","National championship","Road race","Individual time trial"},
		["no"] = {"", "Dato", "#","Ritt", "Land", "Klasse", "Vinner", "Andreplass", "Tredjeplass", "Sammenlagt&shy;leder","UCI Women's World Tour","","UCI World Tour","UCI Europe Tour","UCI Asia Tour","UCI America Tour","UCI Africa Tour","UCI Oceania Tour","Nasjonalt mesterskap","Landevei","Tempo"},
		["pt"] = {"Calendário UCI", "Data", "#", "Corrida", "País", "Clase", "Vencedor", "Segundo", "Terceiro", "Líder", "UCI Women's World Tour", "", "UCI World Tour", "UCI Europe Tour", "UCI Asia Tour", "UCI America Tour", "UCI Africa Tour", "UCI Oceania Tour", "Campeonato nacional", "Corrida de estrada", "Contrarrelógio individual"},
		["ru"] = {"", "Дата", "№","Гонка", "Страна", "Класс", "Победитель","Второй", "Третий", "Лидер генеральной классификации","UCI Women's World Tour","","UCI World Tour","UCI Europe Tour","UCI Asia Tour","UCI America Tour","UCI Africa Tour","UCI Oceania Tour","National championship","Road race","Individual time trial"},
	}
	local l10n = l10nDef[wiki]
	if not l10n then l10n = l10nDef["en"] end  -- default
	if x==1000 then --code
		return title
	else
		return l10n[x]
	end
end

function victories_translate(wiki, x)
	local l10nDef = {
		["ar"] = {"التصنيف العام", "سجل الفوز", "التاريخ", "السباق", "البلد", "الصنف", "الفائز","مرحلة","المقدمة"},
		["fr"] = {"Classement général", "Victoires", "Date", "Course", "Pays", "Classe", "Vainqueur","étape","Prologue"},
		["en"] = {"General classification", "Victories", "Date", "Race", "Country", "Class", "Winner","stage","Prologue"},
		["de"] = {"Gesamtwertung", "Siege", "Datum", "Rennen", "Staat", "Klasse", "Sieger","Etappe","Prolog"},
		["da"] = {"Samlede stilling", "Sejre", "Dato", "Løb", "Land", "Klasse", "Vinder","etape","Prolog"},
		["es"] = {"Clasificación general", "Victorias", "Fecha", "Carrera", "País", "Clase", "Ganador","etapa","Prólogo"},
		["ja"] = {"General classification", "Victories", "開催日", "レース", "国", "国", "勝者","ステージ","プロローグ"},
		["lv"] = {"Kopvērtējums", "Uzvaras", "Datums", "Sacensības", "Valsts", "Kategorija", "Uzvarētājs","posms","prologs"},
		["mk"] = {"General classification", "Victories", "Датум", "Трка", "Земја", "Класа", "Победник","Етапа","Пролог"},
		["no"] = {"Sammenlagt", "Seire", "Dato", "Ritt", "Land", "Klasse", "Vinner","etappe","Prolog"},
		["ru"] = {"генеральная классификация", "Победы", "Дата", "Гонка", "Страна", "Класс", "Победитель","этап","пролог"},
		["ast"] = {"Clasificación xeneral", "Victories", "Data", "Carrera", "País", "Clas", "Ganador","etapa","Prólogu"},
		["br"]={"Renkamant hollek", "Trec'hioù", "Deiziad", "Redadeg", "Bro", "Klas", "Gounezer","tennad","Prolog"},
		["ca"]={"Classifiació general", "Victòries", "Data", "Cursa", "País", "Classe", "Vencedor","etapa","Pròleg"},
		["cs"]={"General classification", "Victories", "Date", "Race", "Country", "Class", "Winner","etapa","Prolog"},
		["eo"]={"General classification", "Victories", "Date", "Race", "Country", "Class", "Winner","Etapo","Prologo"},
		["eu"]={"General classification", "Victories", "Date", "Race", "Country", "Class", "Winner","Etapa","Aitzinetapa"},
		["fi"]={"General classification", "Victories", "Date", "Race", "Country", "Class", "Winner","Etappi","Prologi"},
		["fo"]={"General classification", "Victories", "Date", "Race", "Country", "Class", "Winner","teinur","Forteinur"},
		["he"] = {"סיווג כללי", "נצחונות", "תאריך", "מרוץ", "מדינה", "מחלקה", "מנצח","שלב","פרולוג"},
		["la"]={"General classification", "Victories", "Date", "Race", "Country", "Class", "Winner","Statio","Incipit prologus"},
		["it"]={"General classification", "Victories", "Date", "Race", "Country", "Class", "Winner","Tappa","Prologo"},
		["hu"]={"General classification", "Victories", "Date", "Race", "Country", "Class", "Winner","Szakasz","Prolog"},
		["lb"]={"General classification", "Victories", "Date", "Race", "Country", "Class", "Winner","etapp","Prolog"},
		["nl"]={"Algemeen klassement", "Overwinningen", "Datum", "Race", "Land", "Klassement", "Winnaar","Etappe","Proloog"},
		["pl"]={"General classification", "Victories", "Date", "Race", "Country", "Class", "Winner","Etap","Prologu"},
		["pt"]={"Classificação geral", "Victórias", "Data", "Corrida", "País", "Classe", "Vencedor", "Etapa", "Prólogo"},
		["ro"]={"General classification", "Victories", "Date", "Race", "Country", "Class", "Winner","Etapa","Prolog"},
		["sk"]={"General classification", "Victories", "Date", "Race", "Country", "Class", "Winner","Etapa","Prológ"},
		["sv"]={"General classification", "Victories", "Date", "Race", "Country", "Class", "Winner","Etapp","Prolog"},
	}
	local l10n = l10nDef[wiki]
	if not l10n then l10n = l10nDef["en"] end  -- default
	return l10n[x]
end

local function listofstagesclassification_translate(x)
	local l10nDef = {
		["fr"]={"non attribué","Classements finals"},
		["en"]={"not attributed","Final"},
		["da"]={"ikke uddelt","Samlet"},
		["es"]={"no otorgado","Clasificaciones finales"},
		["no"]={"ikke utdelt","Sammenlagt"},
		["ru"]={"не определялся","Итог"},
	}
	local l10n = l10nDef[wiki]
	if not l10n then l10n = l10nDef["en"] end  -- default
	return l10n[x]
end

local function stageinfobox_translate(x)
	--[[ This function permits to translate fields of the infobox for stages. Take the line below, give a Wikipedia
		(ex : mk), and translate all fields. By default, English values are taken.]]
	local l10nDef = {
		["fr"] = {"Généralités", "Course", "Type", "Date", "Dates", "Distance", "Pays", "Pays",
			"Lieu de départ", "Lieu d'arrivée", "Partants",
			"Arrivants", "Vitesse moyenne", "Coût", "Résultats de l’étape", "Vainqueur", "Deuxième", "Troisième", "Combatif",
			"Classement général à l’issue de l’étape", "Leader", "Deuxième", "Troisième",
			"Classements annexes à l’issue de l’étape", "Points", "Montagne", "Sprints", "Jeune", "Super- combatif",
			"Combiné", "Étapes volantes", "Régularité",
			"Équipe", "Équipe aux points",
			"Image", "Légende", "Carte", "Vue en coupe", "Documentation", "Cima Coppi", "Cima Pantani", "Azzurri d'Italia", "Fuga", "Dénivelé"},
		["ar"] = {"تفاصيل السباق", "سباق", "نوع", "تاريخ", "تاريخ", "مسافة", "بلد", "بلدان", "نقطة البداية", "نقطة النهاية", "الدراجين في البداية",
			"الدراجين في النهاية", "متوسط السرعة", "الكلفة", "نتائج المرحلة", "الفائز", "الثاني", "الثالث", "متمرس",
			"التصنيف العام بعد المرحلة", "القائد", "الثاني", "الثالث",
			"التصنيفات الثانوية بعد المرحلة", "النقاط", "الجبل", "سباقات السرعة", "شاب", "تصنيف القتال", "ممتزجة", "سباقات السرعة", "الانتظام",
			"فريق", "فريق حسب النقاط", "صورة", "أسطورة", "بطاقة", "عرض الاقسام", "توثيق",
			"سيما كوبي", "سيما بانتاني", "أزوري دي إيطاليا", "فوجا بيناريلو"},
		["en"] = {"Race details", "Race", "Type", "Date", "Dates", "Distance", "Country", "Countries",
			"Journey origin", "Lieu d'arrivée", "Starting riders",
			"Arriving riders", "Average speed", "Cost", "Stage results", "Winner", "Second", "Third", "Combative",
			"General classification after stage", "Leader", "Second", "Third",
			"Secondary classifications after stage", "Points", "Mountain", "Sprints", "Young", "Combativity",
			"Combinated", "Intermediate sprints", "Regularity",
			"Team", "Team by points",
			"Image", "Legend", "Card", "Sectional view", "Documentation", "Cima Coppi", "Cima Pantani",
			"Azzurri d'Italia", "Breakaway", "Elevation"},
		["ja"] = {"レース詳細", "レース", "種類", "日付", "日付", "距離", "国", "国", "スタート", "ゴール", "スタート選手",
			"ゴール選手", "平均速度", "Cost", "ステージ結果", "優勝", "2位", "3位", "Combative",
			"ステージ後クラス", "1位", "2位", "3位",
			"ステージ後副次的クラス", "ポイント賞", "山岳賞", "スプリント賞", "新人賞", "敢闘賞", "コンビネーション賞", "Metas volantes", "Regularity",
			"チーム", "ポイント順位",
			"画像", "凡例", "カード", "断面図", "ドキュメンテーション", "Cima Coppi", "Cima Pantani", "Azzurri d'Italia", "Breakaway", "Elevation"},
		["ca"] = {"Detalls de la cursa", "Cursa", "Tipus", "Data", "Dates", "Distància", "País", "Països", "Origen de la cursa", "Lloc d’arribada", "Corredors sortits",
			"Corredors arribats", "Velocitat mitjana", "Durada", "Resultats de l'etapa", "Guanyador", "Segon", "Tercer", "Combatiu",
			"Classificació general després de l'etapa", "Líder", "Segon", "Tercer",
			"Classificacions secundàries després de l'etapa ", "Punts", "Muntanya", "Esprints ", "Jove", "Combativitat", "Combinada", "Metes volants", "Regularitat",
			"Equip", "Equip per punts",
			"Imatge", "Llegenda", "Card", "Sectional view", "Documentació", "Cima Coppi", "Cima Pantani", "Azzurri d'Itàlia", "Fuga", "Elevation"},
		["da"] = {"Etapedetaljer", "Rute", "Type", "Dato", "Datoer", "Distance", "Land", "Lande", "Startby", "Målby", "Startende ryttere",
			"Fuldførende ryttere", "Gennemsnitlig fart", "Omkostninger", "Etaperesultat", "Vinder", "Toer", "Treer", "Mest angrebsivrige",
			"Samlede stilling efter etapen", "Førende rytter", "Toer", "Treer",
			"Klassementerne efter etapen", "Point", "Bjerg", "Sprint", "Ungdom", "Mest angrebsivrige", "Kombination", "Indlagt spurt", "Regularitet",
			"Hold", "Hold efter point",
			"Billede", "Billedtekst", "Kort", "Profil", "Dokumentation", "Cima Coppi", "Cima Pantani", "Azzurri d'Italia", "Udbrud", "Elevation"},
		["es"] = {"Detalles de la carrera", "Carrera", "Tipo", "Fecha", "Fechas", "Distancia", "País", "Países", "Lugar de inicio", "Lugar de llegada", "Ciclistas participantes",
			"Ciclistas finalizados", "Velocidad media", "Duración", "Resultados de la etapa", "Ganador", "Segundo", "Tercero", "Combativo",
			"Clasificación general después de la etapa", "Líder", "Segundo", "Tercero",
			"Clasificaciones secundarias después de la etapa", "Puntos", "Montaña", "Esprint", "Joven", "Combatividad", "Combinada", "Metas volantes", "Regularidad",
			"Equipo", "Equipo por puntos",
			"Imagen", "Leyenda", "Card", "Sectional view", "Documentation", "Cima Coppi", "Cima Pantani", "Azzurri d'Italia", "Fuga", "Elevation"},
		["fo"] = {"Smálutir um kapping", "Kapping", "Slag", "Dagur", "Dagar", "Fjarstøða", "Land", "Lond", "Byrjunarbýur", "Málbýur", "Byrjandi súkklarar",
			"Fullførandi súkklarar", "Miðalferð", "Kostnaður", "Teinaúrslit", "Vinnari", "Annað pláss", "Triðja pláss", "Álopsheiður",
			"Høvuðskappingin eftir teinin", "Førandi súkklari", "Tveyari", "Tríari",
			"Aðrar kappingar eftir teinin", "Stig", "Fjøll", "Spurtar", "Ungdóms", "Álopsheiður", "Kombinatiónsheiður", "Metas volantes", "Regularitetur",
			"Lið", "Lið eftir stigum",
			"Mynd", "Myndatekstur", "Kort", "Brotpartur", "Skjalfesting", "Cima Coppi", "Cima Pantani", "Azzurri d'Italia", "Breakaway", "Elevation"},
		["he"] = {"פרטי מרוץ", "מרוץ", "סוג", "תאריך", "תאריכים", "מרחק", "מדינה", "מדינות",
			"התחלת המסלול", "Lieu d'arrivée", "רוכבים מתחילים",
			"רוכבים מסיימים", "מהירות ממוצעת", "Cost", "Stage results", "מנצח", "מקום שני", "מקום שלישי", "Combative",
			"General classification after stage", "מוביל", "שני", "שלישי",
			"Secondary classifications after stage", "נקודות", "הר", "Sprints", "Young", "Combativity",
			"Combinated", "Intermediate sprints", "Regularity",
			"קבוצה", "קבוצה על פי ניקוד",
			"תמונה", "כיתוב", "Card", "Sectional view", "Documentation", "Cima Coppi", "Cima Pantani",
			"Azzurri d'Italia", "Breakaway", "Elevation"},
		["lb"] = {"Allgemenges", "Course", "Typ", "Datum", "Datumer", "Distanz", "Land", "Land", "Depart", "Arrivée", "Um Start",
			"Ukomm", "Vitess-moyenne", "Käschten", "Résultater vun der Etapp", "Gewënner", "Zweeten", "Drëtten", "Combativ",
			"Generalklassement no der Etapp", "Éischten", "Zweeten", "Drëtten",
			"Aner Klassementer no der Etapp", "Punkten", "Bierg", "Sprint", "Bescht Jonken", "Super- combativ", "Combiné", "Fligend Etappen", "Regelméissegkeet",
			"Equipe", "Equipe no Punkten",
			"Fichier", "Legend", "Kaart", "Profil", "Dokumentatioun", "Cima Coppi", "Cima Pantani", "Azzurri d'Italia", "Breakaway", "Elevation"},
		["no"] = {"Etappedetaljer", "Etappe", "Type", "Dato", "Datoer", "Distanse", "Land", "Land", "Startsted", "Målsted", "Startende ryttere",
			"Fullførende ryttere", "Snittfart", "Omkostninger", "Etapperesultat", "Vinner", "Andre", "Tredje", "Offensiv",
			"Sammenlagtstilling etter etappen", "Sammenlagtleder", "Andre", "Tredje",
			"Klassifisering etter etappen", "Poeng", "Klatring", "Spurt", "Ungdom", "Offensiv", "Kombinasjon", "Innlagte spurter", "Regularitet",
			"Lag", "Lag (poeng)",
			"Bilde", "Bildetekst", "Kart", "Profil", "Dokumentasjon", "Cima Coppi", "Cima Pantani", "Azzurri d'Italia", "Brudd", "Elevation"},
		["pt"] = {"Detalhes da corrida", "Corrida", "Tipo", "Data", "Datas", "Distância", "País", "Países", "Origem da viagem", "Local de chegada", "Partida dos ciclistas",
			"Chegada dos ciclistas", "Velocidade média", "Custo", "Resultados da etapa", "Vencedor", "Segundo", "Terceiro", "Combativo",
			"Classificação geral após a etapa", "Líder", "Segundo", "Terceiro",
			"Classificação secundária após a etapa", "Pontos", "Montanha", "Corridas de velocidade", "Jovem", "Combatividade", "Combinados", "Metas volantes", "Regularidade",
			"Equipe", "Equipe por pontos",
			"Imagem", "Legenda", "Ficha", "Vista secional", "Documentação", "Cima Coppi", "Cima Pantani", "Azzurri d'Italia", "Fuga", "Elevation"},
		["nl"] = {"Race details", "Wedstrijd", "Soort", "Datum", "Datums", "Afstand", "Land", "Landen", "Start van de etappe", "Aankomstplaats", "Coureurs aan de start",
			"Coureurs bij de finish", "Gemiddelde snelheid", "Kosten", "Etappeuitslag", "Winnaar", "Tweede", "Derde", "Combative",
			"Algemeen klassement na de etappe", "Leider", "Tweede", "Derde",
			"Bijkomende uitslagen na de wedstrijd", "Punten", "Berg", "Sprints", "Jongeren", "Combativity", "Combinatie", "Metas volantes", "Regularity",
			"Team", "Team per punten",
			"Afbeelding", "Legenda", "Kaart", "Dwarsdoorsnede", "Documentatie", "Cima Coppi", "Cima Pantani", "Azzurri d'Italia", "Demarrage", "Elevation"},
		["ru"] = {"Детали гонки", "Гонка", "Тип", "Дата", "Даты", "Дистанция", "Страна", "Страны", "Место старта", "Место финиша", "Стартовало гонщиков",
			"Финишировало гонщиков", "Средняя скорость", "Затраты", "Результаты этапа", "Победитель", "Второй", "Третий", "Боец",
			"Генеральная классификация после этапа", "Лидер", "Второй", "Третий",
			"Классификации после этапа", "Очки", "Горная", "Спринтерская", "Молодёжная", "Бойцовская", "Комбинированная", "Промежуточные финиши", "Регулярность",
			"Командная по времени", "Командная по очкам",
			"Изображение", "Описание", "Карта", "Сектора", "Документация", "Cima Coppi", "Cima Pantani", "Azzurri d'Italia", "Breakaway", "Elevation"},
		["ast"] = {"Detalles de la carrera", "Carrera", "Tipu", "Data", "Dates", "Distancia", "País", "Países", "Llugar d'entamu",
			"Llugar de llegada", "Ciclistes participantes", "Ciclistes acabaos", "Velocidá media", "Duración", "Resultaos de la etapa",
			"Ganador", "Segundu", "Terceru", "Combativu", "Clasificación xeneral depués de la etapa", "Líder", "Segundu", "Terceru",
			"Clasificaciones secundaries depués de la etapa", "Puntos", "Monte", "Esprint", "Mozu", "Combatividá", "Combinada", "Metes volantes",
			"Regularidá", "Equipu", "Equipu per puntos", "Imaxe", "Lleenda", "Card", "Sectional view", "Documentación", "Cume Coppi",
			"Cume Pantani", "Azzurri d'Italia", "Fuga", "Elevation"},
		["br"] = {"Hollegezhioù", "Redadeg", "Doare", "Deiziad", "Deiziadoù", "Hed", "Bro", "Broioù",
			"Lec'h loc'hañ", "Lec'h degouezhout", "Loc'herien",
			"Erruerien", "Tizh keitat", "Koust", "Disoc'hoù an tennad", "Gounezer", "Eil", "Trede", "Stourmer",
			"Classement général à l’issue de l’étape", "Levier", "Eil", "Trede",
			"Classements annexes à l’issue de l’étape", "Poentoù", "Menez", "Sprintoù", "Yaouank", "Stourmer meur",
			"Liesrenkadur", "Sprintoù etre", "Régularité",
			"Skipailh", "Skipailh a-boentoù",
			"Skeudenn", "Alc'hwez", "Kartenn", "Gwell e skejad", "Teuliadur", "Cima Coppi", "Cima Pantani", "Azzurri d'Italia", "Fuga", "Elevation"},
		}
	local l10n = l10nDef[wiki]
	if not l10n then l10n = l10nDef["en"] end  -- default
	return l10n[x]
end

local function getSquadTableColumn(x)
	local l10nDef = { -- note (in the table), note (below the table)
		["ar"] = {"المتسابق", "تاريخ الولادة", "الفريق السابق", "ملاحظة", "ملاحظة", "البلد", "قائمة الفريق"},
		["fr"] = {"Cycliste", "Date de naissance", "Équipe précédente", "note", "note", "Pays", "Effectif"},
		["en"] = {"Rider", "Date of birth", "Previous team", "note", "note", "Country", "Team roster"},
		["br"] = {"Reder", "Deiziad genel", "Skipailh a-raok", "notenn", "notenn", "Bro", "Koskor"},
		["ca"] = {"Ciclista", "Data de naixement", "Equip previ", "Nota", "Nota", "País", "Team roster"},
		["cs"] = {"Cyklista", "Datum narození", "Předchozí tým", "note", "note", "Stát", "Týmová soupiska"},
		["da"] = {"Rytter", "Fødselsdag", "Seneste hold", "note", "note", "Land", "Trup"},
		["de"] = {"Name", "Geburtsdatum", "Vorheriges Team", "Anm.", "Anmerkung", "Land", "Team roster"},
		["eo"] = {"Antaŭnomo Nomo", "Naskiĝtago", "Previous team", "note", "note", "Lando", "Team roster"},
		["es"] = {"Corredor", "Fecha de nacimiento", "Equipo previo", "Nota", "Nota", "País", "Integrantes del equipo"},
		["eu"] = {"Izena", "Jaiotze-data", "Aurreko taldea", "Oharra", "Oharra", "Herrialdea", "Team roster"},
		["fi"] = {"Ajaja", "Syntymäaika", "Edellinen joukkue", "huomio", "huomio", "Maa", "Team roster"},
		["fo"] = {"Súkklari", "Føðingardagur", "Undanfarna lið", "note", "note", "Land", "Team roster"},
		["he"] = {"רוכב", "תאריך לידה", "קבוצה קודמת", "הערה", "הערה", "מדינה", "סגל הקבוצה"},
		["hu"] = {"Név", "Születésnap", "Előző csapat", "jegyzet", "jegyzet", "Ország", "Team roster"},
		["it"] = {"Ciclista", "Data di nascita", "Previous team", "Nota", "Nota", "Paese", "Team roster"},
		["ja"] = {"選手名", "生年月日", "前所属", "脚注", "脚注", "国", "Team roster"},
		["lb"] = {"Coureur", "Gebuertsdatum", "Equipe virdrun", "Nott", "Nott", "Staat", "Team roster"},
		["lv"] = {"Braucējs", "Dzimšanas datums", "Iepriekšējā komanda", "piezīme", "piezīme", "Valsts", "Komandas sastāvs"},
		["mk"] = {"Велосипедист", "Датум на раѓање", "Претходна екипа", "Фуснота", "Фуснота", "Држава", "Состав на екипата"},
		["nl"] = {"Naam", "Geboortedatum", "Vorige ploeg", "noot", "noot", "Nationaliteit", "Renners"},
		["no"] = {"Rytter", "Fødselsdato", "Tidligere lag", "note", "note", "Land", "Ryttere"},
		["pl"] = {"Imię i nazwisko", "Data urodzenia", "Poprzednia grupa", "Przypis", "Przypis", "Państwo", "Team roster"},
		["pt"] = {"Ciclista", "Data de nascimento", "Equipe anterior", "Nota", "Nota", "Pais", "Integrantes da equipe"},
		["ro"] = {"Ciclist", "Data nașterii", "Previous team", "note", "note", "Țară", "Team roster"},
		["ru"] = {"Гонщик", "Дата рождения", "Предыдущая команда", "Примечание", "Примечание", "Страна", "Состав"},
		["sv"] = {"Namn", "Födelsedatum", "Previous team", "not", "not", "Land", "Team roster"},
		["zh"] = {"車手", "出生日期", "Previous team", "脚注", "脚注", "国家", "Team roster"},
		["ast"] = {"Corredor", "Data de nacencia", "Equipu previu", "Nota", "Nota", "País", "Integrantes del equipu"},
	}
	local l10n = l10nDef[wiki]
	if not l10n then l10n = l10nDef["en"] end  -- default
	return l10n[x]
end

local function infobox_translate(x)
	-- This function permits to translate fields of the infobox, take the line below, give a Wikipedia (ex : mk), and translate all fields. By default, English values are taken.
	-- l10nDef["//??.wikipedia.org"] = {"RACE DETAILS", "COURSE", "COMPETITION", "COMPETITIONS", "STAGES", "DATE", "DATES", "DISTANCE", "COUNTRY", "COUNTRIES",
	-- "JOURNEY ORIGIN", "JOURNEY DESTINATION", "TEAMS", "STARTING RIDERS", "ARRIVING RIDERS", "AVERAGE SPEED", "COST", "PALMARES", "WINNER", "SECOND", "THIRD",
	-- "POINTS", "MOUNTAINS", "SPRINTS", "YOUTH", "COMBATIVITY", "COMBINATION", "TEAM", "Picture", "Caption", "Map", "Special 1", "Special 2", "Documentation",
	-- "METAS VOLANTES", "REGULARIDAD", "TEAM POINTS"}
	local l10nDef = {
		["ar"] = {"تفاصيل السباق", "سلسلة", "منافسة", "مسابقات", "مراحل", "التاريخ", "التواريخ", "المسافات", "البلد", "البلدان",
			"نقطة البداية", "نقطة النهاية", "الفرق", "عدد المتسابقين في البداية", "عدد المتسابقين في النهاية", "متوسط السرعة", "الكلفة", "المنصة", "الفائز", "الثاني",
			"الثالث", "حسب النقاط", "تسلق الجبل", "سباقات السرعة", "أفضل شاب", "تصنيف القتال", "مجموعة", "الفريق", "صورة", "تعليق", "خريطة", "مميز 1", "مميز 2", "توثيق", "سباقات السرعة", "انتظام", "نقاط الفريق", "فوجا بيناريلو", "أزوري دي إيطاليا","صاعد", "هواة","الجنسية"
			,"الارتفاع"
			},
		["fr"] = {"Généralités", "Course", "Compétition", "Compétitions", "Étapes", "Date", "Dates", "Distance", "Pays", "Pays",
			"Lieu de départ", "Lieu d'arrivée", "Équipes", "Partants", "Arrivants", "Vitesse moyenne", "Coût", "Résultats", "Vainqueur", "Deuxième", "Troisième",
			"Classement par points", "Meilleur grimpeur", "Meilleur sprinteur", "Meilleur jeune", "Super-combatif", "Meilleur au combiné", "Meilleure équipe",
			"Image", "Légende", "Carte", "Special 1", "Special 2", "Documentation", "Étapes volantes", "Régularité", "Meilleure équipe aux points",
			"Fuga", "Azzurri d'Italia", "Néophyte", "Amateur","Nationalité","Dénivelé"},
		["en"] = {"Race details", "Course", "Competition", "Competitions", "Stages", "Date", "Dates", "Distance", "Country", "Countries",
			"Journey origin", "Journey destination", "Teams", "Starting riders", "Arriving riders", "Average speed", "Cost", "Palmares", "Winner", "Second",
			"Third", "Points", "Mountains", "Sprints", "Youth", "Combativity", "Combination", "Team", "Picture", "Caption", "Map", "Special 1", "Special 2",
			"Documentation", "Intermediate sprints", "Regularidad", "Team points", "Breakaway", "Azzurri d'Italia", "Rookie","Amateur","Nationality","Elevation"},
		["ja"] = {"レース詳細", "コース", "競技", "競技", "ステージ", "日付", "日付", "距離", "距離", "国",
			"スタート", "ゴール", "チーム", "参加人数", "完走人数", "平均速度", "Cost", "結果", "優勝", "準優勝",
			"3位", "ポイント賞", "山岳賞", "スプリント賞", "新人賞", "敢闘賞", "チーム総合時間賞", "チーム", "画像", "キャプション", "地図", "Special 1", "Special 2",
			"ドキュメンテーション", "Metas volantes", "Regularidad", "チームポイント", "Breakaway", "Azzurri d'Italia", "Rookie","Amateur","Nationality","Elevation"},
		["br"] = {"Hollegezhioù", "Redadeg", "Kevezadeg", "Kevezadegoù", "Tennadoù", "Deiziad", "Deiziadoù", "Hed", "Bro", "Broioù",
			"Lec'h loc'hañ", "Lec'h degouezhout", "Skipailhoù", "Loc'herien", "Erruerien", "Tizh keitat", "Koust", "Disoc'hoù", "Gounezer", "Eil", "Trede",
			"Renkadur a-boentoù", "Kraper gwellañ", "Sprinter gwellañ", "Yaouank gwellañ", "Stourmer meur", "Gwellañ el liesrenkadur", "Skipailh gwellañ",
			"Skeudenn", "Alc'hwez", "Kartenn", "Dibar 1", "Dibar 2", "Teuliadur", "Metas volantes", "Regularidad", "Skipailh a-boentoù", "Achapadenn", "Azzurri d'Italia", "Rookie","Amateur","Nationality",
			"Elevation"
		},
		["ca"] = {"Detalls de la cursa", "Cursa", "Competició", "Competicions", "Etapes", "Data", "Dates", "Distància", "País", "Països",
			"Sortida", "Arribada", "Equips", "Inscrits", "Finalitzen", "Velocitat mitjana", "Cost", "Palmarès", "Vencedor", "Segon", "Tercer", "Punts", "Muntanya",
			"Esprints", "Joves", "Combativitat", "Combinada", "Equip", "Picture", "Caption", "Map", "Special 1", "Special 2", "Documentació", "Metes volants",
			"Regularitat", "Team points", "Fuga", "Azzurri d'Itàlia", "Rookie","Amateur","Nationality","Elevation"},
		["cs"] = {"Přehled", "Závod", "Soutěž", "Soutěže", "Počet etap", "Datum", "Datum", "Celková délka", "Země", "Země", "Start", "Cíl",
			"Týmy", "Běžci", "Příjezdy", "Rychlostní průměr", "Náklady", "Konečné pořadí", "Celkový vítěz", "2. místo", "3. místo", "Vítěz bodovací soutěže",
			"Nejlepší vrchař", "Nejlepší sprinter", "Nejlepší mladý jezdec", "Nejaktivnější jezdec", "Nejlepší kombinovaná", "Nejlepší družstvo", "Picture",
			"Caption", "Map", "Special 1", "Special 2", "Dokumentace", "Metas volantes", "Regularidad", "Team points", "Breakaway", "Azzurri d'Italia", "Rookie","Amatour","Broadelezh",
			"Elevation"
		},
		["da"] = {"Løbsdetaljer", "Rute", "Konkurrence", "Konkurrencer", "Etaper", "Dato", "Datoer", "Distance", "Land", "Lande",
			"Startby", "Målby", "Hold", "Startende ryttere", "Fuldførende ryttere", "Gennemsnitlig fart", "Pris", "Resultater", "Vinder", "Toer", "Treer",
			"Pointtrøje", "Bjergtrøje", "Sprinttrøje", "Ungdomstrøje", "Mest angrebsivrige", "Kombinationstrøje", "Holdkonkurrence", "Billede", "Billedtekst",
			"Kort", "Special 1", "Special 2", "Dokumentation", "Indlagt spurt", "Regularitet", "Holdkonkurrence efter point", "Udbrud", "Azzurri d'Italia", "Rookie","Amatør","Nationalitet",
			"Elevation"
		},
		["de"] = {"Allgemeines", "Ausgabe", "Rennserie", " Wettbewerb", "Etappen", "Datum", "Datum", "Gesamtlänge", "Austragungsland",
			"Austragungsländer", "Start", "Ziel", "Teams", "Fahrer am Start", "Fahrer im Ziel", "Durchschnitts&#173;geschwindigkeit", "Kosten", "Ergebnis",
			"Sieger", "Zweiter", "Dritter", "Punktewertung", "Bergwertung", "Sprintwertung", "Nachwuchswertung", "Kämpferischster Fahrer", "Kombinationswertung",
			"Teamwertung", "Bild", "Beschriftung", "Karte", "Special 1", "Special 2", "Dokumentation", "Metas volantes", "Regularidad", "Teamwertung (Punkte)",
			"Breakaway", "Azzurri d'Italia", "Rookie","Amateur","Nationality","Elevation"},
		["eo"] = {"Gxeneralajxo", "Bicikla konkurso", "Konkuro", "Konkuroj", "Etapoj", "Dato", "Datoj", "Longo", "Lando", "Landoj",
			"Komencloko", "Alvenloko", "Teamoj", "Startantoj", "Alvenantoj", "Averagxa rapido", "Kosto", "Rezultoj", "Venkinto", "Dua pozicio", "Tria pozicio",
			"Klasifiko laux poentoj", "Plej bona grimpanto", "Plej bona sprinto", "Plej bona juno", "Superbatalema", "Plej bona por kombino", "Plej bona teamo",
			"Picture", "Caption", "Map", "Special 1", "Special 2", "Dokumentado", "Metas volantes", "Regularidad", "Team points", "Breakaway", "Azzurri d'Italia", 
			"Rookie", "Amateur","Nationality","Elevation"},
		["es"] = {"Detalles", "Carrera", "Competición", "Competiciones", "Etapas", "Fecha", "Fechas", "Distancia total", "País", "Países",
			"Lugar de inicio", "Lugar de llegada", "Equipos", "Ciclistas participantes", "Ciclistas finalizados", "Velocidad media", "Costo", "Clasificación final",
			"Ganador", "Segundo", "Tercero", "Puntos", "Montaña", "Metas volantes", "Jóvenes", "Combatividad", "Combinada", "Equipo", "Imagen", "Leyenda", "Mapa",
			"Especial 1", "Especial 2", "Documentación", "Metas volantes", "Regularidad", "Team points", "Fuga", "Azzurri d'Italia", "Novatos","Amateur","Nationality",
			"Elevation"
		},
		["eu"] = {"Lasterketaren xehetasunak", "Ibilbidea", "Lehiaketa", "Lehiaketak", "Etapak", "Data", "Datak", "Distantzia",
			"Herrialdea", "Herrialdeak", "Jardunaldiko abiapuntua", "Jardunaldiko helmuga", "Taldeak", "Abiatutako txirrindulariak", "Iritsitako txirrindulariak",
			"Batez besteko abiadura", "Kostua", "Azken sailkapena", "Irabazlea", "Bigarrena", "Hirugarrena", "Puntuak", "Mendiak", "Esprintak", "Gazteak",
			"Saiatuena", "Konbinatua", "Taldeak", "Picture", "Caption", "Map", "Special 1", "Special 2", "Dokumentazioa", "Metas volantes", "Regularidad",
			"Team points", "Breakaway", "Azzurri d'Italia", "Rookie", "Amateur","Nationality","Elevation"},
		["fi"] = {"Kilpailun tiedot", "Nimi", "Kilpailu", "Kilpailut", "Etapit", "Päivä", "Päivät", "Matka", "Maa", "Maat",
			"Lähtöpaikka", "Saapumispaikka", "Joukkueet", "Osallistuneet pyöräilijät", "Maaliin saapuneet pyöräilijät", "Keskinopeus", "Kustannukset", "Lopputilanne",
			"Voittaja", "Toinen", "Kolmas", "Pistekilpailu", "Mäkikirikilpailu", "Sprintit", "Nuoret", "Yritteliäin", "Yhdistelmä", "Joukkue", "Kuva", "Kuvateksti",
			"Kartta", "Special 1", "Special 2", "Ohjesivu", "Metas volantes", "Regularidad", "Team points", "Breakaway", "Azzurri d'Italia", "Rookie", "Amateur","Nationality",
			"Elevation"
		},
		["fo"] = {"Smálutir", "Leið", "Kapping", "Kappingar", "Teinar", "Dagfesting", "Dagfestingar", "Strekki", "Land", "Lond", "Byrjunarbýur",
			"Málbýur", "Lið", "Byrjandi súkklarar", "Fullførandi súkklarar", "Miðalferð", "Kostnaður", "Palmares", "Vinnari", "Nr. 2", "Nr. 3", "Stig", "Fjøll",
			"Spurtar", "Ungdómur", "Mest álopssinnaður", "Kombinatión", "Lið", "Picture", "Caption", "Map", "Special 1", "Special 2", "Dokumentation", "Metas volantes",
			"Regularidad", "Team points", "Breakaway", "Azzurri d'Italia", "Rookie", "Amateur","Nationality","Elevation"},
		["he"] = {"פרטי מרוץ", "Course", "תחרות", "תחרויות", "Stages", "תאריך", "תאריכים", "מרחק", "מדינה", "מדינות",
			"התחלת מסלול", "סוף מסלול", "קבוצות", "Starting riders", "Arriving riders", "Average speed", "Cost", "Palmares", "מנצח", "שני",
			"שלישי", "ניקוד", "הרים", "ספרינטים", "Youth", "Combativity", "Combination", "קבוצה", "תמונה", "Caption", "Map", "Special 1", "Special 2",
			"תיעוד", "Intermediate sprints", "Regularidad", "Team points", "Breakaway", "Azzurri d'Italia", "Rookie", "Amateur","Nationality","Elevation"},
		["hu"] = {"Verseny adatai", "Verseny", "Sorozat", "Sorozatok", "Szakaszok", "Dátum", "Dátum", "Versenytáv", "Ország", "Országok",
			"Verseny rajtja", "Verseny célja", "Csapatok", "Induló versenyzők", "Beérkező versenyzők", "Átlagsebesség", "Költség", "Rangsor", "Győztes", "Második",
			"Harmadik", "Pontverseny", "Hegyi pontverseny", "Sprint", "Fiatalok versenye", "Legaktívabb versenyző", "Combination", "Csapatverseny", "Kép", "Képaláírás", "Térkép", "Special 1", "Special 2",
			"Dokumentáció", "Intermediate sprints", "Regularidad", "Team points", "Breakaway", "Azzurri d'Italia", "Rookie","Amateur","Nationality","Elevation"},
		["lb"] = {"Detailer", "Course", "Kompetitioun", "Kompetitiounen", "Etappen", "Datum", "Datumer", "Distanz", "Land", "Länner",
			"Depart", "Arrivée", "Equippen", "Um Depart", "Ukomm", "Vitess-Moyenne", "Käschten", "Palmarès", "Gewënner", "Zweeten", "Drëtten", "Beschte Sprinter",
			"Biergpräis", "Sprinter", "Beschte Jonken", "Kombativitéit", "Kombinatioun", "Equipe", "Picture", "Caption", "Map", "Special 1", "Special 2",
			"Dokumentatioun", "Étapes volantes", "Regularidad", "Team points", "Breakaway", "Azzurri d'Italia", "Rookie", "Amateur","Nationality","Elevation"},
		["lv"] = {"Sacensību informācija", "Sacensības", "Kategorija", "Sacensības", "Posmi", "Datums", "Datumi", "Distance", "Valsts",
			"Valstis", "Starts", "Finišs", "Komandas", "Braucēji startā", "Braucēji finišā", "Vidējais ātrums", "Izmaksas", "Rezultāti", "Uzvarētājs", "Otrais",
			"Trešais", "Punkti", "Kalnu karalis", "Sprints", "Jaunais braucējs", "Cīnītājs", "Kombinācija", "Komanda", "Atēls", "Paraksts", "Karte", "Papildinformācija 1",
			"Papildinformācija 2", "Dokumentācija", "Metas volantes", "Regularidad", "Team points", "Breakaway", "Azzurri d'Italia", "Rookie", "Amateur","Nationality","Elevation"},
		["mk"] = {"Детали за трката", "Издание", "Натпреварување", "Натпреварувања", "Етапи", "Датум", "Датуми", "Растојание",
			"Држава", "Држави", "Поаѓалиште", "Одредиште", "Екипи", "Возачи на почеток", "Возачи на крај", "Просечна брзина", "Трошоци", "Добитници на наградите",
			"Победник", "Второпласиран", "Третопласиран", "Бодовен", "Планински", "Спринтерски", "Младински", "Борбеност", "Комбиниран", "Екипен", "слика", "опис",
			"местоположбена карта", "Special 1", "Special 2", "Документација", "Metas volantes", "Regularidad", "Team points", "Breakaway", "Azzurri d'Italia", 
			"Rookie", "Amateur","Nationality","Elevation"},
		["nl"] = {"Wedstrijddetails", "Koers", "Wedstrijd", "Wedstrijden", "Etappes", "Datum", "Datums", "Afstand", "Land", "Landen",
			"Startplaats", "Finishplaats", "Teams", "Aantal coureurs aan de start", "Aantal coureurs bij de aankomst", "Gemiddelde snelheid", "Kosten", "Palmares",
			"Winnaar", "Tweede", "Derde", "Punten", "Bergen", "Sprints", "Jeugd", "Aanvalslust", "Combinatie", "Team", "Afbeelding", "Bijschrift", "Kaart", "Special 1",
			"Special 2", "Documentatie", "Metas volantes", "Regularidad", "Teampunten", "Demarrage", "Azzurri d'Italia", "Rookie", "Amateur",
			"Nationality","Elevation"},
		["no"] = {"Detaljer", "Ritt", "Konkurranse", "Konkurranser", "Etapper", "Dato", "Datoer", "Distanse", "Land", "Land", "Startsted",
			"Målsted", "Lag", "Startende ryttere", "Fullførende ryttere", "Gjennomsnittsfart", "Kostnad", "Resultater", "Vinner", "2. plass", "3. plass", "Poeng",
			"Klatring", "Spurt", "Ungdom", "Mest offensive", "Kombinasjon", "Lagkonkurranse", "Bilde", "Bildetekst", "Kart", "Spesial 1", "Spesial 2", "Dokumentasjon",
			"Innlagte spurter", "Regularitet", "Lagkonkurranse (poeng)", "Brudd", "Azzurri d'Italia", "Nykommer", "Amatør","Nasjonalitet","Elevation"},
		["pl"] = {"Wyrażenia ogólne", "Wyścig", "Konkurencja", "Konkursy", "Etapów", "Data", "Daty", "Dystans", "Państwo", "Państwy",
			"Odejście", "Przyjazd", "Zespoły", "Zgłoszenia", "Ukończyło wyścig", "Średnia prędkość", "Koszt", "Podium", "Pierwsze miejsce", "Drugie miejsce",
			"Trzecie miejsce", "Punktowa", "Górska", "Sprinterska", "Młodzieżowa", "Najaktywniejszych", "Kombinowana", "Drużynowa", "Picture", "Caption", "Map",
			"Special 1", "Special 2", "Dokumentacja", "Metas volantes", "Regularidad", "Team points", "Breakaway", "Azzurri d'Italia", "Rookie", "Amateur",
			"Nationality","Elevation"},
		["pt"] = {"Detalhes", "Corrida", "Válida para", "Válida para", "Etapas", "Data", "Data", "Distância", "País", "Países",
			"Partida", "Chegada", "Nº de equipes", "Ciclistas que iniciaram", "Ciclistas que finalizaram", "Velocidade média", "Custo", "Classificação final",
			"Vencedor", "Segundo", "Terceiro", "Prêmio por pontos", "Prêmio de montanha", "Sprints", "Juventude", "Disputa", "Combinação", "Equipes", "Imagem",
			"Legenda", "Mapa", "Special 1", "Special 2", "Documentação", "Metas volantes", "Regularidad", "Team points", "Breakaway", "Azzurri d'Italia", "Rookie", 
			"Amateur","Nationality","Elevation"},
		["ro"] = {"Detalii cursă", "Cursă", "Competiție", "Competiții", "Etape", "Dată", "Date", "Distanță", "Țară", "Țări", "Start",
			"Sosire", "Echipe", "Cicliști la start", "Cicliști la sosire", "Viteză medie", "Cost", "Palmares", "Câștigător", "Al doilea", "Al treilea", "Clasament pe puncte",
			"Cel mai bun cățărător", "Cel mai bun sprinter", "Cel mai bun tânăr", "Combativitate", "Combinat", "Echipă", "Picture", "Caption", "Map", "Special 1",
			"Special 2", "Documentație", "Metas volantes", "Regularidad", "Team points", "Breakaway", "Azzurri d'Italia", "Rookie", "Amateur","Nationality","Elevation"},
		["ru"] = {"Детали гонки", "Маршрут", "Соревнование", "Соревнования", "Этапы", "Дата", "Даты", "Дистанция", "Страна", "Страны",
			"Место старта", "Место финиша", "Команды", "Стартовало гонщиков", "Финишировало гонщиков", "Средняя скорость", "Призовые", "Призёры", "Победитель",
			"Второй", "Третий", "Очковая", "Горная", "Спринтерская", "Молодёжная", "Бойцовская", "Комбинированная", "Командная по времени", "Вид", "Описание", "Карта", "Сектор 1",
			"Сектор 2", "Документация", "Промежуточные финиши", "Регулярность", "Командная по очкам", "Breakaway", "Azzurri d'Italia", "Rookie", "Amateur","Nationality","Elevation"},
		["sv"] = {"Race details", "Course", "Competition", "Competitions", "Stages", "Date", "Dates", "Distance", "Country", "Countries",
			"Journey origin", "Journey destination", "Teams", "Starting riders", "Arriving riders", "Average speed", "Cost", "Palmares", "Winner", "Second",
			"Third", "Points", "Mountains", "Sprints", "Youth", "Combativity", "Combination", "Team", "Picture", "Caption", "Map", "Special 1", "Special 2",
			"Documentation", "Metas volantes", "Regularidad", "Team points", "Breakaway", "Azzurri d'Italia", "Rookie", "Amateur","Nationality","Elevation"},
		["ast"] = {"Detalles", "Carrera", "Competición", "Competiciones", "Etapes", "Data", "Dates", "Distancia total", "País", "Países",
			"Llugar d'entamu", "Llugar de llegada", "Equipos", "Ciclistes participantes", "Ciclistes acabaos", "Velocidá media", "Costu", "Clasificación final", "Ganador", "Segundu",
			"Terceru", "Puntos", "Monte", "Metes volantes", "Mozos", "Combatividá", "Combinada", "Equipu", "Imaxe", "Lleenda", "Mapa", "Especial 1", "Especial 2",
			"Documentación", "Metes volantes", "Regularidá", "Team points", "Fuga", "Azzurri d'Italia", "Rookie", "Amateur","Nationality","Elevation"}
	}
	local l10n = l10nDef[wiki]
	if not l10n then l10n = l10nDef["en"] end  -- default
	return l10n[x]
end

function unit(x)
	local l10nDef = {
		["ar"] = {"", " س ", " دقيقة ", " ث", ' كم/س', " نقطة", " نقطة"},
		["fr"] = {"en", " h ", " min ", " s", ' km/h', " pt", " pts"},
		["br"] = {"", "e ", "' ", '"', ' km/h', " pt", " ptoù"},
		["da"] = {"", "t ", "' ", '"', ' km/t', " point", " point"},
		["de"] = {"", " h ", " min ", " s", ' km/h', " P.", " P."},
		["en"] = {"", "h ", "' ", '"', ' km/h', " pt", " pts"},
		["es"] = {"", " h ", " min ", " s", ' km/h', " pt&nbsp;&nbsp;", " pts"},
		["eu"] = {"", " h ", " min ", " s", ' km/h', " pt", " pt"},
		["fo"] = {"", "t ", "' ", '"', ' km/t', " pt", " pts"},
		["fi"] = {"", ".", ".", "", ' km/h', " pt", " pts"},
		["he"] = {"", "h ", "' ", '"', ' קמ"ש', " נק\'", " נקודות"},
		["hu"] = {"", " óra ", ":", "", ' km/h', " pt", " pts"},
		["it"] = {"", "h", "'", '"', ' km/h', " pt", " pts"},
		["ja"] = {"", "時間", "分", '秒', 'km/h', "ポイント", "ポイント"},
		["lb"] = {"", " h ", " min ", " s", ' km/h', " pt", " pts"},
		["mk"] = {"", "ч ", "' ", "", ' км/ч', " pt", " pts"},
		["nl"] = {"", "u", "'", '"', ' km/u', " pt", " pts"},
		["no"] = {"", "t ", "' ", '"', ' km/t', " poeng", " poeng"},
		["pt"] = {"", "h", "m", "s", ' km/h', " pt", " pts"},
		["ru"] = {"", "ч ", "' ", "", ' км/ч', " очко", " очков"},
		["ast"] = {"", " h ", " min ", " s", ' km/h', " pt ", " pts"}
	}
	local l10n = l10nDef[wiki] or l10nDef["en"] -- en is the default for lv,cs,en,ca,ro,pt,pl,sv
	return l10n[x]
end

local function headoftable(x) -- En-tête du tableau listant les étapes
	local l10nDef={
		["ar"] = {"المرحلة", "التاريخ", "الدورة", "المسافة (كم)", "الفائز بالمرحلة", "القائد العام"},
		["fr"] = {"Étape", "Date", "Villes étapes", "Distance (km)", "Vainqueur d'étape", "Leader du classement général","Dénivelé (m)"},
		["en"] = {"Stage", "Date", "Course", "Distance - km (mi)", "Stage winner", "Overall leader","Elevation (m)"},
		["br"] = {"Tennad", "Deiziad", "Kêr loc'hañ ha kêr degouezhout", "Hed (km)", "Trec'hour", "E penn ar renkamant hollek","Elevation (m)"},
		["ca"] = {"Etapa", "Data", "Ciutats d'etapa", "Distància (km)", "Vencedor de l'etapa", "Líder de la general","Elevation (m)"},
		["cs"] = {"Etapa", "Datum", "Trasa", "Vzdálenost (km)", "Vítěz", "Průběžný lídr","Elevation (m)"},
		["da"] = {"Etape", "Dato", "Start – Mål", "Afstand (km)", "Etapevinder", "Førende rytter","Elevation (m)"},
		["de"] = {"Etappe", "Datum", "Etappenorte", "Länge (km)", "Etappen&shy;sieger", "Gesamt&shy;führender","Elevation (m)"},
		["eo"] = {"Etapo", "Dato", "Etapa urbo", "Longo (km)", "Venkinto de la etapo", "Estro de la gxeneralo klasado","Elevation (m)"},
		["es"] = {"Etapa", "Fecha", "Recorrido", "Distancia (km)", "Ganador", "Líder","Elevation (m)"},
		["eu"] = {"Etapa", "Data", "Ibilbidea", "Distantzia (km)", "Irabazlea", "Liderra","Elevation (m)"},
		["fi"] = {"Etappi", "Päivä", "Reitti", "Pituus (km)", "Voittaja", "Kokonaiskilpailun johtaja","Elevation (m)"},
		["fo"] = {"Teinur", "Dagur", "Byrjan – Mál", "Vegalongd (km)", "Teina&shy;vinnari", "Gula troyggjan","Elevation (m)"},
		["hu"] = {"Szakasz", "Időpont", "Végpontok", "Hossz (km)", "Szakasz&shy;győztes", "Általános vezető","Elevation (m)"},
		["it"] = {"Tappa", "Data", "Percorso", "Distanza (km)", "Vincitore di tappa", "Leader cl. generale","Elevation (m)"},
		["ja"] = {"ステージ", "開催日", "コース", "距離 (km)", "ステージ勝者", "全体リーダー","Elevation (m)"},
		["la"] = {"Statio", "Dies", "Iter", "Distantia (km)", "Victor", "Altiore princeps","Elevation (m)"},
		["lb"] = {"Etapp", "Datum", "Etappestied", "Längt (km)", "Gewënner", "General&shy;klassement","Elevation (m)"},
		["lv"] = {"Posms", "Datums", "Maršruts", "Posma garums (km)", "Uzvarētājs", "Kopvērtējuma līderis","Elevation (m)"},
		["mk"] = {"Етапа", "Датум", "Тек", "Растојание (км)", "Победник", "Cевкупен лидер","Elevation (m)"},
		["nl"] = {"Etappe", "Datum", "Start – Finish", "Afstand (km)", "Winnaar", "Klassements&shy;leider","Elevation (m)"},
		["no"] = {"Etappe", "Dato", "Start – Målgang", "Distanse (km)", "Etappe&shy;vinner", "Sammenlagt&shy;leder","Elevation (m)"},
		["pl"] = {"Etap", "Data", "Start – Meta", "Dystans (km)", "Zwycięzca etapu", "Lider","Elevation (m)"},
		["pt"] = {"Etapa", "Data", "Percurso", "Distância (km)", "Vencedor", "Líder geral","Elevation (m)"},
		["ro"] = {"Etapa", "Dată", "Start – Sosire", "Distanță (km)", "Câștigător", "Liderul global","Elevation (m)"},
		["ru"] = {"Этап", "Дата", "Маршрут", "Длина (км)", "Победитель", "Лидер генеральной классификации","Elevation (m)"},
		["sk"] = {"Etapa", "Dátum", "Trasa", "Vzdialenosť (km)", "Víťaz", "Priebežný líder","Elevation (m)"},
		["sv"] = {"Etapp", "Datum", "Start – mål", "Distans (km)", "Skede vinnare", "Övergripande ledare","Elevation (m)"},
		["ast"] = {"Etapa", "Data", "Percorríu", "Distancia (km)", "Ganador", "Líder","Elevation (m)"},
	}
	local l10n = l10nDef[wiki]
	if not l10n then l10n = l10nDef["en"] end  -- default
	return l10n[x]
end

local function headoftableII(x) -- En-têtes des tableaux générant les classements
	local l10nDef = {
		["ar"] = {"العداء", "البلد", "الفريق", "الوقت", "إزاحة الوقت", "السرعة", "النقاط", "تصنيف الفرق ضد الساعة", "التصنيف العام", "تصنيف النقاط", "تصنيف الجبال", "تصنيف أفضل عداء", "تصنيف أفضل شاب", "تصنيف الفرق حسب الوقت", "ترتيب الفرق حسب النقاط", "تصنيف المجموعة", "تصنيف أفضل مقاتل", "التصنيف تحت 23","UCI Ranking"},
		["fr"] = {"Coureur", "Pays", "Équipe", "Temps", "Écart de temps", "Vitesse moy.", "Points", "Classement de l'étape", "Classement général", "Classement par points", "Classement de la montagne", "Classement des sprints", "Classement du meilleur jeune", "Classement par équipes", "Classement par équipes aux points", "Classement du combiné", "Classement de la combativité", "Classement du meilleur jeune", "Classement UCI"},
		["en"] = {"Rider", "Country", "Team", "Time", "Time Gap", "Speed", "Points", "Stage classification", "General classification", "Points classification", "Mountains classification", "Sprints classification", "Best young classification", "Teams classification", "Points classification for teams", "Combination classification", "Combative classification", "U23 classification", "UCI Ranking"},
		["br"] = {"Reder", "Bro", "Skipailh", "Amzer", "Forc'had amzer", "Tizh", "Poentoù", "Renkadur an tennad", "Renkadur hollek", "Renkadur a-boentoù", "Renkadur ar menez", "Renkadur ar sprintoù", "Renkadur ar yaouank gwellañ", "Renkadur a-skipailh", "Renkadur a-skipailh a-boentoù", "Liesrenkadur", "Stourm renkadur", "Dindan 23 renkadur", "UCI renkadur"},
		["ca"] = {"Corredor", "País", "Equip", "Temps", "Time Gap", "Velocitat", "Punts", "Classificació de l'etapa", "Classificació general", "Classificació per punts", "Classificació de la muntanya", "Classificació dels esprints", "Classificació del millor jove", "Classificació per equips", "Classificació per equips", "Classificació de la combinada", "Classificació de la combativitat", "Classificació sub-23","Classificació UCI"},
		["da"] = {"Rytter", "Land", "Hold", "Tid", "Tidsforskel", "Gns. fart", "Point", "Etaperesultat", "Samlede stilling", "Pointkonkurrence", "Bjergkonkurrence", "Sprintkonkurrence", "Ungdomskonkurrence", "Holdkonkurrence", "Holdkonkurrence efter point", "Kombinationskonkurrence", "Mest angrebsivrige rytter", "U23-konkurrence","UCI Ranking"},
		["de"] = {"Fahrer", "Land", "Team", "Zeit", "Zeitabstand", "Geschw.", "Punkte", "Etappenergebnis", "Gesamtwertung", "Punktewertung", "Bergwertung", "Sprintwertung", "Nachwuchswertung", "Mannschaftswertung", "Mannschaftswertung", "Combination classification", "Combative classification", "U23 classification","UCI classification"},
		["eo"] = {"Kuranto", "Lando", "Teamo", "Tempo", "Time Gap", "Rapido", "Poentoj", "Etapa klasifiko", "Gxenerala klasifiko", "Klasifiko laux poentoj", "Klasifiko por la montaro", "Klasifiko por la sprintoj", "Klasifiko de la plej bona juno", "Klasifiko po teamo", "Klasifiko po teamo", "Combination classification", "Combative classification", "U23 classification","UCI classification"},
		["es"] = {"Ciclista", "País", "Equipo", "Tiempo", "Intervalo de tiempo", "Velocidad media", "Puntos", "Clasificación de la etapa", "Clasificación general", "Clasificación por puntos", "Clasificación de la montaña", "Clasificación de las metas volantes", "Clasificación del mejor joven", "Clasificación por equipos", "Clasificación por equipos", "Clasificación de la combinada", "Clasificación de la combatividad", "Clasificación sub-23", "Clasificación UCI"},
		["eu"] = {"Txirrindularia", "Herrialdea", "Taldea", "Denbora", "Time Gap", "Speed", "Puntua", "Etapako sailkapena", "Sailkapen orokorra", "Puntukako sailkapena", "Mendiko sailkapena", "Esprinetako sailkapena", "Gazte onenaren sailkapena", "Taldekako sailkapena", "Taldekako sailkapena", "Combination classification", "Combative classification", "U23 classification","UCI Ranking"},
		["fi"] = {"Pyöräilijä", "Maa", "Joukkue", "Aika", "Aikaero", "Nopeus", "Pisteet", "Etapin tulokset", "Kokonaistilanne", "Pistekilpailu", "Vuoristokilpailu", "Sprinttikilpailu", "Nuorten kilpailu", "Joukkuekilpailu", "Joukkuekilpailu", "Combination classification", "Combative classification", "U23 classification","UCI Ranking"},
		["fo"] = {"Súkklari", "Land", "Lið", "Tíð", "Time Gap", "Ferð", "Stig", "Teinaplasering", "Samlað plasering", "Stigkappingin", "Fjallakappingin", "Spurtkappingin", "Ungdómskappingin", "Liðkappingin", "Liðkappingin", "Kombinatiónsheiðurkappingin", "Combative classification", "U23 classification","UCI Ranking"},
		["hu"] = {"Versenyző", "Ország", "Csapat", "Idő", "Időkülönbség", "Átlagsebesség", "Pont", "Szakasz verseny", "Összetett verseny", "Pontverseny", "Hegyi pontverseny", "Gyorsulverseny", "Fiatalok versenye", "Csapatverseny", "Csapatverseny", "Combination classification", "Combative classification", "U23 classification","UCI Ranking"},
		["lb"] = {"Coureur", "Land", "Equipe", "Zäit", "Time Gap", "Vitesse", "Punkten", "Etappeklassement", "Generalklassement", "Klassement no Punkten", "Biergpräis", "Sprintklassement", "Beschte Jonken", "Equippeklassement", "Equippeklassement", "Combinéklassement", "Combative classification", "U23 classification","UCI Ranking"},
		["lv"] = {"Braucējs", "Valsts", "Komanda", "Laiks", "laika atstarpe", "Ātrums", "Punkti", "Posma rezultāti", "Kopvērtējums", "Punktu klasifikācija", "Kalnu klasifikācija", "Sprinta klasifikācija", "Jauno braucēju klasifikācija", "Komandu klasifikācija", "Komandu klasifikācija", "Kombinācijas klasifikācija", "Cīnītāja klasifikācija", "U23 klasifikācija","UCI klasifikācija"},
		["mk"] = {"Возач", "Земја", "Екипа", "Време", "Разлика", "Брзина", "Бодови", "Етапен резултат", "Генерален пласман", "Бодовен пласман", "Планински пласман", "Спринтерски пласман", "Пласман за млад возач", "Екипен пласман", "Екипен пласман", "Combination classification", "Combative classification", "U23 classification","UCI Ranking"},
		["no"] = {"Rytter", "Land", "Lag", "Tid", "Tidsforskjell", "Fart", "Poeng", "Etappeplassering", "Sammenlagtplassering", "Poengkonkurranse", "Klatrekonkurranse", "Spurtkonkurranse", "Ungdomskonkurranse", "Lagkonkurranse", "Lagkonkurranse (poeng)", "Kombinasjonkonkurranse", "Mest offensive rytter", "U23-konkurranse","UCI Ranking"},
		["nl"] = {"Renner", "Land", "Ploeg", "Tijd", "Tijdsverschil", "Snelheid", "Punten", "Etappeklassement", "Algemeen Klassement", "Puntenklassement", "Bergklassement", "Sprintklassement", "Jongerenklassement", "Ploegenklassement", "Ploegenklassement", "Combinatieklassement", "Klassement van de strijdlustigste renner", "U23 classification","UCI Ranking"},
		["pt"] = {"Ciclista", "País", "Equipe", "Tempo", "Intervalo de tempo", "Rapidez", "Pontos", "Classificação por etapas", "Classificação geral", "Classificação por pontos", "Classificação da montanha", "Classificação por velocidade", "Classificação dos jovens", "Classificação por equipes", "Classificação por equipes", "Classificação de combinados", "Classificação da combatividade", "Classificação U23","Classificação UCI"},
		["ro"] = {"Ciclist", "Țară", "Echipă", "Timp", "Time Gap", "Viteză", "Puncte", "Clasamentul etapei", "Clasament general", "Clasament pe puncte", "Clasament cățărători", "Clasament sprinteri", "Clasamentul celui mai bun tânăr", "Clasament pe echipe", "Clasament pe echipe", "Combination classification", "Combative classification", "U23 classification","UCI Ranking"},
		["ru"] = {"Гонщик", "Страна", "Команда", "Время", "Отставание", "Скорость", "Очки", "Результаты этапа", "Генеральная классификация", "Очковая классификация", "Горная классификация", "Спринтерская классификация", "Молодёжная классификация", "Командная классификация по времени", "Командная классификация по очкам", "Комбинированная классификация", "Бойцовская классификация", "Классификация U23","Классификация UCI"},
		["ast"] = {"Ciclista", "País", "Equipu", "Tiempu", "Intervalu de tiempu", "Velocidá media", "Puntos", "Clasificación de la etapa", "Clasificación xeneral", "Clasificación per puntos", "Clasificación de monte", "Clasificación de les metes volantes", "Clasificación del meyor mozu", "Clasificación per equipos", "Clasificación per equipos", "Clasificación de la combinada", "Clasificación de la combatividá", "Clasificación sub-23","Clasificación UCI"},
	}
	local l10n = l10nDef[wiki]
	if not l10n then l10n = l10nDef["en"] end  -- default
	return l10n[x]
end

local function headoftableIII(x) -- En-tête du tableau listant les équipes participantes (P1923)
	local l10nDef = {
		["ar"] = {"اسم الفريق", "البلد", "الرمز", "فريق عالمي", "فرق عالمية", "فريق برو", "فرق برو", "فريق قاري محترف", "فرق قارية محترفة", "فريق قاري", "فرق قارية", "فريق وطني", "فرق وطنية", "فريق إقليمي ونادي", "فرق إقليمية وأندية", "فريق دراجات محترف", "فرق دراجات محترفة", "فريق هواة دراجات", "فرق هواة دراجات", "مجموعة رياضية أولى", "مجموعات رياضية أولى", "مجموعة رياضية ثانية", "مجموعات رياضية ثانية", "مجموعة رياضية ثالثة", "مجموعات رياضية ثالثة", "فريق مختلط", "فرق مختلطة", "فريق إناث محترف", "فرق إناث محترفة", "فريق هواة دراجات إناث", "فرق هواة دراجات إناث"},
		["fr"] = {"Nom de l'équipe", "Pays", "Code", "WorldTeam", "WorldTeams", "ProTeam", "ProTeams", "Équipe continentale professionnelle", "Équipes continentales professionnelles", "Équipe continentale", "Équipes continentales", "Équipe nationale", "Équipes nationales", "Équipe régionale et de club", "Équipes régionales et de clubs", "Équipe cycliste professionnelle", "Équipes cyclistes professionnelles", "Équipe cycliste amateur", "Équipes cyclistes amateurs", "Groupe sportif I", "Groupes sportifs I", "Groupe sportif II", "Groupes sportifs II", "Groupe sportif III", "Groupes sportifs III", "Équipe mixte", "Équipes mixtes", "Équipe féminine professionnelle", "Équipes féminines professionnelles", "Équipe cycliste amateur féminine", "Équipe cycliste amateur féminines"},
		["en"] = {"Team name", "Country", "Code", "WorldTeam", "WorldTeams", "ProTeam", "ProTeams", "Professional continental team", "Professional continental teams", "Continental team", "Continental teams", "National team", "National teams", "Regional and club team", "Regional and club teams", "Professional cycling team", "Professional cycling teams", "Amateur cycling team", "Amateur cycling teams", "Trade Team I", "Trade Teams I", "Trade Team II", "Trade Teams II", "Trade Team III", "Trade Teams III", "Mixed team", "Mixed teams", "Professional woman team", "Professional women teams", "Women's amateur cycling team", "Women's amateur cycling teams"},
		["ja"] = {"チーム名", "国", "コード", "ワールドチーム", "ワールドチーム", "プロチーム", "プロチーム", "プロフェッショナルコンチネンタルチーム", "プロフェッショナルコンチネンタルチーム", "コンチネンタルチーム", "コンチネンタルチーム", "ナショナルチーム", "ナショナルチーム", "地域・クラブチーム", "地域・クラブチーム", "プロ自転車チーム", "プロ自転車チーム", "アマ自転車チーム", "アマ自転車チーム", "Groupe sportif I", "Groupes sportifs I", "Groupe sportif II", "Groupes sportifs II", "Groupe sportif III", "Groupes sportifs III", "Mixt team", "Mixt teams", "プロ女子チーム", "プロ女子チーム", "Women's amateur cycling team", "Women's amateur cycling teams"},
		["br"] = {"Anv skipailh", "Bro", "Kod", "WorldTeam", "WorldTeams", "ProTeam", "ProTeams", "Skipailh kevandir a-vicher", "Skipailhoù kevandir a-vicher", "Skipailh kevandir", "Skipailhoù kevandir", "Skipailh bro", "Skipailhoù bro", "Skipailh rannvro ha klub", "Skipailhoù rannvro ha klub", "Skipailh marc'h-houarn a-vicher", "Skipailhoù marc'h-houarn a-vicher", "Skipailh marc'h-houarn amatour", "Skipailhoù marc'h-houarn amatour", "Strollad sport I", "Strolladoù sport I", "Strollad sport II", "Strolladoù sport II", "Strollad sport III", "Strolladoù sport III", "Skipailh kemmesk", "Skipailhoù kemmesk", "Skipailh a-vicher merc'hed", "Skipailhoù a-vicher merc'hed", "Skipailh amatour merc'hed", "Skipailhoù amatour merc'hed"},
		["ca"] = {"Nom de l'equip", "País", "Codi", "WorldTeam", "WorldTeams", "ProTeam", "ProTeams", "Equip continental professional", "Equips continentals professionals", "Equip continental", "Equips continentals", "Equip nacional", "Equips nacionals", "Equip regional i de club", "Equips regionals i de clubs", "Equip ciclista professional", "Equips ciclistes professionals", "Equip ciclista amateur", "Equips ciclistes amateurs", "Grup esportiu I", "Grups esportius I", "Grup esportiu II", "Grups esportius II", "Grup esportiu III", "Grups esportius III", "Equip mixt", "Equips mixtos", "Equip femení", "Equips femenins", "Equip femení amateur", "Equips femenins amateurs"},
		["da"] = {"Holdnavn", "Land", "Kode", "WorldTeam", "WorldTeams", "ProTeam", "ProTeams", "Professionelt kontinentalhold", "Professionelle kontinentalhold", "Kontinentalhold", "Kontinentalhold", "Landshold", "Landshold", "Regional- og klubhold", "Regional- og klubhold", "Prohold", "Prohold", "Amatørhold", "Amatørhold", "Sportsgruppe I", "Sportsgruppe I", "Sportsgruppe II", "Sportsgruppe II", "Sportsgruppe III", "Sportsgruppe III", "Mix-hold", "Mix-hold", "Kvindehold", "Kvindehold", "Amatørkvindehold", "Amatørkvindehold"},
		["de"] = {"Team", "Land", "Code", "WorldTeam", "WorldTeams", "ProTeam", "ProTeams", "Professional Continental Team", "Professional Continental Teams", "Continental Team", "Continental Teams", "Nationalmannschaft", "Nationalmannschaften", "Regionale Teams und Vereine", "Regionale Teams und Vereine", "Profi-Radsportteam", "Profi-Radsportteams", "Amateurmannschaft", "Amateurmannschaften", "Groupe Sortif I", "Groupes Sportifs I", "Groupe Sportif II", "Groupes Sportifs II", "Groupe Sportif III", "Groupes Sportifs III", "Mixed Team", "Mixed Teams", "UCI Women's Team", "UCI Women's Teams", "Sonstiges Frauenteam", "Sonstige Frauenteams"},
		["eo"] = {"Nomo de la teamo", "Lando", "Kodo", "Monda teamo", "Mondaj teamoj", "ProTeamo", "ProTeamoj", "Profesiista kontinenta teamo", "Profesiistaj kontinentaj teamoj", "Kontinenta teamo", "Kontinentaj teamoj", "Nacia teamo", "Naciaj teamoj", "Regiona aux kluba teamo", "Regionaj aux klubaj teamoj", "Profesiista bicikla teamo", "Profesiistaj biciklaj teamoj", "Amatora bicikla teamo", "Amatoraj biciklaj teamoj", "Sporta grupo 1", "Sportaj grupoj 1", "Sporta grupo 2", "Sportaj grupoj 2", "Sporta grupo 3", "Sportaj grupoj 3", "Miksa teamo", "Miksaj teamoj", "Ina teamo", "Inaj teamoj", "Women's amateur cycling team", "Women's amateur cycling teams"},
		["es"] = {"Nombre del equipo", "País", "Código", "WorldTeam", "WorldTeams", "ProTeam", "ProTeams", "Equipo continental profesional", "Equipos continentales profesionales", "Equipo continental", "Equipos continentales", "Equipo nacional", "Equipos nacionales", "Equipo regional y de club", "Equipos regionales y de clubes", "Equipo ciclista profesional", "Equipos ciclistas profesionales", "Equipo ciclista aficionado", "Equipos ciclistas aficionados", "Grupo deportivo I", "Grupos deportivos I", "Grupo deportivo II", "Grupos deportivos II", "Grupo deportivo III", "Grupos deportivos III", "Equipo mixto", "Equipos mixtos", "Equipo femenino", "Equipos femeninos", "Equipo femenino de ciclismo amateur", "Equipos femeninos de ciclismo amateur"},
		["eu"] = {"Taldearen izena", "Herrialdea", "Kodea", "Munduko taldea", "Munduko taldeak", "Pro taldea", "Pro taldeak", "Kontinenteko talde profesionala", "Kontinenteko talde profesionala", "Kontinenteko taldea", "Kontinenteko taldeak", "Estatuko taldea", "Estatuko taldeak", "Eskualdeko eta klubeko taldea", "Eskualdeko eta klubeko taldeak", "Txirrindulari talde profesionala", "Txirrindulari talde profesionalak", "Txirrindulari talde amateurra", "Txirrindulari talde amateurrak", "I. mailako kirol taldea", "I. mailako kirol taldeak", "II. mailako kirol taldea", "II. mailako kirol taldeak", "III. mailako kirol taldea", "III. mailako kirol taldeak", "Talde mistoa", "Talde mistoak", "Emakume taldea", "Emakume taldeak", "Women's amateur cycling team", "Women's amateur cycling teams"},
		["fi"] = {"Joukkueen nimi", "Maa", "Koodi", "WorldTeam", "WorldTeams", "ProTeam", "ProTeams", "Professional continental -joukkue", "Professional continental -joukkueet", "Continental-joukkue", "Continental-joukkueet", "Maajoukkue", "Maajoukkueet", "Alue- ja seurajoukkue", "Alue- ja seurajoukkueet", "Ammattilaispyöräilytalli", "Ammattilaispyöräilytallit", "Amatööripyöräilytalli", "Amatööripyöräilytallit", "Groupe sportif I", "Groupes sportifs I", "Groupe sportif II", "Groupes sportifs II", "Groupe sportif III", "Groupes sportifs III", "Mixt team", "Mixt teams", "Naisten ammattilaisjoukkue", "Naisten ammattilaisjoukkueet", "Women's amateur cycling team", "Women's amateur cycling teams"},
		["fo"] = {"Liðnavn", "Land", "Kota", "WorldTeam", "WorldTeams", "ProTeam", "ProTeams", "Professionelt kontinentallið", "Professionel kontinentallið", "Kontinentallið", "Kontinental lið", "Landslið", "Landslið", "Regional- og klublið", "Regional- og felagslið", "Prolið", "Prolið", "Amatørlið", "Amatørlið", "Ítróttarbólkur I", "Ítróttarbólkur I", "Ítróttarbólkur II", "Ítróttarbólkur II", "Ítróttarbólkur III", "Ítróttarbólkur III", "Blandaðlið", "Blandaðlið", "Kvinulið", "Kvinnulið", "Women's amateur cycling team", "Women's amateur cycling teams"},
		["he"] = {"שם קבוצה", "מדינה", "קוד", "WorldTeam", "קבוצות [[UCI World Tour|World Tour]]", "קבוצת פרו", "קבוצות פרו", "קבוצת קונטיננטל-פרו", "קבוצות קונטיננטל-פרו", "קבוצת קונטיננטל", "קבוצות קונטיננטל", "קבוצה לאומית", "קבוצות לאומיות", "Regional and club team", "Regional and club teams", "קבוצת רכיבה מקצועית", "קבוצות רכיבה מקצועיות", "Amateur cycling team", "Amateur cycling teams", "Groupe sportif I", "Groupes sportifs I", "Groupe sportif II", "Groupes sportifs II", "Groupe sportif III", "Groupes sportifs III", "Mixt team", "Mixt teams", "Professional woman team", "Professional women teams", "Women's amateur cycling team", "Women's amateur cycling teams"},
		["hu"] = {"Csapat neve", "Ország", "Csapatkód", "WorldTeam", "WorldTeams", "ProTeam", "ProTeams", "Profi Kontinentális Csapat", "Profi Kontinentális Csapatok", "Kontinentális Csapat", "Kontinentális Csapatok", "Nemzeti csapat", "Nemzeti csapatok", "Regional and club team", "Regional and club teams", "Professional cycling team", "Professional cycling teams", "Amateur cycling team", "Amateur cycling teams", "Groupe sportif I", "Groupes sportifs I", "Groupe sportif II", "Groupes sportifs II", "Groupe sportif III", "Groupes sportifs III", "Mixt team", "Mixt teams", "Professional woman team", "Professional women teams", "Women's amateur cycling team", "Women's amateur cycling teams"},
		["lb"] = {"Equippennumm", "Land", "Code", "WorldTeam", "WorldTeams", "ProTeam", "ProTeams", "Professionell Kontinentalequipe", "Professionell Kontinentalequippen", "Kontinentalequipe", "Kontinentalequippen", "Nationalequipe", "Nationalequippen", "Regional- a Klubequipe", "Regional- a Klubequippen", "Professionell Vëlosequipe", "Professionell Vëlosequippen", "Amateursequipe", "Amateursequippen", "Sportsgrupp I", "Sportsgruppen I", "Sportsgrupp II", "Sportsgruppen II", "Sportsgrupp III", "Sportsgruppen III", "Gemëscht Equipe", "Gemëscht Equippen", "Dammenequipe", "Dammenequippen", "Women's amateur cycling team", "Women's amateur cycling teams"},
		["lv"] = {"Komandas nosaukums", "Valsts", "Kods", "WorldTeam", "WorldTeam komandas", "ProTeam", "ProTeam komandas", "Profesionālā kontinentālā komanda", "Profesionālās kontinentālās komandas", "Kontinentālā komanda", "Kontinentālās komandas", "Nacionālā izlase", "Nacionālās izlases", "Reģionālā vai klubu komanda", "Reģionālās vai klubu komandas", "Profesionāla riteņbraukšanas komanda", "Profesionālas riteņbraukšanas komandas", "Amatieru riteņbraukšanas komanda", "Amatieru riteņbraukšanas komandas", "1. sporta grupa", "1. sporta grupa", "2. sporta grupa", "3. sporta grupa", "3. sporta grupa", "3. sporta grupa", "Jauktā komanda", "Jauktās komandas", "Profesionāla sieviešu komanda", "Profesionālas sieviešu komandas", "Amatieru sieviešu komanda", "Amatieru sieviešu komandas"},
		["mk"] = {"Име на екипата", "Земја", "Код", "Екипа од Светската турнеја UCI", "Екипи од Светската турнеја UCI", "ProTeam", "ProTeams", "Професионална континентална екипа", "Професионални континентални екипи", "Континентална екипа", "Континентални екипи", "Национална екипа", "Национални екипи", "Регионална екипа и клуб", "Регионални екипи и клубови", "Професионална велосипедска екипа", "Професионални велосипедски екипи", "Аматерска велосипедска екипа", "Аматерски велосипедски екипи", "Groupe sportif I", "Groupes sportifs I", "Groupe sportif II", "Groupes sportifs II", "Groupe sportif III", "Groupes sportifs III", "Мешана екипа", "Мешани екипи", "Професионална женска екипа", "Професионални женски екипи", "Women's amateur cycling team", "Women's amateur cycling teams"},
		["nl"] = {"Ploegnaam", "Land", "Code", "WorldTeam", "WorldTeams", "ProTeam", "ProTeams", "Professionele continentale ploeg", "Professionele continentale ploegen", "Continentaal ploeg", "Continentale ploegen", "Nationale ploeg", "Nationale ploegen", "Regionale ploeg", "Regionale ploegen", "Professioneel wielerteam", "Professionele wielerteams", "Amateurteam", "Amateurteams", "Groupe sportif I", "Groupes sportifs I", "Groupe sportif II", "Groupes sportifs II", "Groupe sportif III", "Groupes sportifs III", "Gemengd team", "Gemengde teams", "Professioneel vrouwenteam", "Professionele vrouwenteams", "Amateur vrouwenteam", "Amateur vrouwenteams"},
		["no"] = {"Lagnavn", "Land", "Kode", "WorldTour-lag", "WorldTour-lag", "ProTour-lag", "ProTour-lag", "Profesjonelt kontinentallag", "Profesjonelle kontinentallag", "Kontinentallag", "Kontinentallag", "Landslag", "Landslag", "Regional- og klubblag", "Regional- og klubblag", "Profflag", "Profflag", "Amatørlag", "Amatørlag", "Trade Team I", "Trade Teams I", "Trade Team II", "Trade Teams II", "Trade Team III", "Trade Teams III", "Mix-lag", "Mix-lag", "Profflag", "Profflag", "Amatørlag", "Amatørlag"},
		["pt"] = {"Nome da equipe", "País", "Código", "Equipe WorldTeam", "Equipes WorldTeam", "Equipe ProTeam", "Equipes ProTeam", "Equipe profissional Continental", "Equipes profissionais Continentais", "Equipe Continental", "Equipes Continentais", "Equipe nacional", "Equipes nacionais", "Equipe regional e clube", "Equipes regionais e clubes", "Equipe profissional de ciclismo", "Equipes profissionais de ciclismo", "Equipe amadora de ciclismo", "Equipes amadoras de ciclismo", "Grupo esportivo I", "Grupos esportivos I", "Grupo esportivo II", "Grupos esportivos II", "Grupo esportivo III", "Grupos esportivos III", "Equipe mista", "Equipes mistas", "Equipe feminina profissional", "Equipes femininas profissionais", "Equipes femininas amadoras", "Equipes femininas amadoras"},
		["ro"] = {"Numele echipei", "Țară", "Cod", "WorldTeam", "WorldTeams", "ProTeam", "ProTeams", "Echipă continentală profesionistă", "Echipe continentale profesioniste", "Echipă continentală", "Echipe continentale", "Echipă națională", "Echipe naționale", "Echipă regională și de club", "Echipe regionale și de club", "Echipă ciclistă profesionistă", "Echipe cicliste profesioniste", "Echipă ciclistă de amatori", "Echipe cicliste de amatori", "Grup sportiv I", "Grupuri sportive I", "Grup sportiv II", "Grupuri sportive II", "Grup sportiv III", "Grupuri sportive III", "Echipă mixtă", "Echipe mixte", "Echipă feminină", "Echipe feminine", "Women's amateur cycling team", "Women's amateur cycling teams"},
		["ru"] = {"Команда", "Страна", "Код", "WorldTeam", "WorldTeams", "ProTeam", "ProTeams", "Профессиональная континентальная команда", "Профессиональные континентальные команды", "Континентальная команда", "Континентальные команды", "Национальная команда", "Национальные команды", "Региональная команда или клуб", "Региональные команды и клубы", "Профессиональная велокоманда", "Профессиональные велокоманды", "Любительская велокоманда", "Любительские велокоманды", "Groupe sportif I", "Groupes sportifs I", "Groupe sportif II", "Groupes sportifs II", "Groupe sportif III", "Groupes sportifs III", "Смешанная велокоманда", "Смешанные велокоманды", "Женская профессиональная команда", "Женские профессиональные команды", "Женская любительская велокоманда", "Женские любительские велокоманды"},
		["ast"] = {"Nome del equipu", "País", "Códigu", "WorldTeam", "WorldTeams", "ProTeam", "ProTeams", "Equipu continental profesional", "Equipos continentales profesionales", "Equipu continental", "Equipos continentales", "Equipu nacional", "Equipos nacionales", "Equipu rexonal y de club", "Equipos rexonales y de clubes", "Equipu ciclista profesional", "Equipos ciclistes profesionales", "Equipu ciclista aficionáu", "Equipos ciclistes aficionaos", "Grupu deportivu I", "Grupos deportivos I", "Grupu deportivu II", "Grupos deportivos II", "Grupu deportivu III", "Grupos deportivos III", "Equipu mestu", "Equipos mestos", "Equipu femenín", "Equipos femeninos", "Equipu femenín de ciclismu amateur", "Equipos femeninos de ciclismu amateur"},
	}
	local l10n = l10nDef[wiki]
	if not l10n then l10n = l10nDef["en"] end  -- default
	return l10n[x]
end

local function listofwinners_translate(x) -- En-tête du tableau du palmarès d'une course cycliste
	local l10nDef = {
		["ar"] = {"السنة", "الفائز", "الثاني", "الثالث"},
		["fr"] = {"Année", "Vainqueur", "Deuxième", "Troisième","Classement par points", "Meilleur grimpeur", "Meilleur sprinteur", "Meilleur jeune", "Super-combatif", "Meilleur au combiné", "Meilleure équipe","Étapes volantes", "Régularité", "Meilleure équipe aux points",
			"Fuga", "Azzurri d'Italia", "Néophyte", "Amateur","Nationalité"},
		["en"] = {"Year", "Winner", "Second", "Third","Points", "Mountains", "Sprints", "Youth", "Combativity", "Combination", "Team","Intermediate sprints", "Regularidad", "Team points", "Breakaway", "Azzurri d'Italia", "Rookie","Amateur","Nationality"},
		["br"] = {"Bloavezh", "1añ", "2l", "3de"},
		["ca"] = {"Any", "Vencedor", "Segon", "Tercer"},
		["cs"] = {"Ročník", "Vítěz", "Druhý", "Třetí"},
		["da"] = {"År", "Vinder", "Toer", "Treer"},
		["de"] = {"Jahr", "Sieger", "Zweiter", "Dritter"},
		["eo"] = {"Jaro", "Venkinto", "Dua pozicio", "Tria pozicio"},
		["es"] = {"Año", "Ganador", "Segundo", "Tercero"},
		["eu"] = {"Urtea", "Irabazlea", "Bigarrena", "Hirugarrena"},
		["fi"] = {"Vuosi", "Voittaja", "Toinen", "Kolmas"},
		["fo"] = {"Ár", "Vinnari", "Nr. 2", "Nr. 3"},
		["hu"] = {"Év", "Versenyző", "Második", "Harmadik"},
		["it"] = {"Anno", "Vincitore", "Secondo", "Terzo"},
		["ja"] = {"年", "優勝", "準優勝", "3位"},
		["lb"] = {"Joer", "Gewënner", "Zweeten", "Drëtten"},
		["lv"] = {"Gads", "Uzvarētājs", "Otrais", "Trešais"},
		["mk"] = {"Година", "Победник", "Второпласиран", "Третопласиран"},
		["nl"] = {"Jaar", "Winnaar", "Tweede", "Derde"},
		["no"] = {"År", "Vinner", "Andreplass", "Tredjeplass"},
		["pl"] = {"Rok", "Pierwsze", "Drugie", "Trzecie"},
		["pt"] = {"Ano", "Vencedor", "Segundo", "Terceiro"},
		["ro"] = {"An", "Câștigător", "Locul doi", "Locul trei"},
		["ru"] = {"Год", "Победитель", "Второй", "Третий"},
		["sr"] = {"Година", "Победник", "Други", "Трећи"},
		["sv"] = {"År", "Vinnare", "Andra", "Tredje"},
		["ast"] = {"Añu", "Ganador", "Segundu", "Terceru"},
	}
	local l10n = l10nDef[wiki]
	if not l10n then 
		l10n = l10nDef["en"] 
	end
	if l10n[x] then
		return l10n[x]
	else --provisory solution
		local index
		if x>4 then 
			if x<12 then
				index =x+17
			else
				index=x+23
			end
		end
		return infobox_translate(index)
	end
end

local function riderranking_translate(x) 
	local l10nDef = {
		["ar"] = {"السنة", "الفائز", "الثاني", "الثالث"},
		["fr"] = {"Année", "Classement UCI","UCI World Tour" ,"Coupe du monde"}, --,"Classement par points", "Meilleur grimpeur", "Meilleur sprinteur", "Meilleur jeune", "Super-combatif", "Meilleur au combiné", "Meilleure équipe","Étapes volantes", "Régularité", "Meilleure équipe aux points",
		--	"Fuga", "Azzurri d'Italia", "Néophyte", "Amateur","Nationalité"
		["en"] = {"Year", "UCI Ranking", "UCI World Tour","World Cup"},
		["br"] = {"Bloavezh", "UCI Ranking", "UCI World Tour","World Cup"},
		["ca"] = {"Any", "UCI Ranking", "UCI World Tour","World Cup"},
		["cs"] = {"Ročník", "UCI Ranking", "UCI World Tour","World Cup"},
		["da"] = {"År", "UCI Ranking", "UCI World Tour","World Cup"},
		["de"] = {"Jahr", "UCI Ranking", "UCI World Tour","World Cup"},
		["eo"] = {"Jaro", "UCI Ranking", "UCI World Tour","World Cup"},
		["es"] = {"Año", "UCI Ranking", "UCI World Tour","World Cup"},
		["eu"] = {"Urtea", "UCI Ranking", "UCI World Tour","World Cup"},
		["fi"] = {"Vuosi", "UCI Ranking", "UCI World Tour","World Cup"},
		["fo"] = {"Ár", "UCI Ranking", "UCI World Tour","World Cup"},
		["hu"] = {"Év", "UCI Ranking", "UCI World Tour","World Cup"},
		["it"] = {"Anno", "UCI Ranking", "UCI World Tour","World Cup"},
		["ja"] = {"年", "UCI Ranking", "UCI World Tour","World Cup"},
		["lb"] = {"Joer", "UCI Ranking", "UCI World Tour","World Cup"},
		["lv"] = {"Gads", "UCI Ranking", "UCI World Tour","World Cup"},
		["mk"] = {"Година", "UCI Ranking", "UCI World Tour","World Cup"},
		["nl"] = {"Jaar", "UCI Ranking", "UCI World Tour","World Cup"},
		["no"] = {"År", "UCI Ranking", "UCI World Tour","World Cup"},
		["pl"] = {"Rok", "UCI Ranking", "UCI World Tour","World Cup"},
		["pt"] = {"Ano", "UCI Ranking", "UCI World Tour","World Cup"},
		["ro"] = {"An", "UCI Ranking", "UCI World Tour","World Cup"},
		["ru"] = {"Год", "UCI Ranking", "UCI World Tour","World Cup"},
		["sr"] = {"Година", "UCI Ranking", "UCI World Tour","World Cup"},
		["sv"] = {"År", "UCI Ranking", "UCI World Tour","World Cup"},
		["ast"] = {"Añu", "UCI Ranking", "UCI World Tour","World Cup"},
	}
	local l10n = l10nDef[wiki]
	if not l10n then 
		l10n = l10nDef["en"] 
	end
	return l10n[x]
end

local function typeofstage(x, typ, noborder)
	-- plain, hilly, inter, ... must be "" or "any text"
	-- l10nDef[""] = {plain = "", hilly="", inter='', mount='', time_prologue='', time_team='', time_indiv='', uphill='', rest=''}
	local l10nDef = {
		["ar"] = {plain = "مرحلة مستوية", hilly="مرحلة التلال", inter='مرحلة متوسطة', mount='مرحلة جبلية', time_prologue='مرحلة سباق ضد الساعة', time_team='مرحلة سباق الفرق ضد الساعة', time_indiv='مرحلة سباق فردي ضد الساعة', uphill='مرحلة تسلق الجبل ضد الساعة', rest='يوم راحة'},
		["ast"] = {plain = "etapa llana", hilly="etapa escarpada", inter='etapa de mediu monte', mount='etapa de monte', time_prologue='prólogu', time_team='contrarreló per equipos', time_indiv='contrarreló individual', uphill='cronoescalada', rest='xornada de descansu'},
		["fr"] = {plain = "étape de plaine", hilly="étape vallonnée", inter='étape de moyenne montagne', mount='étape de montagne', time_prologue='prologue', time_team='contre-la-montre par équipes', time_indiv='contre-la-montre individuel', uphill='contre-la-montre en côte', rest='étape de repos'},
		["en"] = {plain = "plain stage", hilly="hilly stage", inter='intermediate stage', mount='mountain stage', time_prologue='time trial stage', time_team='team time trial stage', time_indiv='individual time trial stage', uphill='uphill time trial stage', rest='rest day'},
		["br"] = {plain = "tennad plaen", hilly="tennad digompez", inter='tennad damveneziek', mount='tennad meneziek', time_prologue='prolog', time_team='ABEU a-skipailhoù', time_indiv='ABEU', uphill='', rest='devezh diskuizh'},
		["ca"] = {plain = "etapa plana", hilly="etapa accidentada", inter='etapa de mitja muntanya', mount='etapa de muntanya', time_prologue='pròleg', time_team='contrarellotge per equips', time_indiv='contrarellotge individual', uphill='', rest='etapa de descans'},
		["cs"] = {plain = "rovinatá etapa", hilly="", inter='kopcovitá etapa', mount='horská etapa', time_prologue='prolog', time_team='týmová časovka', time_indiv='individuální časovka', uphill='', rest=''},
		["da"] = {plain = "flad etape", hilly="kuperet etape", inter='middel bjergetape', mount='bjergetape', time_prologue='prolog', time_team='holdtidskørsel', time_indiv='enkeltstart', uphill='bjergenkeltstart', rest='hviledag'},
		["de"] = {plain = "Flachetappe", hilly="Hügelige Etappe", inter='Mittelschwere Etappe', mount='Hochgebirgsetappe', time_prologue='Prolog', time_team='Teamzeitfahren', time_indiv='Einzelzeitfahren', uphill='Bergzeitfahren', rest='Ruhetag'},
		["eo"] = {plain = "ebena etapo", hilly="malebena etapo", inter='mezgranda montaro etapo', mount='montara etapo', time_prologue='prologo', time_team='teama kontraux-la-kronometro', time_indiv='individua kontraux-la-kronometro', uphill='malebena kontraux-la-kronometro', rest='ripoza etapo'},
		["es"] = {plain = "etapa llana", hilly="etapa escarpada", inter='etapa de media montaña', mount='etapa de montaña', time_prologue='prólogo', time_team='contrarreloj por equipos', time_indiv='contrarreloj individual', uphill='cronoescalada', rest='jornada de descanso'},
		["eu"] = {plain = "etapa laua", hilly="etapa gorabeheratsua", inter='bitarteko etapa', mount='mendiko etapa', time_prologue='aitzinetapa', time_team='taldekako erlojupekoa', time_indiv='banakako erlojupekoa', uphill='erlojupeko igoera', rest='atseden eguna'},
		["fi"] = {plain = "Tasamaaetappi", hilly="Mäkietappi", inter='Keskivaikea vuorietappi', mount='Vuorietappi', time_prologue='', time_team='Joukkueaika-ajo', time_indiv='Henkilökohtainen aika-ajo', uphill='mäkiaika-ajo', rest='välipäivä'},
		["fo"] = {plain = "Slætt", hilly="Slætt við brúgvasteinum", inter='Óslætt', mount='Fjallateinur', time_prologue='Forteinur', time_team='Liðsúkkling', time_indiv='Einkultstartur', uphill='', rest='Hvílidagur'},
		["hu"] = {plain = "sík szakasz", hilly="dombos szakasz", inter='közepes hegyi szakasz', mount='hegyi szakasz', time_prologue='prolog', time_team='csapat időfutam', time_indiv='egyéni időfutam', uphill='hegyi időfutam', rest=''},
		["ja"] = {plain = "平坦ステージ", hilly="丘陵ステージ", inter='中間ステージ', mount='山岳ステージ', time_prologue='タイムトライアルステージ', time_team='チームタイムトライアルステージ', time_indiv='個人タイムトライアルステージ', uphill='アップヒルタイムトライアルステージ', rest='休養日'},
		["lb"] = {plain = "Flaach Etapp", hilly="Hiwweleg Etapp", inter='Mëttelschwéier Etapp', mount='Biergetapp', time_prologue='Prolog', time_team='Contre-la-montre (Equipe)', time_indiv='Contre-la-montre (Eenzel)', uphill='Biergcourse', rest='Roudag'},
		["lv"] = {plain = "līdzenuma posms", hilly="paugurains posms", inter='vidēju kalnu posms', mount='kalnu posms', time_prologue='individuālais brauciens', time_team='komandu brauciens', time_indiv='individuālais brauciens', uphill='individuālais brauciens kalnā', rest='atpūtas diena'},
		["mk"] = {plain = "рамна етапа", hilly="ридеста етапа", inter='среднопланинска етапа', mount='планинска етапа', time_prologue='пролог', time_team='екипен хронометар', time_indiv='индивидуален хронометар', uphill='', rest='ден за одмор'},
		["nl"] = {plain = "vlakke rit", hilly="heuvelrit", inter='heuvelrit', mount='bergrit', time_prologue='proloog', time_team='ploegentijdrit', time_indiv='individuele tijdrit', uphill='klimtijdrit', rest='rustdag'},
		["no"] = {plain = "flat etappe", hilly="kupert etappe", inter='middels klatreetappe', mount='klatreetappe', time_prologue='prolog', time_team='lagtempo', time_indiv='temporitt', uphill='klatretempoetappe', rest='hviledag'},
		["pl"] = {plain = "płaski", hilly="", inter='pagórkowaty', mount='górski', time_prologue='prologu', time_team='jazda drużynowa na czas', time_indiv='jazda indywidualna na czas', uphill='', rest=''},
		["pt"] = {plain = "etapa plana", hilly="etapa escarpada", inter='média montanha', mount='alta montanha', time_prologue='prólogo', time_team='contrarrelógio por equipes', time_indiv='contrarrelógio individual', uphill='cronoescalada', rest='jornada de descanso'},
		["ro"] = {plain = "etapă de plat", hilly="etapă valonată", inter='etapă intermediară', mount='etapă de munte', time_prologue='prolog', time_team='contratimp pe echipe', time_indiv='contratimp individual', uphill='', rest='zi de repaus'},
		["ru"] = {plain = "равнинный", hilly="холмистый", inter='среднегорный', mount='горный', time_prologue='пролог', time_team='командная разделка', time_indiv='индивидуальная разделка', uphill='горная разделка', rest='день отдыха'},
		["sv"] = {plain = "Flack etapp", hilly="", inter='Kuperat', mount='Bergsetapp', time_prologue='Prolog', time_team='Lagtempoetapp', time_indiv='Tempoetapp', uphill='', rest='Vilodag'},
	}
	local l10n = l10nDef[wiki]
	if not l10n then l10n = l10nDef["en"] end  -- default

	local border
	if noborder then border="" else border="|border|right" end
 
	if x=='plain stage' then return "[[File:Plainstage.svg"..border.."|20px|"..l10n.plain.."]]" end
	if x=='hilly stage' then return "[[File:Hillystage.svg"..border.."|20px|"..l10n.hilly.."]]" end
	if x=='intermediate stage' then return "[[File:Mediummountainstage.svg"..border.."|20px|"..l10n.inter.."]]" end
	if x=='mountain stage' then return "[[File:Mountainstage.svg"..border.."|20px|"..l10n.mount.."]]" end
	if x=='uphill time trial stage' then return "[[File:Mountain Time Trial Stage.svg"..border.."|20px|"..l10n.uphill.."]]" end
	if x=='rest day' then return "[[File:Stage rest day.svg"..border.."|20px|"..l10n.rest.."]]" end
	if x=='time trial stage' then
		if noborder then border="" else border="|right" end
		if typ==2348250 then return "[[File:Team Time Trial Stage.svg"..border.."|20px|"..l10n.time_team.."]]" end
		if typ==2266066 then return "[[File:Time Trial.svg"..border.."|20px|"..l10n.time_indiv.."]]" end
		if typ==485321  then return "[[File:Time Trial.svg"..border.."|20px|"..l10n.time_prologue.."]]" end
	end
end

local function func_prologue() -- returns the word "Prologue"
	local l10nDef = { ["fr"]="Prologue", ["ar"]="المقدمة", ["en"]="Prologue", ["br"]="Prolog", ["ca"]="Pròleg", ["cs"]="Prolog", ["de"]="Prolog", ["da"]="Prolog", ["eo"]="Prologo",
	["es"]="Prólogo", ["eu"]="Aitzinetapa", ["fi"]="Prologi", ["fo"]="Forteinur", ["hu"]="Prológ", ["it"]="Prologo", ["ja"]="プロローグ", ["la"]="Incipit prologus", ["lb"]="Prolog", ["lv"]="Prologs",
	["mk"]="Пролог", ["nl"]="Proloog", ["no"]="Prolog", ["pl"]="Prologu", ["pt"]="Prólogo", ["ro"]="Prolog", ["ru"]="Пролог", ["sk"]="Prológ", ["sv"]="Prolog", ["ast"]="Prólogu"}

	if l10nDef[wiki] ~= nil then return l10nDef[wiki] else return l10nDef["en"] end -- if no translation, show en translation
end

local function stageLink(x, a, b) -- x= 10a: a = 10, b = a. x = 5: a = 5, b = ""
	local l10nDef = {["fr"]="étape", ["en"]="stage", ["ar"]="مرحلة", ["br"]="Tennad", ["ca"]="etapa", ["cs"]="etapa", ["de"]="Etappe", ["da"]="etape", ["eo"]="Etapo",
	["es"]="etapa", ["eu"]="Etapa", ["fi"]="Etappi", ["fo"]="teinur", ["hu"]="szakasz", ["it"]="Tappa", ["ja"]="ステージ", ["la"]="Statio", ["lb"]="etapp",
	["lv"]="Posms", ["mk"]="Етапа", ["nl"]="Etappe", ["no"]="etappe", ["pl"]="Etap", ["pt"]="Etapa", ["ro"]="Etapa", ["ru"]="Этап", ["sk"]="Etapa",
	["sv"]="Etapp", ["ast"]="etapa" }

	local word1, word2
	word2=l10nDef[wiki]
	if word2 == nil then word2=l10nDef["en"] end -- if no translation, show en translation
	local word = word2

	if wiki=="ar" then return word2 .. " " .. ( a or "" ) , "#" .. word2 .. " " .. ( a or "" ) end

-- fr: {{1re}} étape, {{2e}} étape
	if wiki=="fr" or wiki=="lb" then
		if b == "" then -- series_ordinal without character
			if a == "1" then word1 = "1<sup>re</sup> "..word else word1 = a.."<sup>e</sup> "..word end -- table text = {{1re}} étape, {{2ae}} étape,
			if a == "1" then word2 = "#1re "..word else word2 = "#"..a.."e  "..word end --text of section header = #1re étape, #2e étape
			return word1, word2
		end
		if b ~= "" then -- series_ordinal with character: instead of eg "1a re" it is "1re a"
			if a == "1" then word1 = "1<sup>re</sup> "..b.." "..word else word1 = a.."<sup>e</sup> "..b.." "..word end -- table text = {{1re}} étape, {{2ae}} étape,
			if a == "1" then word2 = "#1re "..b.." "..word else word2 = "#"..a.."e"..b.." "..word end --text of section header = #1re étape, #2e étape
			return word1, word2
		end
	end
	if wiki=="hu" then
		if b == "" then return a..". "..word, "#"..a..". "..word
		else return a..b.." "..word, "#"..a..b.." "..word end
	end
	if wiki=="de" or wiki=="da" or wiki=="fo" or wiki=="no" then return a..". "..b.." "..word, "#"..a..". "..b.." "..word end
	if wiki=="ca" then return a.."a "..b.." "..word, "#"..a..". "..b.." "..word end
	if wiki=="es" then return a..".ª "..word.." "..b, "#"..a..".ª "..word.." "..b end
	if wiki=="ast" then
		if b == "" then -- series_ordinal without character
			if a == "1" or a == "3" then word1 = a.."ᵉʳ "..word else word1 = a.."ª "..word end -- table text = 1ᵉʳ etapa, 2ª etapa, 3ᵉʳ etapa,
			if a == "1" or a == "3" then word2 = "#"..a.."ᵉʳ "..word else word2 = "#"..a.."ª  "..word end --text of section header = #1ᵉʳ etapa, #2ª etapa, #3ᵉʳ etapa
			return word1, word2
		end
		if b ~= "" then -- series_ordinal with character: instead of eg "1a re" it is "1re a"
			if a == "1" or a == "3" then word1 = a.."ᵉʳ "..b.." "..word else word1 = a.."ª "..b.." "..word end -- table text = {{1ᵉʳ}} etapa, {{2ª}} etapa,
			if a == "1" or a == "3" then word2 = "#"..a.."ᵉʳ "..b.." "..word else word2 = "#"..a.."ª"..b.." "..word end --text of section header = #1ᵉʳ etapa, #2ª etapa
			return word1, word2
		end
	end

	-- default
	word1 = x                  -- table text = 1, 2a, 3
	word2 = "#"..word.." ".. x -- text of section header = #Etappe 2a, #Stage 4
	return word1, word2
end

local function typeofstagelogo(stageID, noborder)
	local sType 
	p = mw.wikibase.getBestStatements(stageID, 'P31') -- P31 is 'instance of'
	for _,t in pairs(p) do
		if t.mainsnak.snaktype == 'value' then
			local iOf = t.mainsnak.datavalue.value['numeric-id']
			if iOf == 20646667 then sType = typeofstage('plain stage', nil, noborder) break end
			if iOf == 20646670 then sType = typeofstage('hilly stage', nil,moborder) break end
			if iOf == 20680270 then sType = typeofstage('intermediate stage', nil,noborder) break end
			if iOf == 20646668 then sType = typeofstage('mountain stage',nil, noborder) break end
			if iOf == 485321 then sType = typeofstage('time trial stage', 485321, noborder) break end -- prologue
			if iOf == 2266066 then sType = typeofstage('time trial stage', 2266066, noborder) break end -- individual time trial
			if iOf == 2348250 then sType = typeofstage('time trial stage', 2348250, noborder) break end -- team time trial
			if iOf == 20679712 then sType = typeofstage('uphill time trial stage', nil, noborder) break end
		end
	end
	return sType or ''
end

local function getStageLabel(inp)
	local a
	local b='' 
	local this_label=''
	if inp then
		a, _ = string.gsub(inp, "%a", "") -- 20, not 20a
		if string.find(inp, "%a") then 
			b = string.sub(inp, string.find(inp, "%a"))
		end
		if inp == "0" then 
			this_label = func_prologue()
		else
		    this_label = stageLink(inp, a, b)
		end
	end
	return this_label
end

--[[ Make a table row for infoboxes with links to previous and next ]]
local function getPreviousNextLine(raceID, stage)
	local previousID = firstValue(raceID, 'P155', 'id') -- P155 is 'follows'
	local nextID = firstValue(raceID, 'P156', 'id') -- P156 is 'followed by'
	if not nextID or not previousID then
		for _, s in statements(raceID, 'P3450') do		-- for items using P3450
			local q = s.qualifiers
			if q then
				if not previousID and q.P155 and q.P155[1] and	q.P155[1].snaktype == 'value' then
					previousID = q.P155[1].datavalue.value.id
				end
				if not nextID and q.P156 and q.P156[1] and	q.P156[1].snaktype == 'value' then
					nextID = q.P156[1].datavalue.value.id
				end
			end
		end
	end
	if not previousID and not nextID then
		return ''
	end

	local previousText, nextText = '', ''
	local this_label
	if previousID then
		if stage  then
			 local series_ordinal= firstValue(previousID, 'P1545', 'value')
			 this_label=getStageLabel(series_ordinal)
		else
			this_label = getYear(previousID)
		end
		local link = wikibase.getSitelink(previousID)
		if link then
			previousText = '<span style="color:#3366CC">[[' .. link .. '|&#x25C0; ' .. this_label .. ']]</span>'
		else
			previousText = '<span style="color:#3366CC">&#x25C0;</span> ' .. this_label
		end
	end
	if nextID then
		if stage then
			local series_ordinal= firstValue(nextID, 'P1545', 'value')
			this_label=getStageLabel(series_ordinal)
		else
			this_label = getYear(nextID)
		end
		local link = wikibase.getSitelink(nextID)
		if link then
			nextText = '<span style="color:#3366CC">[[' .. link .. '|' .. this_label .. ' &#x25B6;]]</span>'
		else
			nextText = this_label .. ' <span style="color:#3366CC">&#x25B6;</span>'
		end
	end
	local direction = contentLanguage:getDir()
	
	local outputTable = mw.html.create('tr')
	local tCell=outputTable:tag('td')
	tCell:cssText("text-align:" .. ((direction == 'ltr') and 'left' or 'right')):wikitext(previousText)
	if stage ~= nil and wiki=="ar" then 
		tCell:css('width','50%')
	end
	 tCell=outputTable:tag('td')
	 :cssText("text-align:" .. ((direction == 'ltr') and 'right' or 'left')):wikitext( nextText)
    if stage ~= nil and wiki=="ar" then 
		tCell:css('width','50%')
	end
	return outputTable
end

--== V) Main functions
--=== A) Function race reference ===
local function race_reference(raceID)
	-- Allow to display the reference below the classifications --
	local bases={
		{"ProCyclingStats", "P2327", "http://www.procyclingstats.com/race.php?id="},
		{"Cycling Quotient", "P2648", "http://www.cqranking.com/men/asp/gen/race.asp?raceid="},
		{"Cycling Archives", "P2330", "http://www.cyclingarchives.com/ritfiche.php?ritid="},
		{"Cycling Quotient", "P2708", "http://www.cqranking.com/women/asp/gen/race.asp?raceid="}
	}
	local links = {}
	for _, base in pairs(bases) do
		local p = mw.wikibase.getBestStatements(raceID, base[2])
		if p[1] and p[1].mainsnak.snaktype == 'value' then
			table.insert(links, ' [' .. base[3] .. p[1].mainsnak.datavalue.value .. " " .. base[1] ..']')
		end
	end
	if #links == 1 then
		return race_reference_translate(wiki, 1) .. table.concat(links)
	elseif #links > 1 then
		return race_reference_translate(wiki, 2) .. table.concat(links)
	else
		return ''
	end
end

--=== B) Calendar ===
function p.calendarcustom(frame)
	----- function to display calendar of any competition -----
	local function getargs(frame, fieldname, headertemp, tempdic)
		local argindex=tempdic[fieldname][1]

		if frame.args[argindex] ~= nil and tonumber(frame.args[argindex]) ==1 then
			tempdic[fieldname][3]= tempdic[fieldname][4]
			table.insert(headertemp, tempdic[fieldname][2])
		end
		return headertemp, tempdic
	end
	
	-- position in args,  header_column, default value,other value
	local headertemp={2} --date
	local tempdic = {
		['numbering']={2, 3, false, true},
		['displayclass']={4, 6, false, true},
		['displayleader']={6, 10, false, true}
	}

	if wiki == "ar" and string.match(frame:getParent():getTitle(), '%P+') == mw.site.namespaces.Template.name
	then frame = frame:getParent() end

	if frame.args[1] ~= nil then calendarID = string.gsub(frame.args[1], "%c", "") end

	headertemp, tempdic= getargs(frame, 'numbering', headertemp, tempdic)
	if tempdic['numbering'][3] then countrycolumn=3 else countrycolumn=2 end

	local no_countrytemp={}
	if frame.args[3] ~= nil and tonumber(frame.args[3]) ==1 then no_countrytemp={wiki} end
	-- country --
	table.insert(headertemp, 5)
	--race--
	table.insert(headertemp, 4)

	headertemp, tempdic= getargs(frame, 'displayclass', headertemp, tempdic)
	
	local onlywinnertemp =1
	if frame.args[5] ~= nil and tonumber(frame.args[5]) ==1 then
		onlywinnertemp =0
	end
	table.insert(headertemp, 7) --winner
	if onlywinnertemp==0 then
		table.insert(headertemp, 8)
		table.insert(headertemp, 9)
	end
	headertemp, tempdic= getargs(frame, 'displayleader', headertemp, tempdic)	

	local displayteamtemp =false
	if frame.args[7] ~= nil and tonumber(frame.args[7]) ==1 then displayteamtemp =true end

	local data_typetemp={}
	for ii=1,#headertemp do
		table.insert(data_typetemp,'')
	end

	local s = {
		header_function = calendar_translate, -- translations are in function Calendar_translate
		header_1 = 1000, -- translation 1 in function Calendar_translate is printed in the upper part of the table header
		header_2 = headertemp,-- translations 2, 3, 4, 5, 6 in function Calendar_translate are printed in this order
		title=wikibase.getLabel(calendarID),  -- in the lower part of the table header. The second value 3 in {4, 3} tells where the icon will go.
		country_column = countrycolumn,
		data_sort_type = data_typetemp, -- see https://meta.wikimedia.org/wiki/Help:Sorting
		item = calendarID,
		property = 'P527',
		no_country = no_countrytemp,
		only_winner = onlywinnertemp,
		numbering =  tempdic['numbering'][3],
		error_message = 0,
		displayed_class =nil,
		displayteam=displayteamtemp,
		displayclass= tempdic['displayclass'][3],
		leadercolumn= tempdic['displayleader'][3],
		frame=frame
	}
	return calendar_main(s, tableA(s))
end

function p.calendar(frame)
	----- function to display UCI calendar of one year ----
	----- based on WWTcalendar function -----
	----- author: Mr. Ibrahem -----
	local calendarID
	if wiki == "ar" then frame = frame:getParent() end
	local UCI = {}
	UCI["WT"] = { -- Q635366
		['2020'] = 'Q66739340',
		['2019'] = 'Q56966729',['2018'] = 'Q42317185',['2017'] = 'Q21857932',
		['2016'] = 'Q20970765',['2015'] = 'Q18192726',['2014'] = 'Q14979277',
		['2013'] = 'Q1031504',['2012'] = 'Q849059', ['2011'] = 'Q849092'
		}
	UCI["europe"] = { -- Q1194340
		['2020'] = 'Q74842812',
		['2019'] = 'Q57267776',['2018'] = 'Q44497477',['2017'] = 'Q27915850',
		['2016'] = 'Q21029681',['2015'] = 'Q18342122',['2014'] = 'Q15041668',
		['2013'] = 'Q1280387',['2012'] = 'Q961709',['2010–11'] = 'Q751208',
		['2009–10'] = 'Q212197',['2008–09'] = 'Q1811548',['2007–08'] = 'Q1788011',
		['2006–07'] = 'Q1780660',['2005–06'] = 'Q1455600',['2005'] = 'Q1431816'
		}
	UCI["asia"] = { -- Q1063423
		['2020'] = 'Q74121688',
		['2019'] = 'Q57267783',['2018'] = 'Q42204070',['2017'] = 'Q27679728',
		['2016'] = 'Q21622227',['2015'] = 'Q18341318',['2013–14'] = 'Q15041671',
		['2012–13'] = 'Q1606048',['2011–12'] = 'Q2117797',['2010–11'] = 'Q633349',
		['2009–10'] = 'Q630798',['2008–09'] = 'Q565160',['2007–08'] = 'Q1506934',
		['2006–07'] = 'Q966011',['2005–06'] = 'Q459817',['2005'] = 'Q469479',
		}
	UCI["america"] = { -- Q1063430
		['2020'] = 'Q73175384',
		['2019'] = 'Q57267780',['2018'] = 'Q42199340',['2017'] = 'Q27704415',
		['2016'] = 'Q21621040',['2015'] = 'Q18413668',['2013–14'] = 'Q15041669',
		['2012–13'] = 'Q129177',['2011–12'] = 'Q1239608',['2010–11'] = 'Q1849269',
		['2009–10'] = 'Q1303982',['2008–09'] = 'Q1536927',['2007–08'] = 'Q31716',
		['2006–07'] = 'Q31714',['2005–06'] = 'Q1429246',['2005'] = 'Q1431880',
		}
	UCI["africa"] = { -- Q268357
		['2020'] = 'Q74124131',
		['2019'] = 'Q57267785',['2018'] = 'Q42202027',['2017'] = 'Q27679848',
		['2016'] = 'Q21622217',['2015'] = 'Q18342124', ['2013–14'] = 'Q15041670',
		['2012–13'] = 'Q327399', ['2011–12'] = 'Q2296721',['2010–11'] = 'Q1386870',
		['2009–10'] = 'Q2067266', ['2008–09'] = 'Q1812465',['2007–08'] = 'Q676684',
		['2006–07'] = 'Q1436886', ['2005–06'] = 'Q1758917',['2005'] = 'Q1759404',
		}
	UCI["oceania"] = { -- Q1039648
		['2020'] = 'Q74843575',
		['2019'] = 'Q57267787',['2018'] = 'Q42205000', ['2017'] = 'Q27887426',
		['2016'] = 'Q21559636',['2015'] = 'Q18413671', ['2014'] = 'Q15246814',
		['2013'] = 'Q129134',['2011–12'] = 'Q1591132', ['2011'] = 'Q2298207',
		['2009–10'] = 'Q665283',['2008–09'] = 'Q964517', ['2007–08'] = 'Q1788621',
		['2006–07'] = 'Q1473640',['2005–06'] = 'Q1429165', ['2005'] = 'Q937636',
		}
	UCI["WWT"] = {
		['2020'] = 'Q70443700',
		['2019'] = 'Q57277246', ['2018'] = 'Q41787783', ['2017'] = 'Q27431192',
		['2016'] = 'Q21034783',
		}
	UCI["women"] = {
		['2020'] = 'Q74127378',
		['2019'] = 'Q57267790', ['2018'] = 'Q47005682', ['2017'] = 'Q27765666',
		['2016'] = 'Q22696468', ['2015'] = 'Q18348936', ['2014'] = 'Q15831496',
		['2013'] = 'Q6425932', ['2012'] = 'Q2466796', ['2011'] = 'Q2466792',
		['2010'] = 'Q2933831', ['2009'] = 'Q2933830', ['2008'] = 'Q2933828',
		['2007'] = 'Q3650627', ['2006'] = 'Q16154659',
		}
	UCI["Pro"] = {
		['2020'] = 'Q74279750',
		}
		
	local header_1_tab = {["WT"]=13 ,["europe"]=14 ,["asia"]=15,["america"]=16 ,["africa"]=17 ,["oceania"]=18, ["WWT"]=11, ["women"]=1}
	local display_code_tab=  {["WT"]=1 ,["europe"]=2 ,["asia"]=2,["america"]=2 ,["africa"]=2 ,["oceania"]=2, ["WWT"]=1, ["women"]=2}
	local header_1_number = 12
	
	local tempdic
	local tempdic1 = {
		header_2 =  {2, 3,5, 4, 7, 8, 9, 10},
		only_winner =0,
		numbering=true,
		displayteam=false,
		displayclass=false,
		leadercolumn=true
	}	
	local tempdic2 = {
		header_2 =   {2, 5, 4, 6, 7},
		only_winner =1,
		numbering=false,
		displayteam=true,
		displayclass=true,
		leadercolumn=false
	}

	for key, v in pairs(UCI) do
		if not calendarID  and frame.args[key] then
			local year = frame.args[key]
			year = string.gsub(year , "%c", "")
			if v[year] then
				calendarID = v[year]
				header_1_number = header_1_tab[key]
				display_code = display_code_tab[key]
			end
			if wiki == "ar" and frame.args["code"] and frame.args["code"] ~= "" then
				display_code = 1
			end
		end
	end
	if not calendarID then return "" end
	if display_code == 1 then
		tempdic=tempdic1
	else
		tempdic=tempdic2
	end

	local s = {
		header_function = calendar_translate, -- translations are in function Calendar_translate
		header_1 = header_1_number, -- t
		header_2 = tempdic.header_2,
					-- in the lower part of the table header. The second value 3 in {4, 3} tells where the icon will go.
		country_column = 3,
		data_sort_type ={'', 'unsortable', '', '', '','',''},   -- -- see https://meta.wikimedia.org/wiki/Help:Sorting
		item = calendarID,
		property = 'P527',
		no_country = no_country_calendar,
		only_winner = tempdic.only_winner,
		numbering = tempdic.numbering,
		error_message = 0,
		displayed_class = {
			"Q23005603", --
			"Q22231110", -- 1.1
			"Q22231109", -- 2.HC
			"Q22231111", -- 1.2
			"Q22231108", -- 1.HC
			"Q22231106", -- 1.UWT
			"Q74275170", -- 1.Pro
			"Q22231107", -- 2.UWT
			"Q22231113", -- 2.2
			"Q22231112", -- 2.1
			"Q22231113", -- 2.2
			"Q22231109", -- 2.HC
			"Q74275176", -- 2.Pro
			"Q22231118", -- CC
			},
		displayteam=tempdic.displayteam,
		displayclass=tempdic.displayclass,
		leadercolumn=tempdic.leadercolumn,
		frame=frame
	}
	return calendar_main(s, tableA(s))
end

function calendar_main(s, resulttable)--Display the UCI women calendar of one year
	localframe=s.frame
	local calendarID=s.item
	local sortkey
	local t_Body, fn_racetable,fn_datetable, fn_countrytable = {}, {}, {},{}
	local displayed_class=s.displayed_class

	local temp=firstValue(calendarID, s.property)
	if not temp then s.error_message = 2 return '' end

	local country=getcoutrybool (s.no_country)
	if available_list==false then country=false end --otherwise the display put no "country" column...

	----- Begin of the main part of the code
	for kk, p527 in statements(calendarID, 'P527') do
		local RaceID = p527.mainsnak.datavalue.value.id
		---- Create a row ----
		fn_datetable = fn_date(RaceID)
		local timeOfRace = fn_datetable[1]
		fn_racetable=fn_race(RaceID,displayed_class,s.displayclass,timeOfRace,nil,country)

		if fn_racetable[1]~=nil then --otherwise the class is not display
			fn_countrytable=fn_country(RaceID,timeOfRace,country,fn_racetable) 
			
			local tRow = mw.html.create('tr'):cssText( "line-height: 1.8em; padding: 5px;")
			tRow:node(fn_datetable[2])
			sortkey = fn_datetable[3]
			if s.numbering == true then
				tRow:tag('td'):cssText("text-align:center;padding:0 0.5em"):wikitext(tostring(kk))
			end
			
			tRow:node(fn_countrytable[1])
			if country then
				tRow:node(fn_racetable[1])
			end
			if fn_racetable[2] then tRow:node(fn_racetable[2]) end --class
			tRow:node(fn_rider(RaceID,timeOfRace,s.displayteam,s.only_winner))
			if s.leadercolumn==true then
				tRow:node(fn_rider(RaceID,timeOfRace,s.displayteam,3))
			end
			---- Add the row to the table
			t_Body[#t_Body + 1] = {sortkey, tRow}
		end 
	end

	return sortandconcat(t_Body, resulttable)
end

function p.nationalchampionships(frame)
	local calendarroadID, calendarITTID, year
	if wiki == "ar" then
		frame = frame:getParent()
	end
	local UCIroad, UCIITT = {},{}

	UCIroad["women"] = {
		['2020']='Q78466304', ['2019'] = 'Q66362617',
		['2018'] = 'Q66762475', ['2017'] = 'Q66762546', ['2016'] = 'Q66762540',
		['2015'] = 'Q66762534', ['2014'] = 'Q66762524', ['2013'] = 'Q66762521',
		['2012'] = 'Q66762511', ['2011'] = 'Q66762500', ['2010'] = 'Q66762491'
	}
	
	UCIITT["women"] = {
		['2020'] = 'Q78466572', ['2019'] = 'Q66736271',
		['2018'] = 'Q66762631', ['2017'] = 'Q66762614', ['2016'] = 'Q66762604',
		['2015'] = 'Q66762597', ['2014'] = 'Q66762592', ['2013'] = 'Q66762584',
		['2012'] = 'Q66762578', ['2011'] = 'Q66762569', ['2010'] = 'Q66762562'
	}
	
	UCIroad["men"] = UCIroad["women"]
	UCIITT["men"] = UCIITT["women"]
	
	local listOfCalendar={UCIroad, UCIITT}

	for ii, thisCalendar in pairs(listOfCalendar) do --road/ITT
		for key, v in pairs(thisCalendar) do --women/men
			if ((ii==1 and calendarroadID==nil) or (ii==2 and calendarITTID ==nil)) and frame.args[key] then
				year = frame.args[key]
				year = string.gsub( year , "%c", "")
				if v[year] then
					if ii==1 then
						calendarroadID = v[year]
					else
						calendarITTID = v[year]
					end
				end
			end
		end
	end

	local s = {
		header_function = calendar_translate, -- translations are in function Calendar_translate
		header_1 = 19, --
		header_2 = {5, 20, 21},
		country_column = 1,
		data_sort_type = {'', '', ''},   -- -- see https://meta.wikimedia.org/wiki/Help:Sorting
		item= calendarroadID,
		calendarroadID = calendarroadID,
		calendarITTID = calendarITTID,
		property = 'P527',
		year = year,
		no_country = {}, --no sense here to hide the country
		error_message = 0,
		displayteam = true,
		displaycountrylink = true,
		frame = frame
	}
	return nationalchampionships_main(s,tableA(s))
end

function nationalchampionships_main(s, resulttable)--Display the list of national champions for one year
	localframe=s.frame
	local tableChamp, fn_countrytable, t_Body = {}, {}, {}
	local timeOfRace ='+'..tostring(s.year).."-01-01T00:00:00Z"
	local tRace, thereisawinner, parentID, parentParentID, sitelink

	local temp=firstValue(s.calendarroadID, s.property)
	if temp then else s.error_message = 2 return '' end

	local listOfCalendarID={s.calendarroadID, s.calendarITTID}

	--create the table with the information
	for ii, thisCalendarID in ipairs(listOfCalendarID) do
		if thisCalendarID ~= nil then
			for _, p527 in statements(thisCalendarID, 'P527') do
				thisID = p527.mainsnak.datavalue.value.id
				fn_countrytable=fn_country(thisID,timeOfRace,s.country)
				sortkey=string.gsub(fn_countrytable[2], 'É', 'E') --case États Unis

				--create the table
				if tableChamp[sortkey]==nil then 
					tableChamp[sortkey]={}
					tableChamp[sortkey]['countryname']=fn_countrytable[2] --raw
					tableChamp[sortkey]['roadwinner']='<td></td>'
					tableChamp[sortkey]['ITTwinner']='<td></td>'
					--look for sitelink to championship
					sitelink=nil --reinit
					if s.displaycountrylink then --expensive
						parentID = firstValue(thisID, 'P361', 'id') --part of
						if parentID then 
							parentParentID = firstValue(parentID, 'P31', 'id') 
							if parentParentID then sitelink = wikibase.getSitelink(parentParentID) end
						end
					end
					tableChamp[sortkey]['sitelink']=sitelink
					tableChamp[sortkey]['flag']=fn_countrytable[3]
				end
				
				--fill the table
				tRace, thereisawinner=fn_rider(thisID,timeOfRace,s.displayteam,1,true)
				if tableChamp[sortkey]['thereisawinner']~=true then --all other cases
					tableChamp[sortkey]['thereisawinner']=thereisawinner 
				end
				
				if ii==1 then
					tableChamp[sortkey]['roadwinner']=tRace
				else
					tableChamp[sortkey]['ITTwinner']=tRace
				end
			end
		end
	end

	-- structure the display
	for key, thisRow in pairs(tableChamp) do
		if thisRow['thereisawinner'] then --there is a winner
			local tRow = mw.html.create('tr'):cssText( "line-height: 1.8em; padding: 5px;")
			if thisRow['sitelink']~=nil then
				tRow:tag('td'):wikitext(thisRow['flag']..' [['..thisRow['sitelink']..'|'..thisRow['countryname']..']]')
			else
				tRow:tag('td'):wikitext(thisRow['flag']..' '..thisRow['countryname'])
			end
			tRow:node(thisRow['roadwinner'])
			tRow:node(thisRow['ITTwinner'])
			t_Body[#t_Body + 1] = {key, tRow}
		end --no winner
	end --end list of key

	return sortandconcat(t_Body, resulttable)  
end

--=== C) Victory ===
function p.victories(frame)
	local s = {
		header_function = victories_translate, -- translations are in function victories_translate
		header_1 = 2, -- translation 1 in function victories_translate is printed in the upper part of the table header
		header_2 = {3, 4, 5, 6, 7},-- translations 2, 3, 4, 5, 6 in function victories_translate are printed in this order
										-- in the lower part of the table header. The second value 3 in {4, 3} tells where the icon will go.
		data_type = {'date', 'race', 'country', 'class', 'rider'},
		country_column = 3,
		data_sort_type = {'', 'unsortable', '', '', ''}, -- see https://meta.wikimedia.org/wiki/Help:Sorting
		item = frame.args[1],
		property = 'P2522',
		no_country = no_country_victories,
		error_message = 0,
		frame=frame
	}
	return victory_main(s ,tableA(s))
end

function victory_main(s, resulttable)
	localframe=s.frame
	local _
	_, _, s.item = string.find(s.item, "(%w+)")

	local temp=firstValue(s.item, s.property,'id')
	if temp then else s.error_message = 2 return '' end

	local country=getcoutrybool (s.no_country)
	if available_list==false then country=false end

	local sortkey
	local t_Body, fn_countrytable, fn_datetable, fn_racetable = {}, {}, {}, {}

	for _, p2522 in statements(s.item, 'P2522') do
		local RaceID = p2522.mainsnak.datavalue.value.id
		local tRow = mw.html.create('tr'):cssText( "line-height: 1.8em; padding: 5px;")

		fn_datetable = fn_date(RaceID, 'victory')
		local timeOfRace = fn_datetable[1]
		sortkey=fn_datetable[2]
		
		fn_racetable=fn_race(RaceID,nil ,true,timeOfRace, 'victory',country)--displayed_class=nil
		
		if fn_racetable[1]~= nil then --otherwise class not to be displayed
			fn_countrytable=fn_country(RaceID,timeOfRace,country,fn_racetable)
			
			tRow:node(fn_datetable[2])
			if country==true then
				tRow:node(fn_racetable[1])  --race site link is in fn_countrytable
			end
			tRow:node(fn_countrytable[1]) --country
			tRow:node(fn_racetable[2]) --class
			tRow:node(fn_rider(RaceID,timeOfRace,false,1))
			t_Body[#t_Body + 1] = {sortkey, tRow}
		end --no winner
	end --end list of key
	
	return sortandconcat(t_Body, resulttable)
end

--== Cbis) Functions for infobox
-- functions for both infoboxs 
local function infoGetOthers(others, entityID)
	if not others[1].content then --picture
		others[1].content, others[2].content = getImage(entityID) -- picture, caption
	end

	if not others[3].content then  -- map
		others[3].content = firstValue(entityID, 'P242') -- P242 is 'locator map image'
	end
	
	if not others[4].content then  -- map
		others[4].content = firstValue(entityID, 'P2713') -- sectional_view
	end	
end

local function infoGetCountry(details,index, entityID, timeOfRace)
	if not details[index].content then -- country
		-- This function gives countries where the race take place
		local country = {}
		for _, p17 in statements(entityID, 'P17') do -- P17 is 'country'
			local countryID = p17.mainsnak.datavalue.value.id
			country[#country + 1] = flag(countryID, timeOfRace) .. ' ' .. getCountryName(countryID)
		end
		if country[1] then
			if #country > 1 then
				details[index].name = details[index].name_plural
			end
			details[index].content = table.concat(country, '<br/>')
		end
	end
end
	
local function infoGetStartEnd(details,index, entityID)
	if not details[index].content then -- start place
		local place = firstValue(entityID, 'P1427', 'id') -- P1427 is 'start point'
		details[index].content = place and getPlaceLink(place)
	end

	if not details[index+1].content then -- end place
		local place = firstValue(entityID, 'P1444', 'id') -- P1444 is 'destination point'
		details[index+1].content = place and getPlaceLink(place)
	end
end

local function infoGetParticipants(details,index, entityID)
		-- Function that give the number of cyclists at the beginning and at the finishing of a race
	for _, p1132 in statements(entityID, 'P1132') do -- P1132 is 'number of participants'
		local amount = tonumber(p1132.mainsnak.datavalue.value.amount) -- tonumber to remove starting '+'
		for _, q in qualifiers(p1132, 'P276') do -- P276 is 'location'
			local location = q.value['numeric-id']
			if location == 529711 then -- Q529711 is 'beginning'
				if not details[index].content then details[index].content = amount end -- participants at start
			elseif location == 12769393 then -- Q12769393 is 'end'
				if not details[index+1].content then details[index+1].content = amount end -- participants at end
			end
		end
	end
end

local function infoInitTab(width, name, icon)
	if width==nil then width= '320px' end
	
	local tab = mw.html.create('table')
	if wiki == "eo" then
		tab:cssText(standardtablecss):css('width','23em')
		:addClass('infobox')
	else
		tab:attr('cellpadding','4')
		:attr('cellspacing','0')
		:cssText(standardtablecss)
		:cssText("float:"..floatinfobox.."; max-width:"..width)
	end
	local tCell=tab:tag('tr'):tag('td'):attr('colspan','2')
	:cssText('border-bottom:5px solid white; font-size:175%; background:#FFDF80; text-align:center')
	local topTable = tCell:tag('table')
	:cssText('width:100%')
	local tRow=topTable:tag('tr')
	tRow:tag('td'):wikitext(name or '')
	tRow:tag('td'):wikitext(icon or '')
	
	return tab
end

local function infoFillOthersDetails(tab, others, details,title)
		if others[1].content then -- picture
		tab:tag('tr'):tag('td'):attr('colspan','2'):css('text-align','center')
		:wikitext("[[File:" .. others[1].content .."|center|300px]]")
		if others[2].content then -- caption
			tab:tag('tr'):tag('td'):attr('colspan','2'):css('text-align','center'):css('font-size','80%')
			:wikitext(others[2].content)
		end
	end
	tab:tag('tr'):tag('td'):attr('colspan','2'):css('text-align','center'):css('background-color','#FFDF80')
	:css('font-weight','bold')
	:wikitext(title)
	for _, row in ipairs(details) do
		if row.content then
			tRow= tab:tag('tr'):css('vertical-align','top')
			tRow:tag('td'):css('width','40%'):css('font-weight','bold')
			:wikitext(row.name)
			tRow:tag('td'):wikitext(row.content)
		end
	end
end

local function infoFillOthersMap(tab, others)
	if others[3].content then -- map
		tab:tag('tr'):tag('td'):attr('colspan','2'):css('text-align','center')
		:wikitext("[[File:".. others[3].content .. "|center|300px]]")
	end
	if others[4].content then -- map
		tab:tag('tr'):tag('td'):attr('colspan','2'):css('text-align','center')
		:wikitext("[[File:".. others[4].content .. "|center|300px]]")
	end
end

local function wdDoc(tab, s, translation, ID)
	tab:tag('tr'):tag('td'):attr('colspan','2')
	:cssText('text-align:right; border-top:3px solid #FFDF80; font-size:75%')
	:wikitext("[[" .. s .. "|" .. translation .. "]] [[File:Wikidata-logo S.svg|12px|link=d:".. ID .."]]")
end

--== D) Stage infobox
function p.stageinfobox(frame)
	local details = {
		{ name = stageinfobox_translate(2)}, -- course / not used
		{ name =  stageinfobox_translate(2)}, -- competition
		{ name = stageinfobox_translate(3), name_plural = infobox_translate(4)}, -- stage type 
		{ name = stageinfobox_translate(4), name_plural = infobox_translate(7)}, -- date
		{ name = stageinfobox_translate(6)}, -- distance
		{ name = stageinfobox_translate(7), name_plural = infobox_translate(10)}, -- country
		{ name = stageinfobox_translate(9)}, -- start place
		{ name = stageinfobox_translate(10)}, -- endplace
		{ name = stageinfobox_translate(11)}, -- participants at start
		{ name = stageinfobox_translate(12)}, -- participants at end
		{ name = stageinfobox_translate(13)}, -- speed
		{ name = stageinfobox_translate(44)}, -- elevation
		{ name = infobox_translate(32), special = true}, -- special 1
		{ name = infobox_translate(33), special = true}, -- special 2
	}
	local others = {
		{ name = infobox_translate(29)}, -- picture
		{ name = infobox_translate(30)}, -- caption
		{ name = infobox_translate(31)}, -- map
		{ name = 'sectional'}
	}
			--begin of the function
	local t_P642 = {
			[20882747]={'results', 'first'}, 
			[20882748]={'results', 'second'}, 
			[20882749]={'results', 'third'}, 
			[21686770]={'results', 'winner_fighting'},
			[2250962]={'results', 'cima_coppi'}, 
			[10452933]={'results', 'cima_pantani'},
			[20882763]={'gen', 'leader'}, 
			[20882764]={'gen', 'deuxieme'}, 
			[20882765]={'gen', 'troisieme'},
			[20883213]={'annex', 'montagne'}, 
			[20883140]={'annex', 'jeune'}, 
			[20883008]={'annex', 'points'},
			[20883329]={'annex', 'sprints'}, 
			[20893984]={'annex', 'super_combatif'}, 
			[20965880]={'annex', 'combine'},
			[27104688]={'annex', 'stage_volantes'}, 
			[27104684]={'annex', 'regularite'}, 
			[20882922]={'annex', 'equipe'},
			[27104271]={'annex', 'equipe_points'},
			[20882667]={'gen', 'leader'}, 
			[20882668]={'gen', 'deuxieme'}, 
			[20882669]={'gen', 'troisieme'},
			[20883212]={'annex', 'montagne'}, 
			[20883139]={'annex', 'jeune'}, 
			[20883007]={'annex', 'points'},
			[20883328]={'annex', 'sprints'}, 
			[20893983]={'annex', 'super_combatif'}, 
			[20893979]={'annex', 'combine'},
			[27067359]={'annex', 'stage_volantes'}, 
			[27067170]={'annex', 'regularite'},
			[27907747]={'annex', 'azzurri_ditalia'}, 
			[27907748]={'annex', 'azzurri_ditalia'},
			[27907714]={'annex', 'breakaway'}, 
			[27907715]={'annex', 'breakaway'},
			[20882921]={'annex', 'equipe'}, 
			[27104269]={'annex', 'equipe_points'}
	}
	
	local entityID = mw.text.trim(frame.args[1])
	local wikibase = mw.wikibase
	if type(entityID) ~= 'string' then error('parameter must be a string') end
	if not entityID:match('Q%d+') then error ('parameter must be a valid Wikidata item (ex: Q42)') end

	local localframe
	if string.match(frame:getParent():getTitle(), '%P+') == mw.site.namespaces.Template.name then
		localframe = frame:getParent()
	else
		localframe = frame
	end
	
	getLocalContent(details, localframe.args)
	getLocalContent(others, localframe.args)

	local timeOfRace
	local temp = firstValue(entityID, 'P31','id')
	icon = ''
	if temp and temp ~= 'Q18131152' then
		if temp=='Q2266066' or temp=='Q2348250' or temp=='Q485321' then 
			icon = " [[File:Cycling (track) pictogram.svg|35px]]"
		else 
			icon = " [[File:Cycling (road) pictogram.svg|35px]]" 
		end
		details[3].content = typeofstagelogo(entityID, true).." "..WPlinkpure(temp)
	end
	
	local name =  getLabelFallback(entityID, {wikilang, 'en', 'fr', 'de'}) or ''
	if wiki == 'fr' and name ~= nil then 
		name= mw.ustring.gsub(name, "^(%d+)([re]+)", "%1<sup>%2</sup> ") 
	end
    name= mw.ustring.gsub(name, "^(%a)",function (x) return mw.ustring.upper(x) end)
		
	infoGetOthers(others, entityID)	

	--name
	if course==nil then
		temp = firstValue(entityID, 'P1545')
		if temp then
			details[2].content =getStageLabel(temp)
			raceId = firstValue(entityID, 'P361','id')
			if raceId then
				details[2].content = details[2].content or '' .. '، '.. WPlinkpure(raceId)
				for k, p31 in statements(raceId, 'P31') do
					if race==nil then race={} end
					race[k] = p31.mainsnak.datavalue.value.id --for the jersey
				end
			end
		end
	end

	-- This function give a format to dates when P585 (date) is used in a single day race
	local pTime = firstValue(entityID, 'P585', 'time') -- P585 is 'point in time'
	if pTime then
		details[4].content = func_date(pTime, 'long')
		timeOfRace = pTime
	end
	
	local kmdistance
	if not details[5].content then details[5].content, kmdistance = getDistance(entityID, true) end -- distance
	
	infoGetCountry(details,6, entityID, timeOfRace)
	infoGetStartEnd(details,7, entityID)
	infoGetParticipants(details,9, entityID)
	if not details[11].content then details[11].content = getSpeed(entityID, true, kmdistance, 'P2417') end --speed
	if not details[12].content then 
		local elevation=getElevation(entityID) 
		if  elevation ~= nil then details[12].content =elevation else details[12].content = nil end
	end --Elevation

	local jerseyWPID, jersey_name
	local t_s = {
		order={'results', 'gen', 'annex'},
		results={show=false, 
			header=15, 
			order = {'first','second','third','winner_fighting','winner_fighting2','cima_coppi','cima_pantani'},
			first={translation=16},
			second={translation=17},
			third={translation=18},
			winner_fighting={translation=19},
			winner_fighting2={translation=19}, -- two winner_fighting possible
			cima_coppi={translation=40},
			cima_pantani={translation=41}
			},
		gen={show=false, 
			header=20, 
			order = {"leader", "deuxieme", "troisieme"},
			leader={translation=21},
			deuxieme={translation=22},
			troisieme={translation=23}
			},
		annex={show=false, 
			header=24, 
			order={"points","montagne","sprints","jeune","super_combatif","combine",
			"stage_volantes","regularite","azzurri_ditalia","breakaway","equipe","equipe_points"},
			points={translation=25},
			montagne={translation=26},
			sprints={translation=27},
			jeune={translation=28},
			super_combatif={translation=29},
			combine={translation=30},
			stage_volantes={translation=31},
			regularite={translation=32},
			azzurri_ditalia={translation=42},
			breakaway={translation=43},
			equipe={translation=33},
			equipe_points={translation=34}
			}
		}

	--Winner
	for _, p1346 in statements(entityID, 'P1346') do
		local id_speed, id_time, id_time_gap, id_points_a, id_points_b, type_ofclas, name_ofclas
		local q = p1346.qualifiers
		local riderId = p1346.mainsnak.datavalue.value.id

		id_time = qualifieramount(p1346, 'P2781')
		id_time_gap =qualifieramount(p1346, 'P2911')
		id_speed =qualifieramount(p1346, 'P2052')
		id_points_a = qualifieramount(p1346, 'P1358')
		id_points_b =qualifieramount(p1346, 'P1351')

		if riderId ~= nil then
			local riderLink,riderTeam  = subwinner(riderId, timeOfRace, q) --sub function to avoid code in double
			-- looks into race item if the winner has a P642 statement for showing the type of winner (points, mountain, ..)
			if q.P642 and q.P642[1].snaktype == 'value' then
				for _, vv in pairs(q.P642) do
					local qual = vv.datavalue.value['numeric-id']
					if qual~=nil and deprecated~='deprecated' and t_P642[qual] then
						if qual==21686770 and t_s['results']['winner_fighting'][1] ~= "" then 
							t_P642[qual][2] = 'winner_fighting2' 
						end
						type_ofclas=t_P642[qual][1] --annex or gen
						name_ofclas=t_P642[qual][2] --name of ranking
						local v=t_s[type_ofclas][name_ofclas]

						v['link']=riderLink    
						v['team']=riderTeam 
						v['rank']=isdisqualified(p1346,q) 
						v['time']=id_time 
						v['gap']=id_time_gap 
						if id_points_a then v['points']=id_points_a end 
						if id_points_b then v['points']=id_points_b end
						v['speed']=id_speed 
						if qual==27104271 and t_s.annex.equipe_points['link']==nil then
							t_s.annex.equipe_points['link']=riderId 
						end
						if qual==20882922 and t_s.annex.equipe['link']==nil then 
							t_s.annex.equipe['link']=riderId 
						end
						v['genre'] = getgendercode(riderId,'f')
					end
				end
			end
		end
	end
	local rank, deprecated, prop, order, thisorder
	local listoftable = {'results','gen'}

	-- look into P2417, stage classification, then p2321 gen classification
	for ii, thistable in ipairs(listoftable) do
		if ii==1 then
			prop='P2417'
			order = {'first', 'second', 'third'}
		else
			prop='P2321'
			order = {'leader', 'deuxieme', 'troisieme'}
		end
		
		for _, p2417 in statements(entityID, prop) do
			local q = p2417.qualifiers
			if q.P1352 and q.P1352[1].snaktype == 'value' then
				for _, q1352 in pairs(q.P1352) do
					rank = tonumber(q1352.datavalue.value.amount)
				end
				if rank == 1 or rank == 2 or rank == 3 then
					thisorder=order[rank]
					local v=t_s[thistable][thisorder]
					v['rank'] = isdisqualified(p2417, q)
					local thisid= p2417.mainsnak.datavalue.value.id
					v['link'],_  = subwinner(thisid, timeOfRace, q) 

					if v['gap'] == nil and v['time'] == nil then
						v['gap'] = qualifieramount(p2417, 'P2911') 
					end
					if v['gap'] == nil and v['time'] == nil then
						v['time'] = qualifieramount(p2417, 'P2781') 
					end
					v['speed'] = qualifieramount(p2417, 'P2052') 
					v['genre'] = getgendercode(thisid, 'f')
				end
			end
		end
	end

	listoftable={t_s.results,t_s.gen,t_s.annex}
	
	for _, thistable in ipairs(listoftable) do
		for _, v in ipairs(thistable.order) do --order is the list of all classification names
			if thistable[v]['link'] then
				thistable.show = true 
			end
		end
	end
	
	---General table
	local temp
	local width= '320px' -- size standard 320px, special 340px
	if t_s.annex.show == true and (wiki == 'no' or wiki == '..') then width= '340px' end
	tab= infoInitTab(width, name, icon)
	infoFillOthersDetails(tab, others, details,stageinfobox_translate(1))

-- ranking table, general and stage
	for _, value_order in ipairs(t_s.order) do
		local thistable =t_s[value_order] --results or gen or annex
		
		if thistable.show then -- if a section of the stageinfobox should be shown
			tCell=tab:tag('tr'):tag('td'):attr('colspan','2')
			tTab=tCell:tag('table'):attr('cellpadding','0'):attr('cellspacing','0'):css('width','100%')
			tCell=tTab:tag('tr'):tag('td'):attr('colspan','3')
			:cssText('border-bottom:5px solid #fff2cc; background-color:#FFE7A0; text-align:center')
			:css('font-weight','bold')
			:wikitext(stageinfobox_translate(thistable.header))

			for key, value in ipairs(thistable.order) do --value is the name of the class
				local v=thistable[value]
				if v['link'] then
					local a1
					a1, jersey_name, jerseyWPID = jersey_infobox(wiki, value, race, timeOfRace)
					if a1~='' then v['jersey'] = a1 end
					if v['speed']  then
						if wiki == 'fo' then
							v['speed'] = string.gsub(v['speed'], "%.", ",") 
						else
							local lang = mw.language.getContentLanguage()
							v['speed'] = '('.. lang:formatNum(v['speed'])..unit(5)..')'
						end
					end
					if v['points'] then
						if v['points'] > 1 then 
							temp=unit(7)
						else 
						    temp=unit(6) 
						end 
						v['points'] = v['points']..temp
					end
					local title, k = string.gsub(stageinfobox_translate(v['translation']), " ", "&nbsp;")
					if k > 0 then title = string.gsub(title, "&nbsp;", "<br>", 1) end --&#32;
				
					--Create an empty column on the left
					tRow=tTab:tag('tr'):css('vertical-align','top')
					tCell=tRow:tag('td')
					:css('font-weight','bold')
					if v['team']~=nil or v['speed'] ~=nil then
						tCell:attr('rowspan','2')
					end
					tCell:cssText("width:1%;background-color:#fff2cc;text-align:" .. 
					textalign .. ";padding:0 2px 0 2px;white-space:nowrap")
				
					if value_order~='annex' and v['translation']~=40 and v['translation']~=41 then -- Cima Coppi, Cima Pantani with a line break
						if v['jersey'] == nil then
							if (value_order=='results') and (value=='winner_fighting' or value=='winner_fighting2' or value=='cima_coppi' or value=='cima_pantanii') then
								tCell:wikitext(stageinfobox_translate(v['translation']))
							else
								tCell:wikitext(number(v['genre'], key, wiki))
							end
						else
							if jerseyWPID=='' then
								temp=''
							else 
								temp="|link="..jerseyWPID
							end
							tCell:wikitext("[[File:"..v['jersey'].."|20px|"..title..temp.."]]")
						end
					else
						if v['jersey'] == nil then 
							tCell:wikitext(title)
						else
							if jerseyWPID=='' then
								if jersey_name ~= '' then 
									temp = "|"..jersey_name
								else
									temp=''
								end
							else 
								temp= "|link="..jerseyWPID
							end
							tCell:wikitext("[[File:"..v['jersey'].."|20px"..temp.."]]" .. title)
						end
					end
					
					tRow:tag('td'):cssText("padding:0 0.5em 0 0.5em;"..v['rank'])
					:wikitext( v['link'])
					tCell=tRow:tag('td'):cssText('text-align:right;font-size:85%;white-space:nowrap')

					if v['time'] then 
						tCell:wikitext(calculate_time(v['time']))
					end
					if v['gap'] then 
						tCell:wikitext('+ '.. calculate_time(v['gap']))
					end
					tCell:wikitext(v['points'])
				end
				
				tCell=tTab:tag('tr'):tag('td'):attr('colspan','2')
				if v['team']~=nil and v['speed'] ~=nil then -- team row
					tTab2=tCell:tag('table'):attr('cellpadding','0'):attr('cellspacing','0'):css('width','100%')
					tRow = tTab2:tag('tr')
					tRow:tag('td'):cssText('width:100%;text-align:" .. textalign .. ";padding-left:2px')
					:wikitext("("..v['team']..")") --add the team
					tRow:tag('td'):cssText('font-size:85%;vertical-align:top;white-space:nowrap')
					:wikitext(v['speed'])
				else
					if v['team']~=nil or v['speed'] ~=nil then
						tCell:cssText("text-align:" .. textalign .. ";padding-left:2px")
						if v['team'] ~= nil then
							tCell:wikitext("("..v['team']..")") --add the team
						end
						tCell:tag('span'):cssText("float:right;font-size:85%;"):wikitext(v['speed'])
					end
				end
			end
		end
	end
	
	infoFillOthersMap(tab, others)
	tab:node(getPreviousNextLine(entityID,true))
	wdDoc(tab, "d:Wikidata:WikiProject Cycling/Documentation/stageinfobox", stageinfobox_translate(39), frame.args[1])
	return tab
end

--== E) List of teams
function p.listofteams(frame)
	local raceID = frame.args[1]
	local teams = {} -- values will be {teamLink, teamCat, sortkey, index}

	local timeOfRace, errorMessage = gettimeOfRace(raceID)
	if not timeOfRace then return errorMessage end

	local teamCats = { -- {c,d,e} c = singular team type, d = plural team type, e = print order of the team types
		["Q6154783"] = {4,5,1}, -- WorldTeam
		["Q20638319"] = {6,7,2}, -- ProTeam (2005-2014)
		["Q382927"] = {8,9,4}, -- UCI Professional Continental Team (2005-2019)
		["Q78464255"] = {6,7,3},-- ProTeam (2020-)
		["Q1756006"] = {10,11,5}, -- UCI Continental Team
		["Q23726798"] = {12,13,6}, -- national cycling team
		["Q20738667"] = {12,13,7}, -- national cycling team U23
		["Q28492441"] = {12,13,8}, -- équipe cycliste nationale de marque
		["Q20639848"] = {14,15,9}, -- club cycling team
		["Q20639847"] = {16,17,10}, -- professional cycling team
		["Q20652655"] = {18,19,11}, -- amateur cycling team
		["Q20653563"] = {20,21,12}, -- Groupe Sportif I
		["Q20653564"] = {22,23,13}, -- Groupe Sportif II
		["Q20653566"] = {24,25,14}, -- Groupe Sportif III
		["Q80425135"] = {4,5,5}, -- UCI Women’s WorldTeam
		["Q2466826"] = {28,29,13}, -- UCI Women’s Team
		["Q26849121"] = {30,31,14} -- Women's amateur cycling team
	}

	local p1923 = mw.wikibase.getBestStatements(raceID, 'P1923') -- P1923 is participating teams
	local no = 0 -- Index used for stable sorting
	for _, v in pairs(p1923) do
		if v.mainsnak.snaktype == 'value' then
			no = no + 1
			local teamLink, teamCat, countryID = getTeamLinkCat(v.mainsnak.datavalue.value.id, timeOfRace, true, true)
			local flagImage = countryID and flag(countryID, timeOfRace) or ''
			teams[#teams + 1] = {flagImage .. ' ' .. teamLink, teamCat,
				teamCats[teamCat] and teamCats[teamCat][3] or 999, no}
		end
	end

	table.sort(teams, function(a,b)
		if a[3] < b[3] then return true end -- First sort key: Order from table teamCats
		if a[3] > b[3] then return false end
		return a[4] < b[4] -- Second key is the index to ensure stable sorting
	end)

	local function getHeader(CatID, count)
		local header, sitelink
		if teamCats[CatID] then
			if count == 1 then
				header_label = headoftableIII(teamCats[CatID][1]) -- singular name
			else
				header_label = headoftableIII(teamCats[CatID][2]) -- plural name
			end
			if CatID=='Q78464255' then
				sitelink=wikibase.getSitelink('Q382927') --continental
			else
				sitelink=wikibase.getSitelink(CatID)
			end

			if sitelink ~= nil then 
				header = '[['..sitelink..'|'..header_label..']]'
			else
				header= header_label
			end
		end

		local tHeader=  mw.html.create('span'):css('font-size','1.2em'):css('font-weight','bold')
		if not header then
			-- Unknown team category. Get the label for the entity to display if possible
			header = (CatID and getLabelFallback(CatID, {wikilang, 'en', 'fr', 'de'})) or 'Unknown team category'
			tHeader:css('text-transform','capitalize')
		end
		tHeader:wikitext(header)
		
		-- Set parameter to show team count in front of each category
		local tTag=''
		local showcounter = 2
		if count >= showcounter then
			tTag=mw.html.create('small'):wikitext(' (' .. count ..')')
		end
		return tostring(tHeader)..tostring(tTag)
	end

	local oldOrder = 0
	local oldCatID
	local count = 0
	local list = ''
	local header
	
	local resulttable = mw.html.create('table')
	:cssText("max-width:95%; padding:0.5em; margin-right:1em; border:1px solid rgb(200,200,200)")
	local tCell = resulttable:tag('tr'):tag('td')

	for _, team in ipairs(teams) do
		local order = team[3]
		if order ~= oldOrder then --new cat
			if oldOrder > 0 then
				header = getHeader(oldCatID, count)
				tCell:wikitext(header)
				tCell:node(tOl)
			end
			count = 1
			oldOrder = order
			tOl = mw.html.create('ol') --reinit
		else
			count = count + 1
		end
		oldCatID = team[2]
        tOl:tag('li')
		:cssText("text-indent:0em;width:20em;display:inline-block;vertical-align:text-top")
		:wikitext(team[1])
	end
	--add last row
	header = getHeader(oldCatID, count)
	tCell:wikitext(header)
	tCell:node(tOl)

	local tableFooter1=mw.html.create('tr')
	tCell=tableFooter1:tag('td')
	:addClass('navigation-only')
	:attr('colspan',2)
	:cssText('border-top: 2px #FFDF80 solid; font-size: 80%;')
	tCell:tag('span'):css("float",floattable)
	:wikitext('[[File:Wikidata-logo S.svg|12px|link=d:' ..raceID .. '#P1923]]')
	
	resulttable:node(tableFooter1)
	return resulttable
end

--== F) Classifications
function p.UCIclassification(frame)
	local s = {
		header_function = headoftableII, -- translations are in function headoftableII
		header_1 = 19, -- translation 10 in function headoftableII is printed in the upper part of the table header
		header_2 = {1, 2, 7}, -- translations 1, 2, 3, 7 in function headoftableII are printed in this order in the lower part of the table header
		item = string.gsub(frame.args[1] or frame:getParent().args[1], "%c", ""),
		property = 'P3494', -- property to use for this table
		team_classification = false, -- it is not a team classification table, its a rider classification table
		background = 'color', -- there is a background color for the first row
		displayteam=false
		}
	return new_classification(frame, s)
end

function p.pointsclassification(frame)
	local s = {
		header_function = headoftableII, -- translations are in function headoftableII
		header_1 = 10, -- translation 10 in function headoftableII is printed in the upper part of the table header
		header_2 = {1, 2, 3, 7}, -- translations 1, 2, 3, 7 in function headoftableII are printed in this order in the lower part of the table header
		item = string.gsub(frame.args[1], "%c", ""),
		property = 'P3494', -- property to use for this table
		team_classification = false, -- it is not a team classification table, its a rider classification table
		background = 'color' -- there is a background color for the first row
		}
	return new_classification(frame, s)
end

function p.teamsclassificationbytime(frame)
	local s = {
		header_function = headoftableII, -- translations are in function headoftableII
		header_1 = 14, -- translation 10 in function headoftableII is printed in the upper part of the table header
		header_2 = {3, 2, 4}, -- translations 3, 2, 4 in function headoftableII are printed in this order in the lower part of the table header
		item = frame.args[1],
		property = 'P3497', -- property to use for this table
		team_classification = true, -- it is a team classification table, its not a rider classification table
		background = 'strong' -- there is no background color for the first row, but the first row is formated strong
	}
	return new_classification(frame, s)
end

function p.teamsclassificationbypoints(frame)
	local s = {
		header_function = headoftableII, -- translations are in function headoftableII
		header_1 = 15, -- translation 10 in function headoftableII is printed in the upper part of the table header
		header_2 = {3, 2, 7}, -- translations 3, 2, 7 in function headoftableII are printed in this order in the lower part of the table header
		item = frame.args[1],
		property = 'P3496', -- property to use for this table
		team_classification = true, -- it is a team classification table, its not a rider classification table
		background = 'strong' -- there is no background color for the first row, but the first row is formated strong
		}
	return new_classification(frame, s)
end

function p.stageclassification(frame)
	local s = {
		header_function = headoftableII, -- translations are in function headoftableII
		header_1 = 8, -- translation 10 in function headoftableII is printed in the upper part of the table header
		header_2 = {1, 2, 3, 4}, -- translations 1, 2, 3, 4 in function headoftableII are printed in this order in the lower part of the table header
		item = frame.args[1],
		property = 'P2417', -- property to use for this table
		team_classification = false, -- it is not a team classification table, its a rider classification table
		background = false, -- there is no background color for the first row
		display_ref = tonumber(frame.args[2]) == 0 and 0 or 1
		}
	return new_classification(frame, s)
end

function p.generalclassification(frame)
	local s = {
		header_function = headoftableII, -- translations are in function headoftableII
		header_1 = 9, -- translation 10 in function headoftableII is printed in the upper part of the table header
		header_2 = {1, 2, 3, 4}, -- translations 1, 2, 3, 4 in function headoftableII are printed in this order in the lower part of the table header
		item = frame.args[1],
		property = 'P2321', -- property to use for this table
		team_classification = false, -- it is not a team classification table, its a rider classification table
		background = 'color', -- there is a background color for the first row
		display_ref = tonumber(frame.args[2]) == 0 and 0 or 1
		}
	return new_classification(frame, s)
end

function p.generalclassificationforttt(frame)
	local s = {
		header_function = headoftableII, -- translations are in function headoftableII
		header_1 = 9, -- translation 10 in function headoftableII is printed in the upper part of the table header
		header_2 = {3, 2, 4, 5, 6}, -- translations 3, 2, 4, 5, 6 in function headoftableII are printed in this order in the lower part of the table header
		item = frame.args[1],
		property = 'P2321', -- property to use for this table
		team_classification = true, -- it is a team classification table, its not a rider classification table
		background = false, -- there is no background color for the first row
		display_ref = tonumber(frame.args[2]) == 0 and 0 or 1
	}
	return new_classification(frame, s)
end

function p.teamtimetrialclassification(frame)
	local s = {
		header_function = headoftableII, -- translations are in function headoftableII
		header_1 = 8, -- translation 10 in function headoftableII is printed in the upper part of the table header
		header_2 = {3, 2, 4, 5, 6}, -- translations 3, 2, 4, 5, 6 in function headoftableII are printed in this order in the lower part of the table header
		item = frame.args[1],
		property = 'P2417', -- property to use for this table
		team_classification = true, -- it is a team classification table, its not a rider classification table
		background = false, -- there is no background color for the first row
		display_ref = tonumber(frame.args[2]) == 0 and 0 or 1
	}
	return new_classification(frame, s)
end

function p.mountainsclassification(frame)
	local s = {
		header_function = headoftableII, -- translations are in function headoftableII
		header_1 = 11, -- translation 10 in function headoftableII is printed in the upper part of the table header
		header_2 = {1, 2, 3, 7}, -- translations 1, 2, 3, 7 in function headoftableII are printed in this order in the lower part of the table header
		item = string.gsub(frame.args[1], "%c", ""),
		property = 'P4320', -- property to use for this table
		team_classification = false, -- it is not a team classification table, its a rider classification table
		background = 'color' -- there is a background color for the first row
		}
	return new_classification(frame, s)
end

function p.sprintsclassification(frame)
	local s = {
		header_function = headoftableII, -- translations are in function headoftableII
		header_1 = 12, -- translation 10 in function headoftableII is printed in the upper part of the table header
		header_2 = {1, 2, 3, 7}, -- translations 1, 2, 3, 7 in function headoftableII are printed in this order in the lower part of the table header
		item = string.gsub(frame.args[1], "%c", ""),
		property = 'P4322', -- property to use for this table
		team_classification = false, -- it is not a team classification table, its a rider classification table
		background = 'color' -- there is a background color for the first row
		}
	return new_classification(frame, s)
end

function p.bestyoungclassificationbypoints(frame)
	local s = {
		header_function = headoftableII, -- translations are in function headoftableII
		header_1 = 13, -- translation 10 in function headoftableII is printed in the upper part of the table header
		header_2 = {1, 2, 3, 7}, -- translations 1, 2, 3, 7 in function headoftableII are printed in this order in the lower part of the table header
		item = string.gsub(frame.args[1], "%c", ""),
		property = 'P4323', -- property to use for this table
		team_classification = false, -- it is not a team classification table, its a rider classification table
		background = 'color' -- there is a background color for the first row
		}
	return new_classification(frame, s)
end

function p.bestyoungclassification(frame)
	local s = {
		header_function = headoftableII, -- translations are in function headoftableII
		header_1 = 13, -- translation 10 in function headoftableII is printed in the upper part of the table header
		header_2 = {1, 2, 3, 4}, -- translations 1, 2, 3, 7 in function headoftableII are printed in this order in the lower part of the table header
		item = string.gsub(frame.args[1], "%c", ""),
		property = 'P4323', -- property to use for this table
		team_classification = false, -- it is not a team classification table, its a rider classification table
		background = 'color' -- there is a background color for the first row
		}
	return new_classification(frame, s)
end

function p.u23classification(frame)
	local s = {
		header_function = headoftableII, -- translations are in function headoftableII
		header_1 = 18, -- translation 10 in function headoftableII is printed in the upper part of the table header
		header_2 = {1, 2, 3, 4}, -- translations 1, 2, 3, 7 in function headoftableII are printed in this order in the lower part of the table header
		item = string.gsub(frame.args[1], "%c", ""),
		property = 'P4323', -- property to use for this table (same as best young classification)
		team_classification = false, -- it is not a team classification table, its a rider classification table
		background = 'color' -- there is a background color for the first row
		}
	return new_classification(frame, s)
end

function p.combinationclassification(frame)
local s = {
		header_function = headoftableII, -- translations are in function headoftableII
		header_1 = 16, -- translation 10 in function headoftableII is printed in the upper part of the table header
		header_2 = {1, 2, 3, 7}, -- translations 1, 2, 3, 7 in function headoftableII are printed in this order in the lower part of the table header
		item = string.gsub(frame.args[1], "%c", ""),
		property = 'P4324', -- property to use for this table
		team_classification = false, -- it is not a team classification table, its a rider classification table
		background = 'color' -- there is a background color for the first row
		}
	return new_classification(frame, s)
end

function p.combativeclassification(frame)
	local s = {
		header_function = headoftableII, -- translations are in function headoftableII
		header_1 = 17, -- translation 10 in function headoftableII is printed in the upper part of the table header
		header_2 = {1, 2, 3, 7}, -- translations 1, 2, 3, 7 in function headoftableII are printed in this order in the lower part of the table header
		item = string.gsub(frame.args[1], "%c", ""),
		property = 'P4321', -- property to use for this table
		team_classification = false, -- it is not a team classification table, its a rider classification table
		background = 'color' -- there is a background color for the first row
		}
	return new_classification(frame, s)
end

function p.custompointsclassification(frame)
	local s = {
		header_function = headoftableII, -- translations are in function headoftableII
		header_2 = {1, 2, 3, 7}, -- translations 1, 2, 3, 7 in function headoftableII are printed in this order in the lower part of the table header
		header_1_text=string.gsub(frame.args[3], "%c", ""),
		item = string.gsub(frame.args[1], "%c", ""),
		property = string.gsub(frame.args[2], "%c", ""), -- property to use for this table
		team_classification = false, -- it is not a team classification table, its a rider classification table
		background = 'color' -- there is a background color for the first row
		}
	return new_classification(frame, s)
end

function p.customtimeclassification(frame)
	local s = {
		header_function = headoftableII, -- translations are in function headoftableII
		header_2 = {1, 2, 3, 4}, -- translations 1, 2, 3, 7 in function headoftableII are printed in this order in the lower part of the table header
		header_1_text=string.gsub(frame.args[3], "%c", ""),
		item = string.gsub(frame.args[1], "%c", ""),
		property = string.gsub(frame.args[2], "%c", ""), -- property to use for this table
		team_classification = false, -- it is not a team classification table, its a rider classification table
		background = 'color' -- there is a background color for the first row
		}
	return new_classification(frame, s)
end

function new_classification(frame, s)
	local country = true
	for _, value in pairs(no_country_classification) do -- get data if country should be printed in this wiki
		if value == wiki then country = false end
	end
	local raceID = s.item

	--[=[ It is possible to give the classification tables in the article commands to change the standard behaviour. They could look like this:
	{{Cycling race/teamsclassificationbytime|Q18574623|newline=false|country=true}}
	{{Cycling race/teamsclassificationbytime|Q18574623|country= false|newline=false}}
	{{Cycling race/teamsclassificationbypoints|Q18574623|newline =true|country=true}}
	{{Cycling race/teamsclassificationbypoints|Q18574623|newline= true}}
	{{Cycling race/teamsclassificationbypoints|Q18574623|newline = false|country=false}}
	{{Cycling race/teamsclassificationbytime|Q18574623|newline=true|country=true}}

	One additional parameter is "newline" with the values "true" or "false". "newline" says, if there is a line brake after the table. Standard is
	no line break after the tables stageclassification and teamtimetrialclassification.
	The second parameter is "country" with the values "true" or "false". "country" tells the module to print the country column or not.
	Most wikis have as standard to print the country columns, some wikis prefer as standard not to show the country column. A few lines above,
	the command "if wiki == 'da' then country = false end" tells that daWiki do not want to see the country colums as standard. You can add your wiki
	here in, if you do not want to see them as standard. With the new parameter editors are able to tell the module in the article what to do.
	]=]

	local timeOfRace, errorMessage = gettimeOfRace(raceID)
	if not timeOfRace then return errorMessage end

	local plus = ''
	if string.match(frame:getParent():getTitle(), '%P+') == mw.site.namespaces.Template.name
	then localframe = frame:getParent() else localframe = frame end
	if localframe.args[1] ~= nil then localframe.args[1] = string.gsub(localframe.args[1], "%c", "") end

	if localframe.args.country ~= nil then -- switch country column on or off in the article
		if localframe.args.country == 'true' then country = true end
		if localframe.args.country == 'false' then country = false end
	end
	local tableHeader2_size = #s.header_2

	if s.header_1_text ==nil then s.header_1_text=s.header_function(s.header_1) end --for custom title

	local tableBody = mw.html.create('table')
		:addClass('sortable')
		:attr('cellpadding', '0')
		:attr('cellspacing', '0')
		:css('border' , '0')

	local thisspan= mw.html.create('span'):cssText('float:left;'):wikitext('[[File:Wikidata-logo S.svg|12px|link=d:'.. raceID .. '#' .. s.property..']]')
	tableBody:tag('tr'):tag('th')
    :attr('colspan', tostring(tableHeader2_size + 1)):cssText("padding:2px 2px; text-align:center; background-color:#FFDF80")
	:wikitext(tostring(thisspan)..s.header_1_text)

	header= tableBody:tag('tr'):cssText("text-align:center;padding:2px 2px;white-space:nowrap")
	for i, k in ipairs(s.header_2) do
		if i ~= 2 or (country and available_list) then
			local head=header:tag('th'):wikitext(s.header_function(k))
			if i == 1 then
				head:attr('colspan','2')
			end
		end
	end

	local t_Body = {} --contains all rows
	local tCell, bg_color, tStyle, temp, temp2
	local claims = mw.wikibase.getAllStatements(raceID, s.property)
	for l, m in pairs(claims) do -- look into all statements
		if m.mainsnak.snaktype == 'value' then
			local riderID = m.mainsnak.datavalue.value.id
			local q = m.qualifiers or {}
			local rank, riderLink, gender, countryID, teamLink
			local flagLink, countryName = '', ''
			local h = {
				jersey = {}, -- lots of jerseyID
				value = {'', '', '', ''} -- points, time, time_gap, speed
			}
			
			if q.P1352 and q.P1352[1].snaktype == 'value' then -- P1352 is ranking
				rank = tonumber(q.P1352[1].datavalue.value.amount)
			else
				rank = ''
			end

			local cancelled=isdisqualified(m,q)

			if wiki == 'es' or wiki == 'fr' or wiki == 'ast' then
				--[[ These wikis need the gender to display the rank correct. Other wikis can skip this. ]]
				gender = getgendercode(riderID, 'n')
			end

			h.value[1] = qualifieramount(m, 'P1358')
			h.value[2] = qualifieramount(m, 'P2781')
			if q.P2911 and q.P2911[1].snaktype == 'value' then -- P2911 is time gap
				h.value[3] = tonumber(q.P2911[1].datavalue.value.amount)
				plus = '+ '
			end
			h.value[4] = qualifieramount(m, 'P2052')
			if q.P2912 then -- P2912 is distinctive jersey
				for _, v in pairs(q.P2912) do
					if v.snaktype == 'value' then
						table.insert(h.jersey, v.datavalue.value.id)
					end
				end
			end

			if s.team_classification then
				local _
				teamLink, _, countryID = getTeamLinkCat(riderID, timeOfRace, true)
			else
				riderLink = getRiderLink(riderID,timeOfRace)..(getReference(m) or '')
				teamLink = getTeam(riderID, timeOfRace, q)
				local p27 = getStatementForTime(riderID, 'P27', timeOfRace) --P27 is country of citizenship
				if p27 then
					countryID = p27.mainsnak.datavalue.value.id
				end
			end
			if countryID then
				flagLink = flag(countryID, timeOfRace)
				if available_list and country then
					if type(translations.list) == "function" then
						countryName = translations.list(countryID)
					end
					if countryName == '' then
						local label, lang = mw.wikibase.getLabelWithLang(countryID)
						--[[ Uses standard language fallback. Should not be nil, as all countries have English labels. ]]
						if lang == wikilang then
							countryName = label
						else
							countryName = label .. ' (' .. lang .. ')'
						end
					end
				end
			end

			-- find the right background color if a rider has more then one jersey
			-- see Wikidata:WikiProject Cycling/Kit to translate/Jerseys
			bg_color=nil
			if h.jersey[1] then
				if wiki == "ca" then bg_color_table["Q24257763"] = "lightpink" end
				for _, jersey in pairs(h.jersey) do
					if bg_color_table[jersey] then
						bg_color = bg_color_table[jersey]
						break
					end
				end
			end
			
			tStyle=''
			if rank == 1 then
				if s.background then -- values are 'strong' or 'color'
					tStyle = tStyle ..'font-weight:bold;' -- winner is formated bold
					if s.background == 'color' then
						if h.jersey[1] and bg_color then -- background color of winner depending on jersey
							tStyle = tStyle .. 'background-color:' ..bg_color
						end
					end
				end
			end

			local tBody = mw.html.create('tr'):cssText(tStyle) -- a row
			tBody:tag('td'):cssText("text-align:center;padding:2px 0.5em 2px 0.5em;white-space:nowrap;"..cancelled)
			:wikitext(number(gender, rank, wiki))
			tCell= tBody:tag('td'):cssText("text-align:" .. textalign .. ";padding:0 0.2em 0 0.2em;"..cancelled)

			if not s.team_classification then
				if not teamLink then teamLink = '' end
				if not available_list then
					tCell:wikitext(flagLink .. ' '.. riderLink .. jersey(h.jersey))
					if s.displayteam~=false then
						tBody:tag('td'):wikitext(teamLink)
					end
				else
					if country == true then
						tCell:wikitext(riderLink .. jersey(h.jersey) )
						tBody:tag('td'):wikitext( flagLink ..' '.. countryName)
					else
						tCell:wikitext(flagLink .. ' ' .. riderLink .. jersey(h.jersey))
					end
					if s.displayteam~=false then
						tBody:tag('td'):cssText("text-align:".. textalign ..";padding:0 0.2em 0 0.2em")
						:wikitext(teamLink)
					end
				end
			else --team
				if available_list==true and country then
					tCell:wikitext(teamLink .. jersey(h.jersey))
					tBody:tag('td'):wikitext(flagLink .. ' ' .. countryName)
				else
					tCell:wikitext(flagLink .. ' ' .. teamLink .. jersey(h.jersey))
				end
			end

			if s.header_2[4] == 4 then -- for table stageclassification, generalclassification, adds time and time gap
				if rank == 1 and h.value[2] then
					temp=calculate_time(h.value[2])
				elseif rank == 1 and h.value[3]==nil then --avoid a plus with nothing
					temp=''
				else
					temp=plus .. calculate_time(h.value[3])
				end
				tBody:tag('td'):cssText("text-align:right;padding:0 0.2em 0 0.2em"):wikitext(temp)
			end

			if s.header_2[4] == 7 or (s.header_2[3] == 7 and s.header_2[1] == 1) then -- for table pointsclassification, adds points
				--trick for UCI classification
				if h.value[1] then temp=h.value[1] else temp='' end
				tCell=tBody:tag('td'):cssText("text-align:right;padding:0 0.2em 0 0.2em")
				:wikitext(temp)	
				if type(h.value[1]) == "number" then
					if h.value[1] > 1 then
						temp2=unit(7)
					else
						temp2=unit(6)
					end
					tCell:tag('span'):cssText("font-size:80%"):wikitext(temp2)	
				end
			end

			if s.header_2[3] == 4 then
				if s.property == 'P2417' or s.property == 'P2321' then
					-- for tables teamtimetrialclassification or generaltttclassification, adds time
					tBody:tag('td'):cssText("text-align:right;padding:0 0.2em 0 0.2em")
					:wikitext(calculate_time(h.value[2]))
				end
			end

			if s.property == 'P3497' then -- for table teambytimeclassification, adds time and time gap
				if rank == 1 then 
					temp=calculate_time(h.value[2])
				else
					temp=calculate_time(h.value[3])
				end
				tBody:tag('td'):cssText("text-align:right;padding:0 0.2em 0 0.2em"):wikitext(temp)
			end

			if s.property == 'P3496' then -- for table teambypointsclassification, adds points
				tCell=tBody:tag('td'):cssText("text-align:right;padding:0 0.2em 0 0.2em")
			    :wikitext(h.value[1])
				if type(h.value[1]) == "number" then
					if h.value[1] > 1 then
						temp2=unit(7)
					else
						temp2=unit(6)
					end
					tCell:tag('span'):cssText("font-size:80%"):wikitext(temp2)	
				end
			end

			if s.header_2[4] == 5 then -- for table teamtimetrialclassification, adds time gap
				if l > 1 then temp= plus else temp='' end
				tBody:tag('td'):cssText("text-align:right;padding:0 0.2em 0 0.2em"):wikitext(temp..calculate_time(h.value[3]))	
			end

			if s.header_2[5] == 6 then -- for table teamtimetrialclassification, adds speed
				tCell=tBody:tag('td'):cssText("text-align:right;padding:0 0.2em 0 0.2em")
				if type(h.value[4]) == "number" then 
					tCell:wikitext(mw.ustring.format('%.3f', h.value[4]))
					:tag('span'):cssText("font-size:80%"):wikitext(unit(5))
				end
			end
			t_Body[#t_Body + 1] = {(type(rank) == 'number') and rank or 999, tostring(tBody)}
		end
	end
	
    tableBody=sortandconcat(t_Body, tableBody)
	local tableFooter1,tableFooter2
	if s.display_ref == 1 then
		tableFooter1=mw.html.create('tr')
		tCell=tableFooter1:tag('td')
		:addClass('navigation-only')
		:attr('colspan',tostring(tableHeader2_size + 1))
		:cssText('border-top: 2px #FFDF80 solid; font-size: 80%;')
		tableFooter2=mw.html.create('tr')
		tCell=tableFooter2:tag('td')
		:attr('colspan',tostring(tableHeader2_size + 1))
		:cssText("text-align:right")
		tCell:tag('small')
		:wikitext(race_reference(raceID))
	end
	
	--general table style and last line
	local tableStyle, tableNewline
	if localframe.args.newline == 'false' then -- parameter newline in WP article is 'false'
		tableStyle = "float:" .. floattable .. "; margin-right:0.5em; border:1px solid rgb(200,200,200)"
		tableNewline = ''
	end
	if localframe.args.newline == 'true' then -- parameter newline in WP article is 'true'
		tableStyle = "border:1px solid rgb(200,200,200)"
		tableNewline = '<br style="clear:left;">'
	end
	if localframe.args.newline == nil then -- no second parameter, compatible to the old code
		if s.property == 'P2417' then --stageclassification
			tableStyle = "float:"..floattable.."; margin-right:0.5em; border:1px solid rgb(200,200,200)"
			tableNewline = ''
		else
			tableStyle = "border:1px solid rgb(200,200,200)"
			tableNewline = '<br style="clear:left;">' -- everything else
		end
	end

	local finalTable= mw.html.create('table'):cssText(tableStyle)
	finalTable:tag('tr'):tag('td')
	:node(tableBody)
	if tableFooter1 then
		finalTable:node(tableFooter1)
		finalTable:node(tableFooter2)
	end

	return tostring(finalTable)..tableNewline
end

--=== G) Infobox ===
function p.infobox(frame)
	localframe = frame
	-- If true, winners will have Wikidata logos with link to Wikidata
	local WDlink_on = (wiki == "mk" or wiki == "ja")

	-- If true, winners will the team of the cyclist
	local team = true

	local details = {
		{ name = infobox_translate(2)}, -- course
		{ name = infobox_translate(3), name_plural = infobox_translate(4)}, -- competition
		{ name = infobox_translate(5)}, -- stages
		{ name = infobox_translate(6), name_plural = infobox_translate(7)}, -- date
		{ name = infobox_translate(8)}, -- distance
		{ name = infobox_translate(9), name_plural = infobox_translate(10)}, -- country
		{ name = infobox_translate(11)}, -- start place
		{ name = infobox_translate(12)}, -- endplace
		{ name = infobox_translate(13)}, -- teams
		{ name = infobox_translate(14)}, -- participants at start
		{ name = infobox_translate(15)}, -- participants at end
		{ name = infobox_translate(16)}, -- speed
		{ name = infobox_translate(43)}, -- elevation
		{ name = infobox_translate(17)}, -- cost
		{ name = infobox_translate(32), special = true}, -- special 1
		{ name = infobox_translate(33), special = true}, -- special 2
	}
	local others = {
		{ name = infobox_translate(29)}, -- picture
		{ name = infobox_translate(30)}, -- caption
		{ name = infobox_translate(31)}, -- map
		{ name = 'sectional_view '}
	}
	local winners = {
		{ name = infobox_translate(19), QID = 'Q20882667' }, -- first
		{ name = infobox_translate(20), QID = 'Q20882668' }, -- second
		{ name = infobox_translate(21), QID = 'Q20882669' }, -- third
		{ name = infobox_translate(22), QID = 'Q20883007' }, -- points
		{ name = infobox_translate(23), QID = 'Q20883212' }, -- mountains
		{ name = infobox_translate(24), QID = 'Q20883328' }, -- sprints
		{ name = infobox_translate(25), QID = 'Q20883139' }, -- youth
		{ name = infobox_translate(26), QID = 'Q20893983' }, -- combativity
		{ name = infobox_translate(35), QID = 'Q27067359' }, -- volantes
		{ name = infobox_translate(36), QID = 'Q27067170' }, -- regularity
		{ name = infobox_translate(27), QID = 'Q20893979' }, -- combination
		{ name = infobox_translate(38), QID = 'Q27907715' }, -- breakaway
		{ name = infobox_translate(39), QID = 'Q27907747' }, -- azzurri
		{ name = infobox_translate(40), QID = 'Q28092831' }, -- rookie
		{ name = infobox_translate(28), QID = 'Q20882921' }, -- teams
		{ name = infobox_translate(37), QID = 'Q27104269' }, -- teamspoints
		{ name = infobox_translate(41), QID ='Q61976850' },-- amateur
		{ name = infobox_translate(42), QID ='Q61976872' } --nationality
	}

	local entityID = mw.text.trim(frame.args[1])
	local wikibase = mw.wikibase
	if type(entityID) ~= 'string' then error('parameter must be a string') end
	if not entityID:match('Q%d+') then error ('parameter must be a valid Wikidata item (ex: Q42)') end

	local localframe
	if string.match(frame:getParent():getTitle(), '%P+') == mw.site.namespaces.Template.name then
		localframe = frame:getParent()
	else
		localframe = frame
	end
	getLocalContent(details, localframe.args)
	getLocalContent(others, localframe.args)
	getLocalContent(winners, localframe.args)

	local timeOfRace, class
	local icon = (firstValue(entityID, 'P641', 'numeric-id') == 3609) and -- P641 is 'sport', Q3609 is 'road bicycle racing'
		' [[File:Cycling (road) pictogram.svg|35px]]' or ''

	local name =  getLabelFallback(entityID, {wikilang, 'en', 'fr', 'de'}) or ''
	infoGetOthers(others, entityID)	

	if not details[1].content then -- course
		-- For FR Wiki and Wikidata, exception that permit to display 1er, 2e... for the edition number ;
		-- for RU Wiki, -й is written after the value of P393
		local nr = firstValue(entityID, 'P393') -- P393 is 'edition number'
		if nr then
			if wiki == 'fr' then nr = (nr == 1) and "1<sup>re</sup> " or (nr .. "<sup>e</sup> ")
			elseif wiki == "nl" then nr = nr .. "e "
			elseif wiki == "ru" then nr = nr .. "-й "
			elseif wiki == "eo" then nr = nr .. "-a "
			elseif wiki == "hu" then nr = nr .. ". "
			else nr = nr .. ". "
			end
		end
		local is_a
		for _, p31 in statements(entityID, 'P31') do -- P31 is 'instance of'
			local instanceOf = p31.mainsnak.datavalue.value.id
			if instanceOf == 'Q27968055' then -- Q27968055 is 'recurrent event edition'
				-- do nothing
			elseif classes[instanceOf] then
				class = classLink(instanceOf)
			elseif instanceOf == "Q27020041" then -- Q27020041 is 'sports season'
				local season = firstValue(entityID, 'P3450', 'id') -- P3450 is 'sports season of league or competition'
				if season then
					is_a = raceLink(season)
				end
			else
				is_a = raceLink(instanceOf)
			end
		end
		if nr and is_a then
			details[1].content = nr .. ' ' .. is_a
		end
	end

	if not details[2].content then -- competition
		-- Class of a cycling race. Class is: 1.UWT, 2.UWT, 1.HC, ... add new classes, no problem
		-- Competition of the cycling race : UCI World Tour 2016, UCI Europe Tour 2016...
		local tours = {}
		for _, p361 in statements(entityID, 'P361') do -- P361 is 'part of'
			tours[#tours + 1] = raceLink(p361.mainsnak.datavalue.value.id)
		end
		if tours[1] then
			if #tours > 1 then
				details[2].name = details[2].name_plural
			end
			if class then
				tours[1] = tours[1] .. ' ' .. class
			end
			details[2].content = table.concat(tours, '<br/>')
		end
	end

	if not details[3].content then -- stages
		local stages = #wikibase.getAllStatements(entityID, 'P527') -- P527 is 'has part'
		if stages > 0 then
			details[3].content = stages
		end
	end

	if not details[4].content then -- date
		local sTime = firstValue(entityID, 'P580', 'time') -- P580 is 'start time'
		local eTime = firstValue(entityID, 'P582', 'time') -- P582 is 'end time'
		if sTime and eTime then
			local startTime, endTime = getStartEndTime(sTime, eTime)
			details[4].content = startTime .. ' – ' .. endTime
			details[4].name = details[4].name_plural
			timeOfRace = eTime
		else
			-- This function give a format to dates when P585 (date) is used in a single day race
			local pTime = firstValue(entityID, 'P585', 'time') -- P585 is 'point in time'
			if pTime then
				details[4].content = func_date(pTime, 'long')
				timeOfRace = pTime
			end
		end
	end
	
	local kmdistance
	if not details[5].content then details[5].content, kmdistance = getDistance(entityID, true) end -- distance

	infoGetCountry(details,6, entityID, timeOfRace)
	infoGetStartEnd(details,7, entityID)

	if not details[9].content then -- teams
		local teams = #wikibase.getBestStatements(entityID, 'P1923') -- P1923 is 'participating teams'
		if teams > 0 then
			details[9].content = teams
		end
	end

	infoGetParticipants(details,10, entityID)
	if not details[10].content or not details[11].content then
		local Allp710= wikibase.getAllStatements(entityID, 'P710')
		if Allp710 and #Allp710~=0 then
			if not details[10].content then details[10].content=#Allp710 end
			if not details[11].content then
				local maxrank=1
				for _, p710 in pairs(Allp710) do -- look into all statements
					local q = p710.qualifiers
					if q and q.P1352 and q.P1352[1].snaktype == 'value' then -- P1352 is ranking
						local riderRank = tonumber(q.P1352[1].datavalue.value.amount)
						if riderRank > maxrank then maxrank = riderRank end
					end
				end
				if maxrank~=1 then details[11].content=maxrank end
			end
		end
	end

	if not details[12].content then details[12].content = getSpeed(entityID, true, kmdistance, 'P2321') end --speed
	if not details[13].content then 
		local elevation=getElevation(entityID) 
		if  elevation then details[13].content =elevation else details[13].content = nil end
	end --Elevation
	
	if not details[14].content then -- cost
		local cost = firstValue(entityID, 'P2130') -- P2130 is cost
		if cost then
			local unit = cost.unit
			cost = contentLanguage:formatNum(tonumber(cost.amount))
			if wiki == 'fo' then cost = string.gsub(cost, "%.", ",") end
			if unit == "http://www.wikidata.org/entity/Q4916" then cost = cost .. ' €'
			elseif unit == "http://www.wikidata.org/entity/Q4917" then cost = cost .. ' $'
			end
			details[14].content = cost
		end
	end

	tab = infoInitTab("300px", name, icon)
	infoFillOthersDetails(tab, others, details,infobox_translate(1))
	
	local winRows=''
	local win = {}
	for _, v in pairs(winners) do
		if not v.content then
			win[v.QID] = ''
		end
	end
	winner(entityID, win, timeOfRace, false, WDlink_on, team, true)
	for _, v in pairs(winners) do
		if not v.content then
			if win[v.QID] ~= '' then
				v.content = win[v.QID]
			end
		end
		if v.content then
			tRow= mw.html.create('tr') :css('vertical-align','top')
			tRow:tag('td'):css('font-weight','bold'):wikitext(v.name)
			tRow:tag('td'):wikitext(v.content)
			winRows=winRows..tostring(tRow) --not elegant
		end
	end
	if winRows~= '' then
		tab:tag('tr'):tag('td'):attr('colspan','2')
		:cssText('border-bottom:5px solid white; background-color:#FFDF80; text-align:center')
		:css('font-weight','bold')
		:wikitext(infobox_translate(18))
		tab:wikitext(winRows)
	end

	if others[3].content then -- map
		tab:tag('tr'):tag('td'):attr('colspan','2'):css('text-align','center')
		:wikitext("[[File:".. others[3].content .. "|center|300px]]")
	end
	
	tab:node(getPreviousNextLine(entityID))
	wdDoc(tab, "d:Wikidata:WikiProject Cycling/Documentation/infobox", infobox_translate(34), entityID)
	return tab
end

--=== H) Team roster
function p.teamroster(frame)
	localframe=frame
	local squadID
	if frame.args[1] then squadID = string.gsub(frame.args[1], "%c", "") end
	local flags, pays = {}, {}
	local riderName, riderBirthday,riderTeam, timeTeam, correctlanguage,riderStart, riderEnd
	local riderPosition, riderReason, riderRef, errorbool, errortext
	local riderReasonTable, riderTablecorrect, riderTablenotcorrect, riderTable = {}, {}, {}, {}
	local labelMissing = false
	local teamID, startOfSeason, stagiaire

	local slavicWikis = {mk = true, ru = true}
	local wikiisslavic = slavicWikis[wiki]
	local WDlink_on = wiki == "mk" or wiki == "ja" or wiki == "ru" or wiki == "he"

	local function getreason(riderReason, riderRef, p527)
		local listofproperty={'P1642','P1643','P1534'}
		local outputTable={}

		if riderReason == nil then --if no riderReason before then look for it, otherwise don't touch it
			for _,v in ipairs(listofproperty) do
				for _, q in qualifiers(p527, v) do
					riderReason = q.value.id
				end
			end
			if riderReason then
				local label = string.gsub(wikibase.label(riderReason), "%b()", "") or getLabelFallback(riderReason,{'en', 'fr', 'de'})
				riderRef = getReference(p527, 1)
				riderReason = ', ' .. label
			end
		end
		return riderReason, riderRef
	end

	local function getposition(riderPosition,v)
		local stagiaire
		if riderPosition == nil then -- find the 'position' (P39) of a rider
			for _, q in qualifiers(v, 'P39') do
				stagiaire = q.value.id
				local label = string.gsub(wikibase.label(stagiaire), "%b()", "") or getLabelFallback(stagiaire,{'en', 'fr', 'de'})
				riderPosition = ', ' .. label
			end
		end
		return riderPosition
	end

	local function trans(date, month, day)
		if date ~= '' and date~=nil then
			local _, _, y, m, d = string.find(date, "(%d+)-(%d+)-(%d+)")
			if m == '00' then m = month end
			if d == '00' then d = day end
			date = '+'..y..'-'..m..'-'..d..'T00:00:00Z'
			return date
		end
		return ''
	end

	local function findlastname(label,wiki)
		if not label then label = '' end
		local _, count = string.gsub(label, " ", " ")
		local names
		local a,b,c,d = '', '', '', ''
		local done = false
		if count ~= nil then count = count + 1 else count = 1 end

		if count > 1 then
			if count == 2 then
				if label ~= '' then
					a, b = string.match(label, "(%S+)%s+(%S+)")
					names = b..' '..a
				end
			else
				local name_parts_mk = {'да', 'ди', 'де', 'Де', 'ла', 'Ле', 'тен', 'ван', 'Ван'}
				local name_parts_ru = {'да', 'ди', 'де', 'Де', 'ла', 'Ле', 'тен', 'ван', 'Ван'}
				local name_parts    = {'da', 'de', 'di', 'De', 'la', 'Le', 'ten', 'van', 'Van'}
				if count == 3 and label ~= '' then
					a, b, c = string.match(label, "(%S+)%s+(%S+)%s+(%S+)")
					if wiki == 'mk' then
						for _,v in ipairs(name_parts_mk) do if b == v then names = b..' '..c..' '..a done = true break end end
					elseif wiki == 'ru' then
						for _,v in ipairs(name_parts_ru) do if b == v then names = b..' '..c..' '..a done = true break end end
					else
						for _,v in ipairs(name_parts) do if b == v then names = b..' '..c..' '..a done = true break end end
					end
					if not done then
						names = c..' '..a..' '..b
						done = true
					end
				end
				if count > 3 and label ~= '' then
					a, b, c, d = string.find(label, "(%S+)%s+(%S+)%s+(%S+)%s+(%S+)")
					if wiki == 'mk' then
						for _,v in ipairs(name_parts_mk) do if c == v then names = c..' '..d..' '..a..' '..b done = true break end end
						for _,v in ipairs(name_parts_mk) do if b == v then names = b..' '..c..' '..d..' '..a done = true break end end
					elseif wiki == 'ru' then
						for _,v in ipairs(name_parts_ru) do if c == v then names = c..' '..d..' '..a..' '..b done = true break end end
						for _,v in ipairs(name_parts_ru) do if b == v then names = b..' '..c..' '..d..' '..a done = true break end end
					else
						for _,v in ipairs(name_parts) do if c == v then names = c..' '..d..' '..a..' '..b done = true break end end
						for _,v in ipairs(name_parts) do if b == v then names = b..' '..c..' '..d..' '..a done = true break end end
					end
					if not done then names = b..' '..c..' '..d..' '..a end
				end
			end
		end
		return names or ''
	end

	local function findsortkey(riderID, correctlanguage, wiki,wikiisslavic)
		--find the last name to sort
		if wikiisslavic and correctlanguage then
			local label = wikibase.getLabelByLang(riderID, wiki)
			if not label then
				label = getLabelFallback(riderID, {'en', 'fr', 'de', 'es'})
				return findlastname(label,wiki)
			else
				local nametable = mw.text.split(label, ",")
				if nametable[2] then --there is a coma so the lastname is first
					return nametable[1]..nametable[2]
				else --no coma
					return findlastname(label,wiki) 
				end
			end
		else
			local label = getLabelFallback(riderID, {'en', 'fr', 'de', 'es'})
			return findlastname(label,wiki)
		end
	end

	local sort
	--[[
	The word 'sort' is used to sort the riders after the surname. It could look like this in the Wikipedia article
	{{Cycling race/teamroster|Q21769847
	| sort
	}}
	A rider called 'Laurens De Vreese' is sorted after 'De Vreese Laurens'. If you want to sort after 'Vreese Laurens De'
	change that in the code. In lvWiki, mkWiki and ruWiki sorting is standard, there is no need to switch sorting on in the article
	]]
	if string.match(frame:getParent():getTitle(), '%P+') == mw.site.namespaces.Template.name
	then localframe = frame:getParent() else localframe = frame end
	if localframe.args[2] ~= nil then
		if mw.ustring.find(mw.ustring.lower(localframe.args[2]), "sort") then sort = true else sort = false end
	end
	if wiki == "lv" or wiki == "mk" or wiki == "ru" then sort = true end

	local temp = firstValue(squadID, 'P361', 'id')
	if temp then teamID = temp end

	temp = firstValue(squadID, 'P580', 'time')
	if temp then
		startOfSeason = temp
	else
		local Sitelink=getSitelinkFallback(squadID,{'en', 'fr', 'de'})
		if Sitelink == nil then return '> Wikidata is missing data about the start time (P580) and end time (P582) of the season'
		else startOfSeason = '+'..string.match(Sitelink, '%d%d%d%d' ) ..'-01-01T00:00:00Z'
		end
	end

	for _, p527 in statements(squadID, 'P527') do
		--re-init
		riderName, riderBirthday, correctlanguage=nil, nil, nil
		riderTeam, timeTeam, riderReason, riderRef=nil, nil, nil, nil
		riderStart, riderEnd=nil, nil

		errortext=''
		local riderID = p527.mainsnak.datavalue.value.id
		riderName, correctlanguage =getRiderLink(riderID, startOfSeason) --label
		if WDlink_on==true then riderName=riderName..wdLink(riderID) end
		local timeOfRace = startOfSeason

		riderBirthday=firstValue(riderID, 'P569','time')

		if not wikiisslavic then correctlanguage=true end  --actually we never take a cyrillic name if no latin is found
		local sortkey = findsortkey(riderID, correctlanguage, wiki, wikiisslavic)

		riderReason, iderRef=getreason(riderReason,riderRef,p527)

		for _, q in qualifiers(p527, 'P580') do
			local startdate = q.value['time']
			timeOfRace = startdate
			riderStart = func_date(trans(startdate,'01', '01'), 'small')
		end
		for _, q in qualifiers(p527, 'P582') do
			local enddate=q.value['time']
			riderEnd = func_date(trans(enddate,'12', '31'), 'small')
		end
		riderPosition=getposition(riderPosition,p527)

		local y1, m1, d1, y2, m2, d2, y3, m3, d3, date1, date2, date2temp
		local changedTime = '+0000-00-00'

		if teamID == nil then
			local p54 = getStatementForTime(riderID, 'P54', timeOfRace)
			if p54 then teamID = p54.mainsnak.datavalue.value.id end
		else
			for _, v in statements(riderID, 'P54') do -- look into all P54 teams
				date1=nil date2=nil date2temp=nil stagiaire=nil errorbool=nil
				local thisteamID = v.mainsnak.datavalue.value.id
				if thisteamID == teamID then
					riderReason, riderRef=getreason(riderReason,riderRef,v)
					if v.qualifiers and v.qualifiers["P580"] and v.qualifiers["P580"][1].snaktype == 'value' then
						date1=v.qualifiers["P580"][1].datavalue.value.time
					end
					date1 = trans(date1,'01','01')
					_, _, y1, m1, d1 = string.find(date1, "(%d+)-(%d+)-(%d+)")
					if v.qualifiers and v.qualifiers["P582"] and v.qualifiers["P582"][1].snaktype == 'value' then
						date2temp=v.qualifiers["P582"][1].datavalue.value.time
					end
					if date2temp==nil then
						if y1==nil then y1='2040' errorbool=2 end
						date2='+'..y1..'-12-31T00:00:00Z'
					else date2=date2temp end
					date2 = trans(date2,'12','31')
					_, _, y2, m2, d2 = string.find(date2, "(%d+)-(%d+)-(%d+)")
					_, _, y3, m3, d3 = string.find(startOfSeason, "(%d+)-(%d+)-(%d+)")
					if (y1 == y3 or y2 == y3) and ((y1 == y3 and (m1 ~= '01' or d1 ~= '01')) or (y2 == y3 and (m2 ~= '12' or d2 ~= '31'))) then
						-- riders who start after 1 January or end earlier then 31 December in the season
						riderStart = func_date(date1, 'small')
						if date2temp==nil then
							if y1==nil then y1='2040' errorbool=1 end
							riderEnd = func_date('+'..y1..'-12-31T00:00:00Z', 'small')
						else
							riderEnd = func_date(date2temp, 'small')
						end
						riderPosition=getposition(riderPosition,v)
					end
				else
					for _, q in qualifiers(v, 'P39') do
						stagiaire =q.value.id
					end
					if not stagiaire then
						if v.qualifiers and v.qualifiers["P580"] and v.qualifiers["P580"][1].snaktype == 'value' then
							date1=v.qualifiers["P580"][1].datavalue.value.time
						end
						date1 = trans(date1,'01','01')
						_, _, y1, m1, d1 = string.find(date1, "(%d+)-(%d+)-(%d+)")
						if v.qualifiers and v.qualifiers["P582"] and v.qualifiers["P582"][1].snaktype == 'value' then
							date2temp=v.qualifiers["P582"][1].datavalue.value.time
							date2=date2temp
						else
							if y1==nil then y1='2040' errorbool=2 end
							date2='+'..y1..'-12-31T00:00:00Z'
						end
						date2 = trans(date2,'12','31')
						_, _, y2, m2, d2 = string.find(date2, "(%d+)-(%d+)-(%d+)")
						_, _, y3, m3, d3 = string.find(startOfSeason, "(%d+)-(%d+)-(%d+)")
						if y1 <= y3 then -- start time < season time
							if date2temp~=nil then
								local timeP582 = trans(date2temp,'12', '31')
								if timeP582 >= changedTime then -- find maximum end time
									-- Case Pierre-Roger Latour: Chambéry CF (2012 - 2014), time season at 2013
									-- Task: changedTime should be after start time, but before startOfSeason
									local y4 = string.match(timeP582, "(%d+)-%d+-%d+")
									if y4 > y3 then changedTime = '+'..y3..'-12-31T00:00:00Z' else changedTime = timeP582 end
								end
							end
						end
						if changedTime ~= '+0000-00-00' then
							riderTeam = getTeam(riderID, changedTime, nil)
							local _, _, y1, _, _ = string.find(changedTime, "(%d+)-(%d+)-(%d+)")
							timeTeam = ' ('..y1..')'
						end
					end
				end
				if errorbool==1 then
					errortext=errortext..' missing qualifiers by team'
				elseif errorbool==2 then
					errortext=errortext..' missing qualifiers by rider'
				end
			end
		end
		--get the country
		local countryID
		local p27 = getStatementForTime(riderID, 'P27', timeOfRace) --P27 is country of citizenship
		if p27 then
			countryID = p27.mainsnak.datavalue.value.id
		end
		if countryID then
			pays = getCountryName(countryID)
			flags = flag(countryID, timeOfRace)
		end
		--save
		if correctlanguage == true then
			table.insert(riderTablecorrect, {sortkey, riderName, riderBirthday, riderTeam, timeTeam, riderStart, riderEnd, riderPosition, riderReason, riderRef, errorbool, errortext, pays,flags})
		else
			table.insert(riderTablenotcorrect, {sortkey, riderName, riderBirthday, riderTeam, timeTeam, riderStart, riderEnd, riderPosition, riderReason, riderRef, errorbool, errortext, pays,flags})
		end
	end

	-- sorting names
	if sort == true then
		table.sort(riderTablecorrect, function(a,b) return a[1]<b[1] end)
		table.sort(riderTablenotcorrect, function(a,b) return a[1]<b[1] end)
	end
	--merge
	for _, v in pairs (riderTablecorrect) do
		table.insert(riderTable, v)
	end
	for _, v in pairs (riderTablenotcorrect) do
		table.insert(riderTable, v)
	end

	local outputTable = mw.html.create('table')
	                        :addClass('sortable')
	                        :attr('cellpadding', '2')
	                        :attr('cellspacing', '0')
	                        :css('border' , '1px solid rgb(200,200,200)')
	                        :css('padding', '3px')
	outputTable:tag('tr'):cssText('background-color:#FFDF80;line-height:1.8em;')
	    :tag('th'):attr('colspan', 4):cssText('text-align:center;white-space:nowrap')
	    :wikitext('<span style="float:left">[[File:Wikidata-logo S.svg|12px|link=d:'.. frame.args[1].. '#P527]]</span>')
	    :wikitext(getSquadTableColumn(7))
	local header = outputTable:tag('tr')
	header:tag('th'):cssText('text-align:center;padding:2px 20px 2px 2px;white-space:nowrap'):wikitext(getSquadTableColumn(1))
	header:tag('th'):cssText('text-align:center;padding:2px 20px 2px 2px;white-space:nowrap'):wikitext(getSquadTableColumn(2))
	if available_list and wiki ~= 'lv' then
	    header:tag('th'):cssText('text-align:center;padding:2px 20px 2px 2px;white-space:nowrap'):wikitext(getSquadTableColumn(6))
	end
	header:tag('th'):cssText('text-align:center;padding:2px 20px 2px 2px;white-space:nowrap'):wikitext(getSquadTableColumn(3))

	local temp
	local iii = 1
	local i = 1
	for _, v in pairs (riderTable) do
		sortkey=v[1]
		riderName=v[2]
		riderBirthday=v[3]
		riderTeam=v[4]
		timeTeam=v[5]
		riderStart=v[6]
		riderEnd=v[7]
		riderPosition=v[8]
		riderReason=v[9]
		riderRef=v[10]
		errorbool=v[11]
		errortext=v[12]
		pays=v[13]
		flags=v[14]
		
		local tRow=outputTable:tag('tr'):css('line-height','1.8em')
		local tCell= tRow:tag('td'):cssText("padding:0 1em 0 0;white-space:nowrap")

		if not available_list or wiki == 'lv' then temp=flags..' ' else temp='' end
		tCell:wikitext(temp..riderName):attr('data-sort-value',sortkey)

		if riderStart~=nil or riderEnd~=nil then
			tCell:tag('span'):cssText("font-size:80%; color:#686868")
			local note=''
			if riderReason ~= nil then
				note = ', [[#tr_'..i..frame.args[1]..'|'..getSquadTableColumn(4)..']]'
				if wiki == "ar" then note = '، [[#tr_'..i..frame.args[1]..'|'..getSquadTableColumn(4)..']]' end
			end
			tCell:wikitext( ' ('..riderStart..'–'..riderEnd.. (riderPosition or '')..note..')')
		elseif riderReason then
			tCell:tag('span'):cssText("font-size:80%; color:#686868")
			:wikitext('([[#tr_'..i..frame.args[1]..'|'..getSquadTableColumn(4)..']]'.. ')')
		end
		tCell=tRow:tag('td'):cssText("text-align:right;white-space:nowrap")
		if wiki == 'lv' then
			local _, _, y1, m1, d1 = string.find(startOfSeason,"(%d+)-(%d+)-0*(%d+)")
			local _, _, y2, m2, d2 = string.find(riderBirthday or '',"(%d+)-(%d+)-0*(%d+)")
			tCell:wikitext(frame:expandTemplate{ title = 'Template:Birth date and age2', args = { y1, m1, d1, y2, m2, d2 } })
		else
			tCell:wikitext(func_date(riderBirthday or '', 'long'))
			if available_list then 
				tRow:tag('td'):wikitext(flags.. ' '..pays)
			end
		end

		if wiki =='he' then
			local isRtl = (mw.ustring.find(riderTeam, '|.*[א-ת]') or (not mw.ustring.find(riderTeam, '|') and mw.ustring.find(riderTeam, '[א-ת]')))
			if isRtl then
				tCell=tRow:tag('td'):cssText("padding:0 0.5em; text-align:right")
			else
				labelMissing = true -- FIXME: labelMissing is not functional in most languages. once we have infra support for it, move it there
				tCell=tRow:tag('td'):cssText("padding:0 0.5em; text-align:left")
			end
		else
			tCell=tRow:tag('td'):cssText("padding:0 0.5em; text-align:left")
		end
		if riderTeam then
			tCell:wikitext(riderTeam.. timeTeam..errortext)
		end

		if riderReason ~= nil or errortext ~= '' then
			local temp=errortext
			if riderReason and errortext then
				temp=riderReason ..errortext
			elseif riderReason then
				temp=riderReason
			end
			if iii == 1 then
				outputTable:wikitext(getSquadTableColumn(5)..': '.. riderName.. temp)
			else
				outputTable:tag('span'):css('color','white')
				:wikitext(getSquadTableColumn(5))
				outputTable:wikitext(riderName.. temp)
			end
			iii = iii + 1
			if riderRef ~= nil then 
				local tRef=frame:extensionTag{name='ref', content=riderRef, args = {name='tr_'..i..frame.args[1]}}
				outputTable:node(tRef)
			end
			outputTable:wikitext('<br>')
		end
	end
	if labelMissing then outputTable:wikitext(getMissingLabelTrackingCategory()) end
	
	local UCIlink
	if wiki=="fr" then
		UCIlink="https://www.uci.org/fr/route/%C3%A9quipe"
	else
		UCIlink="https://www.uci.org/road/teams"
	end

	outputTable:tag('tr'):tag('td'):addClass("navigation-only")
	:attr('data-sort-value','zz')
	:attr('colspan',4)
	:cssText("border-top: 2px #FFDF80 solid; font-size: 80%;")
	:tag('tr')
	:tag('td'):attr('colspan',4)
	:attr('data-sort-value','zzz')
	:cssText("text-align:right")
	:tag('small'):wikitext(race_reference_translate(wiki, 1).."["..UCIlink..' UCI]')
	
	return outputTable
end

--== I) List of winners ==
function p.listofwinnerscountry(frame)
	local winnersProperty = {'Q72068715','Q72068718','Q72068721'}
	local s = {
		countryflag=true,
		endyear=0,
		beginyear=0,
		winnersProperty=winnersProperty,
		displayteam = true
		}
	return listofwinners_main(frame, s)
end

function p.listofwinnerscountryU23(frame)
	local winnersProperty = {'Q72068724','Q72068725','Q72068729'}
	local s = {
		countryflag=true,
		endyear=0,
		beginyear=0,
		winnersProperty=winnersProperty,
		displayteam = false
		}
	return listofwinners_main(frame, s)
end

function p.generalclassificationpoint(frame)
	local s = {
		header_function = headoftableII, -- translations are in function headoftableII
		header_1 = 9, -- translation 10 in function headoftableII is printed in the upper part of the table header
		header_2 = {1, 2, 3, 7}, -- translations 1, 2, 3, 7 in function headoftableII are printed in this order in the lower part of the table header
		item = frame.args[1],
		property = 'P2321', -- property to use for this table
		team_classification = false, -- it is not a team classification table, its a rider classification table
		background = 'color', -- there is a background color for the first row
		display_ref = tonumber(frame.args[2]) == 0 and 0 or 1
		}
	return new_classification(frame, s)
end

function p.listofwinnersyoung(frame)
	local winnersProperty = {'Q20883139','Q72099969','Q72099972'}
	local s = {
		countryflag=true,
		endyear=0,
		beginyear=0,
		winnersProperty=winnersProperty,
		displayteam = false
		}
	return listofwinners_main(frame, s)
end

function p.listofwinnersChamp(frame)
	local winnersProperty = {'Q20882667','Q20882668','Q20882669'}
	local s = {
		countryflag=false,
		endyear=0,
		beginyear=0,
		winnersProperty=winnersProperty,
		displayteam = false
		}
	return listofwinners_main(frame, s)
end

function p.listofwinners(frame)
	local winnersProperty = {'Q20882667','Q20882668','Q20882669'}
	local s = {
		countryflag=true,
		endyear=0,
		beginyear=0,
		winnersProperty=winnersProperty,
		displayteam = false
		}
	return listofwinners_main(frame, s)
end

function p.listofwinnersfirstpart(frame) --return a html table to be copied directly in wikipedia
	local winnersProperty = {'Q20882667','Q20882668','Q20882669'}
	local s = {
		countryflag=true,
		endyear=tonumber(frame.args[2]) or 0,
		beginyear=0,
		winnersProperty=winnersProperty,
		displayteam = false
		}
	return frame:extensionTag{ name = 'nowiki', content = listofwinners_main(frame, s)}
end

function p.listofwinnerssecondpart(frame)--start the list winners from a given year
	local winnersProperty = {'Q20882667','Q20882668','Q20882669'}
	local s = {
		countryflag=true,
		endyear=0,
		beginyear=tonumber(frame.args[2]) or 0,
		winnersProperty=winnersProperty,
		displayteam = false
		}
	return listofwinners_main(frame, s)
end

function p.listofwinnersChampfirstpart(frame)
	local winnersProperty = {'Q20882667','Q20882668','Q20882669'}
	local s = {
		countryflag=false,
		endyear=tonumber(frame.args[2]) or 0,
		beginyear=0,
		displayteam = false,
		winnersProperty=winnersProperty
		}
	return frame:extensionTag{ name = 'nowiki', content = listofwinners_main(frame, s)}
end

function p.listofwinnersChampsecondpart(frame)
	local winnersProperty = {'Q20882667','Q20882668','Q20882669'}
	local s = {
		countryflag=false,
		endyear=0,
		displayteam = false,
		beginyear=tonumber(frame.args[2]) or 0,
		winnersProperty=winnersProperty
		}
	return listofwinners_main(frame, s)
end

function p.listofpointswinners(frame)
	local winnersProperty = {'Q20883007'}
	local s = {
		countryflag=true,
		endyear=0,
		beginyear=0,
		displayteam = false,
		winnersProperty=winnersProperty
		}
	return listofwinners_main(frame, s)
end

function p.listofmountainwinners(frame)
	local winnersProperty = {'Q20883212'}
	local s = {
		countryflag=true,
		endyear=0,
		beginyear=0,
		displayteam = false,
		winnersProperty=winnersProperty
		}
	return listofwinners_main(frame, s)
end

function p.listofyoungwinners(frame)
	local winnersProperty = {'Q20883139'}
	local s = {
		countryflag=true,
		endyear=0,
		beginyear=0,
		displayteam = false,
		winnersProperty=winnersProperty
		}
	return listofwinners_main(frame, s)
end

function p.listofwinnerswithteam(frame)
	local winnersProperty = {'Q20882667','Q20882668','Q20882669'}
	local s = {
		countryflag=true,
		endyear=0,
		beginyear=0,
		displayteam = true,
		winnersProperty=winnersProperty
		}
	return listofwinners_main(frame, s)
end

function p.listofwinnerscustom(frame)
	local winnersProperty ={}
	--general
	if frame.args[2] ~= nil and tonumber(frame.args[2]) ==1 then table.insert( winnersProperty,'Q20882667') end
	--podium
	if frame.args[3] ~= nil and tonumber(frame.args[3]) ==1 then 
		table.insert( winnersProperty,'Q20882668') 
		table.insert( winnersProperty,'Q20882669') 
	end
	--points
	if frame.args[4] ~= nil and tonumber(frame.args[4]) ==1 then table.insert( winnersProperty,'Q20883007') end
	--mounstain
	if frame.args[5] ~= nil and tonumber(frame.args[5]) ==1 then table.insert( winnersProperty,'Q20883212' ) end
	-- sprints
	if frame.args[6] ~= nil and tonumber(frame.args[6]) ==1 then table.insert( winnersProperty,'Q20883328'  ) end
	-- youth
	if frame.args[7] ~= nil and tonumber(frame.args[7]) ==1 then table.insert( winnersProperty, 'Q20883139' ) end
	-- combativity
	if frame.args[8] ~= nil and tonumber(frame.args[8]) ==1 then table.insert( winnersProperty, 'Q20893983' ) end
	-- volante
	if frame.args[9] ~= nil and tonumber(frame.args[9]) ==1 then table.insert( winnersProperty,'Q27067359' ) end
	-- regularity 
	if frame.args[10] ~= nil and tonumber(frame.args[10]) ==1 then table.insert( winnersProperty,'Q27067170' ) end
	-- combination
	if frame.args[11] ~= nil and tonumber(frame.args[11]) ==1 then table.insert( winnersProperty,'Q20893979' ) end
	-- breakaway
	if frame.args[12] ~= nil and tonumber(frame.args[12]) ==1 then table.insert( winnersProperty,'Q27907715' ) end
	-- azzurri
	if frame.args[13] ~= nil and tonumber(frame.args[13]) ==1 then table.insert( winnersProperty,'Q27907747'  ) end
	-- rookie
	if frame.args[14] ~= nil and tonumber(frame.args[14]) ==1 then table.insert( winnersProperty, 'Q28092831' )	end 
	-- teams
	if frame.args[15] ~= nil and tonumber(frame.args[15]) ==1 then table.insert( winnersProperty, 'Q20882921' )	end
	 -- teamspoints
	if frame.args[16] ~= nil and tonumber(frame.args[16]) ==1 then table.insert( winnersProperty,'Q27104269' ) end	
	-- amateur
	if frame.args[17] ~= nil and tonumber(frame.args[17]) ==1 then table.insert( winnersProperty,  'Q61976850'  ) end	
	 --nationality
	if frame.args[18] ~= nil and tonumber(frame.args[18]) ==1 then table.insert( winnersProperty,'Q61976872' ) end	
	local s = {
		countryflag=true,
		endyear=0,
		beginyear=0,
		displayteam = false,
		winnersProperty=winnersProperty
		}
	return listofwinners_main(frame, s)
end

function listofwinners_main(frame, s)
	local rows = {}
	frame.args[1] = string.gsub(frame.args[1], "%c", "")
	local raceID = frame.args[1]
	local WDlink_on = (wiki == "mk") or (wiki == "ja") or (wiki == "ru")
		-- WDlink_on is used to decide if a Wikidata logo will be shown
	local WPcontent = {
		row ={},
		code = {}
	}
	local beginyear=s.beginyear or 0
	local endyear=s.endyear or 0

	local titletable={
		['Q20882667']=listofwinners_translate(2), --winner		
			[ 'Q27104269' ]=listofwinners_translate(2), --winner team	
			[ 'Q20883139' ]=listofwinners_translate(2), --winner young
			[ 'Q72068715' ]=listofwinners_translate(2), --winner country
			[ 'Q72068724' ]=listofwinners_translate(2), --winner countryU23
		['Q20882668']=listofwinners_translate(3), --second		

		['Q20882669']=listofwinners_translate(4), --third		
	
		[ 'Q20883007' ]=listofwinners_translate(5), -- points  
		[ 'Q20883212' ]=listofwinners_translate(6), -- mountains
		[ 'Q20883328' ]=listofwinners_translate(7), -- sprints
		[ 'Q20883139' ]=listofwinners_translate(8), -- youth
		[ 'Q20893983' ]=listofwinners_translate(9), -- combativity
		[ 'Q20893979' ]=listofwinners_translate(10), -- combination
		[ 'Q20882921' ]=listofwinners_translate(11), -- teams
		[ 'Q27067359' ]=listofwinners_translate(12), -- volantes
		[ 'Q27067170' ]=listofwinners_translate(13), -- regularity
		[ 'Q27104269' ]=listofwinners_translate(14), -- teamspoints
		[ 'Q27907715' ]=listofwinners_translate(15), -- breakaway
		[ 'Q27907747' ]=listofwinners_translate(16), -- azzurri
		[ 'Q28092831' ]=listofwinners_translate(17), -- rookie
		[ 'Q61976850' ]=listofwinners_translate(18), -- amateur
		[ 'Q61976872' ]=listofwinners_translate(19), -- nationality
		-- 1, 2 and 3 place of team, young, country, countryU23 :
			[ 'Q72065970' ]=listofwinners_translate(3), --second team	
			[ 'Q72099969' ]=listofwinners_translate(3), --second young			
			[ 'Q72068718' ]=listofwinners_translate(3), --second country
			[ 'Q72068725' ]=listofwinners_translate(3), --second countryU23
			
			[ 'Q72065977' ]=listofwinners_translate(4), --third team	
			[ 'Q72099972' ]=listofwinners_translate(4), --third young			
			[ 'Q72068721' ]=listofwinners_translate(4), --third country
			[ 'Q72068729' ]=listofwinners_translate(4), --third countryU23	
	}

	--localframe defined as global for references
	if string.match(frame:getParent():getTitle(), '%P+') == mw.site.namespaces.Template.name then
		localframe = frame:getParent()
	else
		localframe = frame
	end
	if localframe.args[1] then
		localframe.args[1] = string.gsub(localframe.args[1], "%c", "")
	end
--[=[
It is possible to give the table listofwinners in the article commands. It could look like this:
{{Cycling race/listofwinners|Q18574623
| above row 1: '''[[aaa bbb ccc]]''' xxx
}}
"above row x" inserts a new row above row x into the table. Content is what is behind the ":".
]=]
	if localframe.args[2] then
		for num, _ in pairs(localframe.args) do
			if num > 1 and mw.ustring.find(mw.ustring.lower(localframe.args[num]), 'row') then
				local _, _, key1, val = mw.ustring.find(localframe.args[num], "([^:]+)%s*:%s*(%C+)")
				local _, _, key01, key11, key12 = mw.ustring.find(key1, "(%a+)%s*(%a+)%s*(%d+)")
				key12 = tonumber(key12) key11 = mw.ustring.lower(key01..key11)
				if key11 == 'aboverow' then WPcontent.row[key12] = val WPcontent.code[key12] = 0  end --0 is above
				if key11 == 'belowrow' then WPcontent.row[key12] = val WPcontent.code[key12] = 1  end --0 is above	
			end
		end
	end
	
	local firstyeartodisplay=2100
	local parts = mw.wikibase.getAllStatements(raceID, 'P527') -- P527 is 'has part'
	for _, part in ipairs(parts) do
		if part.rank ~= 'deprecated' and part.mainsnak.snaktype == 'value' then
			local partID = part.mainsnak.datavalue.value.id
			local timeOfRace
			local p = mw.wikibase.getBestStatements(partID, 'P585') -- P585 is 'point in time'
			if p[1] and p[1].mainsnak.snaktype == 'value' then
				timeOfRace = p[1].mainsnak.datavalue.value.time
			else
				p = mw.wikibase.getBestStatements(partID, 'P580') -- P580 is 'start time'
				if p[1] and p[1].mainsnak.snaktype == 'value' then
					timeOfRace = p[1].mainsnak.datavalue.value.time
				end
			end
			local year = timeOfRace and string.sub(timeOfRace, 2, 5) or '?'
			local month = timeOfRace and string.sub(timeOfRace, 7, 8) or '01'	
			if year == "?" then mw.log("no year at " .. partID ) end
			if endyear==0 or (tonumber(year) or 0)<=endyear then
					if (tonumber(year) or 0) >= beginyear then
						local thereisawinner=false
						
						local sitelink = mw.wikibase.getSitelink(partID)
						if sitelink then
							sitelink = '[[' .. sitelink .. '|' .. year .. ']]'
						else
							sitelink = year
						end
						if WDlink_on then
							sitelink = sitelink .. ' ' .. wdLink(partID)
						end
						local winners = {}
						for _, property in ipairs(s.winnersProperty) do winners[property]='' end
						local tCell
						local tCellstr=''
						
		 				local temp=firstValue(partID, 'P1346','id')
						if temp and temp=='Q30108381' then --race cancelled
							local cancelledlabel = getLabelFallback('Q30108381', {wikilang, 'en', 'fr', 'de'})
							tCell=mw.html.create('td'):attr('colspan','4')
							:cssText('text-align:center; font-style: italic')
							:wikitext(cancelledlabel)
							tCellstr=tostring(tCell)
						else
							winner(partID, winners, timeOfRace, not s.countryflag, WDlink_on,s.displayteam,true)
							for _, property in ipairs(s.winnersProperty) do
								tCell=mw.html.create('td'):wikitext(winners[property])
								if winners[property]~='' then 
									thereisawinner=true 
									if tonumber(year)<firstyeartodisplay then firstyeartodisplay=tonumber(year) end
								end
								tCellstr= tCellstr..tostring(tCell)
							end
						end
						if firstyeartodisplay<=tonumber(year) then
						    rows[#rows+1]={year..month, sitelink, tCellstr}
						end
					end
				end
			end
		end
	table.sort(rows, function(a, b) return a[1] < b[1] end) -- Sort by year
	
	local clear = "left"
	if wiki == "ar" then clear = "right" end
	
	--do not use hw.html here otherwise the begin and end year won't work
	local table_first = "<table cellpadding='4' cellspacing='0' style='"..standardtablecss.."'>"

	local tTitleRow=mw.html.create('tr')
	:cssText('background:#FFDF80; text-align:center')
	local tCell=tTitleRow:tag('th')
	if WDlink_on == false then
		tCell:tag('span'):css("float","left")
		:wikitext("[[File:Wikidata-logo S.svg|12px|link=d:"..raceID .. "#P527]]")
	end
	tCell:wikitext(listofwinners_translate(1)) --year
	for _, pp in ipairs(s.winnersProperty) do
		tTitleRow:tag('th'):wikitext(titletable[pp])
	end
	
	local table_center=''
	local nb_year_inrow=1
	local lastyear
	
	for i, row in ipairs(rows) do
		sitelink=row[2]

		local tRowWD=mw.html.create('tr')
		local tCell=tRowWD:tag('td'):css('text-align','left')
		
		if lastyear and mw.ustring.sub(row[1],1,4)==lastyear then
				nb_year_inrow=nb_year_inrow+1
				tCell:wikitext(sitelink..' ('..tostring(nb_year_inrow)..')') 
		else
			tCell:wikitext(sitelink)
			nb_year_inrow=1
		end
		lastyear=mw.ustring.sub(row[1],1,4)
		tRowWD:node(row[3]) --add the end of the row
		
		if WPcontent.row[i] then
			tRow=mw.html.create('tr'):tag('td'):attr('colspan','4')
			:css('text-align','center')
			tRow:wikitext(WPcontent.row[i])

			if WPcontent.code[i]==0 then --above
				table_center=table_center..tostring(tRow)
				table_center=table_center..tostring(tRowWD)
			else --below
				table_center=table_center..tostring(tRowWD)
				table_center=table_center..tostring(tRow)
			end
		else
			table_center=table_center..tostring(tRowWD)
		end
	end
	--firstpart with header no foot
	if endyear > 0 then
		return table_first .. tostring(tTitleRow) .. table_center
	elseif beginyear > 0 then
		return table_center .. table_last
	else
		return table_first .. tostring(tTitleRow) .. table_center .. "</table>"
	end
end

--== J) List of stages
function p.listofstages(frame)
	-- WDlink_on is used to decide if a Wikidata logo will be shown
	local WDlink_on = wiki == "mk" or wiki == "ja"
	local WPcontent = {}
	local raceID = frame.args[1]
	local thereiselevation=false
	local result, tableBody

	local localframe
	if string.match(frame:getParent():getTitle(), '%P+') == mw.site.namespaces.Template.name then
		localframe = frame:getParent()
	else
		localframe = frame
	end
	if localframe.args[1] then
		localframe.args[1] = string.gsub(localframe.args[1], "%c", "")
	end
--[=[ It is possible to give the table listofstages in the article commands which overwrites data from Wikidata.
It could look like this:
{{Cycling race/listofstages|Q18574623
| RoW 1: locaTION Ab : [[1a1b]]
| after row 1 : date : 99 août
| after row 1 : icon : [[File:Stage rest day.svg|vbght frthzt fdgtr]]
| after row 1: text : rest day at [[aaa bbb ccc]]
| row 4:  location A : [[4a4a]]abc
| row 3 : winner a : <sup>tzhgt</sup>
| row 4 : winner b : kjuzhgt<br />bbjje
| row 4 : icon : [[File:Mediummountainstage.svg|xcvbbgf fgtr]]
| row 4 : distance : <s>141.8</s> 122<ref>test</ref>
}}
The first paramer is "row x" or "after row x". "after row" adds a new row after row x into the table to print e.g. a rest day.
The second parameters are "location [a/b/ab]", "date", "icon", "text", "winner [a/b]" and "distance".
"a" and "b" means the first and the second location or winner. "ab" could be used if start location and
end location are the same. The file data for the icon looks this way: [[File:Stage rest day.svg|any text]]
]=]
	if localframe.args[2] then
		local WProw, WPnew_row, WPcourse, WPtext, WPdate, WPwinner, WPicon, WPdistance
			= 'row', 'afterrow', 'location', 'text', 'date', 'winner', 'icon', 'distance'
		local _, key1, key2, val
		local key01, key11, key12
		local key21, key22
		for num, var in pairs(localframe.args) do
			if num > 1 and mw.ustring.find(mw.ustring.lower(var), WProw) then
				_, _, key1, key2, val = mw.ustring.find(var, "([^:]+)%s*:?%s*([^:]*)%s*:%s*(%C+)")
				_, _, key01, key11, key12 = mw.ustring.find(key1, "(%a+)%s*(%a+)%s*(%d+)")
				key12 = tonumber(key12)
				key11 = mw.ustring.lower(key01 .. key11)
				key2 = mw.ustring.lower(mw.text.trim(key2))
				_, _, key21, key22 = mw.ustring.find(key2, "(%a+)%s*(%a*)")

				if not WPcontent[key12] then WPcontent[key12] = {} end
				if key11 == WProw and key21 == WPcourse then WPcontent[key12][key22] = val end
				if key11 == WPnew_row and key2 == WPdate then
					WPcontent[key12]['date'] = val
					WPcontent[key12]['text'] = WPcontent[key12]['text'] or ''
					WPcontent[key12]['icon (new row)'] = WPcontent[key12]['icon (new row)'] or ''
				end
				if key11 == WPnew_row and key2 == WPtext then
					WPcontent[key12]['text'] = val
					WPcontent[key12]['date'] = WPcontent[key12]['date'] or ''
					WPcontent[key12]['icon (new row)'] = WPcontent[key12]['icon (new row)'] or ''
				end
				if key11 == WPnew_row and key2 == WPicon then
					val = string.gsub(val, "|", "|border|right|20px|", 1)
					WPcontent[key12]['icon (new row)'] = val
					WPcontent[key12]['date'] = WPcontent[key12]['date'] or ''
					WPcontent[key12]['text'] = WPcontent[key12]['text'] or ''
				end
				if key11 == WProw and key21 == WPwinner and key22 == 'a' then WPcontent[key12]['stage winner'] = val end
				if key11 == WProw and key21 == WPwinner and key22 == 'b' then WPcontent[key12]['general winner'] = val end
				if key11 == WProw and key21 == WPicon then
					val = string.gsub(val, "|", "|border|right|20px|", 1)
					WPcontent[key12]['icon'] = val end
				if key11 == WProw and key21 == WPdistance then WPcontent[key12]['distance'] = val end
			end
		end
	end
	local countries = wikibase.getAllStatements(raceID, 'P17')
	local onecountry, firstcountryID
	if countries and #countries>1 then
		onecountry=false
		if countries[1] then
			firstcountryID=countries[1].mainsnak.datavalue.value.id
		end
	else
		onecountry=true
	end

	local rows = {}
	local stages = mw.wikibase.getBestStatements(raceID, 'P527') -- P527 is 'has part'
	for _, v in pairs(stages) do
		if v.mainsnak.snaktype == 'value' then
			local stageID = v.mainsnak.datavalue.value.id
			local p = mw.wikibase.getBestStatements(stageID, 'P1545') -- P1545 is 'series ordinal'
			local sOrdinal = p[1] and p[1].mainsnak.snaktype == 'value' and p[1].mainsnak.datavalue.value
				or ''
			local _, _, sNumber, sLetter = string.find(sOrdinal, '(%d+)(.*)')
			if not sNumber then sNumber = '' end
			if not sLetter then sLetter = '' end
			local WDLink = WDlink_on and wdLink(stageID) or ''
			local sitelink = mw.wikibase.getSitelink(stageID)

			p = mw.wikibase.getBestStatements(stageID, 'P585') -- P585 is 'point in time'
			local timeOfRace = p[1] and p[1].mainsnak.snaktype == 'value' and p[1].mainsnak.datavalue.value.time
				or ''
			p = mw.wikibase.getBestStatements(stageID, 'P1427') -- P1427 is 'start point'
			local sPointID = p[1] and p[1].mainsnak.snaktype == 'value' and p[1].mainsnak.datavalue.value.id
			local sPoint = sPointID and getPlaceLink(sPointID) or ''
			if sPointID and not onecountry and timeOfRace then
				local startcountry= getStatementForTime(sPointID, 'P17',timeOfRace)
				if startcountry then
					local startcountryID = startcountry.mainsnak.datavalue.value.id
					if firstcountryID ~= startcountryID then
						local sflag = flag(startcountryID, timeOfRace)
						sPoint = sflag.." "..sPoint
					end
				end
			end

			p = mw.wikibase.getBestStatements(stageID, 'P1444') -- P1444 is 'destination point'
			local dPointID = p[1] and p[1].mainsnak.snaktype == 'value' and p[1].mainsnak.datavalue.value.id
			local dPoint = dPointID and getPlaceLink(dPointID) or ''
			if dPointID and not onecountry and timeOfRace then
				local dcountry= getStatementForTime(dPointID, 'P17',timeOfRace)
				if dcountry then
					local dcountryID = dcountry.mainsnak.datavalue.value.id
					if firstcountryID ~= dcountryID then
						local dflag = flag(dcountryID, timeOfRace)
						dPoint = dflag.." "..dPoint
					end
				end
			end

			local sDistance = getDistance(stageID, false) or ''
			local sElevation = getElevation(stageID) 
			if sElevation then thereiselevation=true end
			
			local winners = {
				Q20882747 = '', -- Q20882747 is 'stage winner'
				Q20882763 = '', -- Q20882763 is 'overall leader at the end of the stage'
				Q20882667 = '', -- Q20882667 is 'overall winner' not supposed to be used
			}
			winner(stageID, winners, timeOfRace, false, WDlink_on)

			-- find the type of stage
			local sType = typeofstagelogo(stageID)
			local label, section_title
			if sOrdinal == "0" then
				label, section_title = func_prologue(), "#" .. func_prologue()
			else
				label, section_title = stageLink(sOrdinal, sNumber, sLetter)
			end
			-- if there is a Wikipedia article of that stage show it or show the section
			local sLink = sitelink and ("[[" .. sitelink .. "|" .. label .. "]]") or
				("[[" .. section_title .. "|" .. label .. "]]")

			local sDate = func_date(timeOfRace, 'small')
			local tempoverall
			if  winners['Q20882763']~='' then tempoverall=winners['Q20882763'] else	tempoverall=winners['Q20882667'] end
			rows[#rows + 1] = {
				tonumber(sNumber) or 0, sLetter,  -- Sort keys
				sLink, sDate, WDLink, sPoint, dPoint, sType, sDistance, sElevation, winners['Q20882747'], tempoverall -- Content
			}
		end
	end

	table.sort(rows, function(a, b)
		if a[1] ~= b[1] then return a[1] < b[1] end
		return a[2] < b[2]
	end)
	
	tab=mw.html.create('table')
	:attr('cellpadding','4' )
	:attr('cellspacing','0')
	:cssText(standardtablecss)

	local tRow=tab:tag('tr'):cssText('background:#FFDF80; text-align:center;')
	tRow:tag('th'):css('white-space','nowrap')
	:wikitext(((not WDlink_on and wdLink(string.gsub(raceID, '%s', '') .. "#P527")) or "")..
	headoftable(1))
	tRow:tag('th'):wikitext(headoftable(2))
	tRow:tag('th'):wikitext(headoftable(3))
	tRow:tag('th'):css('color','#FFDF80'):wikitext("type")
	tRow:tag('th'):wikitext(headoftable(4))
	if thereiselevation then 
		tRow:tag('th'):wikitext(headoftable(7))
	end
	tRow:tag('th'):wikitext(headoftable(5))
	tRow:tag('th'):wikitext(headoftable(6))

	for num, row in pairs(rows) do
		local sLink, sDate, WDLink, sPoint, dPoint, sType, sDistance, sElevation, sSWin, sGWin
			= row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[11], row[12]

		local WPc = WPcontent[num]
		if WPc then
			if WPc['a'] then sPoint = WPc['a'] end
			if WPc['b'] then dPoint = WPc['b'] end
			if WPc['ab'] then sPoint, dPoint = WPc['ab'], '' end
			if WPc['icon'] then sType = WPc['icon'] end
			if WPc['distance'] then sDistance = WPc['distance'] end
		end

		local tRow = tab:tag('tr')
		local tCell= tRow:tag('td'):cssText('text-align:center; white-space:nowrap'):wikitext(sLink)
		tCell:tag('span'):css('white-space','nowrap'):wikitext("&nbsp;".. WDLink )
		tRow:tag('td'):css('white-space','nowrap'):cssText("text-align:right; padding-right:0px")
		:wikitext(sDate)
		tCell=tRow:tag('td'):cssText("padding-right:0px"):wikitext( sPoint)
		if dPoint ~= '' then
			tCell:wikitext(" – " .. dPoint)
		end
		tRow:tag('td'):cssText("padding-right:0px"):wikitext(sType)
		tRow:tag('td'):css('text-align','center'):wikitext( sDistance)
		if thereiselevation then
			tRow:tag('td'):css('text-align','center'):wikitext(sElevation)
		end

		if WPc and WPc['stage winner'] then
			tRow:tag('td'):css('text-align',textalign):wikitext( WPc['stage winner'])
		else
			tRow:tag('td'):wikitext(sSWin)
		end
		if WPc and WPc['general winner'] then
			tRow:tag('td'):css('text-align',textalign):wikitext( WPc['general winner'])
		else
			tRow:tag('td'):wikitext(sGWin)
		end
		if WPc and (WPc['date'] or WPc['text'] or WPc['icon (new row)']) then
			tRow = tab:tag('tr')
			tRow:tag('td') --empty

			if WPc['icon (new row)'] == '' then
				tRow:tag('td'):cssText('text-align:right; padding:3px 0px 10px 0px;white-space:nowrap')
				:wikitext(WPc['date'])
				tRow:tag('td'):cssText("text-align:" .. textalign .. "; padding:3px 4px 10px")
				:wikitext(WPc['text'])
			else
				tRow:tag('td'):cssText('text-align:right; padding-right:0px')
				:wikitext(WPc['date'])
				tRow:tag('td'):cssText("text-align:" .. textalign)
				:wikitext(WPc['text'])
			end
			tRow:tag('td'):css('padding-top','10px'):wikitext(WPc['icon (new row)'])
			tRow:tag('td'):attr('colspan','3')
		end
	end
	return tab
end

function p.stagetitle(frame)
	-- WDlink_on is used to decide if a Wikidata logo will be shown
	local stageID = frame.args[1]
	-- from to 
	local p = mw.wikibase.getBestStatements(stageID, 'P1427') -- P1427 is 'start point'
	local sPointID = p[1] and p[1].mainsnak.snaktype == 'value' and p[1].mainsnak.datavalue.value.id
	local sPoint = sPointID and getPlaceLink(sPointID) or ''
	p = mw.wikibase.getBestStatements(stageID, 'P1444') -- P1444 is 'destination point'
	local dPointID = p[1] and p[1].mainsnak.snaktype == 'value' and p[1].mainsnak.datavalue.value.id
	local dPoint = dPointID and getPlaceLink(dPointID) or ''

	local sDistance = getDistance(stageID, true) or ''
	-- find the type of stage
	local sType = typeofstagelogo(stageID)
	
	tab=mw.html.create('table')
	tab:tag('th'):wikitext(sPoint.." - "..dPoint)
	tab:tag('td'):wikitext(sType)
	tab:tag('td'):css('font-weight','bold'):wikitext("("..sDistance..")")
	return tab
end

--[[ Give access to a local variable. Used by other modules. ]]
function p.getLocal(name)
	if name == 'getTeamLinkCat' then return getTeamLinkCat end
	if name == 'getStatementForTime' then return getStatementForTime end
end


local function champtitle(h) --!h is h.jersey
	local road, ITT, result
	local hcountry, hnotcountry = {},{}
	
	--the jersey for a stage race and the jersey from national championship should be differentiated
	--to avoid to look every time, below is a list of all national championships
	local womenRoadtable= {Q934877=true, Q50064341=true,Q50061750=true,Q31271454=true,Q54315111=true,Q30894544=true,
	Q66082905=true,Q65965631=true,Q45083914=true,Q31271492=true,Q43286073=true,Q55185740=true,Q65371835=true,
	Q31094517=true,QQ27043949=true,	Q30332924=true,Q30349395=true,Q53869580=true,Q31505332=true,Q30349364=true,
	Q31271605=true,Q43745198=true,Q30332844=true,Q30332239=true,Q30349468=true,	Q30332737=true,Q55221006=true,
	Q32161692=true,Q33083546=true,Q30332988=true,Q30556990=true,Q32604159=true,Q30557561=true,Q64624273=true,
	Q30333102=true,	Q31271010=true,Q31276622=true,Q45084873=true,Q32609249=true,Q31271644=true,Q31298588=true,
	Q45171831=true,Q30332625=true,Q30349432=true,Q31092105=true,Q30577809=true,Q30349499=true, Q45172931=true
	}
	local womenITTtable={Q2630733=true,Q50063172=true,Q50062728=true,Q31271381=true,Q54314912=true,Q30894543=true,
	QQ31093255=true,Q31271615=true,Q29642128=true,Q30349411=true,Q53869589=true,
	Q31506358=true,Q30349371=true,Q31271315=true,Q43745136=true,Q30332806=true,
	Q30332311=true,Q30349480=true,Q30332699=true,Q55220999=true,Q32163348=true,
	Q33083817=true,Q30333018=true,Q30556121=true,Q32603438=true,Q30557504=true,
	Q64624304=true,Q30333137=true,Q31271024=true,Q30456396=true,Q45084954=true,
	Q32611136=true,Q31272638=true,Q31300263=true,Q45171898=true,Q30332486=true,
	Q30349441=true,Q30584268=true,Q30577837=true,Q30349507=true,Q45172978=true
	}
	local menRoadtable={Q13603535=true,Q30894537=true,Q23069702=true,Q23889469=true,
	Q66250756=true,	Q22284173=true, Q30967435=true, Q24617852=true, Q27043944=true,
	Q24628140=true,Q27056312=true,Q62024698=true,Q26960669=true,Q22951216=true,
	Q27048382=true,Q27133468=true,Q26971246=true,Q24621530=true,Q27048391=true,
	Q27048399=true,Q27681895=true,Q27681898=true,Q27055629=true,Q26976092=true,
	Q26985335=true,Q27048419=true,Q27043957=true,Q27055631=true,Q24050070=true,
	Q26973043=true,Q27133456=true,Q26834056=true,Q27043924=true,Q27048374=true,
	Q26972921=true,Q27043324=true,Q27056303=true,Q27042502=true,Q27042790=true,
	Q27133451=true,Q27056305=true,Q24731826=true,Q27230607=true,Q22680990=true,
	Q27043353=true,Q27048408=true,Q22303186=true,Q27042375=true,Q27133460=true,
	Q27133465=true,Q22680842=true,Q27230606=true,Q27230610=true,Q26972715=true,
	Q24718413=true,Q3754283=true,Q27230604=true,Q27043932=true,Q27230611=true,
	Q24733085=true,Q27055624=true,Q24731406=true,Q27056308=true
	}
	local menITTtable={Q2557477=true,Q33315723=true,Q22284183=true, Q31023710=true,
	Q24618030=true, Q27043945=true,Q24628162=true,Q27056389=true,Q26960674=true,
	Q5147941=true,Q27048383=true,Q27133626=true,Q26971248=true,Q24621627=true,
	Q27793536=true,Q27048400=true,Q27793536=true,Q27793496=true,Q27055699=true,
	Q26976108=true, Q26985336=true, Q27048421=true,Q27043958=true,Q27055700=true,
	Q26973044=true,Q27133617=true,Q26834055=true,Q27043925=true,Q24050074=true,
	Q27048375=true,Q26972922=true,Q27043325=true,Q27056383=true,Q27042506=true,
	Q17319607=true,Q27133615=true,Q17005940=true,Q24731829=true,Q27235634=true,
	Q22680998=true,Q3754388=true,Q27048410=true,Q22303252=true,Q27042376=true,
	Q27133620=true,Q27133623=true,Q22680863=true,Q7382088=true,Q27235638=true,
	Q26972716=true,Q24718416=true,Q27043341=true,Q27230443=true,Q27043933=true,
	Q27235639=true,Q24733090=true,Q27055696=true,Q24731482=true,Q27056386=true
	}

	if type(h) == 'table' and h[1] then
		for _, v in ipairs(h) do
			roadtemp=false
			ITTtemp=false
			if womenRoadtable[v] or menRoadtable[v] then
				 road = true
				 roadtemp=true
			elseif womenITTtable[v] or menITTtable[v] then
				 ITT = true
				 ITTtemp=true
	    	else
		    	local Racelabel = mw.wikibase.getLabelByLang(v,"fr")
				if Racelabel then
					local testMenRoadrace, testMenITT, testWomenRoadrace, testWomenITT
					local Racelabelmod = string.gsub(Racelabel, '-', 'x')
					testMenRoadrace = string.find( Racelabel, 'Course en ligne masculine aux' ) 
					testMenITT = string.find( Racelabelmod, 'Contrexlaxmontre masculin aux' ) 
					testWomenRoadrace = string.find( Racelabel, 'Course en ligne féminine aux' ) 
					testWomenITT = string.find( Racelabelmod, 'Contrexlaxmontre féminin aux' ) 
					if testWomenRoadrace or testMenRoadrace then road = true roadtemp=true end
					if testWomenITT or testMenITT then ITT = true ITTtemp=true end
				end
			end
			if roadtemp or ITTtemp then
				table.insert(hcountry,v)
			else
				table.insert(hnotcountry,v)	
			end
		end
	end
	if road and ITT then
		local image = {}
		for ii, v in ipairs(hcountry) do
			local p18 = mw.wikibase.getBestStatements(v, 'P18')
			if p18[1] and p18[1].mainsnak.snaktype == 'value' then
				local temp = p18[1].mainsnak.datavalue.value
				local alreadythere = 0
				for _, vv in ipairs(image) do
					if vv==temp then alreadythere = 1 end
				end
				if alreadythere==0 then
					table.insert(image,temp)
				else hcountry[ii] = nil
				end
			end
		end
		--avoid double display of jersey
		result = "<small>("..startlist_translate(10).." "..startlist_translate(12).." "..startlist_translate(11)..")</small>"
	elseif road then
		result = "<small>("..startlist_translate(10)..")</small>"
	elseif ITT then
		result = "<small>("..startlist_translate(11)..")</small>"
	else
		result = ""
	end
	return jersey(hcountry)..result..jersey(hnotcountry)
end

-- K) List of stages classification
local function winnerjersey(raceID, winners)
	local jerseytable, bgcolortable={}, {}
	local p1346 = wikibase.getAllStatements(raceID, 'P1346') -- P1346 is 'winner'
	for _, winner in pairs(p1346) do
		local wOf, thisjersey, bg_color
		local q = winner.qualifiers
		if q then
			if q.P642 and q.P642[1].snaktype == 'value' then
				wOf = q.P642[1].datavalue.value.id -- P642 is 'of'
			end
			if q.P2912 and q.P2912[1].snaktype == 'value' then
				thisjersey=q.P2912[1].datavalue.value.id
				if bg_color_table[thisjersey] then
					bg_color = bg_color_table[thisjersey]
				end
			end
		end
		if winners[wOf] and thisjersey then
			jerseytable={}
			table.insert(jerseytable,thisjersey)
			winners[wOf] = jersey(jerseytable)
			bgcolortable[wOf] = bg_color
		end
	end
	return winners, bgcolortable
end

function p.listofstagesclassification(frame)
	-- WDlink_on is used to decide if a Wikidata logo will be shown
	local WDlink_on = wiki == "mk" or wiki == "ja"
	local displaytypeofstage = true
	local stageinfotable = {}
	local raceID = frame.args[1]
	local sType
	local localframe
	if string.match(frame:getParent():getTitle(), '%P+') == mw.site.namespaces.Template.name then
		localframe = frame:getParent()
	else
		localframe = frame
	end
	if localframe.args[1] then
		localframe.args[1] = string.gsub(localframe.args[1], "%c", "")
	end

	--link for Grand Tour
	local GTid={['Q33881']=true,['Q33861']=true,['Q33937']=true}
	local thisGT

	for _, p31 in statements(raceID, 'P31') do
		if GTid[p31.mainsnak.datavalue.value.id]==true then thisGT=p31.mainsnak.datavalue.value.id break end
	end

	local Sitelink,overallname, pointsname, mountainname, youngname, teamname, combativityname, combinedname
	if thisGT then
		if thisGT=='Q33881' then
			Sitelink = wikibase.getSitelink('Q2267539')
			if Sitelink then overallname="[["..Sitelink .."|"..headoftableII(9).."]]" end
			Sitelink = wikibase.getSitelink('Q175399')
			if Sitelink then pointsname="[["..Sitelink .."|"..infobox_translate(22).."]]" end
			Sitelink = wikibase.getSitelink('Q927157')
			if Sitelink then mountainname="[["..Sitelink .."|"..infobox_translate(23).."]]" end
			Sitelink = wikibase.getSitelink('Q641662')
			if Sitelink then youngname="[["..Sitelink .."|"..infobox_translate(25).."]]" end
			Sitelink = wikibase.getSitelink('Q1436680')
			if Sitelink then teamname="[["..Sitelink .."|"..infobox_translate(28).."]]" end
			Sitelink = wikibase.getSitelink('Q2094179')
			if Sitelink then combativityname="[["..Sitelink .."|"..infobox_translate(26).."]]" end
			Sitelink = wikibase.getSitelink('Q1835362')
			if Sitelink then combinedname="[["..Sitelink .."|"..infobox_translate(27).."]]" end
		elseif thisGT=='Q33861' then
			Sitelink = wikibase.getSitelink('Q1164275')
			if Sitelink then overallname="[["..Sitelink .."|"..headoftableII(9).."]]" end
			Sitelink = wikibase.getSitelink('Q641083')
			if Sitelink then pointsname="[["..Sitelink .."|"..infobox_translate(22).."]]" end
			Sitelink = wikibase.getSitelink('Q641060')
			if Sitelink then mountainname="[["..Sitelink .."|"..infobox_translate(23).."]]" end
			Sitelink = wikibase.getSitelink('Q641662')
			if Sitelink then youngname="[["..Sitelink .."|"..infobox_translate(25).."]]" end
		else
			Sitelink = wikibase.getSitelink('Q2532554')
			if Sitelink then overallname="[["..Sitelink .."|"..headoftableII(9).."]]" end
			Sitelink = wikibase.getSitelink('Q2241695')
			if Sitelink then pointsname="[["..Sitelink .."|"..infobox_translate(22).."]]" end
			Sitelink = wikibase.getSitelink('Q1118296')
			if Sitelink then mountainname="[["..Sitelink .."|"..infobox_translate(23).."]]" end
			Sitelink = wikibase.getSitelink('Q2330008')
			if Sitelink then combinedname="[["..Sitelink .."|"..infobox_translate(27).."]]" end
		end
	end

	local winners = {
		{ name = infobox_translate(19), QID = 'Q20882747'}, -- stage
		{ name = overallname or headoftableII(9), QID = 'Q20882763' }, -- overall
		{ name = pointsname or infobox_translate(22), QID = 'Q20883008' }, -- points
		{ name = mountainname or infobox_translate(23), QID = 'Q20883213' }, -- mountains
		{ name = infobox_translate(24), QID= 'Q20883329' }, -- sprints
		{ name = youngname or infobox_translate(25), QID='Q20883140' }, -- youth
		{ name = combativityname or infobox_translate(26), QID= 'Q20893984' }, -- combativity
		{ name = infobox_translate(35), QID= 'Q27104688' }, -- volantes
		{ name = infobox_translate(36), QID= 'Q27104684' }, -- regularity
		{ name = combinedname or infobox_translate(27), QID='Q20965880' }, -- combination
		{ name = infobox_translate(38), QID='Q27907714' }, -- breakaway
		{ name = infobox_translate(39), QID='Q27907748' }, -- azzurri
		{ name = infobox_translate(40), QID='Q28096780'}, -- rookie
		{ name = teamname or infobox_translate(28), QID='Q20882922' }, -- teams
		{ name = infobox_translate(37), QID ='Q27104271' }, -- teamspoints
		{ name = infobox_translate(41), QID ='Q61976847' },-- amateur
		{ name = infobox_translate(42), QID ='Q61976871' } --nationality
	}

	local winnersgen = {
		{ QID = 'Q20882667' }, -- overall
		{ QID = 'Q20883007' }, -- points
		{ QID = 'Q20883212' }, -- mountains
		{ QID = 'Q20883328' }, -- sprints
		{ QID = 'Q20883139' }, -- youth
		{ QID = 'Q20893983' }, -- combativity
		{ QID = 'Q27067359' }, -- volantes
		{ QID = 'Q27067170' }, -- regularity
		{ QID = 'Q20893979' }, -- combination
		{ QID = 'Q27907715' }, -- breakaway
		{ QID = 'Q27907747' }, -- azzurri
		{ QID = 'Q28092831' }, -- rookie
		{ QID = 'Q20882921' },  -- teams
		{ QID = 'Q27104269' }, -- teamspoints
		{ QID = 'Q61976850' },  -- amateur
		{ QID = 'Q61976872' } --nationality
	}

	local generaltoleader = {
		['Q20882747']= nil,
		['Q20882667']= 'Q20882763', -- overall
		['Q20883007']= 'Q20883008', -- points
		['Q20883212']= 'Q20883213', -- mountains
		['Q20883328']= 'Q20883329', -- sprints
		['Q20883139']= 'Q20883140', -- youth
		['Q20893983']= 'Q20893984', -- combativity
		['Q27067359']= 'Q27104688', -- volantes
		['Q27067170']= 'Q27104684', -- regularity
		['Q20893979']= 'Q20965880', -- combination
		['Q27907715']= 'Q27907714', -- breakaway
		['Q27907747']= 'Q27907748', -- azzurri
		['Q28092831']= 'Q28096780', -- rookie
		['Q20882921']= 'Q20882922', -- teams
		['Q27104269']= 'Q27104271', -- teamspoints
		['Q61976850']= 'Q61976847', -- amateur
		['Q61976872']= 'Q61976871'  --nationality
	}

	--read stages
	local stages = mw.wikibase.getBestStatements(raceID, 'P527') -- P527 is 'has part'
	local columntable, jerseytable, bgcolortable={}, {}, {}
	for ii, v in ipairs(winners) do
		if v.QID then
			local t = {key=ii, name=v.name, jersey='', bg_color='', used=false}
			for ii = 1, #stages+1 do
				t[ii] = { {}, {}, {} }  -- ?, first stage, number of stages consecutive
			end
			columntable[v.QID] = t
		end
	end
	local function itercolumns(columntable)
		local keys = {}
		for k, v in pairs(columntable) do
			keys[v.key] = k
		end
		local upto = 1
		return function ()
			while keys[upto] do
				upto = upto + 1
				return columntable[keys[upto-1]]
			end
		end
	end

	local timeOfRace
	for ii, v in pairs(stages) do
		if v.mainsnak.snaktype == 'value' then
			local somewinner = false
			local stageID = v.mainsnak.datavalue.value.id
			local sitelink = mw.wikibase.getSitelink(stageID)
			if displaytypeofstage==true then
				sType = typeofstagelogo(stageID)
			end
			local p = mw.wikibase.getBestStatements(stageID, 'P1545') -- P1545 is 'series ordinal'
			local sOrdinal = p[1] and p[1].mainsnak.snaktype == 'value' and p[1].mainsnak.datavalue.value
				or ''
			local _, _, sNumber, sLetter = string.find(sOrdinal, '(%d+)(.*)')
			if not sNumber then sNumber = '' end
			if not sLetter then sLetter = '' end

			local label, section_title
			if sOrdinal == "0" then
				label, section_title = func_prologue(), "#" .. func_prologue()
			else
				label, section_title = stageLink(sOrdinal, sNumber, sLetter)
			end
			-- If there is a Wikipedia article of that stage show it or show the section.
			local sLink = sitelink and ("[[" .. sitelink .. "|" .. label .. "]]") or
				("[[" .. section_title .. "|" .. label .. "]]")

			local sTime = firstValue(stageID, 'P580', 'time') -- P580 is 'start time'
			local eTime = firstValue(stageID, 'P582', 'time') -- P582 is 'end time'
			if sTime and eTime then
				timeOfRace = eTime
			else
				-- This function give a format to dates when P585 (date) is used in a single day race.
				local pTime = firstValue(stageID, 'P585', 'time') -- P585 is 'point in time'
				if pTime then
					timeOfRace = pTime
				end
			end

			local win= {}
			for _, v in pairs(winners) do
				win[v.QID] = ''
				if ii==1 then jerseytable[v.QID]='' end
			end
			winner(stageID, win, timeOfRace, false, WDlink_on, false, false)
			if ii==1 then --only first stage
				jerseytable, bgcolortable=winnerjersey(stageID, jerseytable)
			end
			for _, v in pairs(winners) do
				if v.QID and win[v.QID] ~= '' then
					--column info
					somewinner=true
					columntable[v.QID][ii][1]=win[v.QID]
					if ii==1 then --first stage
						columntable[v.QID][ii][2]=1
						columntable[v.QID][ii][3]=1
					elseif columntable[v.QID][ii-1][1]==win[v.QID] then --same winner as past stage
						local initialstage=columntable[v.QID][ii-1][2]
						columntable[v.QID][ii][2]=initialstage
						columntable[v.QID][initialstage][3]=columntable[v.QID][initialstage][3]+1
						columntable[v.QID][ii][3]=0
					else --new winner
						columntable[v.QID][ii][2]=ii
						columntable[v.QID][ii][3]=1
					end
					columntable[v.QID].used=true
					if ii==1 then
						columntable[v.QID].jersey=jerseytable[v.QID]
						columntable[v.QID].bg_color=bgcolortable[v.QID]
					end
				end
			end
			table.insert(stageinfotable,{sLink=sLink, sType=sType, somewinner=somewinner})
		end
	end

	--read parent
	local win= {}
	for _, v in pairs(winnersgen) do
		if v.QID then
			win[v.QID] = ''
			jerseytable[v.QID]=''
		end
	end
	local thiskey
	somewinner = false
	jerseytable, bgcolortable=winnerjersey(raceID, jerseytable)
	winner(raceID, win, timeOfRace, false, WDlink_on, false, false)
	for _, v in pairs(winnersgen) do
		if win[v.QID] and win[v.QID] ~= '' then
			somewinner=true
			thiskey=generaltoleader[v.QID]
			columntable[thiskey][#stages+1][1]=win[v.QID]
			columntable[thiskey][#stages+1][2]=#stages+1
			columntable[thiskey][#stages+1][3]=1
			if type(columntable[thiskey][#stages][1])~="string" then --check nil actually, but it is a table..
				columntable[thiskey][#stages][1]=win[v.QID] --no need to fill last stage of a stage race
				if type(columntable[thiskey][#stages-1][1])=="string" and win[v.QID]==columntable[thiskey][#stages-1][1] then
					local initialstage=columntable[thiskey][#stages-1][2]
					columntable[thiskey][#stages][2]=initialstage
					columntable[thiskey][initialstage][3]=columntable[thiskey][initialstage][3]+1
					columntable[thiskey][#stages][3]=0
				else
					columntable[thiskey][#stages][2]=#stages
					columntable[thiskey][#stages][3]=1
				end
			end
			columntable[thiskey].used=true
			if jerseytable[v.QID] and jerseytable[v.QID]~='' then
				columntable[thiskey].jersey=jerseytable[v.QID]
				columntable[thiskey].bg_color=bgcolortable[v.QID]
			end
		end
	end
	table.insert(stageinfotable,{sLink=listofstagesclassification_translate(2), sType=nil, somewinner=somewinner})

	--build the table
	local	tab=mw.html.create('table')
	:attr('cellpadding','4' )
	:attr('cellspacing','0')
	:cssText(standardtablecss)
	local tRow=tab:tag('tr'):cssText('background:#FFDF80; text-align:center;')
	tRow:tag('th'):css('white-space','nowrap')
	:wikitext(((not WDlink_on and wdLink(string.gsub(raceID, '%s', '') .. "#P527")) or "")..
	headoftable(1))
	
	if displaytypeofstage==true then tRow:tag('th') end

	for v in itercolumns(columntable) do
		if v.used == true then
			if v.jersey == '' then v.jersey = "_" end
			tRow:tag('th'):wikitext(v.name.."<br />"..v.jersey)
		end
	end

	local style
	--then fill the table
	for ii, v in pairs(stageinfotable) do --one stage=one row
		--stages link
		tRow=tab:tag('tr')
		local tCell=tRow:tag('td')
		if ii==#stageinfotable then 
			tCell:attr('colspan','2'):cssText('font-weight:bold; border-top: 2px black solid;')
		end
		tCell:wikitext(v.sLink)
		
		tCell=tRow:tag('td')
		if ii==#stageinfotable then
			tCell:cssText('font-weight:bold; border-top: 2px black solid;')
		end
		if displaytypeofstage == true then
			if v.sType then
				tCell:wikitext(v.sType)
			end
		end

		--add winners
		for y in itercolumns(columntable) do
			if y.used==true and not (ii==#stageinfotable and columntable['Q20882747']==y) then --only display used QID
				if type(y[ii][1])=="string" and type(y[ii][3])=="number" then --actually check nil but it is a table
					style=""
					if y[ii][3]~=0 and (columntable['Q20882747']==y)==false then
						if ii~=1 and ii~=#stageinfotable then style=style.." border-top:1px gray solid;" end
						if y.bg_color then style=style.." background-color:"..y.bg_color..";" end
						if ii==#stageinfotable then style=style.."font-weight:bold; border-top: 2px black solid;" end
						tRow:tag('td'):attr('rowspan',tostring(y[ii][3])):cssText(style):wikitext(y[ii][1])
					elseif (columntable['Q20882747']==y) then --no rowspan for stages
						tRow:tag('td'):wikitext(y[ii][1])
					end
				else
					tCell=tRow:tag('td')
					if ii~=#stageinfotable and v.somewinner==true then
						tCell:wikitext(listofstagesclassification_translate(1)) --not attributed
					elseif ii~=#stageinfotable then
						 --empty
					elseif v.somewinner==true then
						tCell:cssText('border-top: 2px black solid')
						:wikitext(listofstagesclassification_translate(1))
					else
						tCell:cssText('border-top: 2px black solid') --empty
					end
				end
			end
		end
	end
	return tab
end

--I) Start list
function p.startlist(frame)
	local IDtemp
	if frame.args[1] ~= nil then
		IDtemp=string.gsub(frame.args[1], "%c", "")
	end

	local s = {
		header_function = startlist_translate,
		header_1 = 1, -- translation 1 in function victories_translate is printed in the upper part of the table header
		header_2 = {2, 3,4,5},
		item=IDtemp,
		title="Start list",
		data_sort_type={'unsortable', 'unsortable', 'unsortable'},
		property ='P710',
		no_roll_startlist=no_roll_startlist
	}

	local resulttable, tag = tableB(s)
	return startlist_main(s, resulttable, tag)  
end

function p.startlisttable(frame)
	local IDtemp
	if frame.args[1] ~= nil then
		IDtemp=string.gsub(frame.args[1], "%c", "")
	end

	local s = {
		header_function = startlisttable_translate,
		header_1 = 1, -- translation 1 in function victories_translate is printed in the upper part of the table header
		header_2 = {2, 3,4,5},-- translations 2, 3, 4, 5, 6 in function victories_translate are printed in this order
		item=IDtemp,
		title="Start list", -- in the lower part of the table header. The second value 3 in {4, 3} tells where the icon will go.
		no_country ={'fr'},
		data_sort_type={'', '', ''},
		property ='P710',
		no_roll_startlist=no_roll_startlist
	}
	return startlisttable_main(s, tableA(s))
end

local function startlist_sub(p710, timeOfRace,  WDlink_on, istable)
	local h, resulttable= {}, {}
	local tBody = '' --row in our case
	local riderID, riderTeam, riderDossard, riderLink, riderRank, q, gender, riderTeamCode, riderDNF, DSQ

	riderID = p710.mainsnak.datavalue.value.id
	q= p710.qualifiers
	riderLink= getRiderLink(riderID, timeOfRace)
	if WDlink_on then riderLink=riderLink..wdLink(riderID) end
	if q and q.P1618 and q.P1618[1].snaktype == 'value' then
		riderDossard = q.P1618[1].datavalue.value or ''
	else
		riderDossard = ''
	end
	riderDNF='' riderRank = '' DSQ=''
	if q and q.P1352 and q.P1352[1].snaktype == 'value' then -- P1352 is ranking
		riderRank = tonumber(q.P1352[1].datavalue.value.amount)
		--look for DSQ--
		DSQ=isdisqualified(p710, q)
	else
		--look for DNF...
		if q and q.P1534 and q.P1534[1].snaktype == 'value' then
			local dnf=q.P1534[1].datavalue.value.id
			if dnf=='Q1210380' then riderDNF =startlist_translate(6)--"HD","NP","DQ"
			elseif dnf=='Q54881674' or dnf=='Q7113430' then riderDNF =startlist_translate(7)
			elseif dnf=='Q1210382' then riderDNF =startlist_translate(8)
			elseif dnf=='Q1229261' then riderDNF =startlist_translate(9)
			else riderDNF=''
			end
			if q.P1545 and q.P1545[1].snaktype == 'value' then
				local stageofdnf=q.P1545[1].datavalue.value
				if stageofdnf and string.len(stageofdnf)>1 then
					riderDNF='<small>'..riderDNF.."-"..stageofdnf..'</small>'
				else
					riderDNF=riderDNF.."-"..stageofdnf
				end
			end
		end
	end

	h = {
		jersey = {}, -- lots of jerseyID
		value = {'', '', '', ''} -- points, time, time_gap, speed
	}

	if q and q.P2912 then -- P2912 is distinctive jersey
		for _, v in pairs(q.P2912) do
			if v.snaktype == 'value' then
				table.insert(h.jersey, v.datavalue.value.id)
			end
		end
	end

	if wiki == 'es' or wiki == 'fr' or wiki == 'ast' then
		--[[ These wikis need the gender to display the rank correct. Other wikis can skip this. ]]
		gender = getgendercode(riderID, 'n')
	end

	local p27 = getStatementForTime(riderID, 'P27', timeOfRace) --P27 is country of citizenship
	if p27 then
		local countryID = p27.mainsnak.datavalue.value.id
		if countryID then
			riderLink = flag(countryID, timeOfRace) ..' '..riderLink.. ucicodeCountry(countryID)
			if wiki == "ar" then 
				riderLink = flag(countryID, timeOfRace) ..' '..riderLink
			end
		end
	end
	
	if h.jersey[1] then
		riderLink=riderLink..champtitle(h.jersey) -- champtitle manages also the jersey
	end
	
	riderTeam = getTeam(riderID, timeOfRace, q)
	riderTeamCode= getTeamCode(riderID, timeOfRace, q)
	
	if riderTeam == nil then riderTeam ="" end
	local sortkey = riderDossard == "" and 0 or tonumber(riderDossard)

	tBody =   mw.html.create('tr'):cssText("line-height: 1.8em; padding: 5px;")
	tBody:tag('td'):cssText("text-align:right;padding:0 0.5em"):wikitext(riderDossard)
	tBody:tag('td'):cssText('text-align:'..textalign.. ';padding:0 0.5em;'..DSQ):wikitext(riderLink)
	if istable then
		tBody:tag('td'):cssText("text-align:right;padding:0 0.5em"):wikitext(riderTeam)
	end
	tBody:tag('td'):cssText('text-align:'..textalign.. ';padding:0 0.5em;'..DSQ):wikitext(number(gender,riderRank,wiki)..riderDNF)

	table.insert(resulttable, {sortkey=sortkey, riderTeam=riderTeam,riderTeamCode=riderTeamCode, tBody=tBody})
	return resulttable
end

function startlist_main(s, resulttable, tag)
	local ridertable, DStable, subtable  = {}, {}, {}, {}
	local DSID, DSLink, DSteamID, DSteam
	local WDlink_on = (wiki == "mk" or wiki == "ja" or wiki == "ru")

	local fn_datetable=fn_date(s.item)
	local timeOfRace=fn_datetable[1]

	for _,p286 in statements(s.item, 'P286') do--look for DS
		DSID = p286.mainsnak.datavalue.value.id
		DSLink= getRiderLink(DSID, timeOfRace)
		q= p286.qualifiers
		if q.P642 and q.P642[1].snaktype == 'value' then
			DSteamID=q.P642[1].datavalue.value.id
			DSteam=getTeamLinkCat(DSteamID, timeOfRace)
		end
		table.insert(DStable, {DSLink=DSLink, DSteam=DSteam})
	end

	for _, p710 in statements(s.item, 'P710') do -- P710 is participants
		subtable=startlist_sub(p710, timeOfRace, WDlink_on, false)
		ridertable[#ridertable + 1] = {subtable[1].sortkey, riderTeam=subtable[1].riderTeam,riderTeamCode=subtable[1].riderTeamCode, tBody=subtable[1].tBody}
	end
	
	--sort
	table.sort(ridertable, function(a, b) return a[1] < b[1] end)

	local thisTableRow, thisTeamTable, thisDS, insideTable, test
	local tSubtitle, tTitle
	
	if wiki == "ar" then
		tSubtitle=mw.html.create('tr')
		tSubtitle:tag('td'):attr('width','30px')
		:css("align:right;text-align:right")
		:wikitext(startlist_translate(2))
		tSubtitle:tag('td'):attr('width','200px')
		:css("align:right;text-align:right")
		:wikitext(startlist_translate(3))
		tSubtitle:tag('td'):attr('width','85px')
		:css("align:right;text-align:right")
		:wikitext(startlist_translate(4))
	else
		tSubtitle=mw.html.create('tr')
		tSubtitle:tag('td'):attr('width','30px'):wikitext(startlist_translate(2))
		tSubtitle:tag('td'):attr('width','250px'):wikitext(startlist_translate(3))
		tSubtitle:tag('td'):attr('width','35px'):wikitext(startlist_translate(4))
	end

	--look for transition between teams
	local numberofteam=0

	if #ridertable==0 then--empty table
		return nil
	else
		for ii=1,#ridertable  do
			if ridertable[ii].riderTeam==nil then ridertable[ii].riderTeam=startlist_translate(13) end
			if ii~=1 and ridertable[ii].riderTeam and ridertable[ii].riderTeam==ridertable[ii-1].riderTeam then test=0 else test=1 end--team change
				--new team
			if test==1 or ii==1 then
				if thisDS and ii~=1 then
					tDS=insideTable:tag('tr')
					tDS:tag('td'):attr('colspan','3'):attr('align','center')
					:wikitext(startlist_translate(5).." "..thisDS)
					thisDS=nil
				end
				
				numberofteam=numberofteam+1
				if math.fmod(numberofteam, 3 )==1 then
					if ii~=1 then
						tag:node(thisTableRow) --a row with 3 tables inside, save and re-init
					end
					thisTableRow=mw.html.create('tr') 
				end
				thisTeamTable= thisTableRow:tag('td'):cssText("width:33%;"):attr('valign','top')
				insideTable=thisTeamTable:tag('table') --reinit
				:attr('cellpadding','4') --solid rgb(200,200,200)
				:attr('background-color','rgb(255, 255, 255)')
				:attr('margin', '0 0 0.5em 0')
				:attr('padding','5px')
				:attr('float','left')
				:attr('text-align',textalign)
				:attr('line-height','1.8em')
				:attr('clear',floattable)

				tTitle =  mw.html.create('tr'):cssText("background-color:#FFDF80"):attr('align','center')
				local tCell=tTitle:tag('th'):attr('colspan','3')
				tCell:tag('big'):wikitext(ridertable[ii].riderTeam.."<br/>"..(ridertable[ii].riderTeamCode or "___"))
				
				insideTable:node(tTitle)
				insideTable:node(tSubtitle)
				
				tDS=nil
				--look for the DS of this team
				for _,v in pairs(DStable) do
					if v.DSteam==ridertable[ii].riderTeam then thisDS=v.DSLink break end
				end
			end
			insideTable:node(ridertable[ii].tBody)
		end
		--last DS
		if tDS then	thisTeamTable:node(tDS) end
		tag:node(thisTableRow)

		return resulttable
	end
end

function startlisttable_main(s, resulttable)
	local  t_Body, fn_datetable, subtable = {}, {}, {}, {}
	local WDlink_on = (wiki == "mk" or wiki == "ja" or wiki == "ru")

	fn_datetable=fn_date(s.item)
	local timeOfRace=fn_datetable[1]

	for _, p710 in statements(s.item, 'P710') do -- P710 is participants
		subtable=startlist_sub(p710, timeOfRace, WDlink_on, true)
		t_Body[#t_Body + 1] = {subtable[1].sortkey, tostring(subtable[1].tBody)}
	end
	return sortandconcat(t_Body, resulttable)
end

-- J) Rider ranking
local function checkminmaxyear(minmaxyear,thisyear)
	if minmaxyear.minimum ==0 or thisyear<minmaxyear.minimum then
		minmaxyear.minimum=thisyear
	end
	if minmaxyear.maximum==0 or thisyear>minmaxyear.maximum then
		minmaxyear.maximum=thisyear
	end
   return minmaxyear
end

function p.riderranking(frame)
	local s = {
		gender = 1, --tonumber(frame.args[2]) 0 = men, 1 = women
		item = string.gsub(frame.args[1], "%c", ""),
		}
	return riderranking_main(frame, s)
end

function riderranking_main(frame,s)
	local thisCompetition, rank, thisyear, sitelink, q, gender
	local Resulttable, listofcalendar, UCI, UCImaster={},{},{}, {}
	local minmaxyear= {
		minimum = 0, -- lots of jerseyID
		maximum = 0 -- points, time, time_gap, speed
	}
	local calendarlistpresent={
		["UCIwomen"]=false
	}
	
	UCI["UCIwomen"] = { ['Q57267790']='2019',['Q47005682']='2018',['Q27765666']='2017',
		['Q22696468']='2016',['Q18348936']='2015', ['Q15831496']='2014',
		['Q6425932']='2013',[ 'Q2466796']='2012',['Q2466792']='2011',
		['Q2933831']='2010',['Q2933830']='2009',['Q2933828']='2008',
		['Q3650627']='2007',[ 'Q16154659']='2006'}
	
	UCI["WWT"] = { ['Q57277246']='2019', ['Q41787783']='2018', ['Q27431192']='2017',
		['Q21034783']='2016'
		}
		
	UCI["WWC"] = { ['Q18589848']='2015', ['Q15076094']='2014', ['Q3000659']='2013',
		['Q326406']='2012',['Q326401']='2011',['Q120210']='2010',['Q326012']='2009',
		['Q326006']='2008',['Q326001']='2007',['Q325995']='2006',['Q127681']='2005',
		['Q80792']='2004',['Q16451']='2003',['Q746107']='2002',['Q979663']='2001',
		['Q44096']='2000',['Q44095']='1999',['Q39077']='1998'
	}	
	
	UCImaster={["UCIwomen"]='Q1693153', ['WWT']='Q21075974', ['WWC']='Q1517550'}
	UCImastername={["UCIwomen"]=riderranking_translate(2), ['WWT']=riderranking_translate(3), ['WWC']=riderranking_translate(4)}
	
	local listofwomencalendar={"UCIwomen", "WWC", "WWT"}

	if s.gender==1 then
		listofcalendar=listofwomencalendar
		gender='f'
	else
		gender='m'
	end
	
	ff=1
	--init table
	for ii=1900,2100,1 do
		Resulttable[tostring(ii)]={}
		for _, calendar  in pairs(listofcalendar) do
			Resulttable[tostring(ii)][calendar]={
				rank=nil, 
				sitelink=nil
			}
		end
	end

	--build the table
	for _, p1344 in statements(s.item, 'P1344') do
		thisCompetition = p1344.mainsnak.datavalue.value.id
	
		for _, calendar  in pairs(listofcalendar) do
			if UCI[calendar][thisCompetition] then
				thisyear=UCI[calendar][thisCompetition]
				minmaxyear=checkminmaxyear(minmaxyear,thisyear)
				q = p1344.qualifiers
				if q and q.P1352 and q.P1352[1].snaktype == 'value' then --rank
					rank = tonumber(q.P1352[1].datavalue.value.amount)
				else
					rank= nil
				end
				if rank then
					Resulttable[thisyear][calendar]["rank"]=tostring(rank)
					calendarlistpresent[calendar]=true
					sitelink=mw.wikibase.getSitelink(thisCompetition)
					Resulttable[thisyear][calendar]["sitelink"]=sitelink
				end
			end
		end
	end

	--display result
	if minmaxyear.minimum~=0 then
		local finalTable =mw.html.create('table'):attr('cellspacing','0')
		:attr("align","center"):cssText("text-align:center; border: 1px solid #999;  line-height: 1.8em;")
		
		local wdLin = wdLink(string.gsub(s.item, '%s', '') .. "#P1344")
		local tRow= finalTable:tag('tr'):tag('th'):cssText("background-color:#FFDF80"):wikitext(wdLin..' '..riderranking_translate(1))

		for ii=minmaxyear.minimum,minmaxyear.maximum,1 do
			tRow:tag('th'):attr("width","50px"):cssText("text-align:center; background-color:#FFDF80;padding:1px 1px;")
			:wikitext(tostring(ii))
		end

		for _, calendar  in pairs(listofcalendar) do
			if calendarlistpresent[calendar] then
				sitelink=mw.wikibase.getSitelink(UCImaster[calendar])
				local tRow=finalTable:tag('tr')
				local tCell = tRow:tag('th'):cssText("text-align:left;")
				if sitelink then
					tCell:wikitext('[['..sitelink..'|'..UCImastername[calendar]..']]')
				else
					tCell:wikitext(UCImastername[calendar])
				end
				
				for ii=minmaxyear.minimum,minmaxyear.maximum,1 do
					thisyear=tostring(ii)
					color="white"
					if Resulttable[	thisyear][calendar]["rank"] then
						if Resulttable[thisyear][calendar]["rank"]=="1" then
							color="gold"
						elseif (2<=tonumber(Resulttable[thisyear][calendar]["rank"])) and (tonumber(Resulttable[thisyear][calendar]["rank"])<=3) then
							color="YellowGreen"
						elseif (4<=tonumber(Resulttable[thisyear][calendar]["rank"])) and (tonumber(Resulttable[thisyear][calendar]["rank"])<=10) then
							color="silver"
						end
						
						tCell=tRow:tag('td'):attr("bgcolor",color)
						if Resulttable[thisyear][calendar]["sitelink"] then
							tCell:wikitext('[['..Resulttable[thisyear][calendar]["sitelink"]..'|'..
							number(gender,Resulttable[thisyear][calendar]["rank"],wiki)..']]')
						else
							tCell:wikitext(number(gender,Resulttable[thisyear][calendar]["rank"],wiki))
						end
					else
						tRow:tag('td'):wikitext(' - ')
					end
				end
			end
		end

		local UCIlink
		if wiki=="fr" then
			UCIlink="https://www.uci.org/fr/route/classements"
		else
			UCIlink="https://www.uci.org/road/rankings"
		end
		
		local tableyearsize=minmaxyear.maximum-minmaxyear.minimum+2
		
		finalTable:tag('tr'):tag('td'):addClass("navigation-only")
		:attr('colspan',tostring(tableyearsize))
		:cssText("border-top: 2px #FFDF80 solid; font-size: 80%;")
		:tag('tr')
		:tag('td'):attr('colspan',tostring(tableyearsize))
		:cssText("text-align:right")
		:tag('small'):wikitext(race_reference_translate(wiki, 1).."["..UCIlink..' UCI]')

		return 	finalTable
	end
end	

return p