Diferència entre revisions de la pàgina «Mòdul:Cycling race»

14.415 octets eliminats ,  fa 6 mesos
update
(upgrade a 20191203 versiion)
(update)
wiki = "fr"
end
 
local contentLanguage = mw.getContentLanguage()
local wikilang = contentLanguage:getCode()
----- B) Calendar
----- C) Victory
----- Cbis) Function for infobox
----- D) Stage infobox
----- E) List of teams
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'}
["Q65665708"] ="#FFC0CB" , -- Jersey polkadot.svg (Points)
["Q25265958"] ="#FFC0CB" , -- Jersey polkadot.svg (Mountain)
["Q11636369"] ="#FFC0CB" , -- Jersey polkadot.svg (Mountain)
["Q25265959"] ="#E0FFFF" , -- Jersey blue dotted.png (Mountain)
["Q25265960"] ="#FFC0CB" , -- Jersey climbing Dauphine.png (Mountain)
for _, q in qualifiers(element, property) do
result = tonumber(q.value.amount)
break
end
return result
 
--[[ Get start time of race as a timevalue ('+2016-01-01T00:00:00Z') or nil ]]
local function getTimeOfRacegettimeOfRace (raceID)
local timeOfRace
local p580 = mw.wikibase.getBestStatements(raceID, "P580") -- P580 is start time
local y, m = string.match(sTime, "(%d+)-(%d+)-%d+")
local y2, m2 = string.match(eTime, "(%d+)-(%d+)-%d+")
if y ~= y2 then
if modem=='long00' 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
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
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
if mode=='long' then
starttime = lang:formatDate( "j", sTime ) .." de ".. lang:formatDate( "F", sTime )
else starttime = lang:formatDate( "j F", sTime ) .." "
else
starttime = lang:formatDate( "j M", sTime )
end
else
starttime = lang:formatDate( "j", sTime )
end
elseif wiki == "cs" then
if wiki == "ar" then
if y ~= y2 then starttime = lang:formatDate( "j. xg Y", sTime )
elseif if my ~= m2y2 then starttime = lang:formatDate( "j.d xgF Y", sTime )
else elseif m ~= m2 then starttime = lang:formatDate( "jd F", sTime )
else starttime = lang:formatDate( "d ", sTime ) end
end
elseif wiki == "de" or wiki == "da" or wiki == "fo" or wiki == "nobr" 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 == "fica" or wiki == "es" or wiki == "ast" then
if y ~= y2 then starttime = lang:formatDate( 'j. F"ta" Y', sTime )
elseif m starttime ~= m2lang:formatDate( then"j", starttimesTime =) .." de ".. lang:formatDate( 'j"F", sTime ) .." de ".. lang:formatDate( F"taY"', sTime )
elseif m ~= m2 then
else starttime = lang:formatDate( "j.", sTime )
starttime = lang:formatDate( "j", sTime ) .." de ".. lang:formatDate( "F", sTime )
end
else starttime = lang:formatDate( "j", sTime ) .." "
elseif wiki == "eo" then
end
if y ~= y2 then starttime = lang:formatDate( "j", sTime ) .."-a de ".. lang:formatDate( "F Y", sTime )
elseif wiki == "cs" then
elseif m ~= m2 then starttime = lang:formatDate( "j", sTime ) .."-a de ".. lang:formatDate( "F", sTime )
else if y ~= y2 then starttime = lang:formatDate( "j. xg Y", sTime ) .."-a "
elseif m ~= m2 then starttime = lang:formatDate( "j. xg", sTime )
end
else starttime = lang:formatDate( "j", sTime )
elseif wiki == "eu" then
end
if y ~= y2 then starttime = lang:formatDate( "Y", sTime ) ..".eko ".. lang:formatDate( "F", sTime ) .."k ".. lang:formatDate( "j", sTime )
elseif mwiki ~== m2"de" thenor starttimewiki = lang:formatDate(= "Fda", sTimeor )wiki .."k== "..fo" lang:formatDate(or wiki == "jno", sTime )then
else if starttimey ~= lang:formatDate(y2 "F",then sTimestarttime ) .."k "..= lang:formatDate( "j. F Y", sTime )
elseif m ~= m2 then starttime = lang:formatDate( "j. F", sTime )
end
else starttime = lang:formatDate( "j.", sTime )
elseif wiki == "hu" then
end
starttime = lang:formatDate( "Y. F j.", sTime)
elseif wiki == "jafi" then
if y ~= y2 then starttime = lang:formatDate( 'j. F"Y年m月d日ta" Y', sTime )
elseif m ~= m2 then starttime = lang:formatDate( 'j. F"Y年m月d日ta"', sTime )
else starttime = lang:formatDate( "Y年m月d日j.", sTime )
end
elseif wiki == "lveo" then
if y ~= y2 then starttime = lang:formatDate( "Y.j", \\g\\a\\d\\sTime ) .."-a jde ".. lang:formatDate( "F Y", sTime )
elseif m ~= m2 then starttime = lang:formatDate( "Y.j", \\g\\a\\d\\sTime ) .."-a jde ".. lang:formatDate( "F", sTime )
else starttime = lang:formatDate( "Y. \\g\\a\\d\\a j.", sTime ) .."-a "
end
elseif wiki == "pleu" then
if y ~= y2 then starttime = lang:formatDate( "Y", sTime ) ..".eko ".. lang:formatDate( "F", sTime ) .."k ".. lang:formatDate( "j", sTime )
local date_pl = {"stycznia", "lutego", "marca", "kwietnia", "maja", "czerwca", "lipca", "sierpnia", "września", "października", "listopada", "grudnia"}
if elseif ym ~= y2m2 then starttime = lang:formatDate( "j F", sTime ) .. date_pl[tonumber(lang:formatDate("k "n", sTime ))] .. lang:formatDate( " Yj", sTime )
elseif m ~= m2 then else starttime = lang:formatDate( "j F", sTime ) .."k ".. date_pl[tonumber(lang:formatDate( "nj", sTime ))]
end
else starttime = lang:formatDate( "j", sTime )
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 modem2=='long00' orthen y--manage ~=the y230 thenNovember 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
endtime = lang:formatDate( "j", eTime ) .." de "..'-'
lang:formatDate( "F", eTime )
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
endtime = lang:formatDate( "j. F Y", eTime )
else
endtime = lang:formatDate( "j. M", eTime )
end
if wiki == "ar" then
elseif wiki == "eo" then endtime = lang:formatDate( "j", eTime ) .."-a de ".. lang:formatDate( "F Y", eTime )
elseif wiki if mode=='long' "eu"or y ~= y2 then endtime = lang:formatDate( "Y",d eTimeF ) ..".eko ".. lang:formatDate( "FY", eTime ) .."k "..
elseif m ~= m2 then endtime = lang:formatDate( "jd F Y", eTime )
elseif wiki == "fi" then else endtime = lang:formatDate('j F"ta"d F Y'", eTime )
end
elseif wiki == "hu" then
ifelseif ywiki ~== y2"br" then endtime = lang:formatDate( "Yj", eTime ) .." Fa jviz ".. lang:formatDate( "F Y", eTime )
elseif mwiki ~== m2"ca" thenor endtimewiki = lang:formatDate(= "F j.es", eTimeor )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( "YF", eTime ) ..". de ".. lang:formatDate( "F jY", eTime ) .."."
else
elseif wiki == "ja" then
if y ~= y2 then endtime = lang:formatDate( "Y年m月d日j", eTime ) .." de "..
elseif m ~= m2 then endtime = lang:formatDate( "m月d日F", eTime )
end
else endtime = lang:formatDate( "d日", eTime )
elseif wiki == "cs" then endtime = lang:formatDate( "j. xg Y", eTime )
end
elseif wiki == "lvde" 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 )
elseif m ~= m2 then endtime = lang:formatDate( "j. F Y", eTime )
else
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
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
return starttime, endtime
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
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
 
local wikiisslavic = slavicWikis[wiki]
local correctlanguage=true
local listOfProperty={'P1813','P1448'}
 
for _, p1813prop in statementsipairs(riderID, 'P1813'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 language = slavicWikis[p1813.mainsnak.datavalue.value.language]
local languageisslavic = slavicWikis[language]
if (languageisslavic==true and wikiisslavic==true) or (languageisslavic==nil and wikiisslavic==nil) then
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
if local q then= p1813.qualifiers
if q then
local temp = checktime(officialnametemp,q,startOfSeason)
if local temp then officialname = checktime(officialnametemp end--if the time is correct than it is finished,q,startOfSeason)
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
 
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
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
end
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
 
 
--=== C) Function for the output ===
local function tableA(s,getcoutrybool tableBody(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
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 tableHeader2_size country=getcoutrybool #(s.header_2no_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
if i == s.country_column 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
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.. :cssText('<th style="text-align:center;padding:2px 20px 2px 2px;white-space:nowrap">' .. s.header_function (wiki, k) .. '</th>'
:wikitext(s.header_function (wiki, k))
if s.data_sort_type[i] == 'unsortable' then
column:addClass('unsortable')
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
 
local function tableB(s, tableBody) --for startlist
local error_message = ''
if wiki == "ar" and s.item == "" or not s.item then return "" end
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
--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
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
--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
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'}},
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'}},
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'}},
{'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'}},
{'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'}},
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'},
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'},
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'},
end
 
local function jersey_infobox(wiki, winner_classification, item, timeofracetimeOfRace)
local jersey, jersey_name = '', ''
local jerseyWPID = ''
{'Q17619325', 'winner_fighting', '+2016', '+2500', 'Q30035039', 'Q30020302'}, -- Jersey orange.svg
}
--timeofracetimeOfRace = '+1968-07-01T00:00:00Z'
timeofracetimeOfRace = string.match(timeofracetimeOfRace, "+%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 (timeofracetimeOfRace >= value[3]) and (timeofracetimeOfRace <= value[4]) then
jersey = value[5]
jerseyWPID = value[6]
 
-- local starttime, endtime = '', '+2500'
if jersey ~= '' then --and (timeofracetimeOfRace > starttime) and (timeofracetimeOfRace < endtime) then
local entity_jersey = mw.wikibase.getEntity(jersey)
jersey = entity_jersey.claims['P18'][1].mainsnak.datavalue.value
end
 
local function subwinner(riderId, timeofracetimeOfRace, q)
local outputtable={}
local riderTeam, riderLink, countryID
if riderId then
if isHuman(riderId) then
riderLink = getRiderLink(riderId, timeofracetimeOfRace)
local p27 = getStatementForTime(riderId, 'P27', timeofracetimeOfRace) --P27 is country of citizenship
if p27 then
countryID = p27.mainsnak.datavalue.value.id
end
if countryID then
riderLink = flag(countryID, timeofracetimeOfRace) .. ' ' .. riderLink
end
riderTeam = getTeam(riderId, timeofracetimeOfRace, q) or ''
else
local _
riderLink, _, countryID = getTeamLinkCat(riderId, timeofracetimeOfRace, true)
if countryID then
riderLink = flag(countryID, timeofracetimeOfRace) .. ' ' .. riderLink
end
end
end
outputtable[1]=return riderLink, riderTeam
outputtable[2]=riderTeam
return outputtable
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, dateOfRacetimeOfRace, sortkey, sortkeyDate
local outputtable={}
local sTime = firstValue(entityID, 'P580', 'time') -- P580 is 'start time'
sortkeyDate =eTime
end
dateOfRacetimeOfRace = eTime
else
-- This function give a format to dates when P585 (date) is used in a single day race
if pTime then
tempdate = func_date(pTime, 'small')
dateOfRacetimeOfRace = pTime
sortkeyDate = pTime
end
end
 
local tCell = mw.html.create('td'):attr('data-sort-value',sortkey)
outputtable[1]=dateOfRace
outputtable[2]='<td data-sort-value=:cssText("'..sortkey.. '" style="text-align:right;padding:0 0.5em">'..tempdate.. '</td>')
:wikitext(tempdate)
outputtable[1]=timeOfRace
outputtable[2]=tostring(tCell)
outputtable[3]=sortkey
return outputtable
end
 
local function fn_country(entityID, dateOfRacetimeOfRace,countrybool, ParentIDfn_racetable)
-- This function gives countries where the race take place
-- ParentIDparentID 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, beginofstrparentID, 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
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( if countryID, dateOfRace)== 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 country[#countrynamecountry + 1] = getCountryNameflag(countryID, timeOfRace).." "..countryname[#countryname]
end
if countrybool==false or not countryname[#countryname] then
country outputtable[#country + 13]=flag(countryID, dateOfRacetimeOfRace)
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
outputtable[3]=flag(countryID, dateOfRace)
end
end
end
 
if countryID == nil then outputtable[3]="no flag" end
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
outputtable[1]=beginofstr..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
if country[1] then
outputtable[1]=beginofstr..country[1]..'</td>'
else
outputtable[1]=beginofstr..'</td>'
end
else
outputtable[2]=''
outputtable[1]='<td></td>'
end
end
outputtable[1]=tCell
return outputtable
end
local temp=firstValue(stageID, 'P1545')
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 --prologue
stagenumber= victories_translate(wiki,9)
else
end
 
local function getmainraceLinkgetMainRaceLink(entityID,entity_type,stageID, functionName,dateOfRacetimeOfRace) --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=0false
for i=1_,#thisClass in ipairs(class) do--we don't want the class, but the main race
if instanceOf == class[i]thisClass then isclass=1true end
end
if isclass==0false then
for _, p2561prop in statementsipairs(instanceOf, 'P2561'listOfProperty) do --name for championship
for _, p2561 in statements(instanceOf, prop) do --name for championship
local lang_WD = p2561.mainsnak.datavalue.value.language
if wiki label== lang_WDnil then
local nametemplang_WD = p2561.mainsnak.datavalue.value.textlanguage
if dateOfRace~wiki == nillang_WD then
local qnametemp = p2561.qualifiersmainsnak.datavalue.value.text
if qtimeOfRace~= nil then
local tempq = checktime(nametemp,q,dateOfRace)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
if temp then label = nametemp end--if the time is correct than it is finished
end else
label = nametemp
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
 
local function fn_getclassinfofn_getClassInfo(entityID,displayed_class) --get the class of the race
local display=false
local outputtable={}
display=true
else
for i=1_,# thisClass in ipairs(displayed_class) do
if entityID ==displayed_class[i]thisClass then display=true break 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
for i=1_,#class_without2x thisClass in ipairs(thisClassesList) do
if entityID == class_without2x[i]thisClass then
entity_type = '1'listOfClassesName[ii]
class_text = mw.wikibase.label(class_without2x[i]thisClass)
sortkey_class = class_sort[class_without2x[i]thisClass]
end
end
end
if entity_type==nil then entity_type = 'nada' end--to allow display of race without class...
end
if entity_type==nil then entity_type = 'nada' end--to allow display of race without class...
 
if display=~=false then
else
outputtable[1]=entity_type
outputtable[2]=class_text
end
 
local function fn_race(entityID,displayed_class,displayclass,dateOfRacetimeOfRace, 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
if instanceOf == stages[i] then
entity_type = 'stage' --then the class is one stage above!
local ParentIDparentID = getParentID(entityID)
entityID = ParentIDparentID
outputtable[3] = ParentIDparentID --as we read it here, no need to read it afterwards
display = true
for _, p31bis in statements(ParentIDparentID, 'P31') do
local instanceOfbis = p31bis.mainsnak.datavalue.value.id
inputtable=fn_getclassinfofn_getClassInfo(instanceOfbis,displayed_class)
if inputtable[1]=~=nil orand inputtable[1]=~='nada' then
else
class_text =inputtable[2]
sortkey_class=inputtable[3]
end
if entity_type==nil then --bypass if stage
inputtable=fn_getclassinfofn_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
if display then
if entity_type == 'stage' then
Sitelink=getmainraceLinkgetMainRaceLink(entityID,entity_type,stageID, functionName,dateOfRacetimeOfRace)
else
Sitelink=getmainraceLinkgetMainRaceLink(entityID,entity_type,nil, functionName,dateOfRacetimeOfRace)
end
if country~=false then
outputtable[1]local tCell=mw.html.create('<td style='):cssText("text-align:'".. textalign ..'";padding:0 2.3em">'..):wikitext(Sitelink.. '</td>')
outputtable[1]=tostring(tCell)
else
outputtable[1]=Sitelink.. '</td>' --already opened
end
if displayclass == true then
end
-- 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
 
local function fn_rider(entityID,dateOfRacetimeOfRace,displayteam,only_winner,country)
local winners, boolcountrytemp, countrytempresult
local WDlink_on = (wiki == "mk" or wiki == "ja")
local thereisawinner=false
if only_winner == 1 then
winners = {Q20882667 = '', Q20882747=''} -- first, general or stage
end
if country==nil then countrytemp=false else countrytemp=country end
winner(entityID, winners, dateOfRacetimeOfRace, 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)
return
result=tostring(tCell)
'<td style="text-align:'.. textalign ..';padding:0 0.5em">'..winners.Q20882667.. '</td>' ..
tCell=mw.html.create('<td style='):css("text-align:'".. textalign ..'";padding:0 0.5em">'..):wikitext(winners.Q20882668.. '</td>' ..)
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
local tempwinner
tempwinner=winners.Q47640757
end
if tempwinner=~='' orand tempwinner=~=nil then bool=0 else boolthereisawinner=1true end
return '<td style="text-aligntCell:'.. textalign ..';padding:0 0.5em">'..wikitext(tempwinner.. '</td>'), boolthereisawinner
end
end
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, timeofracetimeOfRace
local lang = contentLanguage
if p[1] and p[1].mainsnak.snaktype == 'value' then
end
if rank == 1 then
timeofracetimeOfRace=qualifieramount(p2321[1], 'P2781') --get time
end
end
 
-- if true then return tostring( timeofrace) end
if timeofracetimeOfRace then
found=true
kmh=math.modf(1000*kmdistance/(timeofracetimeOfRace/3600))/1000
end
end
["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"] = {"Команда", "Страна", "Код", "[[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|Женские профессиональные команды]]", "Женская любительская велокоманда", "Женские любительские велокоманды"},
["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"},
}
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=''}
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'noborder then returnborder="" else border="[[File:Hillystage.svg|border|right|20px|"..l10n.hilly.."]]" end
if x=='intermediate stage' then return "[[File:Mediummountainstage.svg|right|border|20px|"..l10n.inter.."]]" end
if x=='mountainplain stage' then return "[[File:MountainstagePlainstage.svg|"..border|right.."|20px|"..l10n.mountplain.."]]" end
if x=='uphill time trialhilly stage' then return "[[File:Mountain Time Trial StageHillystage.svg|"..border|right.."|20px|"..l10n.uphillhilly.."]]" end
if x=='restintermediate daystage' then return "[[File:Stage rest dayMediummountainstage.svg|"..border|right.."|20px|"..l10n.restinter.."]]" 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 typ==2348250noborder then return border=""[[File:Team Timeelse Trial Stage.svgborder="|right|20px|"..l10n.time_team.."]]" end
if typ==22660662348250 then return "[[File:Team Time Trial Stage.svg|right"..border.."|20px|"..l10n.time_indivtime_team.."]]" end
if typ==485321 2266066 then return "[[File:Time Trial.svg|right"..border.."|20px|"..l10n.time_prologuetime_indiv.."]]" end
if typ==485321 then return "[[File:Time Trial.svg"..border.."|20px|"..l10n.time_prologue.."]]" end
end
end
end
 
local function typeofstagelogo(stageID, noborder)
local sType
p = mw.wikibase.getBestStatements(stageID, 'P31') -- P31 is 'instance of'
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
 
return race_reference_translate(wiki, 1) .. table.concat(links)
elseif #links > 1 then
return race_reference_translate(wiki, 12) .. table.concat(links)
else
return ''
--=== B) Calendar ===
function p.calendarcustom(frame)
----- function to display calendar ófof 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
then frame = frame:getParent() 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
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={}
if frame.args[3] ~= nil and tonumber(frame.args[3]) ==1 then no_countrytemp={wiki} end
-- country --
table.insert(headertemp[ll]=, 5)
data_typetemp[ll] = ''
ll=ll+1
 
--race--
table.insert(headertemp[ll]=, 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
table.insert(headertemp, 7) --winner
 
if frame.args[5] ~onlywinnertemp= nil=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
headertemp, tempdic= getargs(frame, 'displayleader', headertemp, tempdic)
 
displayleadertemplocal 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
 
local titletemp=wikibase.getLabel(calendarID)
local data_typetemp={}
for ii=1,#headertemp do
table.insert(data_typetemp,'')
end
 
local s = {
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=titletempwikibase.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
no_country = no_countrytemp,
only_winner = onlywinnertemp,
numbering = numberingtemp tempdic['numbering'][3],
error_message = 0,
displayed_class =nil,
displayteam=displayteamtemp,
displayclass=displayclasstemp tempdic['displayclass'][3],
leadercolumn=displayleadertemp tempdic['displayleader'][3],
frame=frame
}
return tableAcalendar_main(s, calendar_maintableA(s))
end
 
----- based on WWTcalendar function -----
----- author: Mr. Ibrahem -----
local calendarID = ""
if wiki == "ar" then frame = frame:getParent() end
local UCI = {}
['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 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_code1tempdic1 = {2, 3,5, 4, 7, 8, 9, 10}
local header_2_tab_code2 header_2 = {2, 3,5, 4, 67, 78, 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_code1tempdic2 = false{
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
if calendarIDnot ==calendarID "" and frame.args[key] then
local year = frame.args[key]
year = string.gsub(year , "%c", "")
end
end
if wikinot ==calendarID "ar"then and calendarID ==return "" thenend
return ""
end
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
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
 
header_function = calendar_translate, -- translations are in function Calendar_translate
header_1 = header_1_number, -- t
header_2 = header_2temptempdic.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,
property = 'P527',
no_country = no_country_calendar,
only_winner = only_winnertemptempdic.only_winner,
numbering = numberingtemptempdic.numbering,
error_message = 0,
displayed_class = {
"Q22231118", -- CC
},
displayteam=displayteamtemptempdic.displayteam,
displayclass=displayclasstemptempdic.displayclass,
leadercolumn=leadercolumntemptempdic.leadercolumn,
frame=frame
}
return tableAcalendar_main(s, calendar_maintableA(s))
end
 
function calendar_main(s, resulttable)--Display the UCI women calendar of one year
localframe=s.frame
local calendarID=s.item
local sortkey, displayed_class
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)
if not temp then else s.error_message = 2 return '' end
 
local country=truegetcoutrybool (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...
 
----- 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 = tRow:node(fn_datetable[12])
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 = tRow:tag('<tr style= td'):cssText("linetext-heightalign: 1.8emcenter; padding:0 5px;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 == truecountry then
tRow:node(fn_racetable[1])
tBody = tBody..'<td style="text-align:center;padding:0 0.5em">'..tostring(kk).. '</td>'
end
fn_countrytable=fn_country(RaceID,dateOfRace,country,if fn_racetable[32]) then --tRow:node(fn_racetable[12]) isend parentID--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..tRow:node(fn_rider(RaceID,dateOfRacetimeOfRace,s.displayteam,s.only_winner3))
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
---- 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
 
function p.nationalchampionships(frame)
local calendarroadID, calendarITTID, = "",""year
if wiki == "ar" then
frame = frame:getParent()
end
local UCI, 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"] = {
['2020']='Q78466304', ['2019'] = 'Q66362617',
['2018'] = 'Q66762475', ['2017'] = 'Q66762546', ['2016'] = 'Q66762540',
['2015'] = 'Q66762534', ['2014'] = 'Q66762524', ['2013'] = 'Q66762521',
UCIITT["women"] = {
['2020'] = 'Q78466572', ['2019'] = 'Q66736271',
['2018'] = 'Q66762631', ['2017'] = 'Q66762614', ['2016'] = 'Q66762604',
['2015'] = 'Q66762597', ['2014'] = 'Q66762592', ['2013'] = 'Q66762584',
}
UCI["men"] = UCI["women"]
UCIroad["men"] = UCIroad["women"]
UCIITT["men"] = UCIITT["women"]
local yearlistOfCalendar={UCIroad, modetempUCIITT}
 
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)
yearif ((ii==1 and calendarroadID==nil) or (ii==2 and calendarITTID ==nil)) and frame.args[key] then
year = stringframe.gsub( year , "%c", "")args[key]
year = string.gsub( year , "%c", "")
modetemp=key
if v[year] then
calendarroadID if ii==1 v[year]then
calendarroadID = v[year]
else
calendarITTID = v[year]
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 = {
header_function = calendar_translate, -- translations are in function Calendar_translate
country_column = 1,
data_sort_type = {'', '', ''}, -- -- see https://meta.wikimedia.org/wiki/Help:Sorting
item= calendarroadID,
calendarroadID = calendarroadID,
calendarITTID = calendarITTID,
property = 'P527',
year = year,
mode = modetemp,
no_country = {}, --no sense here to hide the country
error_message = 0,
frame = frame
}
return tableAnationalchampionships_main(s, nationalchampionships_maintableA(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 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
 
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(ITTIDthisID,dateOfRacetimeOfRace,s.country)
sortkey=string.gsub(fn_countrytable[2], 'É', 'E') --case États Unis
 
tITT, tempbool=fn_rider(ITTID,dateOfRace,s.displayteam,1,true)
--initcreate the linetable
if tableChamp[sortkey]==nil then
tableChamp[sortkey]={}
tableChamp[sortkey][1'countryname']=sortkeyfn_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
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
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
tableChamp[sortkey][6]=tITT
end
end
 
-- structure the display
for ii=1,#listofsortkey,1 do
for key, thisRow in pairs(tableChamp) do
key=listofsortkey[ii]
if tableChampthisRow[key'thereisawinner'][4]==1 then --there is a winner
tBodylocal tRow = mw.html.create('<tr style='):cssText( "line-height: 1.8em; padding: 5px;">')
if tableChampthisRow[key'sitelink'][2]=~=nil then
tBody=tRow:tag('<td>'..tableChamp):wikitext(thisRow[key][3'flag']..' [['..tableChampthisRow[key][1'sitelink']..'</td>|'..tableChampthisRow[key][5'countryname']..tableChamp[key'][6]')
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
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 --end list of key
 
return table.concat (tableBody)
return sortandconcat(t_Body, resulttable)
end
 
frame=frame
}
return tableAvictory_main(s, victory_main,tableA(s))
end
 
function victory_main(s, resulttable)
localframe=s.frame
local _
if temp then else s.error_message = 2 return '' end
 
local country =getcoutrybool true(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
 
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
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')
local dateOfRacetimeOfRace = fn_datetable[1]
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
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
tBody = tBody..tRow:node(fn_racetable[1]..) --race site link is in fn_countrytable[1]
else
tBody = tBody..fn_countrytable[1]..fn_racetable[1]
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
 
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
 
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 entityIdcountry = frame.args[1]{}
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
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
-- Function that give the starting place of a race
local place = firstValue(entityIdentityID, 'P1427P1444', 'id') -- P1427P1444 is 'startdestination point'
t_g details[index+1].startplacecontent = place or "" -- 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
 
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 '+'
for _, q in qualifiers(p1132, 'P276') do -- P276 is 'location'
local location = q.value['numeric-id']
if location == 529711 then -- Q529711 is 'beginning'
if t_gnot details[index].nr_participants_start==""content then t_gdetails[index].nr_participants_startcontent = amount end -- participants at start
elseif location == 12769393 then -- Q12769393 is 'end'
if t_gnot details[index+1].nr_participants_end==""content then t_gdetails[index+1].nr_participants_endcontent = amount end -- participants at 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
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
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
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
for _, p1346 in statements(entityIdentityID, 'P1346') do
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 riderId = p1346.mainsnak.datavalue.value.id
 
if riderId ~= nil then
subwinnertablelocal riderLink,riderTeam = subwinner(riderId, timeofracetimeOfRace, 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, ..)
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 riderId~=nil and 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
t_s[t_P642[qual][1]][ t_P642[qual][2]][1] =riderLink 'winner_fighting2'
end
t_s[t_P642[qual][1]][t_P642[qual][2]][5]=riderTeam or ""
t_s[type_ofclas=t_P642[qual][1]][t_P642[qual][2]][10]=isdisqualified(p1346,q) --annex or gen
if id_time then t_s[t_P642[qual][1]][name_ofclas=t_P642[qual][2]][6]=id_time end--name of ranking
local v=t_s[type_ofclas][name_ofclas]
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
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
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
local rank, deprecated, prop, order, thisorder
local listoftable = {'results','gen'}
 
-- look into P2417, stage classification, then p2321 gen classification
order = {'leader', 'deuxieme', 'troisieme'}
for _ii, p2321thistable in statementsipairs(entityId, 'P2321'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
prop='P2321'
t_g.previous = span1 .. label_previous
order = {'leader', 'deuxieme', 'troisieme'}
if wiki == "ar" then t_g.previous = span2 .. label_previous 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
else
t_g.next = label_next.. span2
if wiki == "ar" then t_g.next = label_next .. span1 end
end
else t_g.next = ''
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
 
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
local temp
local width= '320px' -- size standard 320px, special 340px
if t_s.classement_annexannex.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
for _, value_order in ipairs(t_s.order) do
iflocal thistable =t_s[value_order].show == true then --results if a section of the stageinfoboxor shouldgen beor shownannex
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]thistable.order) do --value is the name of the class
iflocal t_s[value_order]v=thistable[value][1]~="" then
if v['link'] then
local a1
a1, jersey_name, jerseyWPID = jersey_infobox(wiki, value, t_g.race, timeofracetimeOfRace)
if a1~='' then t_sv[value_order][value][4'jersey'] = a1 end
if t_sv[value_order][value][9'speed'] ~= '' then
if wiki == 'fo' then
t_s[value_order][value][9] = '('.. lang:formatNum(t_s[value_order][value][9])..unit(5)..')'
if wiki == v['fospeed' then t_s[value_order][value][9] = string.gsub(t_sv[value_order][value][9'speed'], "%.", ",") end
else
local lang = mw.language.getContentLanguage()
v['speed'] = '('.. lang:formatNum(v['speed'])..unit(5)..')'
end
end
if t_sv[value_order][value][8] ~= '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;
--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
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
tab=tab..tCell:wikitext(stageinfobox_translate(t_s[value_order][value]v[2'translation']))
else
else tab=tab..number(t_s[value_order][value][3], key, wiki) end
tCell:wikitext(number(v['genre'], key, wiki))
end
else
if jerseyWPID=='' then tab=tab.."[[File:"..t_s[value_order][value][4].."|20px|"..title.."]]"
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
else
if t_sv[value_order][value][4'jersey'] == ""nil then tab=tab..title
tCell:wikitext(title)
else
if jerseyWPID=='' then
if jersey_name ~= '' then tab=tab.."[[File:"..t_s[value_order][value][4].."|20px|"..jersey_name.."]]" .. title
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
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
 
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 tTab2= tab.. "<tCell:tag('table border='0):attr(' cellpadding=','0' ):attr('cellspacing=','0' style=):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
if t_sv[value_order][value][5'team']~=""nil or t_s[value_order][value]v[9'speed'] ~=""nil then
tab=tab..tCell:cssText("<tr><td colspan='2' style='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
tab=tab.. "</table></td></tr>"
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
end
local raceID = frame.args[1]
local teams = {} -- values will be {teamLink, teamCat, sortkey, index}
local text = ''
 
local timeOfRace, errorMessage = getTimeOfRacegettimeOfRace(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,34}, -- UCI Professional Continental Team (2005-2019)
["Q1756006Q78464255"] = {106,117,43}, -- UCIProTeam Continental Team(2020-)
["Q1756006"] = {10,11,5}, -- UCI Continental Team
["Q23726798"] = {12,13,6}, -- national cycling team
["Q20738667"] = {12,13,67}, -- national cycling team U23
["Q28492441"] = {12,13,68}, -- équipe cycliste nationale de marque
["Q20639848"] = {14,15,79}, -- club cycling team
["Q20639847"] = {16,17,810}, -- professional cycling team
["Q20652655"] = {18,19,911}, -- amateur cycling team
["Q20653563"] = {20,21,1012}, -- Groupe Sportif I
["Q20653564"] = {22,23,1113}, -- Groupe Sportif II
["Q20653566"] = {24,25,1214}, -- Groupe Sportif III
["Q2466826Q80425135"] = {284,295,5}, -- UCI Women’s TeamWorldTeam
["Q26849121Q2466826"] = {3028,3129,13}, -- Women's amateurUCI cyclingWomen’s teamTeam
["Q26849121"] = {30,31,14} -- Women's amateur cycling team
}
 
 
local function getHeader(CatID, count)
local header, sitelink
if teamCats[CatID] then
if count == 1 then
headerheader_label = headoftableIII(teamCats[CatID][1]) -- singular name
else
headerheader_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 text
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')
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
tHeader:wikitext(header)
-- Set parameter to show team count in front of each category
local tTag=''
local showcounter = 2
if count >= showcounter then
text tTag= text mw.html. create(' <small>'):wikitext(' (' .. count ..')</small>')
end
return texttostring(tHeader)..tostring(tTag)
end
 
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
textheader = text .. getHeader(oldCatID, count) .. '<ol>' .. list .. '</ol>'
tCell:wikitext(header)
tCell:node(tOl)
end
count = 1
oldOrder = order
listtOl = mw.html.create('ol') --reinit
else
count = count + 1
end
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
--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
 
]=]
 
local timeOfRace, errorMessage = getTimeOfRacegettimeOfRace(raceID)
if not timeOfRace then return errorMessage end
 
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
if i ~==1 2 or (country and available_list) then
tableHeader2local head= tableHeader2.. header:tag('<th colspan="2">'.. ):wikitext(s.header_function(k) .. '</th>')
elseif if i ==2 and available_list and country or i>=31 then
head:attr('colspan','2')
tableHeader2 = tableHeader2.. '<th>'.. s.header_function(k) .. '</th>'
end
end
end
tableHeader2 = tableHeader2.. '</tr>'
 
local tableBodyt_Body = ''{} --contains all rows
local t_BodytCell, =bg_color, {}tStyle, temp, temp2
local bg_color
local claims = mw.wikibase.getAllStatements(raceID, s.property)
for l, m in pairs(claims) do -- look into all statements
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)
end
 
local tBody = '<tr'
-- 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
end
end
tStyle=''
if rank == 1 then
if s.background then -- values are 'strong' or 'color'
tBodytStyle = tBodytStyle ..' style="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
tBodytStyle = tBodytStyle .. 'background-color:' ..bg_color
end
end
tBody = tBody .. '"'
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 teamLink then teamLink = '' end
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
else
if country == true then
tCell:wikitext(riderLink .. jersey(h.jersey) )
if s.displayteam==false then
tBody = tBody .. riderLink .. jersey:tag(h.jersey'td'):wikitext( flagLink ..'</td><td> ' .. 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
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 :tag('td'):cssText("text-align:".. flagLinktextalign ..";padding:0 ' ' .0.2em riderLink0 0.. jersey(h.jersey2em") ..
:wikitext(teamLink)
'</td><td style="text-align:' .. textalign .. ';padding:0 0.2em 0 0.2em">'.. teamLink
end
end
end
else --team
if not available_list==true and country then
tBody = tBody .. flagLink .. ' ' .. tCell:wikitext(teamLink .. jersey(h.jersey))
tBody:tag('td'):wikitext(flagLink .. ' ' .. countryName)
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
tBody = tBody.. '</td>'
 
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])
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
temp=''
tBody = tBody.. '<td style="text-align:right;padding:0 0.2em 0 0.2em">'..
'' .. '</td>'
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
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
local temp
if h.value[1] then temp=h.value[1] else temp='' end
tBody tCell= tBody.. :tag('<td style='):cssText("text-align:right;padding:0 0.2em 0 0.2em">'..temp)
:wikitext(temp)
.. '<span style="font-size:80%">'
if type(h.value[1]) == "number" then
if h.value[1] > 1 then
tBody temp2= tBody..unit(7)
else
tBody temp2= tBody..unit(6)
end
tCell:tag('span'):cssText("font-size:80%"):wikitext(temp2)
end
tBody = tBody.. '</span>' .. '</td>'
end
 
if s.property == 'P2417' or s.property == 'P2321' then
-- for tables teamtimetrialclassification or generaltttclassification, adds time
tBody = tBody.. :tag('<td style='):cssText("text-align:right;padding:0 0.2em 0 0.2em">'..)
:wikitext(calculate_time(h.value[2]) .. '</td>')
end
end
 
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">'..
temp=calculate_time(h.value[2]) .. '</td>'
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
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
tBody tCell= tBody.. :tag('<td style='):cssText("text-align:right;padding:0 0.2em 0 0.2em">'.. h.value[1]..)
:wikitext(h.value[1])
'<span style="font-size:80%">'
if type(h.value[1]) == "number" then
if h.value[1] > 1 then
tBody temp2= tBody..unit(7)
else
tBody temp2= tBody..unit(6)
end
tCell:tag('span'):cssText("font-size:80%"):wikitext(temp2)
end
tBody = tBody.. '</span>' .. '</td>'
end
 
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
 
if s.header_2[5] == 6 then -- for table teamtimetrialclassification, adds speed
tBody tCell= tBody.. :tag('<td style='):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])..
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
tBody = tBody.. '</td>'
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
table.sort(t_Body, function(a, b) return a[1] < b[1] end)
for _, m in ipairstableBody=sortandconcat(t_Body) do, tableBody = tableBody .. m[2] end)
local tableFooter1,tableFooter2
 
local tableFooter = ''
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
 
--general table style and last line
local tableEnd = '</table>'
 
local tableStyle, tableNewline
if localframe.args.newline == 'false' then -- parameter newline in WP article is 'false'
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
 
{ name = infobox_translate(30)}, -- caption
{ name = infobox_translate(31)}, -- map
{ name = 'sectional_view '}
}
local winners = {
getLocalContent(winners, localframe.args)
 
local dateOfRacetimeOfRace, 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 = wikibase.getLabel 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
details[4].content = startTime .. ' – ' .. endTime
details[4].name = details[4].name_plural
dateOfRacetimeOfRace = eTime
else
-- This function give a format to dates when P585 (date) is used in a single day race
if pTime then
details[4].content = func_date(pTime, 'long')
dateOfRacetimeOfRace = pTime
end
end
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
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
local Allp710= wikibase.getAllStatements(entityID, 'P710')
end
end
if maxrank~=1 then details[11].content=maxrank end
end
end
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
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 = {}
for _, v in pairs(winners) do
end
end
winner(entityID, win, dateOfRacetimeOfRace, false, WDlink_on, team, true)
for _, v in pairs(winners) do
if not v.content then
end
if v.content then
winRows tRow= winRows mw.html. "<create('tr') style= :css('vertical-align:top'><td>,'top''" .. v.name ..)
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
if winRows ~= '' then
tab:tag('tr'):tag('td'):attr('colspan','2')
tab = tab .. "<tr><td colspan='2' style='border-bottom:5px solid white; background-color:#FFDF80; text-align:center'>'''"
:cssText('border-bottom:5px solid white; background-color:#FFDF80; text-align:center')
.. infobox_translate(18) .. "'''</td></tr>" .. winRows
:css('font-weight','bold')
:wikitext(infobox_translate(18))
tab:wikitext(winRows)
end
 
if others[3].content then -- map
tab = tab .. "<:tag('tr><'):tag('td '):attr('colspan=','2' style=):css('text-align:center'>[[File:".. others[3].content .. "|,'center|300px]]</td></tr>"')
:wikitext("[[File:".. others[3].content .. "|center|300px]]")
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
end
end
end
outputTable[1]=return riderReason, riderRef
outputTable[2]= riderRef
return outputTable
end
 
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
 
local function findlastname(label,wiki)
if not label then label = '' end
local _, count = string.gsub(label, " ", " ")
local names
end
end
return names or ''
end
 
local label = wikibase.getLabelByLang(riderID, wiki)
if not label then
label = getLabelFallback(riderID, {'en', 'fr', 'de', 'es'})
return findlastname(label,wiki)
else
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
riderName, correctlanguage =getRiderLink(riderID, startOfSeason) --label
if WDlink_on==true then riderName=riderName..wdLink(riderID) end
local timeofracetimeOfRace = startOfSeason
 
local tempriderBirthday=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
local sortkey = findsortkey(riderID, correctlanguage, wiki, wikiisslavic)
 
riderReasonTableriderReason, iderRef=getreason(riderReason,riderRef,p527)
riderReason=riderReasonTable[1]
riderRef=riderReasonTable[2]
 
for _, q in qualifiers(p527, 'P580') do
local startdate = q.value['time']
timeofracetimeOfRace = startdate
riderStart = func_date(trans(startdate,'01', '01'), 'small')
end
 
if teamID == nil then
local p54 = getStatementForTime(riderID, 'P54', timeofracetimeOfRace)
if p54 then teamID = p54.mainsnak.datavalue.value.id end
else
local thisteamID = v.mainsnak.datavalue.value.id
if thisteamID == teamID then
riderReasonTableriderReason, 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
date1=v.qualifiers["P580"][1].datavalue.value.time
--get the country
local countryID
local p27 = getStatementForTime(riderID, 'P27', timeofracetimeOfRace) --P27 is country of citizenship
if p27 then
countryID = p27.mainsnak.datavalue.value.id
if countryID then
pays = getCountryName(countryID)
flags = flag(countryID, timeofracetimeOfRace)
end
--save
end
 
local tableBodyoutputTable = 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 ~= :tag('lvth'):attr('colspan', then tableHeader = tableHeader.. 4):cssText('</th><th style="text-align:center;padding:2px 20px 2px 2px;white-space:nowrap">'..getSquadTableColumn(6) end
: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 tableEndTextheader = 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]
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)
 
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
tableBody=tableBody..tCell:tag('<span style='):cssText("font-size:80%; color:#686868"> ('..riderStart..'–'..riderEnd.. (riderPosition or '')
local note=''
if riderReason ~= nil then
local note = ', [[#tr_'..i..frame.args[1]..'|'..getSquadTableColumn(4)..']]'
if wiki == "ar" then note = '، [[#tr_'..i..frame.args[1]..'|'..getSquadTableColumn(4)..']]' end
tableBody = tableBody .. note
end
tCell:wikitext( ' ('..riderStart..'–'..riderEnd.. (riderPosition or '')..note..')')
tableBody=tableBody .. ')</span>'
elseif riderReason then
tableBody=tableBody.. tCell:tag('<span style='):cssText("font-size:80%; color:#686868"> ([[#tr_'..i..frame.args[1]..'|'..getSquadTableColumn(4)..']]'.. ')</span>'
:wikitext('([[#tr_'..i..frame.args[1]..'|'..getSquadTableColumn(4)..']]'.. ')')
end
tableBody tCell= tableBody.. tRow:tag('</td><td style='):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+)")
tableBody = tableBody.. tCell:wikitext(frame:expandTemplate{ title = 'Template:Birth date and age2', args = { y1, m1, d1, y2, m2, d2 } }.. '</td>')
else
tableBody = tableBody.. 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
 
local isRtl = (mw.ustring.find(riderTeam, '|.*[א-ת]') or (not mw.ustring.find(riderTeam, '|') and mw.ustring.find(riderTeam, '[א-ת]')))
if isRtl then
tableBody tCell= tableBody.. tRow:tag('<td style='):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
tableBody tCell= tableBody.. tRow:tag('<td style='):cssText("padding:0 0.5em; text-align:left">')
end
else
tableBody tCell= tableBody.. tRow:tag('<td style='):cssText("padding:0 0.5em; text-align:left">')
end
if riderTeam then
tCell:wikitext(riderTeam.. timeTeam..errortext)
end
 
if riderTeam then tableBody = tableBody.. riderTeam.. timeTeam..errortext end
tableBody = tableBody..'</td></tr>'
 
if riderReason ~= nil or errortext ~= '' then
end
if iii == 1 then
tableEndText = tableEndText.. outputTable:wikitext(getSquadTableColumn(5)..': '.. riderName.. temp)
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
iii = iii + 1
if riderRef ~= nil then tableEndText = tableEndText..
local tRef=frame:extensionTag{name='ref', content=riderRef, args = {name='tr_'..i..frame.args[1]}} end
outputTable:node(tRef)
tableEndText = tableEndText.. '<br>'
end
outputTable:wikitext('<br>')
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
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
 
 
local titletable={
['Q20882667']=listofwinners_translate(2), --winner
[ 'Q20882668Q27104269' ]=listofwinners_translate(32), --secondwinner team
[ 'Q20882669Q20883139' ]=listofwinners_translate(42), --thirdwinner young
[ 'Q20883007Q72068715' ]=listofwinners_translate(52), --points winner country
[ 'Q20883212Q72068724' ]=listofwinners_translate(62), --winner mountainscountryU23
['Q20883328Q20882668' ]=listofwinners_translate(73), -- sprintssecond
 
[ '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
[ 'Q20893979' ]=listofwinners_translate(10), -- combination
[ 'Q20882921' ]=listofwinners_translate(11), -- teams
[ 'Q27067359' ]=listofwinners_translate(12), -- volantes
[ 'Q27067170' ]=listofwinners_translate(13), -- regularity
[ '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
}
 
local winners = {}
for _, property in ipairs(s.winnersProperty) do winners[property]='' end
local tCell
 
local temprow = "<tr><td styletCellstr='text-align:left'>" .. sitelink
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')
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
winner(partID, winners, timeOfRace, not s.countryflag, WDlink_on,s.displayteam,true)
for _, property in ipairs(s.winnersProperty) do
temprowtCell=temprowmw.html."</create('td><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, temprowsitelink, .. "</td></tr>"tCellstr}
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
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
tCell:tag('span'):css("float","left")
table_proto = table_proto .. '<span style="float:left">[[File:Wikidata-logo S.svg|12px|link=d:' ..
:wikitext("[[File:Wikidata-logo S.svg|12px|link=d:"..raceID .. '"#P527]]</span>'")
end
table_proto = table_proto .. tCell:wikitext(listofwinners_translate(1).. "</th>" ) --year
for kk_, pp in ipairs(s.winnersProperty) do
table_proto = table_proto.."<tTitleRow:tag('th>".. '):wikitext(titletable[pp] .. "</th>")
end
table_proto =table_proto .."</tr>"
local table_center, table_last = "", "</table>"''
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 .. "<tr><td colspan='4' style='text-align:center'>" ..tostring(tRow)
table_center=table_center..tostring(tRowWD)
WPcontent.row[i] .. "</td></tr>"
table_center = table_center .. row[2]
else --below
table_center = table_center .. row[2]tostring(tRowWD)
table_center = table_center .. "<tr><td colspan='4' style='text-align:center'>" ..tostring(tRow)
WPcontent.row[i] .. "</td></tr>"
end
else
table_center = table_center .. row[2]tostring(tRowWD)
end
end
--firstpart with header no foot
if endyear > 0 then
return table_first .. table_prototostring(tTitleRow) .. table_center
elseif beginyear > 0 then
return table_center .. table_last
else
return table_first .. table_prototostring(tTitleRow) .. table_center .. table_last"</table>"
end
end
local sDistance = getDistance(stageID, false) or ''
local sElevation = getElevation(stageID)
if sElevation ~= "" then thereiselevation=true end
local winners = {
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
end
 
local tRow = tab:tag('tr')
local t = "<tr><td style='text-align:center; white-space:nowrap'>" .. sLink ..
"<spanlocal styletCell= tRow:tag('td'):cssText('text-align:center; white-space:nowrap'>&nbsp;".. WDLink ..):wikitext(sLink)
"</tCell:tag('span></td><td style='):css('white-space:','nowrap; text-align'):rightwikitext("&nbsp; padding-right:0px'>" .. sDateWDLink ..)
"</tRow:tag('td><td style='):css('white-space','nowrap'):cssText("text-align:right; padding-right:0px'>" .. sPoint)
: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
t = t.."<tRow:tag('td style='):css('text-align:','center'>" .. ):wikitext(sElevation .. "</td>")
end
 
if WPc and WPc['stage winner'] then
t = t .. "<tRow:tag('td style='):css('text-align',textalign):" .. textalign .. "'>" ..wikitext( WPc['stage winner'] .. "</td>")
else
t = t .. "<tRow:tag('td>" .. '):wikitext(sSWin .. "</td>")
end
if WPc and WPc['general winner'] then
t = t .. "<tRow:tag('td style='):css('text-align',textalign):" .. textalign .. "'>" ..wikitext( WPc['general winner'] .. "</td></tr>")
else
t = t .. "<tRow:tag('td>" .. '):wikitext(sGWin .. "</td></tr>")
end
if WPc and (WPc['date'] or WPc['text'] or WPc['icon (new row)']) then
ttRow = t .. "<tab:tag('tr><td></td>"')
tRow:tag('td') --empty
 
if WPc['icon (new row)'] == '' then
t = t .. "<tRow:tag('td style='):cssText('text-align:right; padding:3px 0px 10px 0px;white-space:nowrap'>" .. WPc['date'] ..)
: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
t = t .. "<tRow:tag('td style='):cssText('text-align:right; padding-right:0px'>" .. WPc['date'] ..)
:wikitext(WPc['date'])
"</td><td style='text-align:" .. textalign .. "'>" .. WPc['text']
tRow:tag('td'):cssText("text-align:" .. textalign)
:wikitext(WPc['text'])
end
t = t .. "</tRow:tag('td><td style='):css('padding-top:','10px'>" .. ):wikitext(WPc['icon (new row)'] .. "</td><td colspan='3' ></td></tr>")
tRow:tag('td'):attr('colspan','3')
end
rows[num] = t
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
 
-- find the type of stage
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
 
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,
end
 
local dateOfRacetimeOfRace
for ii, v in pairs(stages) do
if v.mainsnak.snaktype == 'value' then
local eTime = firstValue(stageID, 'P582', 'time') -- P582 is 'end time'
if sTime and eTime then
dateOfRacetimeOfRace = 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
dateOfRacetimeOfRace = pTime
end
end
if ii==1 then jerseytable[v.QID]='' end
end
winner(stageID, win, dateOfRacetimeOfRace, false, WDlink_on, false, false)
if ii==1 then --only first stage
jerseytable, bgcolortable=winnerjersey(stageID, jerseytable)
end
end
local thiskey
somewinner = false
jerseytable, bgcolortable=winnerjersey(raceID, jerseytable)
winner(raceID, win, dateOfRacetimeOfRace, 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[generaltoleader[v.QID]][#stages+1][1]=win[v.QID]
columntable[generaltoleader[v.QID]thiskey][#stages+1][21]=#stages+1win[v.QID]
columntable[generaltoleader[v.QID]thiskey][#stages+1][32]=#stages+1
if type(columntable[generaltoleader[v.QID]thiskey][#stages+1][13])~="string" then --check nil actually, but it is a table..1
if type(columntable[generaltoleader[v.QID]thiskey][#stages][1])~=win[v.QID]"string" then --nocheck neednil toactually, fillbut lastit stage ofis a stage racetable..
if type(columntable[generaltoleader[v.QID]thiskey][#stages-1][1])=="string" and win[v.QID]==columntable[generaltoleader[v.QID]][#stages -1][1]-no need to fill last stage of a stage thenrace
localif initialstage=type(columntable[generaltoleaderthiskey][#stages-1][1])=="string" and win[v.QID]==columntable[thiskey][#stages-1][21] then
local initialstage=columntable[generaltoleader[v.QID]thiskey][#stages-1][2]=initialstage
columntable[generaltoleader[v.QID]thiskey][initialstage#stages][32]=columntable[generaltoleader[v.QID]][initialstage][3]+1
columntable[generaltoleaderthiskey][v.QIDinitialstage][3]=columntable[#stagesthiskey][initialstage][3]=0+1
columntable[thiskey][#stages][3]=0
else
columntable[generaltoleader[v.QID]thiskey][#stages][2]=#stages
columntable[generaltoleader[v.QID]thiskey][#stages][3]=1
end
end
columntable[generaltoleader[v.QID]thiskey].used=true
if jerseytable[v.QID] and jerseytable[v.QID]~='' then
columntable[generaltoleader[v.QID]thiskey].jersey=jerseytable[v.QID]
columntable[generaltoleader[v.QID]thiskey].bg_color=bgcolortable[v.QID]
end
end
 
--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
if v.used == true then
if v.jersey == '' then v.jersey = "_" end
tableheader=tableheader.."<tRow:tag('th>"..'):wikitext(v.name.."<br />"..v.jersey.."</th>")
end
end
tableheader=tableheader.."</tr>"
 
local row, tablebody='',''
local style, tdtemp
 
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
tdtemp="<td tCell:attr('colspan=','2 style='):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
row=tdtemp..tCell:wikitext(v.sLink.."</td>")
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
row=row..tdtemp2..tCell:wikitext(v.sType.."</td>")
else
row=row..tdtemp2.."</td>"
end
end
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=" 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])
style=style.."'>"
row=row.."<td rowspan="..tostring(y[ii][3])..style..y[ii][1].."</td>"
elseif (columntable['Q20882747']==y) then --no rowspan for stages
row=row.."<tRow:tag('td>"..'):wikitext(y[ii][1].."</td>")
end
else
tCell=tRow:tag('td')
if ii~=#stageinfotable and v.somewinner==true then
row=row.."<td>"..tCell:wikitext(listofstagesclassification_translate(1).."</td>") --not attributed
elseif ii~=#stageinfotable then
row=row.."<td>".."</td>" --empty
elseif v.somewinner==true then
row=row.."<td style=tCell:cssText('border-top: 2px black solid'>"..listofstagesclassification_translate(1).."</td>"
:wikitext(listofstagesclassification_translate(1))
else
row=row.."<td style=tCell:cssText('border-top: 2px black solid'>".."</td>") --empty
end
end
end
end
tablebody=tablebody.."<tr>"..row.."</tr>"
end
return tab
return tablebegin..tableheader..tablebody.."</table>"
end
 
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},-- translations 2, 3, 4, 5, 6 in function victories_translate are printed in this order
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'},
property ='P710',
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
 
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.
-- data_type = {'date', 'race', 'country', 'class', 'rider'},
-- country_column = 3,
no_country ={'fr'},
data_sort_type={'', '', ''},
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
 
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 = '<tr style= mw.html.create('tr'):cssText("line-height: 1.8em; padding: 5px;">')
tBody=tBody..:tag('<td style='):cssText("text-align:right;padding:0 0.5em">'..):wikitext(riderDossard..'</td>')
tBody = tBody..:tag('<td style="'):cssText('text-align:'..textalign.. ';padding:0 0.5em;'..DSQ..'>'..):wikitext(riderLink..'</td>' )
if istable then
tBody = tBody..:tag('<td style='):cssText("text-align:'..textalign.. 'right;padding:0 0.5em">'..):wikitext(riderTeam..' </td>' )
end
tBody = tBody..:tag('<td style="'):cssText('text-align:right'..textalign.. ';padding:0 0.5em;'..DSQ..'>'..):wikitext(number(gender,riderRank,wiki)..riderDNF..'</td>' )
tBody = tBody.. '</tr>'
 
table.insert(resulttable, {sortkey=sortkey, riderTeam=riderTeam,riderTeamCode=riderTeamCode, tBody=tBody})
end
 
function startlist_main(s, resulttable, tag)
local tableBody, sortindex, fn_datetable, ridertable, DStable, subtable = {}, {}, {}, {}, {}, {}
local DSID, DSLink, DSteamID, DSteam
local numberoflines
local WDlink_on = (wiki == "mk" or wiki == "ja" or wiki == "ru")
 
local 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, 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
 
--look for transition between teams
--look for transition between teams
local test
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
for ii=1,numberoflines+1#ridertable do
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
--new team
if test==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
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
table.insert(tableBody, endRow)
end
thisTableRow=mw.html.create('tr')
table.insert(tableBody, beginRow)
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
for _,v in pairs(DStable) do
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
insideTable:node(ridertable[ii].tBody)
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
 
function startlisttable_main(s, resulttable)
local tableBody, sortindext_Body, fn_datetable, subtable = {}, {}, {}, {}
local tBody = '' --row in our case
local sortkey
local WDlink_on = (wiki == "mk" or wiki == "ja" or wiki == "ru")
 
for _, p710 in statements(s.item, 'P710') do -- P710 is participants
subtable=startlist_sub(p710, timeOfRace, WDlink_on, true)
sortkeyt_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
return table.concat sortandconcat(tableBodyt_Body, resulttable)
end
 
 
function riderranking_main(frame,s)
local thisCompetition, rank, thisyear, sitelink, cell, q, gender
local Resulttable, listofcalendar, UCI, UCImaster={},{},{}, {}
local minmaxyear= {
Resulttable[thisyear][calendar]["rank"]=tostring(rank)
calendarlistpresent[calendar]=true
sitelink=mw.wikibase.getSitelink(thisCompetition) or "Jean"
Resulttable[thisyear][calendar]["sitelink"]=sitelink
end
--display result
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
tableyear=tableyear..tRow:tag('<th '):attr("width=","50px" style=):cssText("text-align:center; background-color:#FFDF80;padding:1px 1px;"> '..tostring(ii)..' </th>'--
:wikitext(tostring(ii))
end
 
tableyear=tableyear..'</tr>'
local tablebody=''
for _, calendar in pairs(listofcalendar) do
if calendarlistpresent[calendar] then
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
thisyear=tostring(ii)
color="silver"
end
tCell=tRow:tag('td'):attr("bgcolor",color)
if Resulttable[thisyear][calendar]["sitelink"] then
cell=tCell:wikitext('<td bgcolor='..color..'>[['..Resulttable[thisyear][calendar]["sitelink"]..'|'..
number(gender,Resulttable[thisyear][calendar]["rank"],wiki)..']]'..'</td>')
else
cell='<td bgcolor='..color..'>'..tCell:wikitext(number(gender,Resulttable[thisyear][calendar]["rank"],wiki)..'</td>')
end
else
cell=tRow:tag('<td >'):wikitext(' - </td>')
end
tablebody=tablebody..cell
end
tablebody=tablebody..'</tr>'
end
end
local tableyearsize=minmaxyear.maximum-minmaxyear.minimum+2
local tableFooter = finalTable:tag('<tr><'):tag('td class='):addClass("navigation-only" colspan=' .. tostring(tableyearsize) ..
: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