Module:Sandbox/psemdel/CR explained

local p = local wiki, onwikidatawiki = string.match(mw.site.server, "%a+")if wiki

"www" then wiki = "fr" onwikidata = trueelse onwikidata = falseendlocal contentLanguage = mw.getContentLanguagelocal wikilang = contentLanguage:getCodelocal wikibase = mw.wikibaselocal localframe -- Value may be given by functions which use frame functions like getReference

--

Structure of the code

-- I) Constant-- II) Basic functions (fooA)-- III) Functions less basic called from other functions -----A) Time functions (new)-----B) Time functions (obsolete)-----C) Link functions (new)-----D) Link functions (obsolete)-----E) Functions for the output, like table-----F) Jersey, flag functions-----G) Other (winner)-- IV) Translation-- V) Main functions ----- A) Function race reference ----- B) Calendar----- C) Victory----- D) Stage infobox----- E) List of teams----- F) Classifications----- G) Infobox----- H) Team roster----- I) Function list of winners (palmarès)----- J) List of stages--Tipps: search "--

" to navigate between the sections

--

I) Classes declared as global

-- Class of a cycling race. Class is: 1.UWT, 2.UWT, 1.HC, ... add new classes, no problemlocal class = local classes =

local class_2x = --multi stage raceslocal class_without2x = local class_champ =

local class_sort=local stages = -- UCI Europe Tour,..., UCI ProTour, UCI World Calendar, UCI WorldTour, UCI Women’s WorldTour, UCI Women's Road World Rankingslocal UCI_Circuits =

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

"function"local available_lang_priority = available

true and type(translations.lang_priority)

"table"

local textalign = "left"local floattable = "left"local floatinfobox = "right"if wiki

"ar" or wiki

"fa" or wiki

"ur" or wiki

"he" then textalign = "right" floattable = "right" floatinfobox = "left"end

--

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

'value' then return field and s.mainsnak.datavalue.value[field] or s.mainsnak.datavalue.value end endend

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

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

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

function fooA (mode,entity,property,var) --Obsolete local snak if mode

"value" then snak=entity.claims[property][var].mainsnak.datavalue.value else snak=entity.claims[property][var].mainsnak.datavalue.value[mode] end return snak, entity.claims[property][var].rankend

function fooB (mode, entity_var, property, var1, var2, ref, var3) --Obsolete local snak if mode

'value' then snak = entity_var.claims[property][var1].references[var2].snaks[ref][var3].datavalue.value else snak = entity_var.claims[property][var1].references[var2].snaks[ref][var3].datavalue.value[mode] end return snakend

function fooC (mode, entity_var, property, var1, quali, var2) --Obsolete local snak if mode

'value' then snak = entity_var.claims[property][var1].references[var2].snaks[ref][var3].datavalue.value else snak = entity_var.claims[property][var1].qualifiers[quali][var2].datavalue.value[mode] end return snakend

function foo1 (arg) --Obsolete local entity = mw.wikibase.getEntity(arg)end

function foo2 (entity_var, property, var) --Obsolete local snak = entity_var.claims[property][var].mainsnak.datavalue.value.amountend

function foo3 (entity_var, property, var1, quali, var2) --Obsolete local snak = entity_var.claims[property][var1].qualifiers[quali][var2].datavalue.value.amountend

--Iterator to get all statements for an entity and property which are not deprecated and have a valuelocal function nextStatement(state, i) local s repeat i = i + 1 local s = state[i] if s and s.rank ~= 'deprecated' and s.mainsnak.snaktype

'value' then return i, s end until s

nilendlocal function statements(QID, PID) return nextStatement, wikibase.getAllStatements(QID, PID), 0end

--Iterator to get all qualifier values for a property for a statementlocal function nextQualifier(state, i) local q repeat i = i + 1 local q = state[i] if q and q.snaktype

'value' then return i, q.datavalue end until q

nilendlocal function qualifiers(statement, PID) return nextQualifier, statement.qualifiers and statement.qualifiers[PID] or, 0end

--

III) Functions less basic called from other functions

--

A) Time functions (new)

--Get a Wikidata statement for an entity and property valid at the given timevalue local function getStatementForTime(ID, property, time) for _, s in statements(ID, property) do local start, startPrecision, END, endPrecision local q = s.qualifiers if q then if q.P580 and q.P580[1] and q.P580[1].snaktype

'value' then -- P580 is start time start = q.P580[1].datavalue.value.time startPrecision = q.P580[1].datavalue.value.precision if startPrecision

9 then -- precision is years start = string.sub(start, 1, 5) -- Cut of everything after year elseif startPrecision

10 then -- precision is months start = string.sub(start, 1, 8) -- Cut of everything after month end end if q.P582 and q.P582[1] and q.P582[1].snaktype

'value' then -- P582 is end time END = q.P582[1].datavalue.value.time endPrecision = q.P582[1].datavalue.value.precision end end if not start or start <= time then if not END then return s end if endPrecision

9 then -- precision 9 is 'years' END = string.sub(END, 1, 6) .. '13' -- Set month to 13 elseif endPrecision

10 then -- precision 10 is 'months' END = string.sub(END, 1, 9) .. '32' -- Set day to 32 end if END > time then return s end end endend

--local function getTimeOfRace (raceID) local timeOfRace local p580 = mw.wikibase.getBestStatements(raceID, "P580") -- P580 is start time if p580[1] and p580[1].mainsnak.snaktype

'value' then timeOfRace = p580[1].mainsnak.datavalue.value.time else local p585 = mw.wikibase.getBestStatements(raceID, "P585") -- P585 is point in time if p585[1] and p585[1].mainsnak.snaktype

'value' then timeOfRace = p585[1].mainsnak.datavalue.value.time else local link = getSitelinkFallback(raceID,) if link then local year = string.match(link, '%d%d%d%d') if year then timeOfRace = year .. '-01-01T00:00:00Z' end end end end return timeOfRace, '> Wikidata is missing data about start time (P580) or point in time (P582)'end

local function getStartEndTime(sTime, eTime, mode) -- Note: Add the formats to "formats" and use func_date local wiki = wiki local lang = contentLanguage local starttime, endtime --local format = formats[wiki] or formats[''] if mode

nil then mode='long' end -- Timevalues is like "+2015-07-04T00:00:00Z" local _, _, y, m, d = string.find(sTime, "(%d+)-(%d+)-(%d+)") local _, _, y2, m2, d2 = string.find(eTime, "(%d+)-(%d+)-(%d+)") if y ~= y2 then if mode

'long' then starttime = lang:formatDate("j F Y", sTime) else starttime = lang:formatDate("j M Y", sTime) end elseif m ~= m2 then if mode

'long' then starttime = lang:formatDate("j F", sTime) else starttime = lang:formatDate("j M", sTime) end else starttime = lang:formatDate("j", sTime) end

if wiki

"ar" then if y ~= y2 then starttime = lang:formatDate("d F Y", sTime) elseif m ~= m2 then starttime = lang:formatDate("d F", sTime) else starttime = lang:formatDate("d F", sTime) end elseif wiki

"br" then if y ~= y2 then starttime = lang:formatDate("j", sTime) .." a viz ".. lang:formatDate("F Y", sTime) elseif m ~= m2 then starttime = lang:formatDate("j", sTime) .." a viz ".. lang:formatDate("F", sTime) else starttime = lang:formatDate("j", sTime) .." " end elseif wiki

"ca" or wiki

"es" or wiki

"ast" then if y ~= y2 then starttime = lang:formatDate("j", sTime) .." de ".. lang:formatDate("F", sTime) .." de ".. lang:formatDate("Y", sTime) elseif m ~= m2 then starttime = lang:formatDate("j", sTime) .." de ".. lang:formatDate("F", sTime) else starttime = lang:formatDate("j", sTime) .." " end elseif wiki

"cs" then if y ~= y2 then starttime = lang:formatDate("j. xg Y", sTime) elseif m ~= m2 then starttime = lang:formatDate("j. xg", sTime) else starttime = lang:formatDate("j", sTime) end elseif wiki

"de" or wiki

"da" or wiki

"fo" or wiki

"no" then if y ~= y2 then starttime = lang:formatDate("j. F Y", sTime) elseif m ~= m2 then starttime = lang:formatDate("j. F", sTime) else starttime = lang:formatDate("j.", sTime) end elseif wiki

"fi" then if y ~= y2 then starttime = lang:formatDate('j. F"ta" Y', sTime) elseif m ~= m2 then starttime = lang:formatDate('j. F"ta"', sTime) else starttime = lang:formatDate("j.", sTime) end elseif wiki

"en" then if y ~= y2 then starttime = lang:formatDate("F d, Y", sTime) elseif m ~= m2 then starttime = lang:formatDate("F d", sTime) else starttime = lang:formatDate("F d", sTime) end elseif wiki

"eo" then if y ~= y2 then starttime = lang:formatDate("j", sTime) .."-a de ".. lang:formatDate("F Y", sTime) elseif m ~= m2 then starttime = lang:formatDate("j", sTime) .."-a de ".. lang:formatDate("F", sTime) else starttime = lang:formatDate("j", sTime) .."-a " end elseif wiki

"eu" then if y ~= y2 then starttime = lang:formatDate("Y", sTime) ..".eko ".. lang:formatDate("F", sTime) .."k ".. lang:formatDate("j", sTime) elseif m ~= m2 then starttime = lang:formatDate("F", sTime) .."k ".. lang:formatDate("j", sTime) else starttime = lang:formatDate("F", sTime) .."k ".. lang:formatDate("j", sTime) end elseif wiki

"hu" then if y ~= y2 then starttime = lang:formatDate("Y", sTime) ..". ".. lang:formatDate("F j", sTime) .."." elseif m ~= m2 then starttime = lang:formatDate("F j", sTime) .."." else starttime = lang:formatDate("F j", sTime) .."." end 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 y ~= y2 then starttime = lang:formatDate("Y. \\g\\a\\d\\a j. F", sTime) elseif m ~= m2 then starttime = lang:formatDate("Y. \\g\\a\\d\\a j. F", sTime) else starttime = lang:formatDate("Y. \\g\\a\\d\\a j.", sTime) end elseif wiki

"pl" then local date_pl = 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 if mode

'long' or y ~= y2 then endtime = lang:formatDate("j F Y", eTime) else endtime = lang:formatDate("j M", eTime) end if wiki

"ar" then if 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، 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 endtime = lang:formatDate("j", eTime) .." de ".. lang:formatDate("F", eTime) .." de ".. lang:formatDate("Y", eTime) 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 endtime = lang:formatDate("j. F Y", eTime) elseif wiki

"en" then if y ~= y2 then endtime = lang:formatDate("F d, Y", eTime) elseif m ~= m2 then endtime = lang:formatDate("F d, Y", eTime) else endtime = lang:formatDate("d, Y", eTime) --suspect way to write it 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 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) elseif m ~= m2 then endtime = lang:formatDate("j. F", eTime) else endtime = lang:formatDate("j. F", eTime) end elseif wiki

"pl" then local date_pl = endtime = lang:formatDate("j ", eTime) .. date_pl[tonumber(lang:formatDate("n", eTime))] .. lang:formatDate(" Y", eTime) end return starttime, endtimeend

local formats = function func_date (date, mode) -- local date = '+2016-05-20' -- local mode = 'small' local contentLanguage = contentLanguage local format = formats[wiki] or formats[''] return contentLanguage:formatDate(format[mode], date)end

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

--

B) Time functions (obsolete)

-- Kaldt med timeStartEnd_entity(entity, 'P1448', 'text', startOfSeason)local function timeStartEnd_entity(entity, property, mode, timeofrace) -- mode = 'numeric-id', property = 'P54', Qid = 'Q123' --local entity = mw.wikibase.getEntity(Qid) local a, b = pcall(fooA, mode, entity, property, 1) -- holdets første officielle navn ifølge entity local starttime, endtime = '+0000-01-01', '+9999-12-31' local available_lang_priority = available_lang_priority

if a

true then local timeStartEnd = local num = 1 local v for _, v in pairs(entity.claims[property]) do if pcall(function local test = v.mainsnak.datavalue.value[mode] end) then -- test if not 'unnown value' if pcall(function starttime = v.qualifiers["P580"][1].datavalue.value.time end) then starttime = v.qualifiers["P580"][1].datavalue.value.time -- starttid fot officiel navn local _,_,year,m,d = string.find(starttime,"(%d+)-(%d+)-(%d+)") if m

'00' and d

'00' then starttime = '+'..year..'-01-01T00:00:00Z' end end if pcall(function endtime = v.qualifiers["P582"][1].datavalue.value.time end) then endtime = v.qualifiers["P582"][1].datavalue.value.time -- sluttid for officielt navn local _,_,year,m,d = string.find(endtime,"(%d+)-(%d+)-(%d+)") if m

'00' and d

'00' then endtime = '+'..year..'-12-31T23:59:59Z' end if m

'01' and d

'01' then endtime = '+'..year..'-12-31T23:59:59Z' end end if v.qualifiers then if (not v.qualifiers["P580"] or starttime <= timeofrace) and (not v.qualifiers["P582"] or endtime >= timeofrace) then if available_lang_priority

true and property

"P1448" then local test = false pcall(function if type(v.qualifiers["P1448"])

'table' then test=true end end) if test

false then timeStartEnd[num] = v.mainsnak.datavalue.value[mode] else local lang_module, lang_WD local language= local zaehler for i,j in ipairs(translations.lang_priority) do lang_module = j for number in pairs(v.qualifiers["P1448"]) do lang_WD = v.qualifiers["P1448"][number].datavalue.value.language if lang_WD

lang_module then zaehler = number break end end -- for number in pairs if lang_WD

lang_module then language = lang_WD break end end -- for i,j if language~= then -- a WD translation matching translations.lang_priority exist local t = v.qualifiers["P1448"][zaehler].datavalue.value.text timeStartEnd[num] = t else timeStartEnd[num] = v.mainsnak.datavalue.value[mode]-- no matching between lang module and "official name" qualifier end -- if language~= end -- test if official name qualifier exist else timeStartEnd[num] = v.mainsnak.datavalue.value[mode] end -- if property

"P1448" num = num + 1 end else timeStartEnd[num] = v.mainsnak.datavalue.value[mode] num = num + 1 end end end return a, timeStartEnd[1] else return false, endend

function timeStartEnd_entity(entity, property, mode, timeofrace) -- mode = 'numeric-id', property = 'P54', Qid = 'Q123' --local entity = mw.wikibase.getEntity(Qid) local a, b = pcall(fooA, mode, entity, property, 1) local starttime, endtime = '+0000-01-01', '+9999-12-31' local available_lang_priority = available_lang_priority

if a

true then local timeStartEnd = local num = 1 local v for _, v in pairs(entity.claims[property]) do if pcall(function local test = v.mainsnak.datavalue.value[mode] end) then -- test if not 'unnown value' if pcall(function starttime = v.qualifiers["P580"][1].datavalue.value.time end) then starttime = v.qualifiers["P580"][1].datavalue.value.time local _,_,year,m,d = string.find(starttime,"(%d+)-(%d+)-(%d+)") if m

'00' and d

'00' then starttime = '+'..year..'-01-01T00:00:00Z' end end if pcall(function endtime = v.qualifiers["P582"][1].datavalue.value.time end) then endtime = v.qualifiers["P582"][1].datavalue.value.time local _,_,year,m,d = string.find(endtime,"(%d+)-(%d+)-(%d+)") if m

'00' and d

'00' then endtime = '+'..year..'-12-31T23:59:59Z' end if m

'01' and d

'01' then endtime = '+'..year..'-12-31T23:59:59Z' end end if v.qualifiers then if (not v.qualifiers["P580"] or starttime <= timeofrace) and (not v.qualifiers["P582"] or endtime >= timeofrace) then if available_lang_priority

true and property

"P1448" then local test = false pcall(function if type(v.qualifiers["P1448"])

'table' then test=true end end) if test

false then timeStartEnd[num] = v.mainsnak.datavalue.value[mode] else local lang_module, lang_WD local language= local zaehler for i,j in ipairs(translations.lang_priority) do lang_module = j for number in pairs(v.qualifiers["P1448"]) do lang_WD = v.qualifiers["P1448"][number].datavalue.value.language if lang_WD

lang_module then zaehler = number break end end -- for number in pairs if lang_WD

lang_module then language = lang_WD break end end -- for i,j if language~= then -- a WD translation matching translations.lang_priority exist local t = v.qualifiers["P1448"][zaehler].datavalue.value.text timeStartEnd[num] = t else timeStartEnd[num] = v.mainsnak.datavalue.value[mode]-- no matching between lang module and "official name" qualifier end -- if language~= end -- test if official name qualifier exist else timeStartEnd[num] = v.mainsnak.datavalue.value[mode] end -- if property

"P1448" num = num + 1 end else timeStartEnd[num] = v.mainsnak.datavalue.value[mode] num = num + 1 end end end return a, timeStartEnd[1] else return false, endend

function timeStartEnd(Qid, property, mode, timeofrace) -- mode = 'numeric-id', property = 'P54', Qid = 'Q123' local entity = mw.wikibase.getEntity(Qid) local a, b = pcall(fooA, mode, entity, property, 1) local starttime, endtime local available_lang_priority = available_lang_priority

if a

true then local timeStartEnd = local num = 1 local v for _, v in pairs(entity.claims[property]) do if pcall(function local test = v.mainsnak.datavalue.value[mode] end) then -- test if not 'unnown value' if pcall(function starttime = v.qualifiers["P580"][1].datavalue.value.time end) then starttime = v.qualifiers["P580"][1].datavalue.value.time local _,_,year,m,d = string.find(starttime,"(%d+)-(%d+)-(%d+)") if m

'00' and d

'00' then starttime = '+'..year..'-01-01T00:00:00Z' end end if pcall(function endtime = v.qualifiers["P582"][1].datavalue.value.time end) then endtime = v.qualifiers["P582"][1].datavalue.value.time local _,_,year,m,d = string.find(endtime,"(%d+)-(%d+)-(%d+)") if m

'00' and d

'00' then endtime = '+'..year..'-12-31T00:00:00Z' end if m

'01' and d

'01' then endtime = '+'..year..'-12-31T00:00:00Z' end end if v.qualifiers then if (not v.qualifiers["P580"] or starttime <= timeofrace) and (not v.qualifiers["P582"] or endtime >= timeofrace) then if available_lang_priority

true and property

"P1448" then local test = false pcall(function if type(v.qualifiers["P1448"])

'table' then test=true end end) if test

false then timeStartEnd[num] = v.mainsnak.datavalue.value[mode] else local lang_module, lang_WD local language= local zaehler for i,j in ipairs(translations.lang_priority) do lang_module = j for number in pairs(v.qualifiers["P1448"]) do lang_WD = v.qualifiers["P1448"][number].datavalue.value.language if lang_WD

lang_module then zaehler = number break end end -- for number in pairs if lang_WD

lang_module then language = lang_WD break end end -- for i,j if language~= then -- a WD translation matching translations.lang_priority exist local t = v.qualifiers["P1448"][zaehler].datavalue.value.text timeStartEnd[num] = t else timeStartEnd[num] = v.mainsnak.datavalue.value[mode]-- no matching between lang module and "official name" qualifier end -- if language~= end -- test if official name qualifier exist else timeStartEnd[num] = v.mainsnak.datavalue.value[mode] end -- if property

"P1448" num = num + 1 end else timeStartEnd[num] = v.mainsnak.datavalue.value[mode] num = num + 1 end end end return a, timeStartEnd[1] else return false, endend

--

C) Link functions (new)

local function getOfficialName(teamID, timeOfRace) local p1448 = getStatementForTime(teamID, 'P1448', timeOfRace) -- P1448 is official name if p1448 then if available_lang_priority and p1448.qualifiers and p1448.qualifiers.P1448 then local q = p1448.qualifiers.P1448 local wantedLanguages = local best = 999 local name for i, lang in ipairs(translations.lang_priority) do wantedLanguages[lang] = i end for _, l in pairs(q) do if l.snaktype

'value' then local lang = l.datavalue.value.language if wantedLanguages[lang] and wantedLanguages[lang] < best then best = wantedLanguages[lang] name = l.datavalue.value.text end end end if name then return name, true end end return p1448.mainsnak.datavalue.value.text, false end return wikibase.getLabel(teamID) -- No official name, try labelend

local function getRiderLink(riderID) local sitelink = wikibase.getSitelink(riderID) if sitelink then if wiki

"de" then -- Russian riders get label as alias, to shorten the name local label = wikibase.getLabelByLang(riderID, wiki) if label then local p27 = wikibase.getBestStatements(riderID, 'P27') -- P27 is country of citizenship if p27[1] and p27[1].mainsnak.snaktype

'value' then local c = p27[1].mainsnak.datavalue.value['numeric-id'] if c

159 or c

184 or c

212 or c

232 then -- Q159, Q184, Q212, Q232 is Russia, Belarus, Ukraine, Kazakhstan return "" .. label .. "" end end end end return "" .. mw.text.trim(mw.ustring.gsub(sitelink, "%b", "")) .. "" end

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

'ar' then local title = mw.title.new(label) if title and title.exists then link = label else link = mw.getCurrentFrame:expandTemplate --"" .. Label.. "" end else if black_list(wiki, label) then link = label else local title = mw.title.new(label) if title and title.exists then link = label else link = "" .. label.. "" end end end return link end

-- No label in the local language. Try other languages, but don't link. if wiki

'ar' then link = getLabelFallback(riderID,) else link = getLabelFallback(riderID,) end if link then link = mw.ustring.gsub(link, "%b", "") else link = "(label missing)" end return linkend

--Get the name of a country local function getCountryName(countryID) local name = if available_list then name = translations.list(countryID) end if name

then local label, lang = wikibase.getLabelWithLang(countryID) --Uses standard language fallback. Should not return nil, nil, as all countries have English labels. if lang

wikilang then name = label elseif lang then name = label .. ' (' .. lang .. ')' end end return nameend

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

--Get sitelink, categoryID and maybe country for a team. Returns sitelink, team category ID, countryID (only countryID if country arg is true local function getTeamLinkCat(teamID, timeOfRace, country) local name, sitelink, parentID -- Find team category local catID = firstValue(teamID, 'P31', 'id') -- P31 is 'instance of' -- Find country if needed local countryID if country or catID

'Q23726798' or catID

'Q20738667' then countryID = firstValue(teamID, 'P17', 'id') -- P17 is country end if countryID and (catID

'Q23726798' or catID

'Q20738667') then -- It is a national cycling team name = getCountryName(countryID) if catID

'Q20738667' then -- national cycling team U23 local s if wiki

'fr' then s = ' espoirs' elseif wiki

'mk' then s = ' под 23 години' elseif wiki

'ar' then s = ' تحت 23' elseif wiki

'es' then s = ' sub-23' else s = ' U23' end name = name .. s end sitelink = getRawTeamLink(teamID) else -- It is not a national cycling team local isLocal parentID = getParentID(teamID) if parentID then -- try parent team first sitelink = wikibase.getSitelink(parentID) name, isLocal = getOfficialName(parentID, timeOfRace) end if not sitelink then sitelink = wikibase.getSitelink(teamID) end

if not name or (not isLocal and available_lang_priority) then local partName, partIsLocal = getOfficialName(teamID, timeOfRace) if partName and (not name or partIsLocal) then name = partName end end end if sitelink then if name then sitelink = '' .. name .. '' else sitelink = '' .. sitelink .. '' end else if name then sitelink = name else sitelink = (ParentID and wikibase.getLabel(ParentID)) or wikibase.getLabel(TeamID) or 'No name' end end return sitelink, catID, countryIDend

local function getReference(statement) local function formatRefDate(date, precision) if precision

9 then -- Precision is year return string.sub(date, 2, 5) elseif precision

10 then -- Precision is month return contentLanguage:formatDate("F Y", string.sub(date, 2, 8)) elseif precision >= 11 then -- Precision is day (or less) return func_date (date, 'long') end end

local ref = statement.references if not ref or not ref[1] then return nil end local text ref = ref[1].snaks if ref.P854 and ref.P854[1] and ref.P854[1].snaktype

'value' then -- P854 is 'reference URL' local refURL = ref.P854[1].datavalue.value local refTitle = local refDate = local refRetrieved = local refLang = if ref.P1476 and ref.P1476[1] and ref.P1476[1].snaktype

'value' then -- P1476 is 'title URL' refTitle = ref.P1476[1].datavalue.value.text local lang = ref.P1476[1].datavalue.value.language if lang ~= wikilang then refLang = '(' .. lang .. ')' end end if ref.P577 and ref.P577[1] and ref.P577[1].snaktype

'value' then -- P577 is 'publication date' local value = ref.P577[1].datavalue.value refDate = formatRefDate(value.time, value.precision) if (wiki

'ar') then refDate = '، ' .. refDate else refDate = ', ' .. refDate end end if ref.P813 and ref.P813[1] and ref.P813[1].snaktype

'value' then -- P813 is 'retrieved' local value = ref.P813[1].datavalue.value refRetrieved = formatRefDate(value.time, value.precision) if wiki

"de" then refRetrieved = ", (abgerufen am " .. refRetrieved .. ')' elseif wiki

"ar" then refRetrieved = " تاريخ الوصول " .. refRetrieved .. '.' elseif wiki

"fr" then refRetrieved = " (consulté le " .. refRetrieved .. ')' else refRetrieved = " Retrieved " .. refRetrieved .. '.' end end local domain = mw.ustring.match(refURL, '//([^/]+)') if string.sub(domain, 1, 4)

'www.' then domain = string.sub(domain, 5) end local refText if wiki

"fr" then -- fr: "(en) « Lloyd Mondory ... EPO », sur velonews.competitor.com (consulté le 30 april 2016), 30 octobre 2015." local sur = ', sur

' .. domain .. '' refText = refLang .. ' « ['.. refURL .. ' '.. refTitle .. '] »' .. sur .. refRetrieved .. refDate .. '.' elseif wiki

"de" then local In = ' In:

' .. domain .. '' refText = '['.. refURL.. ' '.. refTitle.. '.] ' .. In .. refDate .. refRetrieved ..'.' else local at = ', ' .. domain .. '' refText = refLang .. ' [' .. refURL .. ' ' .. refTitle .. ']' .. at .. refDate .. '.' .. refRetrieved end return localframe:extensionTag('ref', refText,) endend

function black_list(wiki, Label) --List of Wikipedia articles with the same lemma as the non existing rider article. Those lemmas are printed as text "black" in the tables, not "blue" or "red". This way there will be no false wikilinks at the WhatLinksHere entry. List should be updated maybe once a year. local black_list = if wiki

'de' then black_list= end if wiki

'en' then black_list= end if wiki

'fr' then black_list= end return black_list[Label]end

local function getImage(QID) local wikilang = wikilang local p18 = wikibase.getBestStatements(QID, 'P18') -- P18 is 'image' local first for _, image in pairs(p18) do if image.mainsnak.snaktype

'value' then if not first then first = image.mainsnak.datavalue.value end local q = image.qualifiers if q then for _, caption in pairs(q.P2096) do -- P2096 is 'caption' if caption.snaktype

'value' and caption.datavalue.value.language

wikilang then return image.mainsnak.datavalue.value, caption.datavalue.value.text end end end end end return firstend

--Get link for race or competitionlocal function raceLink(QID) local sitelink = wikibase.getSitelink(QID) local instanceOf = firstValue(QID, 'P31', 'id') -- P31 is 'instance of' if instanceOf

'Q1137352' then -- Q1137352 is 'French Road Cycling Cup' local label2 = wikibase.getLabel(instanceOf) if sitelink then if label2 then return '' .. label2 .. '' end return '' .. sitelink .. '' end local sitelink2 = wikibase.getSitelink(instanceOf) if sitelink2 then return '' .. mw.ustring.gsub(sitelink2, " %b", "") .. '' end if label2 then return label2 end end if sitelink then return "".. sitelink.. "" end return wikibase.getLabel(QID) or end

local function getPlaceLink(placeID) local link local sitelink = wikibase.getSitelink(placeID) if sitelink then if wiki

'en' then -- For English, delete string ", ..." from e.g. "Unley, South Australia" return '' .. string.gsub(sitelink, ',.*', ) .. '' end -- For others, delete " (...)" form e.g. "Unley (South Australia)" return '' .. mw.ustring.gsub(sitelink, ' %b', ) .. '' end local label = wikibase.getLabel(placeID) or if wiki

'ar' then local title = mw.title.new(label) if title and title.exists then return label end return mw.getCurrentFrame:expandTemplate -- '' .. label.. '' end return contentLanguage:ucfirst(label)end

local function classLink(class) local link = wikibase.getSitelink('Q22348500') -- Q22348500 is 'cycling race class' local label = getLabelFallback(class,) if not label then return end if link then return '' .. label .. '' end return labelend

--Get local content to a infoboxe from template args local function getLocalContent(contents, args)

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

local function getTeam(riderID, timeOfRace, q) -- q: qualifiers of statement in race entity where the rider is the value local teamID, link if q.P54 and q.P54[1].snaktype

'value' then -- P54 is member of sports team teamID = q.P54[1].datavalue.value.id link = getTeamLinkCat(teamID, timeOfRace) else p54 = getStatementForTime(riderID, 'P54', timeOfRace) if p54 then teamID = p54.mainsnak.datavalue.value.id link = getTeamLinkCat(teamID, timeOfRace) end end return linkend

--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 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 = '

&#x25C0; ' .. year .. '' else previousText = '&#x25C0; ' .. year end end if nextID then local year = getYear(nextID) local link = wikibase.getSitelink(nextID) if link then nextText = '' .. year .. ' &#x25B6;' else nextText = year .. ' &#x25B6;' end end local direction = contentLanguage:getDir return "" .. previousText .. "" .. nextText .. ""end

--

D) Link functions (obsolete)

function wdLink (id) return ""end

function WPlink(Qnumber, ...) local link= local entity = mw.wikibase.getEntity(Qnumber) local Sitelink = entity:getSitelink -- link to WParticle local Sitelink2 = Sitelink local Label = entity:getLabel or local a, b local official_name = ""

if arg[1]

nil then if pcall(foo1, Qnumber) then if Sitelink ~= nil then if wiki

"en" then --delete string ", ..." from e.g. "Unley, South Australia" if Sitelink~=nil then local i, _ = mw.ustring.find(Sitelink, ",") if i ~= nil then Sitelink2 = mw.ustring.sub(Sitelink, 1, i-1) end end end link = "" .. mw.text.trim(mw.ustring.gsub(Sitelink2, "%b", "")..' ') .. "" if wiki

"de" then -- ru riders get label as alias, to shorten the name local a, b = pcall(fooA, 'numeric-id', entity, 'P27', 1) if a

true and (b

159 or b

184 or b

212 or b

232) then link = "" .. Label .. "" end end elseif Label ~= then if wiki

'ar' then local title = mw.title.new(Label) if title and title.exists then link = Label else link = mw.getCurrentFrame:expandTemplate--"" .. Label.. "" end elseif wiki

'he' then local Label_he = mw.wikibase.getLabelByLang(Qnumber, 'he') if Label_he then link = '' .. Label .. '' else link = Label end else if black_list(wiki, Label)

true then link = Label -- function black_list: articles that are printed as text, not wikilinks else -- detect if there is a different local article with the same name local title = mw.title.new(Label) if title and title.exists then link = Label else link = "" .. Label.. "" end end end else link = Label end else return "unknown ID in function WPlink" end if link

then link = entity:getLabel('fr') or entity:getLabel('en') or entity:getLabel('de') or if wiki

"ar" then link = entity:getLabel or entity:getLabel('en') or entity:getLabel('fr') or entity:getLabel('de') or end if link ~= then link = mw.ustring.gsub(link, "%b", "") else link = "(label missing)" end end end -- if arg[1]

nil

if arg[1]

'team' then -- add '(team of the winner)' a, b = timeStartEnd(Qnumber, 'P1448', 'text', arg[2]) --officialName(entity) local a1, b1 = pcall(fooA, 'numeric-id', entity, 'P361', 1) if a1

true then local a2, b2 = timeStartEnd('Q'..b1, 'P1448', 'text', arg[2]) if a2

true then a = a2 b = b2 end entity = mw.wikibase.getEntity('Q'..b1) Sitelink2 = entity:getSitelink -- link to WParticle end if a

true then official_name = b end

if available_lang_priority

false then a, b = pcall(fooA, 'text', entity, 'P1448', 2) -- test if more then two official names if a

true then a, b = timeStartEnd(Qnumber, 'P1448', 'text', arg[2]) --officialName(entity) if a

true then official_name = b end else a, b = pcall(fooA, 'text', entity, 'P1448', 1) if a

true then official_name = b end end end

if Sitelink ~= nil then if official_name

nil then link = "".. mw.text.trim(mw.ustring.gsub(Sitelink,"%b","").. ' ') .. "" else if wiki

"en" then --delete string ", ..." from e.g. "Unley, South Australia" local i, _ = mw.ustring.find(Sitelink, ",") if i ~= nil then Sitelink = mw.ustring.sub(Sitelink, 1, i-1) end end link = link .. '".. official_name.. '' end end if link

and Sitelink2 ~= nil then -- code goes from season item to team item if official_name

nil or official_name

then link = "".. mw.text.trim(mw.ustring.gsub(Sitelink2,"%b","").. ' ') .. "" else if wiki

"en" then --delete string ", ..." from e.g. "Unley, South Australia" local i, _ = mw.ustring.find(Sitelink2, ",") if i ~= nil then Sitelink2 = mw.ustring.sub(Sitelink2, 1, i-1) end end link = link .. '".. official_name.. '' end end

if Sitelink

nil and Sitelink2

nil then if official_name ~= then link = official_name else link = entity:getLabel end if link

nil then link = "(label missing)" end end

-- mw.log('Sitelink=', Sitelink, 'Sitelink2=', Sitelink2, 'official_name=', official_name) end -- end arg[1] if arg[1]

'pure' then if pcall(foo1, Qnumber) then if wiki

"en" then --delete string ", ..." from e.g. "Unley, South Australia" if Sitelink~=nil then local i, _ = mw.ustring.find(Sitelink, ",") if i ~= nil then Sitelink2 = mw.ustring.sub(Sitelink, 1, i-1) end end end if Sitelink ~= nil then link = "" .. mw.text.trim(mw.ustring.gsub(Sitelink2, "%b", "")..' ') .. "" elseif wiki

'ar' then local title = mw.title.new(Label) if title and title.exists then link = Label else link = mw.getCurrentFrame:expandTemplate--"" .. Label.. "" end else link = mw.ustring.gsub(Label, "^(%a)", function (x) return mw.ustring.upper(x) end) end end end if arg[1]

'race' then -- for infobox "Competitions" local a, b = pcall(fooA, 'numeric-id', entity, 'P31', 1) if a

true and b

1137352 then local entity_race = mw.wikibase.getEntity('Q' .. b) local Label_race = entity_race:getLabel or local Sitelink_race = entity_race:getSitelink or if Label_race ~= and Sitelink ~= nil then link = '' .. Label_race .. '' elseif Sitelink ~= nil then link = '' .. Sitelink .. '' else if Sitelink_race ~= then link = '' .. mw.text.trim(mw.ustring.gsub(Sitelink_race, "%b", "") .. ' ') .. '' else link = Label_race or Label end end if onwikidata

true then link = ''..entity_race:getLabel('fr')..'' end

else if Sitelink ~= nil then link = "".. Sitelink.. "" else link = Label end end end if arg[1]

"Q22348500" then -- add weblink from item "Q22348500" if available local Sitelink_claas = mw.wikibase.getEntity('Q22348500'):getSitelink if pcall(foo1, Qnumber) then --Sitelink_claas if Sitelink

nil then if Sitelink_claas ~= nil then link = "" .. Label .. "" elseif entity:getLabel('ar')~=nil then link = entity:getLabel('ar') elseif entity:getLabel('fr')~=nil then link = entity:getLabel('fr') elseif entity:getLabel('en')~=nil then link = entity:getLabel('en') elseif entity:getLabel('de')~=nil then link = entity:getLabel('de') else link = Label end end end end return linkend

function WPlink_entity(entity, ...) local link= local Sitelink = entity:getSitelink -- link to WParticle local Sitelink2 = Sitelink local Label = entity:getLabel or local a, b local official_name = ""

if arg[1]

'team' then -- add '(team of the winner)' a, b = timeStartEnd_entity(entity, 'P1448', 'text', arg[2]) --officialName(entity) local a1, b1 = pcall(fooA, 'numeric-id', entity, 'P361', 1) if a1

true then entity = mw.wikibase.getEntity('Q'..b1) local a2, b2 = timeStartEnd_entity(entity, 'P1448', 'text', arg[2]) if a2

true then a = a2 b = b2 end

Sitelink2 = entity:getSitelink -- link to WParticle end if a

true then official_name = b end

if available_lang_priority

false then a, b = pcall(fooA, 'text', entity, 'P1448', 2) -- test if more then two official names if a

true then a, b = timeStartEnd_entity(entity, 'P1448', 'text', arg[2]) --officialName(entity) if a

true then official_name = b end else a, b = pcall(fooA, 'text', entity, 'P1448', 1) if a

true then official_name = b end end end

if Sitelink ~= nil then if official_name

nil then link = "".. mw.text.trim(mw.ustring.gsub(Sitelink,"%b","").. ' ').. "" else if wiki

"en" then --delete string ", ..." from e.g. "Unley, South Australia" local i, _ = mw.ustring.find(Sitelink, ",") if i ~= nil then Sitelink = mw.ustring.sub(Sitelink, 1, i-1) end end link = link .. '".. official_name.. '' end end if link

and Sitelink2 ~= nil then -- code goes from season item to team item if official_name

nil then link = "".. mw.text.trim(mw.ustring.gsub(Sitelink2,"%b","").. ' ').. "" else if wiki

"en" then --delete string ", ..." from e.g. "Unley, South Australia" local i, _ = mw.ustring.find(Sitelink2, ",") if i ~= nil then Sitelink2 = mw.ustring.sub(Sitelink2, 1, i-1) end end link = link .. '".. official_name.. '' end end

if Sitelink

nil and Sitelink2

nil then if official_name ~= then link = official_name else link = entity:getLabel end if link

nil then link = "(label missing)" end end

end -- end arg[1] return linkend

function transform(q_number, command, timeofrace) -- transforms Q/q-number into flag / WPlink / WDlink local wd = " " else --look into P17 (country) to get the Qnumber of that country a, b = pcall(fooA, 'numeric-id', mw.wikibase.getEntity(q_number), 'P17', 1) if a

true then return flag("Q"..b, timeofrace).." "..WPlink(q_number)..wd..q_number.."]]" else return WPlink(q_number)..wd..q_number.."]]" end end end if command

"f" then -- no WDitem icon --look into P27 (country of citizenship) to get the Qnumber of that country a, b = timeStartEnd(q_number, "P27", 'numeric-id', timeofrace) if a

true then return flag('Q'..b, timeofrace).." "..WPlink(q_number) else --look into P17 (country) to get the Qnumber of that country a, b = pcall(fooA, 'numeric-id', mw.wikibase.getEntity(q_number), 'P17', 1) if a

true then return flag("Q"..b, timeofrace).." "..WPlink(q_number, 'team', timeofrace) else return WPlink(q_number, 'team', timeofrace) end end end if command

"c" then return WPlink(q_number, "Q22348500") end -- find "class"-items if command

"t" then return WPlink(q_number, 'team', timeofrace) end if command

"2t" then return q_number end return q_numberend

function national_team(riderID, startOfSeason, entity, property, k) -- property: statement where the rider is the value -- k: loop local national_team, team, nationality, teamID -- national team for U23 or older riders if pcall(function local i,j, s for _, v in pairs(entity.claims[property][k].qualifiers['P54']) do -- for property 'member of sports team' teamID = 'Q'.. v.datavalue.value['numeric-id'] break end

national_team = mw.wikibase.getEntity(teamID) -- calculate s for national team item a, b = pcall(fooA, 'numeric-id', national_team, 'P31', 1) -- test if country if a

true and b

20738667 then -- Q20738667 = national cycling team U23 if wiki

'fr' then s = ' espoirs' elseif wiki

'mk' then s = ' под 23 години' elseif wiki

'ar' then s = ' تحت 23' elseif wiki

'es' then s = ' sub-23' elseif wiki

'ast' then s = ' sub-23' else s = ' U23' end elseif a

true and (b

1194951 or b

23726798) then s = end -- Q1194951 = national sports team, Q23726798 = national cycling team

a, b = timeStartEnd(riderID, "P27", 'numeric-id', startOfSeason) if a

true then local nation = mw.wikibase.getEntityObject('Q'..b) nationality = nation:getLabel or nation:getLabel('en') .. ' (en)' if national_team:getSitelink

nil then team = nationality.. s else team = "".. nationality.. s.. '' end end

a, b = timeStartEnd(riderID, "P17", 'numeric-id', startOfSeason) if a

true then --team = 'abc'.. b --riderID local nation = mw.wikibase.getEntityObject('Q'..b) nationality = nation:getLabel or nation:getLabel('en') .. ' (en)' if national_team:getSitelink

nil then team = nationality.. s else team = "".. nationality.. s.. '' end end end) then else --standard team pcall(function a, b = timeStartEnd(riderID, 'P54', 'numeric-id', startOfSeason) if a

true then national_team = mw.wikibase.getEntity('Q'..b) -- g.team[rank] = national_team:getLabel or g.country[rank].. s team = WPlink('Q'..b, 'team', startOfSeason) end -- guest team if teamID ~= nil then team = WPlink(teamID, 'team') end end) end

return teamend

function references(entity, property, var1) local ref1, ref2, ref2b, ref3, ref4 = "", " ", "", "", "" local url, ref local lang = mw.language.getContentLanguage local a, b

if onwikidata then lang = mw.getLanguage('fr') end

a, b = pcall(fooB, 'value', entity, property, var1, 1, 'P854', 1) -- url if a

true then ref1 = b end a, b = pcall(fooB, 'text', entity, property, var1, 1, 'P1476', 1) -- Originaltitel der webpage, "language": "fr" if a

true then ref2 = b ref2b= entity.claims[property][var1].references[1].snaks['P1476'][1].datavalue.value.language or if ref2b

wiki then ref2b = else ref2b = '(' .. ref2b .. ') ' end end a, b = pcall(fooB, 'time', entity, property, var1, 1, 'P577', 1) -- publication date if a

true then local _, _, year, m, d = string.find(b,"(%d+)-(%d+)-(%d+)") if d ~= '00' and m ~= '00' then if wiki

"de" then ref3 = ', ' .. lang:formatDate("j. F Y", b) elseif wiki

"ar" then ref3 = '، ' .. lang:formatDate("j F Y", b) .. '.' elseif wiki

"en" then ref3 = ', ' .. lang:formatDate("Y F, j", b) .. '.' elseif wiki

"fr" then ref3 = ', ' .. lang:formatDate("j F Y", b) else ref3 = ', ' .. func_date (b, 'long') .. '.' --lang:formatDate("j n Y", b) .. '.' end elseif d

'00' and m ~= '00' then d = '01' if wiki

"de" then ref3 = ', ' .. lang:formatDate("F Y", year..'-'..m..'-'..d) elseif wiki

"ar" then ref3 ='، ' .. lang:formatDate("F Y", year..'-'..m..'-'..d)..'.' elseif wiki

"en" then ref3 =', ' .. lang:formatDate("Y F", year..'-'..m..'-'..d)..'.' elseif wiki

"fr" then ref3 =', ' .. lang:formatDate("F Y", year..'-'..m..'-'..d) else ref3 = ', ' .. lang:formatDate("F Y", year..'-'..m..'-'..d)..'.' end else ref3 = year end end a, b = pcall(fooB, 'time', entity, property, var1, 1, 'P813', 1) -- Retrieved if a

true then if wiki

"de" then ref4 = ", (abgerufen am " .. lang:formatDate("j. F Y", b).. ')' elseif wiki

"ar" then ref4 = " تاريخ الوصول " .. lang:formatDate("j F Y", b) .. '.' elseif wiki

"en" then ref4 = " Retrieved " .. lang:formatDate("Y F, j", b) .. '.' elseif wiki

"fr" then ref4 = " (consulté le " .. lang:formatDate("j F Y", b) .. ')' else ref4 = " Retrieved " .. func_date (b, 'long').. '.' --lang:formatDate("j n Y", b) .. '.' end end

if ref1~= then --and ref2~= then local _, start = string.find(ref1, '//') local ende, _ = string.find(ref1, '/', start + 1) local s = string.sub(ref1, start + 1, ende - 1) local s2 = string.gsub(s, "www.", "") if wiki

"fr" then -- fr: "(en) « Lloyd Mondory ... EPO », sur velonews.competitor.com (consulté le 30 april 2016), 30 octobre 2015." if ref2~=' ' then url= ', sur

' .. s2 .. '' else url= end ref = ref2b .. '« ['.. ref1.. ' '.. ref2.. '] »' .. url .. ref4 .. ref3 ..'.' elseif wiki

"en" then -- en: "Inflation ... recession", Pittsburgh Post-Gazette, October 16, 2009. Retrieved 2010-01-21. if ref2~=' ' then url= ',

' .. s2 .. '' else url= end ref = '"['.. ref1.. ' '.. ref2.. '"]'.. ref2b .. url .. ref3 .. ref4 elseif wiki

"de" then if ref2~=' ' then url= ' In:

' .. s2 .. '' else url= end ref = '['.. ref1.. ' '.. ref2.. '.] '.. url.. ref3 .. ref4 ..'.' else if ref2~=' ' then url= ' ' .. s2 .. '' else url= end ref = ref2b .. '['.. ref1.. ' '.. ref2.. '] ' .. url.. ref3 .. ref4 end return ref or else return endend

--

E) Function for the output

function tableA(s, tableBody) local s = s local tableBody = tableBody local available_list = available_list local entity = mw.wikibase.getEntityObject(s.item)

local error_message = if wiki

"ar" and s.item

"" or not s.item then return "" end if s.error_message

1 then error_message = func_error_message(wiki, 1) error_message = mw.ustring.gsub(error_message, "<1>", s.property) error_message = mw.ustring.gsub(error_message, "<2>", mw.wikibase.label(s.item)) error_message = mw.ustring.gsub(error_message, "<3>", s.item) error_message = ' ' end

local tableHeader2_size = table.getn(s.header_2) local tableStart = '

' local tableHeader1 = ''.. error_message .. '' .. s.header_function (wiki, s.header_1, s.title) .. '
'.. s.header_function (wiki, k) .. '' .. s.header_function (wiki, k) .. '' .. s.header_function (wiki, k) .. '
'

return '

' .. tableStart .. tableHeader1 .. tableHeader2 .. tableBody .. tableEnd .. '
'end

--

E) Jersey, flag functions

function flag (countryID, date)

local trackingCategory = --If you uncomment the line under this comment, all pages with look-up misses in the flag table will be placed in a tracking category. You can use this to find more flags to add to the table. -- trackingCategory = '' local flags = local entry = flags[countryID] local IOC local file if entry then for i, v in ipairs(entry) do if i

1 then IOC = v else if not date then file = v[1] break else local from = v[2] local to = v[3] if (not from or from <= date) and (not to or to > date) then file = v[1] break end end end end end if file then return '' elseif not date then local p41 = mw.wikibase.getBestStatements(countryID, "P41") -- P41 is flag image if p41[1] and p41[1].mainsnak.snaktype

'value' then return '' .. trackingCategory end else -- Search flag for specific date local p41 = getStatementForTime(countryID, "P41", date) -- P41 is flag image if p41 then return '' .. trackingCategory end end return trackingCategoryend

function jersey(wiki, winner_classification, item, timeofrace) local jersey, jersey_name = , local jerseyWPID = local starttime, endtime = , '+2500' local a1, b1

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

local data= -- Jersey orange.svg

--timeofrace = '+1968-07-01T00:00:00Z' timeofrace = string.sub(timeofrace, string.find(timeofrace, "+%d%d%d%d")) for k, v in pairs(item) do for key, value in pairs(data) do if v

value[1] then if winner_classification

value[2] then if (timeofrace >= value[3]) and (timeofrace <= value[4]) then jersey = value[5] jerseyWPID = value[6] end end end end end

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

--

G) Other (winner, getkm)

function winner(raceID, winners, timeOfRace, countryflag, WDlink_on, team, ref) local p1346 = wikibase.getAllStatements(raceID, 'P1346') -- P1346 is 'winner' for _, winner in pairs(p1346) do local wID = winner.mainsnak.snaktype

'value' and winner.mainsnak.datavalue.value.id local wOf, wCause, wCriterion, riderLink local q = winner.qualifiers if q then if q.P642 and q.P642[1].snaktype

'value' then for _, q642 in pairs(q.P642) do wOf = q642.datavalue.value.id -- P642 is 'of' if not wOf then -- Try P1346 (winner) instead -- Assume Q20882667 ('overall winner general classification') if neither are found wOf = q.P1346 and q.P1346[1].snaktype

'value' and q.P1346[1].datavalue.value.id or 'Q20882667' end wCause = q.P828 and q.P828[1].snaktype

'value' and q.P828[1].datavalue.value.id -- P828 is 'has cause' wCriterion = q.P1013 and q.P1013[1].snaktype

'value' and q.P1013[1].datavalue.value.id -- P1013 is 'criterion used' if winners[wOf] then if wID then -- The winner can be a rider or a team, so check if it is a human. local isHuman local p31 = wikibase.getBestStatements(wID, 'P31') -- P31 is 'instance of' for _, iOf in pairs (p31) do if iOf.mainsnak.snaktype

'value' and iOf.mainsnak.datavalue.value['numeric-id']

5 then -- Q5 is 'human' isHuman = true break end end local reference = ref and getReference(winner) local _, countryID if isHuman then riderLink = getRiderLink(wID) if reference then riderLink = riderLink .. reference end if team then riderTeam = getTeam(wID, timeOfRace, q) if riderTeam then riderLink = riderLink .. ' (' .. riderTeam .. ')' end end else riderLink, _, countryID = getTeamLinkCat(wID, timeOfRace, countryflag) if reference then riderLink = riderLink .. reference end end if countryflag then if not countryID then local p27 = getStatementForTime(wID, 'P27', timeOfRace) --P27 is country of citizenship if p27 then countryID = p27.mainsnak.datavalue.value.id end end if countryID then riderLink = flag(countryID, timeOfRace) .. ' ' .. riderLink end end if WDlink_on then riderLink = riderLink .. ' ' .. wdLink(wID) end else riderLink = wCriterion and contentLanguage:ucfirst(wikibase.getLabel(wCriterion) or ) or if wCause then local cause = wikibase.getLabel(wCause) if cause then riderLink = riderLink .. ' (' .. cause .. ')' end end end if winners[wOf]

then winners[wOf] = riderLink else winners[wOf] = winners[wOf] .. '
' .. riderLink end end end end end endend

local function getKm(wiki) local km if wiki

"ar" then km = 'كم' elseif wiki

"mk" then km = 'км' elseif wiki

"ru" then km = 'км' elseif wiki

"ja" then km = 'キロメートル' else km = 'km' end return kmend local function getDistance(raceID, addUnit) local p = mw.wikibase.getBestStatements(raceID, 'P3157') -- P3157 is 'event distance' if not p[1] then p = mw.wikibase.getBestStatements(raceID, 'P2043') -- P2043 is 'length' end local km, unit local text local wiki = wiki local lang = contentLanguage if p[1] and p[1].mainsnak.snaktype

'value' then km = tonumber(p[1].mainsnak.datavalue.value.amount) unit = p[1].mainsnak.datavalue.value.unit if unit

'http://www.wikidata.org/entity/Q828224' then -- Q828224 is 'kilometre' -- The unit should always be km. Skip if it isn't. text = lang:formatNum(km) if wiki

'fo' then text = string.gsub(text, "%.", ",") end if addUnit then text = text .. ' ' .. getKm(wiki) end if wiki

'en' then -- Show miles also local miles = math.modf(10*km/1.609344)/10 text = text .. ' (' .. lang:formatNum(miles) if addUnit then text = text .. ' mi' end text = text .. ')' end end end return textend

local function getKmh(wiki) local kmh if wiki

"ar" then kmh = 'كم/س' elseif wiki

"da" then kmh = 'km/t' elseif wiki

"fo" then kmh = 'km/t' elseif wiki

"nl" then kmh = 'km/u' elseif wiki

"no" then kmh = 'km/t' elseif wiki

"mk" then kmh = 'км/ч' elseif wiki

"ru" then kmh = 'км/ч' elseif wiki

"ja" then kmh = 'キロメートル毎時' else kmh = 'km/h' end return kmhend

local function getSpeed(raceID, addUnit) local p = mw.wikibase.getBestStatements(raceID, 'P2052') -- P2052 is 'speed' local kmh, unit local text local wiki = wiki local lang = contentLanguage if p[1] and p[1].mainsnak.snaktype

'value' then kmh = tonumber(p[1].mainsnak.datavalue.value.amount) unit = p[1].mainsnak.datavalue.value.unit if unit

'http://www.wikidata.org/entity/Q180154' then -- Q180154 is 'kilometre per hour' -- The unit should always be km/h. Skip if it isn't. text = lang:formatNum(kmh) if wiki

'fo' then text = string.gsub(text, "%.", ",") end if addUnit then text = text .. ' ' .. getKmh(wiki) end if wiki

'en' then -- Show miles per hour also local mih = math.modf(1000*kmh/1.609344)/1000 text = text .. ' (' .. lang:formatNum(mih) if addUnit then text = text .. ' mi/h' end text = text .. ')' end end end return textend

function number(gender, b, wiki) local str if b

"" then return "" end if wiki

"ca" then if b

1 then str = b.."r" elseif b

2 then str = b.."n" elseif b

3 then str = b.."r" elseif b

4 then str = b.."t" else str = b.."è" end elseif wiki

"en" then if b

1 then str="1st" elseif b

2 then str="2nd" elseif b

3 then str="3rd" else str=b.."th" end elseif wiki

"es" then if gender

'm' or gender

'n' then str = b..".º" elseif gender

'f' then str = b..".ª" else str = b.."." end elseif wiki

"fr" then if b

1 then if gender

'm' then str="1er" elseif gender

'f' or gender

'n' then str="1re" else str="1e" end else str=b.."e" end elseif wiki

"nl" then str=b.."e" elseif wiki

"ru" then str=b.."-й" elseif wiki

"eo" then str=b.."-a" elseif wiki

"ast" then if gender

'm' or gender

'n' then str = b.."ᵘ" elseif gender

'f' then str = b..".ª" else str = b.."." end else str = b .. ". " end return strend

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

if time

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

if h>0 then str = str..mw.ustring.format ('%i'..unit(2), h) end if m>=0 and h>0 then str = str.. mw.ustring.format('%02i'..unit(3), m) end if m>0 and h

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

0 and m

0 then str = str.. mw.ustring.format('%i'..unit(4), s) end return str --time..': '..h..' '..m..' '..send

function func_error_message(wiki,x) local l10nDef = local l10n = l10nDef[wiki] if not l10n then l10n = l10nDef["en"] end -- default return l10n[x]end

function changetemplate -- for eoWiki local frame = mw.getCurrentFrame local n = frame:expandTemplate return nend

function getMissingLabelTrackingCategory local l10nDef = local l10n = l10nDef[mw.site.server] if not l10n then l10n = end return l10nend

--

IV) Translation

local function race_reference_translate(wiki, x) local l10nDef = local l10n = l10nDef[wiki] or l10nDef["en"] -- default return l10n[x]end

function calendar_translate(wiki, x, title) local l10nDef = local l10n = l10nDef[wiki] if not l10n then l10n = l10nDef["en"] end -- default if x

1000 then --code return title else return l10n[x] endend

function victories_translate(wiki, x) local l10nDef = local l10n = l10nDef[wiki] if not l10n then l10n = l10nDef["en"] end -- default return l10n[x]end

function stageinfobox_translate(x) -- local l10nDef = local l10n = l10nDef[wiki] if not l10n then l10n = l10nDef["en"] end -- default return l10n[x]end

function getSquadTableColumn(x) local l10nDef = local l10n = l10nDef[wiki] if not l10n then l10n = l10nDef["en"] end -- default return l10n[x]end

function infobox_translate(x) -- This function permits to translate fields of the infobox, take the line below, give a Wikipedia (ex : mk), and translate all fields. By default, English values are taken. -- l10nDef["//??.wikipedia.org"] = local l10nDef = local l10n = l10nDef[wiki] if not l10n then l10n = l10nDef["en"] end -- default return l10n[x]end

function unit(x) local l10nDef = local l10n = l10nDef[wiki] if not l10n then l10n = l10nDef["en"] end -- default for lv,cs,en,ca,ro,pt,pl,sv return l10n[x]end

function func_month(x) local l10nDef = local l10n = l10nDef[wiki] if not l10n then l10n = l10nDef["en"] end -- default return l10n[x]end

function headoftable(x) -- En-tête du tableau listant les étapes local l10nDef= local l10n = l10nDef[wiki] if not l10n then l10n = l10nDef["en"] end -- default return l10n[x]end

function headoftableII(x) -- En-têtes des tableaux générant les classements local l10nDef = local l10n = l10nDef[wiki] if not l10n then l10n = l10nDef["en"] end -- default return l10n[x]end

function headoftableIII(x) -- En-tête du tableau listant les équipes participantes (P1923) local l10nDef = local l10n = l10nDef[wiki] if not l10n then l10n = l10nDef["en"] end -- default return l10n[x]end

function headoftableIV(x) -- En-tête du tableau du palmarès d'une course cycliste local l10nDef = return l10nDef[wiki][x]end

function typeofstage(x, typ) -- plain, hilly, inter, ... must be "" or "any text" -- l10nDef[""] = local l10nDef = local l10n = l10nDef[wiki] if not l10n then l10n = l10nDef["en"] end -- default

if x

'plain stage' then return "" end if x

'hilly stage' then return "" end if x

'intermediate stage' then return "" end if x

'mountain stage' then return "" end if x

'uphill time trial stage' then return "" end if x

'rest day' then return "" end if x

'time trial stage' then if typ

2348250 then return "" end if typ

2266066 then return "" end if typ

485321 then return "" end endend

function func_prologue -- returns the word "Prologue" local l10nDef =

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

function stageLink(x, a, b) -- x= 10a: a = 10, b = a. x = 5: a = 5, b = "" local l10nDef =

local word1, word2 word2=l10nDef[wiki] if word2

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

-- fr: étape, étape if wiki

"fr" or wiki

"lb" then if b

"" then -- series_ordinal without character if a

"1" then word1 = "1re "..word else word1 = a.."e "..word end -- table text = étape, étape, if a

"1" then word2 = "#1re "..word else word2 = "#"..a.."e "..word end --text of section header = #1re étape, #2e étape return word1, word2 end if b ~= "" then -- series_ordinal with character: instead of eg "1a re" it is "1re a" if a

"1" then word1 = "1re "..b.." "..word else word1 = a.."e "..b.." "..word end -- table text = étape, étape, if a

"1" then word2 = "#1re "..b.." "..word else word2 = "#"..a.."e"..b.." "..word end --text of section header = #1re étape, #2e étape return word1, word2 end end if wiki

"de" or wiki

"da" or wiki

"fo" or wiki

"no" then return a..". "..b.." "..word, "#"..a..". "..b.." "..word end if wiki

"ca" then return a.."a "..b.." "..word, "#"..a..". "..b.." "..word end if wiki

"es" then return a..".a "..b.." "..word, "#"..a..". "..b.." "..word end if wiki

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

--

V) Main functions --

A) Function race reference

local function race_reference(raceID) -- Allow to display the reference below the classifications -- local bases= local links = for _, base in pairs(bases) do local p = mw.wikibase.getBestStatements(raceID, base[2]) if p[1] and p[1].mainsnak.snaktype

'value' then table.insert(links, ' [' .. base[3] .. p[1].mainsnak.datavalue.value .. " " .. base[1] ..']') end end if #links

1 then return race_reference_translate(wiki, 1) .. table.concat(links) elseif #links > 1 then return race_reference_translate(wiki, 1) .. table.concat(links) else return endend

--

B) Calendar

function p.calendarcustom(frame) ----- function to display calendar óf any competition ----- ----- based on victories function ----- ----- author: psemdel ----- local countryflagonlytemp, numberingtemp, displayclasstemp,onlywinnertemp, displayteamtemp, displayleadertemp local headertemp, data_typetemp=, local ll=1

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

1 then numberingtemp =true headertemp[ll]=3 data_typetemp[ll] = ll=ll+1 end countryflagonlytemp=true if frame.args[3] ~= nil and tonumber(frame.args[3])

1 then countryflagonlytemp =false end -- country -- headertemp[ll]=5 data_typetemp[ll] = ll=ll+1

--race-- headertemp[ll]=4 data_typetemp[ll] = ll=ll+1 displayclasstemp =false if frame.args[4] ~= nil and tonumber(frame.args[4])

1 then displayclasstemp =true headertemp[ll]=6 data_typetemp[ll] = ll=ll+1 end

if frame.args[5] ~= nil then if tonumber(frame.args[5])

1 then 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 displayleadertemp =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 s = return tableA(s, calendar_main(s))end

function p.calendar(frame) ----- function to display UCI calendar of one year ---- ----- based on WWTcalendar function ----- ----- author: Mr. Ibrahem ----- local calendarID = "" if wiki

"ar" then frame = frame:getParent end UCI = UCI["WT"] = UCI["europe"] = UCI["asia"] = UCI["america"] = UCI["africa"] = UCI["oceania"] =

UCI["WWT"] =

UCI["women"] =

header_1_tab = header_1_number = 12 display_code_tab = --Can depends on the wiki header_2_tab_code1= header_2_tab_code2= data_sort_type_code1= data_sort_type_code2= only_winner_code1 = 0 only_winner_code2 = 1 numbering_code1= true numbering_code2=false displayteam_code1=false displayteam_code2=true displayclass_code1=false displayclass_code2=true leadercolumn_code1=true leadercolumn_code2=false

for key, v in pairs(UCI) do if calendarID

"" and frame.args[key] then year = frame.args[key] year = string.gsub(year, "%c", "") if v[year] then calendarID = v[year] header_1_number = header_1_tab[key] display_code=display_code_tab[key] end end end if wiki

"ar" and calendarID

"" then return "" end if display_code

1 then header_2temp= header_2_tab_code1 data_sort_typetemp=data_sort_type_code1 only_winnertemp=only_winner_code1 numberingtemp=numbering_code1 displayteamtemp=displayteam_code1 displayclasstemp=displayclass_code1 leadercolumntemp=leadercolumn_code1 else header_2temp= header_2_tab_code2 data_sort_typetemp=data_sort_type_code2 only_winnertemp=only_winner_code2 numberingtemp=numbering_code2 displayteamtemp=displayteam_code2 displayclasstemp=displayclass_code2 leadercolumntemp=leadercolumn_code2 end

local s = return tableA(s, calendar_main(s))end

--------- Definition sub-functions for calendar and victory ------local function fn_date(entityID, functionName) --to move as a general function local tempdate, dateOfRace, sortkey, sortkeyDate local outputtable= local sTime = firstValue(entityID, 'P580', 'time') -- P580 is 'start time' local eTime = firstValue(entityID, 'P582', 'time') -- P582 is 'end time' if sTime and eTime then local startTime, endTime = getStartEndTime(sTime, eTime, 'small') local _, _, y, m, d = string.find(sTime, "(%d+)-(%d+)-(%d+)") if functionName

nil then --calendar tempdate = startTime .. ' – ' .. endTime --mettre year en option! sortkeyDate =sTime else --victory, general classification tempdate =endTime sortkeyDate =eTime end dateOfRace = eTime else -- This function give a format to dates when P585 (date) is used in a single day race local pTime = firstValue(entityID, 'P585', 'time') -- P585 is 'point in time' if pTime then tempdate = func_date (pTime, 'small') dateOfRace = pTime sortkeyDate = pTime end end local _, _, y, m, d = string.find(sortkeyDate, "(%d+)-(%d+)-(%d+)") if y~= nil and m~= nil and d~=nil then sortkey = y..m..d elseif y~= nil and m~= nil then sortkey = y..m elseif y~= nil then sortkey = y else sortkey = '0000' end

outputtable[1]=dateOfRace outputtable[2]=''..tempdate.. '' outputtable[3]=sortkey return outputtableend

local function fn_country(entityID, dateOfRace,countryflagonly, ParentID) -- This function gives countries where the race take place -- ParentID taken from fn_race, optional local country, countryname, outputtable=,, local countryID for _, p17 in statements(entityID, 'P17') do -- P17 is 'country' --we have to select the right one countryID = p17.mainsnak.datavalue.value.id countryname[#countryname + 1] = getCountryName(countryID) if countryflagonly

true or not countryname[#countryname] then country[#country + 1]=flag(countryID, dateOfRace) else country[#country + 1]=flag(countryID, dateOfRace)..countryname[#countryname] end end --no country in entity, look by parent if countryID

nil and ParentID ~= 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 countryflagonly

true or not countryname[#countryname] then country[#country + 1]=flag(countryID, dateOfRace) else country[#country + 1]=flag(countryID, dateOfRace)..countryname[#countryname] end end end if countryname[1] then outputtable[2]=countryname[1] beginofstr='' if country[1] then outputtable[1]=beginofstr..country[1]..'' else outputtable[1]=beginofstr..'' end else outputtable[2]= outputtable[1]='' end return outputtableend

local function commastage(stageID,racelabel) --how to write "stage, " local outputtable= local stagenumber= local substage = local stagenumberonly, stageletter outputtable[1]= outputtable[2]= 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 stagenumber= victories_translate(wiki,9) else if stagenumber

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

local comma = ", " if wiki

'ar' then comma = " ، " end if wiki

'fr' then local correpondance= for ii, v in ipairs(correpondance) do local i, _ = mw.ustring.find(racelabel, correpondance[ii].name) if i ~= nil then comma = correpondance[ii].article end end end if wiki

'fr' or wiki

"lb" or wiki

"ca" or wiki

"es" or wiki

"ast" then outputtable[1]=stagenumber..comma elseif wiki

"de" or wiki

"da" or wiki

"fo" or wiki

"no" or wiki

"ru" or wiki

"en" then outputtable[2]=comma..stagenumber end return outputtableend

local function getmainraceLink(entityID,entity_type,stageID, functionName) --the link to the edition but with a general name local instanceOf, label, Sitelink, isclass, prefix, postfix Sitelink=wikibase.getSitelink(entityID) prefix=; postfix= for _, p31 in statements(entityID, 'P31') do instanceOf = p31.mainsnak.datavalue.value.id isclass=0 for i=1,#class do--we don't want the class, but the main race if instanceOf

class[i] then isclass=1 end end if isclass

0 then local p2561 = wikibase.getBestStatements(instanceOf, 'P2561') --name for championship if p2561[1] and p2561[1].mainsnak.snaktype

'value' then label = p2561[1].mainsnak.datavalue.value.text end --if label

nil then --if label

nil then --should be with a "today" -- local p1448 = wikibase.getBestStatements(instanceOf, 'P1448') --official name -- if p1448[1] and p1448[1].mainsnak.snaktype

'value' then label = "blibli" end --p1448[1].mainsnak.datavalue.value.text end --end if label

nil then label=wikibase.label(instanceOf) end if Sitelink

nil then --only if no link to the race direct Sitelink=wikibase.getSitelink(instanceOf) end if Sitelink

nil and entity_type

'champ' then --only for champ local p361=wikibase.getBestStatements(instanceOf, 'P361') if p361[1] and p361[1].mainsnak.snaktype

'value' then Sitelink=wikibase.getSitelink(p361[1].mainsnak.datavalue.value.id) end end end end --look for link to the race if nothing --if different languages have to be added, a language table can be created if entity_type

'2' then if functionName~=nil then --calendar=nil if wiki

'fr' then prefix= victories_translate(wiki,1)..', ' --general classification else postfix = ', '..victories_translate(wiki,1) end end elseif entity_type

'stage' then --how to write "stage, " is concentrated in one function local commatable=commastage(stageID, label) prefix= commatable[1] postfix=commatable[2] end

if Sitelink

nil then if label

nil then return prefix..wikibase.label(entityID)..postfix else return prefix..label..postfix end else if label

nil then return prefix..''..wikibase.label(entityID)..''..postfix else return prefix..''..label..''..postfix end endend

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

nil then display=true else for i=1,#displayed_class do if entityID

displayed_class[i] then display=true break end end end --is it a championship? for i=1,#class_champ do if entityID

class_champ[i] then 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 do if entityID

class_without2x[i] then entity_type = '1' class_text = mw.wikibase.label(class_without2x[i]) sortkey_class = class_sort[class_without2x[i]] end end end if entity_type

nil then entity_type = 'nada' end--to allow display of race without class... end if display

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

local function fn_race(entityID,displayed_class,displayclass, functionName)--return link to the race and class --first function read from victory main local Sitelink,instanceOf,circuitID,parentCircuitID, displayedCircuitID, Circuitlink local Classlink, entity_type, classID, class_text local inputtable, outputtable=, local display=false local stageID=entityID

for _, p31 in statements(entityID, 'P31') do instanceOf = p31.mainsnak.datavalue.value.id for i=1,#stages do --is it a stage? if instanceOf

stages[i] then entity_type = 'stage' --then the class is one stage above! local ParentID=getParentID(entityID) entityID=ParentID outputtable[3]=ParentID --as we read it here, no need to read it afterwards display=true for _, p31bis in statements(ParentID, 'P31') do instanceOfbis = p31bis.mainsnak.datavalue.value.id inputtable=fn_getclassinfo(instanceOfbis,displayed_class) if inputtable[1]

nil or inputtable[1]

'nada' then else class_text =inputtable[2] sortkey_class=inputtable[3] classID=inputtable[4] end end end end if entity_type

nil then --bypass if stage inputtable=fn_getclassinfo(instanceOf,displayed_class) if inputtable[1]

nil then elseif inputtable[1]

'nada' then --no display="inputtable[1]

nil" inputtable[1]

'nada'--> display but empty display=true else display=true entity_type=inputtable[1] class_text =inputtable[2] sortkey_class=inputtable[3] classID=inputtable[4] end end end --Now we have the class and know the type of race it is --Get the circuit, if we display it only if class_text ~=nil then Classlink = class_text else Classlink = sortkey_class= end

if display then if entity_type

'stage' then Sitelink=getmainraceLink(entityID,entity_type,stageID, functionName) else Sitelink=getmainraceLink(entityID,entity_type,nil, functionName) end outputtable[1]=''..Sitelink.. '' if displayclass

true then if classID

'Q23005601' or classID

'Q23005603' then --1WWT 2WWT clear displayedCircuitID = 'Q21075974' elseif classID

'Q22231106' or classID

'Q22231107' then --1UWT 2UWT clear displayedCircuitID = 'Q635366' else --we have to look in the item for _, p361 in statements(entityID, 'P361') do circuitID = p361.mainsnak.datavalue.value.id for _, p31 in statements(circuitID, 'P31') do --is it a UCI circuit? parentCircuitID = p31.mainsnak.datavalue.value.id for i=1,#UCI_Circuits do if parentCircuitID

UCI_Circuits[i] then --Yes it is displayedCircuitID=circuitID break end end end end end if displayedCircuitID~=nil then Circuitlink = wikibase.getSitelink(displayedCircuitID) --we display the circuit of the year if Circuitlink ~= nil then Classlink = ''..class_text..'' end end -- class outputtable[2]=''..Classlink.. '' end end return outputtableend

local function fn_rider(entityID,dateOfRace,displayteam,only_winner) local winRows = local win, winners =, if only_winner

1 then winners= -- first, general or stage elseif only_winner

0 then winners= -- Q20882668 is 'second overall' else --3 winners= -- World Tour -- name not used here end winner(entityID, winners, dateOfRace, true, WDlink_on, displayteam, true) if only_winner

0 then winRows = winRows .. ''..winners.Q20882667.. '' winRows = winRows .. ''..winners.Q20882668.. '' winRows = winRows .. ''..winners.Q20882669.. '' return winRows else local tempwinner if only_winner

1 then if winners.Q20882667~=nil and winners.Q20882667~= then tempwinner=winners.Q20882667 else tempwinner=winners.Q20882747 end else tempwinner=winners.Q47640757 end return winRows .. ''..tempwinner.. '' endend

function calendar_main(s)--Display the UCI women calendar of one year local calendarID=s.item local sortkey_class, sortkey local tBody = local tableBody, sortindex =, local timeofrace, displayed_class if displayed_class

nil then displayed_class=class else displayed_class=s.displayed_class end

local p527 = wikibase.getBestStatements(calendarID, s.property) -- P27 is country of citizenship if p527[1] and p527[1].mainsnak.snaktype

'value' then --every thing fine else s.error_message = 2 return end

----- Begin of the main part of the code if calendarID ~= nil then local kk=0 local fn_racetable,fn_datetable, fn_countrytable =,,

for _, p527 in statements(calendarID, 'P527') do RaceID = p527.mainsnak.datavalue.value.id ---- Create a row ---- fn_racetable=fn_race(RaceID,displayed_class,s.displayclass) if fn_racetable[1]~=nil then --otherwise the class is not display tBody = '' fn_datetable=fn_date(RaceID) dateOfRace=fn_datetable[1] tBody = tBody..fn_datetable[2] sortkey=fn_datetable[3] kk=kk+1 --only if displayed if s.numbering

true then tBody = tBody..''..tostring(kk).. '' end if s.country

true then fn_countrytable=fn_country(RaceID,dateOfRace,s.countryflagonly,fn_racetable[3]) --fn_racetable[1] is parentID tBody = tBody..fn_countrytable[1] end tBody = tBody..fn_racetable[1] if fn_racetable[2] then tBody = tBody..fn_racetable[2] end tBody = tBody..fn_rider(RaceID,dateOfRace,s.displayteam,s.only_winner) if s.leadercolumn

true then tBody = tBody..fn_rider(RaceID,dateOfRace,s.displayteam,3) end tBody = tBody.. '' ---- Add the row to the table local number = table.getn(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 for i=number,2,-1 do if sortkey >= sortindex[i] then table.insert(sortindex, i+1, sortkey) table.insert(tableBody, i+1, tBody) break end end end end end return table.concat (tableBody) end -- no calendarend

function p.nationalchampionships(frame) local calendarID = "" local mode = "" if wiki

"ar" then frame = frame:getParent end UCI = UCI["women"] = UCI["men"] =UCI["women"]

for key, v in pairs(UCI) do if calendarID

"" 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 calendarID = v[year] end end end

local s = return tableA(s, nationalchampionships_main(s))end

function nationalchampionships_main(s)--Display the list of national champions for one year local calendarID=s.item local sortkey_class, tRoadrace, tITT local tBody = local tableBody, sortindex =, local p527 = wikibase.getBestStatements(calendarID, s.property) -- P27 is country of citizenship if p527[1] and p527[1].mainsnak.snaktype

'value' then --every thing fine else s.error_message = 2 return end

if calendarID ~= nil then local championshipID, RaceIDRoadrace, sortkey local fn_datetable, fn_countrytable =,

for _, p527 in statements(calendarID, 'P527') do championshipID = p527.mainsnak.datavalue.value.id tRoadrace= tITT= for _, p527bis in statements(championshipID, 'P527') do RaceID = p527bis.mainsnak.datavalue.value.id Racelabel= mw.wikibase.label(RaceID) if Racelabel~=nil then Racelabelmod=mw.ustring.gsub(Racelabel, '-', 'x') testMenRoadrace=string.find(Racelabel, 'Course en ligne masculine aux') testMenITT=string.find(Racelabelmod, 'Contrexlaxmontre masculin aux') testWomenRoadrace=string.find(Racelabel, 'Course en ligne féminine aux') testWomenITT=string.find(Racelabelmod, 'Contrexlaxmontre féminin aux') end --fn_datetable[3] ~= nil then year =fn_datetable[3] end--otherwise keep the old one if s.mode

"women" then if testWomenRoadrace ~= nil then tRoadrace=fn_rider(RaceID,s.year,s.displayteam,1) end if testWomenITT ~= nil then tITT=fn_rider(RaceID,s.year,s.displayteam,1) end else--men if testMenRoadrace ~= nil then tRoadrace=fn_rider(RaceID,year,s.displayteam,1) end if testMenITT ~= nil then tITT=fn_rider(RaceID,s.year,s.displayteam,1)end end fn_countrytable=fn_country(RaceID,dateOfRace,s.countryflagonly) sortkey=fn_countrytable[2] if fn_countrytable[1]

nil then tBody=''..tRoadrace..tITT -- else tBody=fn_countrytable[1]..tRoadrace..tITT end tBody = tBody.. '' end ---- Add the row to the table local number = table.getn(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 for i=number,2,-1 do if sortkey >= sortindex[i] then table.insert(sortindex, i+1, sortkey) table.insert(tableBody, i+1, tBody) break end end end--this championship end return table.concat (tableBody) end -- no calendarend

--

C) Victory

function p.victories(frame) local s = return tableA(s, victory_main(s, Qnumber))end

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

local p2522 = wikibase.getBestStatements(s.item, s.property) if p2522[1] and p2522[1].mainsnak.snaktype

'value' then --every thing fine else s.error_message = 2 return end 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 sortkey, sortkey_class local tBody = local tableBody, sortindex, fn_countrytable, fn_datetable, fn_racetable =,,,,

for _, p2522 in statements(s.item, 'P2522') do RaceID = p2522.mainsnak.datavalue.value.id tBody = '' -- start the table row fn_datetable=fn_date(RaceID, 'victory') dateOfRace=fn_datetable[1] sortkey=fn_datetable[2] fn_racetable=fn_race(RaceID,nil,true, 'victory')--displayed_class=nil if fn_racetable[1]~= nil then --otherwise class not to be displayed tBody = tBody..fn_datetable[2] tBody = tBody..fn_racetable[1] if country

true then fn_countrytable=fn_country(RaceID,dateOfRace,s.countryflagonly,fn_racetable[3]) --fn_racetable[3] is parentID tBody = tBody..fn_countrytable[1] end tBody = tBody..fn_racetable[2] tBody = tBody..fn_rider(RaceID,dateOfRace,false,1) tBody = tBody.. '' -- end the table row local number = table.getn(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 for i=number,2,-1 do if sortkey >= sortindex[i] then table.insert(sortindex, i+1, sortkey) table.insert(tableBody, i+1, tBody) break end end end end end return table.concat (tableBody)end

--

D) Stage infoboxfunction p.stageinfobox(frame) local vvv= local tab local entityId = frame.args[1] local lang = mw.language.getContentLanguage local timeofrace local a1, b1, c1, a2, b2, a3, b3 local jerseyWPID, jersey_name local t_g = local t_s =

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 entity = mw.wikibase.getEntity(entityId)

if entity:getLabel ~= nil then t_g.name = entity:getLabel else t_g.name = entity:getLabel or entity:getLabel('en') or end if wiki

'fr' and t_g.name ~= then t_g.name= mw.ustring.gsub(t_g.name, "^(%d+)([re]+)", "%1%2 ") end t_g.name= mw.ustring.gsub(t_g.name, "^(%a)",function (x) return mw.ustring.upper(x) end)

a1, b1 = pcall(fooA, 'numeric-id', entity, 'P31', 1) -- If stage is a "stage" or a timetrial stage if a1

true and b1~=18131152 then t_g.is_a = 'Q'.. b1 end

if t_g.is_a

'Q2266066' or t_g.is_a

'Q2348250' or t_g.is_a

'Q485321' then t_g.icon = " " else t_g.icon = " " end

a1, b1 = pcall(fooA, 'value', entity, 'P18', 1) -- picture, legende if a1

true and t_g.picture

"" then local v t_g.picture = b1 if pcall(foo3, entity, "P18", 1, "P2096", 1) then for _, v in pairs(entity.claims["P18"]) do pcall(function for num=1,#v.qualifiers["P2096"] do -- find right language if v.qualifiers["P2096"][num].datavalue.value.language

lang:getCode then t_g.caption = v.qualifiers["P2096"][num].datavalue.value.text end end end) end end end

-- Function that give the starting place of a race a1, b1, c1 = pcall(fooA, 'numeric-id', entity, 'P1427', 1) if a1

true and t_g.startplace

"" then i = 1 while a1

true and c1

'deprecated' do i = i + 1 a1, b1, c1 = pcall(fooA, 'numeric-id', entity, 'P1427', i) end t_g.startplace = "Q" .. b1 end -- Function that give the finishing place of a race a1, b1, c1 = pcall(fooA, 'numeric-id', entity, 'P1444', 1) if a1

true and t_g.endplace

"" then i = 1 while a1

true and c1

'deprecated' do i = i + 1 a1, b1, c1 = pcall(fooA, 'numeric-id', entity, 'P1444', i) end t_g.endplace = "Q" .. b1 end

-- This function give a format to dates when P585 (date) is used in a single day race a1, b1, c1 = pcall(fooA, 'time', entity, 'P585', 1) if a1

true and t_g.time

"" then i = 1 while a1

true and c1

'deprecated' do i = i + 1 a1, b1, c1 = pcall(fooA, 'time', entity, 'P585', i) end t_g.time = func_date (b1, 'long') timeofrace = b1 end

-- Function that give the number of cyclists at the beginning and at the finishing of a race a1, b1, c1 = pcall(fooA, 'amount', entity, 'P1132', 1) if a1

true and t_g.nr_participants_start

"" and t_g.nr_participants_end

"" then i = 1 while a1

true and c1

'deprecated' do i = i + 1 a1, b1, c1 = pcall(fooA, 'amount', entity, 'P1132', i) end local v for _, v in pairs(entity.claims["P1132"]) do if pcall(function if v.qualifiers["P276"][1].datavalue.value["numeric-id"]

529711 then t_g.nr_participants_start = string.gsub(v.mainsnak.datavalue.value.amount, "+", "") end end ) then else t_g.nr_participants_start = "" end if pcall(function if v.qualifiers["P276"][1].datavalue.value["numeric-id"]

12769393 then t_g.nr_participants_end = string.gsub(v.mainsnak.datavalue.value.amount, "+", "") end end ) then else t_g.nr_participants_end = "" end end end

t_g.length = getDistance(entityId, true) or t_g.speed = getSpeed(entityId, true) or

a1, b1 = pcall(fooA, 'numeric-id', entity, 'P17', 1) -- This function gives countries where the race take place if a1

true then for i, v in pairs(entity.claims["P17"]) do t_g.country[i] = "Q" .. v.mainsnak.datavalue.value["numeric-id"] end end

a1, b1 = pcall(fooA, 'value', entity, 'P242', 1) -- locator map image if a1

true and t_g.map

"" then t_g.map = b1 end a1, b1 = pcall(fooA, 'value', entity, 'P2713', 1) -- sectional view if a1

true and t_g.sectional_view

"" then t_g.sectional_view = b1 end

a1, b1 = pcall(fooA, 'numeric-id', entity, 'P155', 1) if a1

true and t_g.previous

"" then t_g.previous = "Q"..b1 a2, b2 = pcall(fooA, 'value', mw.wikibase.getEntity(t_g.previous), 'P1545', 1) if a2

true then t_g.series_ordinal_previous = b2 end end a1, b1 = pcall(fooA, 'numeric-id', entity, 'P156', 1) if a1

true and t_g.next

"" then t_g.next = "Q"..b1 a2, b2 = pcall(fooA, 'value', mw.wikibase.getEntity(t_g.next), 'P1545', 1) if a2

true then t_g.series_ordinal_next = b2 end end

local t_P642 =

a1, b1 = pcall(fooA, 'numeric-id', entity, "P1346", 1) if a1

true then local deprecated, qual, id, id_team, id_time, id_time_gap, id_speed, id_points_a, id_points_b for k, v in pairs(entity.claims["P1346"]) do id_team, id_speed, id_time, id_time_gap, id_points_a, id_points_b = , , , , , a, b = pcall(fooC, 'numeric-id', entity, 'P1346', k, 'P54', 1) if a

true then id_team = 'Q'..b end

if pcall(function id=v.mainsnak.datavalue.value['numeric-id'] -- id = rider id deprecated = entity.claims["P1346"][k].rank end) then else id=nil end if id ~= nil then --timeofrace = "+2016-03-00T00:00:00Z" -- function timeStartEnd finds the team of the rider at the time (timeofrace) of the race if id_team

and timeofrace ~= nil and timeofrace ~= then a, b = timeStartEnd('Q'..id, 'P54', 'numeric-id', timeofrace) if a

true and b ~= nil then id_team = 'Q' .. b end end

-- looks into race item if the winner has a P54 statement for beeng a member of a national team pcall(function for _, vv in pairs(entity.claims["P1346"][k].qualifiers['P54']) do id_team = national_team('Q'..id, timeofrace, entity, 'P1346', k) -- timeofrace -> startOfSeason ????? if id_team

nil then id_team = end end end)

pcall(function -- for property 'race time' for _, v in pairs(entity.claims['P1346'][k].qualifiers['P2781']) do id_time = tonumber(v.datavalue.value.amount) end end)

pcall(function -- for property 'time gap' for _, v in pairs(entity.claims['P1346'][k].qualifiers['P2911']) do id_time_gap = tonumber(v.datavalue.value.amount) end end)

pcall(function -- for property 'speed' for _, v in pairs(entity.claims['P1346'][k].qualifiers['P2052']) do id_speed = tonumber(v.datavalue.value.amount) end end)

pcall(function -- for property 'points for' for _, v in pairs(entity.claims['P1346'][k].qualifiers['P1358']) do id_points_a = tonumber(v.datavalue.value.amount) end end)

pcall(function -- for property 'number of points/goals/set scored' for _, v in pairs(entity.claims['P1346'][k].qualifiers['P1351']) do id_points_b = tonumber(v.datavalue.value.amount) end end)

-- looks into race item if the winner has a P642 statement for showing the type of winner (points, mountain, ..) pcall(function for _, vv in pairs(entity.claims["P1346"][k].qualifiers['P642']) do qual=vv.datavalue.value['numeric-id']

if id~=nil and qual~=nil and v.rank~='deprecated' then if qual

21686770 and t_s['results']['winner_fighting'][1] ~= then t_P642[qual][2] = 'winner_fighting2' end pcall(function -- inserts WD data into table t_s t_s[t_P642[qual][1]][t_P642[qual][2]][1]='Q'..id t_s[t_P642[qual][1]][t_P642[qual][2]][5]=id_team t_s[t_P642[qual][1]][t_P642[qual][2]][10]=deprecated if id_time~= then t_s[t_P642[qual][1]][t_P642[qual][2]][6]=id_time end if id_time_gap~= then t_s[t_P642[qual][1]][t_P642[qual][2]][7]=id_time_gap end if id_points_a~= then t_s[t_P642[qual][1]][t_P642[qual][2]][8]=id_points_a end if id_points_b~= then t_s[t_P642[qual][1]][t_P642[qual][2]][8]=id_points_b end if id_speed~= then t_s[t_P642[qual][1]][t_P642[qual][2]][9]=id_speed end end) if qual

27104271 and t_s.classement_annex.equipe_points[1]

then t_s.classement_annex.equipe_points[1]='Q'..id end if qual

20882922 and t_s.classement_annex.equipe[1]

then t_s.classement_annex.equipe[1]='Q'..id end

a1, b1 = pcall(fooA, 'numeric-id', mw.wikibase.getEntityObject('Q'..id), 'P21', 1) -- detect gender if a1

true then if b1

6581097 then t_s[t_P642[qual][1]][t_P642[qual][2]][3] = 'm' -- men elseif b1

6581072 then t_s[t_P642[qual][1]][t_P642[qual][2]][3] = 'f' -- female end else t_s[t_P642[qual][1]][t_P642[qual][2]][3] = 'f' -- female end end end end) end end end local rank, deprecated local order = local property = 'P2417' a1, b1 = pcall(fooA, 'numeric-id', entity, property, 1) if a1

true then for k, _ in pairs(entity.claims[property]) do -- look into P2417, stage classification for _, v in pairs(entity.claims[property][k].qualifiers['P1352']) do -- for property 'rank' rank = tonumber(v.datavalue.value.amount) deprecated = entity.claims[property][k].rank end if rank

1 or rank

2 or rank

3 then t_s.results[order[rank]][10] = deprecated if t_s.results[order[rank]][1]

or t_s.results[order[rank]][10]

'normal' then -- name or rider / team t_s.results[order[rank]][1] = 'Q' .. entity.claims[property][k].mainsnak.datavalue.value['numeric-id'] if t_s.results[order[rank]][7]

and t_s.results[order[rank]][6]

then pcall(function for _, v in pairs(entity.claims[property][k].qualifiers['P2911']) do -- for property 'time gap' t_s.results[order[rank]][7] = tonumber(v.datavalue.value.amount) end end) end if t_s.results[order[rank]][7]

and t_s.results[order[rank]][6]

then pcall(function for _, v in pairs(entity.claims[property][k].qualifiers['P2781']) do -- for property 'race time' t_s.results[order[rank]][6] = tonumber(v.datavalue.value.amount) end end) end if t_s.results[order[rank]][9]

then pcall(function for _, v in pairs(entity.claims[property][k].qualifiers['P2052']) do -- for property 'speed' t_s.results[order[rank]][9] = tonumber(v.datavalue.value.amount) end end) end a1, b1 = pcall(fooA, 'numeric-id', mw.wikibase.getEntityObject(t_s.results[order[rank]][1]), 'P21', 1) -- detect gender if a1

true then if b1

6581097 then t_s.results[order[rank]][3] = 'm' -- men elseif b1

6581072 then t_s.results[order[rank]][3] = 'f' -- female end else t_s.results[order[rank]][3] = 'f' -- female end end end end end order = property = 'P2321' a1, b1 = pcall(fooA, 'numeric-id', entity, property, 1) if a1

true then for k, _ in pairs(entity.claims[property]) do -- look into P2321, stage classification for _, v in pairs(entity.claims[property][k].qualifiers['P1352']) do -- for property 'rank' rank = tonumber(v.datavalue.value.amount) deprecated = entity.claims[property][k].rank end if rank

1 or rank

2 or rank

3 then t_s.classement_gen[order[rank]][10] = deprecated if t_s.classement_gen[order[rank]][1]

or t_s.classement_gen[order[rank]][10]

'normal' then -- name or rider / team t_s.classement_gen[order[rank]][1] = 'Q' .. entity.claims[property][k].mainsnak.datavalue.value['numeric-id'] if t_s.classement_gen[order[rank]][7]

and t_s.classement_gen[order[rank]][6]

then pcall(function for _, v in pairs(entity.claims[property][k].qualifiers['P2911']) do -- for property 'time gap' t_s.classement_gen[order[rank]][7] = tonumber(v.datavalue.value.amount) end end) end if t_s.classement_gen[order[rank]][7]

and t_s.classement_gen[order[rank]][6]

then pcall(function for _, v in pairs(entity.claims[property][k].qualifiers['P2781']) do -- for property 'race time' t_s.classement_gen[order[rank]][6] = tonumber(v.datavalue.value.amount) end end) end if t_s.classement_gen[order[rank]][9]

then pcall(function for _, v in pairs(entity.claims[property][k].qualifiers['P2052']) do -- for property 'speed' t_s.classement_gen[order[rank]][9] = tonumber(v.datavalue.value.amount) end end) end a1, b1 = pcall(fooA, 'numeric-id', mw.wikibase.getEntityObject(t_s.classement_gen[order[rank]][1]), 'P21', 1) -- detect gender if a1

true then if b1

6581097 then t_s.classement_gen[order[rank]][3] = 'm' -- men elseif b1

6581072 then t_s.classement_gen[order[rank]][3] = 'f' -- female end else t_s.classement_gen[order[rank]][3] = 'f' -- female end end end end end

local a, b local span1, span2 = "

&#x25C0; ", " &#x25B6;"

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 = transform(t_g.previous,'Q', timeofrace) 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 t_g.previous = span1 .. label_previous if wiki

"ar" then t_g.previous = span2 .. label_previous end end else t_g.previous = end

if t_g.series_ordinal_next~= then a, _ = string.gsub(t_g.series_ordinal_next, "%a", "") -- 20, not 20a 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")) else b = "" end local label_next = stageLink(t_g.series_ordinal_next, a, b) if t_g.series_ordinal_next

"0" then label_next = func_prologue end if mw.wikibase.sitelink(t_g.next) ~= nil then local k = transform(t_g.next,'Q', timeofrace) 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

if t_g.course

then a1, b1 = pcall(fooA, 'value', entity, 'P1545', 1) if a1

true then a, _ = string.gsub(b1, "%a", "") -- 20, not 20a if string.find(b1, "%a") then b = string.sub(b1, string.find(b1, "%a")) else b = "" end local label = stageLink(b1, a, b) if b1

"0" then label = func_prologue end t_g.course = label a2, b2 = pcall(fooA, 'numeric-id', entity, 'P361', 1) if a2

true then t_g.course = t_g.course .. ', '.. WPlink('Q'..b2,'pure') if wiki

"ar" then t_g.course = t_g.course .. '، '.. WPlink('Q'..b2,'pure') end --t_g.race = 'Q'..b2

local entity_race = mw.wikibase.getEntity('Q'..b2) a3, b3 = pcall(fooA, 'numeric-id', entity_race, 'P31', 1) if a3

true then for k, v in pairs(entity_race.claims["P31"]) do t_g.race[k] = 'Q'..v.mainsnak.datavalue.value["numeric-id"] end end end end end

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

function stage_icon(x) if x

'Q20646667' then return " " end if x

'Q20646670' then return " " end if x

'Q20680270' then return " " end if x

'Q20646668' then return " " end if x

'Q20679712' then return " " end if x

'Q2348250' then return " " end if x

'Q2266066' then return " " end if x

'Q485321' then return " " end return end

local width= '320px' -- size standard 320px, special 340px if t_s.classement_annex.show

true and (wiki

'no' or wiki

'..') then width= '340px' end

tab = "

" tab = tab .. "
" .. t_g.name .."
" .. t_g.icon .. "
"

if t_g.picture ~= "" then tab = tab .. "".." " end if t_g.picture ~= "" and t_g.caption ~= "" then tab = tab .. ""..t_g.caption.."" 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..""..stageinfobox_translate(1).."" end if t_g.course ~= "" then tab = tab..""..stageinfobox_translate(2).."" .. t_g.course .. "" end if t_g.is_a ~= "" then tab = tab..""..stageinfobox_translate(3).."" ..stage_icon(t_g.is_a).. WPlink(t_g.is_a,'pure').. "" end if t_g.time~="" then tab = tab..""..stageinfobox_translate(4).."" .. t_g.time.."" end if t_g.length ~= "" then tab = tab .. "" .. stageinfobox_translate(6) .. "" .. t_g.length .. "" end if t_g.startplace ~= "" then tab = tab..""..stageinfobox_translate(9).."" .. WPlink(t_g.startplace,'pure').. "" end if t_g.endplace ~= "" then tab = tab..""..stageinfobox_translate(10).."" .. WPlink(t_g.endplace,'pure').. "" end if t_g.country ~= nil then for i=1,#t_g.country do t_g.country[i] = flag(t_g.country[i], timeofrace).." ".. WPlink(t_g.country[i],'pure') end end if t_g.country[1] ~= nil then tab = tab.."" if #t_g.country

1 then tab = tab..stageinfobox_translate(7).."" else tab = tab..stageinfobox_translate(8).."" end for i=1,#t_g.country-1 do tab = tab .. t_g.country[i].."
" end tab = tab .. t_g.country[#t_g.country].."" end if t_g.nr_participants_start ~= "" then tab = tab..""..stageinfobox_translate(11).."" .. t_g.nr_participants_start .. "" end if t_g.nr_participants_end ~= "" then tab = tab..""..stageinfobox_translate(12).."" .. t_g.nr_participants_end .. "" end if t_g.speed ~= "" then tab = tab .. "" .. stageinfobox_translate(13) .. "" .. t_g.speed .. "" end

for _, value_order in ipairs(t_s.order) do if t_s[value_order].show

true then -- if a section of the stageinfobox should be shown tab=tab.."" tab=tab.."

".. stageinfobox_translate(t_s[value_order].header).."
" else tab=tab.."
" end 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 if t_s[value_order][value][4]

"" then if (value_order

'results') and (value

'winner_fighting' or value

'winner_fighting2' or value

'cima_coppi' or value

'cima_pantanii') then tab=tab..stageinfobox_translate(t_s[value_order][value][2]) else tab=tab..number(t_s[value_order][value][3], key, wiki) end else if jerseyWPID

then tab=tab.."" else tab=tab.."" end end else if t_s[value_order][value][4]

"" then tab=tab..title else if jerseyWPID

then if jersey_name ~= then tab=tab.."" .. title else tab=tab.."" .. title end else tab=tab.."" .. title end end end if t_s[value_order][value][10]

'deprecated' then tab=tab.. "

".. '' .. transform(t_s[value_order][value][1],'f', timeofrace) .. '' else tab=tab.. "".. transform(t_s[value_order][value][1],'f', timeofrace) end tab=tab.."" 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].. "
" tab = tab.. "
("..transform(t_s[value_order][value][5],'t', timeofrace).. ")
"..t_s[value_order][value][9] .. "
" else if t_s[value_order][value][5]~="" or t_s[value_order][value][9] ~="" then -- team row tab=tab.."" if t_s[value_order][value][5] ~= then tab=tab..'('..transform(t_s[value_order][value][5],'t', timeofrace)..')' end tab = tab.. ''.. t_s[value_order][value][9].."" end end end tab=tab.. "" end end

if t_g.map ~= "" then tab = tab .. "".." ".."" end if t_g.sectional_view ~= "" then tab = tab .. "".." ".."" end

prevNextLine = ""..t_g.previous.."" .. t_g.next .. "" if wiki

"ar" then prevNextLine = ""..t_g.previous.."" .. t_g.next .. "" end tab = tab .. prevNextLine

local s = "d:Wikidata:WikiProject Cycling/Documentation/stageinfobox" tab = tab .. "".. --infobox_bottom(1) "" .. stageinfobox_translate(39).. " " tab = tab .. "" tab= tab.."" return tabend

--

E) List of teamsfunction p.listofteams(frame) local raceID = frame.args[1] local teams = -- values will be local text =

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

local teamCats =

local p1923 = mw.wikibase.getBestStatements(raceID, 'P1923') -- P1923 is participating teams local no = 0 -- Index used for stable sorting for _, v in pairs(p1923) do if v.mainsnak.snaktype

'value' then no = no + 1 local teamLink, teamCat, countryID = getTeamLinkCat(v.mainsnak.datavalue.value.id, timeOfRace, true) local flagImage = countryID and flag(countryID, timeOfRace) or teams[#teams + 1] = end end

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

local function getHeader(CatID, count) local header if teamCats[CatID] then if count

1 then header = headoftableIII(teamCats[CatID][1]) -- singular name else header = headoftableIII(teamCats[CatID][2]) -- plural name end end local text if not header then -- Unknown team category. Get the label for the entity to display if possible header = (CatID and getLabelFallback(CatID,)) or 'Unknown team category' text = '

' .. header .. '' else text = '' .. header .. '' end -- Set parameter to show team count in front of each category local showcounter = 2 if count >= showcounter then text = text .. ' (' .. count ..')' end return text end local oldOrder = 0 local oldCatID local count = 0 local list = for _, team in ipairs(teams) do local order = team[3] if order ~= oldOrder then if oldOrder > 0 then text = text .. getHeader(oldCatID, count) .. '
    ' .. list .. '
' end count = 1 oldOrder = order list =
else count = count + 1 end oldCatID = team[2] list = list .. '
  • ' .. team[1] .. '
  • ' end

    return '

    ' .. text .. getHeader(oldCatID, count) .. '
      ' .. list .. '
    'end

    --

    F) Classificationsfunction p.pointsclassification(frame) local s = return new_classification(frame, s)end

    function p.teamsclassificationbytime(frame) local s = return new_classification(frame, s)end

    function p.teamsclassificationbypoints(frame) local s = return new_classification(frame, s)end

    function p.stageclassification(frame) if frame.args[2] then display_reftemp=tonumber(frame.args[2]) else display_reftemp=0 end local s = return new_classification(frame, s)end

    function p.generalclassification(frame) if frame.args[2] then display_reftemp=tonumber(frame.args[2]) else display_reftemp=0 end local s = return new_classification(frame, s)end

    function p.generalclassificationforttt(frame) if frame.args[2] then display_reftemp=tonumber(frame.args[2]) else display_reftemp=0 end

    local s = return new_classification(frame, s)end

    function p.teamtimetrialclassification(frame) if frame.args[2] then display_reftemp=tonumber(frame.args[2]) else display_reftemp=0 end

    local s = return new_classification(frame, s)end

    function p.mountainsclassification(frame) local s = return new_classification(frame, s)end

    function p.sprintsclassification(frame) local s = return new_classification(frame, s)end

    function p.bestyoungclassificationbypoints(frame) local s = return new_classification(frame, s)end

    function p.bestyoungclassification(frame) local s = return new_classification(frame, s)end

    function p.u23classification(frame) local s = return new_classification(frame, s)end

    function p.combinationclassification(frame)local s = return new_classification(frame, s)end

    function p.combativeclassification(frame) local s = return new_classification(frame, s)end

    function new_classification(frame, s) local country = true

    if wiki

    'da' then country = false end -- those wikis do not want to show the country column as standard if wiki

    'es' then country = false end -- those wikis do not want to show the country column as standard local s = s local available_list = available_list local raceID = s.item

    --[=[ It is possible to give the classification tables in the article commands to change the standard behaviour. They could look like this: {{Cycling race/teamsclassificationbytime|Q18574623|newline=false|country=true}} {{Cycling race/teamsclassificationbytime|Q18574623|country= false|newline=false}} {{Cycling race/teamsclassificationbypoints|Q18574623|newline =true|country=true}} {{Cycling race/teamsclassificationbypoints|Q18574623|newline= true}} {{Cycling race/teamsclassificationbypoints|Q18574623|newline = false|country=false}} {{Cycling race/teamsclassificationbytime|Q18574623|newline=true|country=true}} One additional parameter is "newline" with the values "true" or "false". "newline" says, if there is a line brake after the table. Standard is no line break after the tables stageclassification and teamtimetrialclassification. The second parameter is "country" with the values "true" or "false". "country" tells the module to print the country column or not. Most wikis have as standard to print the country columns, some wikis prefer as standard not to show the country column. A few lines above, the command "if wiki == 'da' then country = false end" tells that daWiki do not want to see the country colums as standard. You can add your wiki here in, if you do not want to see them as standard. With the new parameter editors are able to tell the module in the article what to do. ]=]

    local function jersey(h) local jersey_string = ' ' local jerseys =

    if type(h)

    'table' and h[1] then for _, v in ipairs(h) do local jersey_name if jerseys[v] then jersey_string = jersey_string .. '' else p18 = mw.wikibase.getBestStatements(v, 'P18') if p18[1] and p18[1].mainsnak.snaktype

    'value' then jersey_string = jersey_string .. '' end end end end return jersey_string end -- function end

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

    local v = local plus = local localFrame if string.match(frame:getParent:getTitle, '%P+')

    mw.site.namespaces.Template.name then localFrame = frame:getParent else localFrame = frame end if localFrame.args[1] ~= nil then localFrame.args[1] = string.gsub(localFrame.args[1], "%c", "") end

    if localFrame.args.country ~= nil then -- switch country column on or off in the article if localFrame.args.country

    'true' then country = true end if localFrame.args.country

    'false' then country = false end end local tableHeader2_size = table.getn(s.header_2)

    local tableStart = '

    ' local tableHeader1 = ''.. s.header_function(s.header_1) .. '
    '.. s.header_function(k) .. ''.. s.header_function(k) .. '
    '.. number(gender, rank, wiki).. ''

    if not s.team_classification then if not teamLink then teamLink = end if not available_list then tBody = tBody .. flagLink .. ' '.. riderLink .. jersey(h.jersey) .. '

    '.. teamLink else if country

    true then tBody = tBody .. riderLink .. jersey(h.jersey) ..'

    ' .. flagLink .. ' '.. countryName .. ''.. teamLink else tBody = tBody .. flagLink .. ' ' .. riderLink .. jersey(h.jersey) .. ''.. teamLink end end else if not available_list then tBody = tBody .. flagLink .. ' ' .. teamLink .. jersey(h.jersey) else if country then tBody = tBody .. teamLink .. jersey(h.jersey) .. ''.. flagLink .. ' ' .. countryName else tBody = tBody .. flagLink .. ' ' .. teamLink .. jersey(h.jersey) end end end tBody = tBody.. ''.. calculate_time(h.value[2]) .. ''.. plus .. calculate_time(h.value[3]) .. ''.. h.value[1] .. '' if type(h.value[1])

    "number" then if h.value[1] > 1 then tBody = tBody..unit(7) else tBody = tBody..unit(6) end end tBody = tBody.. '

    ' .. '
    '.. calculate_time(h.value[2]) .. ''.. calculate_time(h.value[2]) .. ''.. plus.. calculate_time(h.value[3]) .. ''.. h.value[1].. '' if type(h.value[1])

    "number" then if h.value[1] > 1 then tBody = tBody..unit(7) else tBody = tBody..unit(6) end end tBody = tBody.. '

    ' .. '
    ' if l > 1 then tBody = tBody.. plus end tBody = tBody.. calculate_time(h.value[3]) .. '' if type(h.value[4])

    "number" then tBody = tBody.. mw.ustring.format('%.3f', h.value[4]).. '

    '.. unit(5).. '' end tBody = tBody.. '
    ' .. race_reference(raceID) ..'
    '

    local tableStyle, tableNewline if localFrame.args.newline

    'false' then -- parameter newline in WP article is 'false' tableStyle = "float:" .. floattable .. "; margin-right:0.5em; border:1px solid rgb(200,200,200)" tableNewline = end if localFrame.args.newline

    'true' then -- parameter newline in WP article is 'true' tableStyle = "border:1px solid rgb(200,200,200)" tableNewline = '
    ' end if localFrame.args.newline

    nil then -- no second parameter, compatible to the old code if s.property

    'P2417' then --stageclassification tableStyle = "float:"..floattable.."; margin-right:0.5em; border:1px solid rgb(200,200,200)" tableNewline = else tableStyle = "border:1px solid rgb(200,200,200)" tableNewline = '
    ' -- everything else end end

    return '

    ' .. tableStart .. tableHeader1 .. tableHeader2 .. tableBody .. tableFooter..tableEnd .. '
    ' .. tableNewlineend

    --

    G) Infobox

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

    "mk" or wiki

    "ja")

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

    local details = local others = local winners =

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

    local localFrame if string.match(frame:getParent:getTitle, '%P+')

    mw.site.namespaces.Template.name then localFrame = frame:getParent else localFrame = frame end getLocalContent(details, localFrame.args) getLocalContent(others, localFrame.args) getLocalContent(winners, localFrame.args)

    local name, dateOfRace, class local icon = (firstValue(entityID, 'P641', 'numeric-id')

    3609) and -- P641 is 'sport', Q3609 is 'road bicycle racing' ' ' or

    local name = wikibase.getLabel(entityID) if not name then name = getLabelFallback(entityID,) 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 -- For FR Wiki and Wikidata, exception that permit to display 1er, 2e... for the edition number ; -- for RU Wiki, -й is written after the value of P393 local nr = firstValue(entityID, 'P393') -- P393 is 'edition number' if nr then if wiki

    'fr' then nr = (nr

    1) and "1re " or (nr .. "e ") elseif wiki

    "nl" then nr = nr .. "e " elseif wiki

    "ru" then nr = nr .. "-й " elseif wiki

    "eo" then nr = nr .. "-a " elseif wiki

    "hu" then nr = nr .. "-ik " else nr = nr .. ". " end end local is_a for _, p31 in statements(entityID, 'P31') do -- P31 is 'instance of' local instanceOf = p31.mainsnak.datavalue.value.id if instanceOf

    'Q27968055' then -- Q27968055 is 'recurrent event edition' -- do nothing elseif classes[instanceOf] then class = classLink(instanceOf) elseif instanceOf

    "Q27020041" then -- Q27020041 is 'sports season' local season = firstValue(entityID, 'P3450', 'id') -- P3450 is 'sports season of league or competition' if season then is_a = raceLink(season) end else is_a = raceLink(instanceOf) end end if nr and is_a then details[1].content = nr .. ' ' .. is_a end end if not details[2].content then -- competition -- Class of a cycling race. Class is: 1.UWT, 2.UWT, 1.HC, ... add new classes, no problem -- Competition of the cycling race : UCI World Tour 2016, UCI Europe Tour 2016... local tours = for _, p361 in statements(entityID, 'P361') do -- P361 is 'part of' tours[#tours + 1] = raceLink(p361.mainsnak.datavalue.value.id) end if tours[1] then if #tours > 1 then details[2].name = details[2].name_plural end if class then tours[1] = tours[1] .. ' ' .. class end details[2].content = table.concat(tours, '
    ') end end

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

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

    if not details[6].content then -- country -- This function gives countries where the race take place local country = for _, p17 in statements(entityID, 'P17') do -- P17 is 'country' 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, '
    ') 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 local teams = #wikibase.getBestStatements(entityID, 'P1923') -- P1923 is 'participating teams' if teams > 0 then details[9].content = teams end end

    -- 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[12].content then details[12].content = getSpeed(entityID, true) end --speed

    if not details[13].content then -- cost local cost = firstValue(entityID, 'P2130') -- P2130 is cost if cost then local unit = cost.unit cost = contentLanguage:formatNum(tonumber(cost.amount)) if wiki

    'fo' then cost = string.gsub(t.cost, "%.", ",") end if unit

    "http://www.wikidata.org/entity/Q4916" then cost = cost .. ' €' elseif unit

    "http://www.wikidata.org/entity/Q4917" then cost = cost .. ' $' end details[13].content = cost end end

    local tab if wiki

    "eo" then tab = "

    " .. "
    " .. name .."
    " .. icon .. "
    "

    if others[1].content then -- picture tab = tab .. "" if others[2].content then -- caption tab = tab .. "" .. others[2].content .. "" end end tab = tab .. "" .. infobox_translate(1) .. "" for _, row in ipairs(details) do if row.content then tab = tab .. "" .. row.name .. "" .. row.content .. "" end end

    local winRows = local win = for _, v in pairs(winners) do if not v.content then win[v.QID] = end end winner(entityID, win, dateOfRace, true, WDlink_on, team, true) for _, v in pairs(winners) do if not v.content then local QID = v.QID if win[v.QID] ~= then v.content = win[v.QID] end end if v.content then winRows = winRows .. "" .. v.name .. "" .. v.content .. "" end end if winRows ~= then tab = tab .. "" .. infobox_translate(18) .. "" .. winRows end

    if others[3].content then -- map tab = tab .. "" end tab = tab .. getPreviousNextLine(entityID) local s = "d:Wikidata:WikiProject Cycling/Documentation/infobox" tab = tab .. "" .. "" .. infobox_translate(34) .. " " return tabend

    --

    H) Team rosterfunction p.teamroster(frame) if frame.args[1] ~= nil then frame.args[1] = string.gsub(frame.args[1], "%c", "") end local squadSeason = mw.wikibase.getEntityObject(frame.args[1]) local flags, pays =, local riderIds, riderNames, riderBirthdays, givenname, familyname, riderTeam, time =,,,,,, local riderStart, riderEnd, riderPosition, riderReason, riderRef =,,,, local index, riderNames_transl, riderNames_notransl =,, local labelMissing = false local lang = mw.language.getContentLanguage local WDlink_on local team, rider, startOfSeason local v =

    local function trans(date, month, day) if date ~= then local _, _, y, m, d = string.find(date, "(%d+)-(%d+)-(%d+)") if m

    '00' then m = month end if d

    '00' then d = day end date = '+'..y..'-'..m..'-'..d..'T00:00:00Z' return date else return end end local function name(i, wiki, transl, names, givenname, familyname) -- transform name "A B ..." into "B ... A" local _, count = mw.ustring.gsub(names, " ", " ") local a,b,c,d = , , , local done = false if count ~= nil then count = count + 1 else count = 1 end

    if count > 1 then if count

    2 then if names~= then _, _, a, b = mw.ustring.find(names, "(%S+)%s+(%S+)") names=b..' '..a..":"..i end else local name_parts_lv = local name_parts_mk = local name_parts_ru = local name_parts = local v if count

    3 and names~= then _, _, a, b, c = mw.ustring.find(names, "(%S+)%s+(%S+)%s+(%S+)") if wiki

    'mk' then for _,v in ipairs(name_parts_mk) do if b

    v then names = b..' '..c..' '..a..":"..i done = true break end end end if wiki

    'lv' then for _,v in ipairs(name_parts_lv) do if b

    v then names = b..' '..c..' '..a..":"..i done = true break end end end if wiki

    'ru' then for _,v in ipairs(name_parts_ru) do if b

    v then names = b..' '..c..' '..a..":"..i done = true break end end end if wiki ~= 'lv' and wiki ~= 'mk' and wiki ~= 'ru' then for _,v in ipairs(name_parts) do if b

    v then names = b..' '..c..' '..a..":"..i done = true break end end end if transl

    'notransl' then --or (wiki~='lv' and wiki~='mk' and wiki~='ru' and wiki~='ja') then for _,v in ipairs(name_parts) do if b

    v then names = b..' '..c..' '..a..":"..i done = true break end end end if not done and familyname

    2 then names = b..' '..c..' '..a..":"..i done = true end if not done and familyname

    1 then names = c..' '..a..' '..b..":"..i done = true end if not done and familyname

    0 then names = c..' '..a..' '..b..":"..i done = true end end if count > 3 and names~= then _, _, a, b, c, d = mw.ustring.find(names, "(%S+)%s+(%S+)%s+(%S+)%s+(%S+)") if wiki

    'mk' then for _,v in ipairs(name_parts_mk) do if c

    v then names = c..' '..d..' '..a..' '..b..":"..i done = true break end end for _,v in ipairs(name_parts_mk) do if b

    v then names = b..' '..c..' '..d..' '..a..":"..i done = true break end end end if wiki

    'lv' then for _,v in ipairs(name_parts_lv) do if c

    v then names = c..' '..d..' '..a..' '..b..":"..i done = true break end end for _,v in ipairs(name_parts_lv) do if b

    v then names = b..' '..c..' '..d..' '..a..":"..i done = true break end end end if wiki

    'ru' then for _,v in ipairs(name_parts_ru) do if c

    v then names = c..' '..d..' '..a..' '..b..":"..i done = true break end end for _,v in ipairs(name_parts_ru) do if b

    v then names = b..' '..c..' '..d..' '..a..":"..i done = true break end end end if wiki ~= 'lv' and wiki ~= 'mk' and wiki ~= 'ru' then for _,v in ipairs(name_parts) do if c

    v then names = c..' '..d..' '..a..' '..b..":"..i done = true break end end for _,v in ipairs(name_parts) do if b

    v then names = b..' '..c..' '..d..' '..a..":"..i done = true break end end end if transl

    'notransl' then --or (wiki~='lv' and wiki~='mk' and wiki~='ru' and wiki~='ja') then for _,v in ipairs(name_parts) do if c

    v then names = c..' '..d..' '..a..' '..b..":"..i done = true break end end for _,v in ipairs(name_parts) do if b

    v then names = b..' '..c..' '..d..' '..a..":"..i done = true break end end end if not done then names = b..' '..c..' '..d..' '..a..":"..i end end end end return names end

    local localFrame local sort --Q21769847 | sort }} A rider called 'Laurens De Vreese' is sorted after 'De Vreese Laurens'. If you want to sort after 'Vreese Laurens De' change that in the code. In lvWiki, mkWiki and ruWiki sorting is standard, there is no need to switch sorting on in the article if string.match(frame:getParent:getTitle, '%P+')

    mw.site.namespaces.Template.name then localFrame = frame:getParent else localFrame = frame end if localFrame.args[2] ~= nil then if mw.ustring.find(mw.ustring.lower(localFrame.args[2]), "sort") then sort = true else sort = false end end if wiki

    "lv" or wiki

    "mk" or wiki

    "ru" then sort = true end

    pcall(function team = squadSeason.claims["P361"][1].mainsnak.datavalue.value['numeric-id'] end)

    -- WDlink_on is used to decide if a Wikidata flag will be shown if wiki

    "mk" or wiki

    "ja" or wiki

    "ru" or wiki

    "he" then WDlink_on = true else WDlink_on = false end

    if pcall(function startOfSeason = squadSeason.claims["P580"][1].mainsnak.datavalue.value.time end) then else local Sitelink = squadSeason:getSitelink(wiki .. 'wiki') or squadSeason:getSitelink('enwiki') or squadSeason:getSitelink('frwiki') or squadSeason:getSitelink('dewiki') or if Sitelink

    then return '> Wikidata is missing data about the start time (P580) and end time (P582) of the season' else startOfSeason = '+'..string.match(Sitelink, '%d%d%d%d') ..'-01-01T00:00:00Z' end end

    local i = 1 pcall(function while squadSeason.claims["P527"][i] do riderIds[i] = 'Q' .. squadSeason.claims["P527"][i].mainsnak.datavalue.value['numeric-id'] riderNames[i] = WPlink(riderIds[i])

    rider = mw.wikibase.getEntityObject(riderIds[i]) if pcall(function riderBirthdays[i] = rider.claims["P569"][1].mainsnak.datavalue.value.time end ) then else riderBirthdays[i] = end if pcall(function local k for k, _ in pairs(rider.claims["P735"]) do givenname[i] = k end end ) then else givenname[i] = 0 end if pcall(function local k for k, _ in pairs(rider.claims["P734"]) do familyname[i] = k end end ) then else familyname[i] = 0 end

    pcall(function local language language = wiki local entity=mw.wikibase.getEntity(riderIds[i]) if wiki

    'mk' or wiki

    'ru' then if entity:getLabel(language) ~= nil and (mw.ustring.byte(entity:getLabel(language), 1, 1) > 127 and mw.ustring.byte(entity:getLabel(language), 3, 3) > 127) then riderNames_transl[i] = entity.labels[language].value riderNames_notransl[i] = else riderNames_notransl[i] = entity.labels['en'].value or entity.labels['fr'].value or entity.labels['de'].value riderNames_transl[i] = end end if wiki ~= 'mk' and wiki ~= 'ru' then if entity:getLabel(language) ~= nil then riderNames_transl[i] = entity.labels[language].value riderNames_notransl[i] = else riderNames_notransl[i] = entity.labels['en'].value or entity.labels['fr'].value or entity.labels['de'].value riderNames_transl[i] = end end end)

    if sort

    true then riderNames_transl[i] = name(i, wiki, 'transl', riderNames_transl[i], givenname[i], familyname[i]) riderNames_notransl[i] = name(i, wiki, 'notransl', riderNames_notransl[i], givenname[i], familyname[i]) else index[i] = i end

    if pcall(function local date = squadSeason.claims["P527"][i].qualifiers["P580"][1].datavalue.value.time or riderStart[i] = func_date(trans(date,'01', '01'), 'small') end ) then else riderStart[i] = end

    if pcall(function local date = squadSeason.claims["P527"][i].qualifiers["P582"][1].datavalue.value.time riderEnd[i] = func_date(trans(date,'12', '31'), 'small') end ) then else riderEnd[i] = end

    if pcall(function riderPosition[i] = 'Q' .. squadSeason.claims["P527"][i].qualifiers["P39"][1].datavalue.value['numeric-id'] local entity = mw.wikibase.getEntity(riderPosition[i]) local label = string.gsub(entity:getLabel, "%b", "") or entity:getLabel('en') --if label

    null then label = entity:getLabel('en') end riderPosition[i] = ', ' .. label end ) then else riderPosition[i] = end

    riderReason[i] = pcall(function riderReason[i] = 'Q'.. squadSeason.claims["P527"][i].qualifiers["P1643"][1].datavalue.value['numeric-id'] end) if riderReason[i]

    then pcall(function riderReason[i] = 'Q'.. squadSeason.claims["P527"][i].qualifiers["P1642"][1].datavalue.value['numeric-id'] end) end if riderReason[i]

    then pcall(function riderReason[i] = 'Q'.. squadSeason.claims["P527"][i].qualifiers["P1534"][1].datavalue.value['numeric-id'] end) end if riderReason[i] ~= then local entity = mw.wikibase.getEntity(riderReason[i]) local label = string.gsub(entity:getLabel, "%b", "") or entity:getLabel('en') --if label

    null then label = entity:getLabel('en') end riderRef[i] = references(squadSeason, 'P527', i) riderReason[i] = ', ' .. label end

    local a, b local timeofrace local changedTime = '+0000-00-00' local changedTeam = local entity, label local stagiaire time[i]= riderTeam[i] = if pcall(function timeofrace = squadSeason.claims["P527"][i].qualifiers["P580"][1].datavalue.value.time end) then else timeofrace = startOfSeason end if team ~= nil then a = true b = team -- if team known, don´t search for team else a, b = timeStartEnd(riderIds[i], 'P54', 'numeric-id', timeofrace) team = b end if a

    true and b ~= nil then pcall(function local v for _, v in pairs(rider.claims["P54"]) do -- look into all P54 teams pcall(function -- get trainee data from rider item if v.mainsnak.datavalue.value['numeric-id']

    b then -- print riderStart[i], riderEnd[i], riderPosition[i], riderReason[i] if riderReason[i]

    then pcall(function riderReason[i] = 'Q'.. v.qualifiers["P1643"][1].datavalue.value['numeric-id'] end) end if riderReason[i]

    then pcall(function riderReason[i] = 'Q'.. v.qualifiers["P1642"][1].datavalue.value['numeric-id'] end) end if riderReason[i]

    then pcall(function riderReason[i] = 'Q'.. v.qualifiers["P1534"][1].datavalue.value['numeric-id'] end) end if string.sub(riderReason[i],1,1)

    'Q' then -- only for these pcall-functions, not for those at line 970 local entity = mw.wikibase.getEntity(riderReason[i]) local label = string.gsub(entity:getLabel, "%b", "") or entity:getLabel('en') if pcall(function riderRef[i] = references(squadSeason, 'P527', i) end) then else riderRef[i]= end -- riderRef[i] = references(squadSeason, 'P527', i) riderReason[i] = ', ' .. label end

    local date1 = v.qualifiers["P580"][1].datavalue.value.time date1 = trans(date1,'01','01') local _, _, y1, m1, d1 = string.find(date1, "(%d+)-(%d+)-(%d+)") local date2 if pcall(function date2 = v.qualifiers["P582"][1].datavalue.value.time end) then else date2='+'..y1..'-12-31T00:00:00Z' end date2 = trans(date2,'12','31') local _, _, y2, m2, d2 = string.find(date2, "(%d+)-(%d+)-(%d+)") local _, _, y3, m3, d3 = string.find(startOfSeason, "(%d+)-(%d+)-(%d+)")

    if (y1

    y3 or y2

    y3) and ((y1

    y3 and (m1 ~= '01' or d1 ~= '01')) or (y2

    y3 and (m2 ~= '12' or d2 ~= '31'))) then -- riders who start after 1 January or end earlier then 31 December in the season riderStart[i] = func_date(date1, 'small') if pcall(function local date = v.qualifiers["P582"][1].datavalue.value.time riderEnd[i] = func_date(date2, 'small') end ) then else riderEnd[i] = func_date('+'..y1..'-12-31T00:00:00Z', 'small') end

    if riderPosition[i]

    then -- find the 'position' (P39) of a rider pcall(function riderPosition[i] ='Q' ..v.qualifiers["P39"][1].datavalue.value['numeric-id'] local entity = mw.wikibase.getEntity(riderPosition[i]) local label = string.gsub(entity:getLabel, "%b", "") or entity:getLabel('en') riderPosition[i] = ', ' .. label end) end end end end)

    stagiaire = pcall(function stagiaire = v.qualifiers["P39"][1].datavalue.value['numeric-id'] end) if v.mainsnak.datavalue.value['numeric-id'] ~= b and stagiaire

    then -- find previous team and end time for the rider at that team local date1 = v.qualifiers["P580"][1].datavalue.value.time date1 = trans(date1,'01','01') local _, _, y1, m1, d1 = string.find(date1, "(%d+)-(%d+)-(%d+)") local date2 if pcall(function date2 = v.qualifiers["P582"][1].datavalue.value.time end) then else date2='+'..y1..'-12-31T00:00:00Z' end date2 = trans(date2,'12','31') local _, _, y2, m2, d2 = string.find(date2, "(%d+)-(%d+)-(%d+)") local _, _, y3, m3, d3 = string.find(startOfSeason, "(%d+)-(%d+)-(%d+)") if y1 <= y3 then -- start time < season time pcall(function local timeP582 = v.qualifiers["P582"][1].datavalue.value.time timeP582 = trans(timeP582,'12', '31') if timeP582 >= changedTime then -- find maximum end time -- Case Pierre-Roger Latour: Chambéry CF (2012 - 2014), time season at 2013 -- Task: changedTime should be after start time, but before startOfSeason local _, _, y4, m4, d4 = string.find(timeP582, "(%d+)-(%d+)-(%d+)") if y4 > y3 then changedTime = '+'..y3..'-12-31T00:00:00Z' else changedTime = timeP582 end changedTeam = v.mainsnak.datavalue.value['numeric-id'] end -- end if end) -- end function -- print riderTeam[i], time[i] if changedTime ~= '+0000-00-00' then pcall(function riderTeam[i] = WPlink('Q'..changedTeam, 'team', changedTime) end) local _, _, y1, _, _ = string.find(changedTime, "(%d+)-(%d+)-(%d+)") time[i] = ' ('..y1..')' end end end -- end if end -- end for end) -- end function end -- end if

    local a, b = timeStartEnd(riderIds[i], 'P27', 'numeric-id', startOfSeason) if a then flags[i] = flag('Q' .. b, startOfSeason) if available_list

    true and type(translations.list)

    'function' then pays[i] = translations.list('Q'..b) if pays[i]

    then local country = mw.wikibase.getEntityObject('Q'..b) pays[i] = country:getLabel or country:getLabel('en') .. ' (en)' end end else flags[i] = pays[i] = end

    i = i + 1 end end)

    -- sorting names after surname if sort

    true then if language~='ja' then table.sort(riderNames_transl, function(a,b) return a then v1, v2 = mw.ustring.find(name1, ":") number = mw.ustring.sub(name1, v2+1) name2, _ = mw.ustring.gsub(name1, ":%d+", "") index[i] = tonumber(number) i = i + 1 end end -- sorting riders without a translation for ii,name1 in ipairs(riderNames_notransl) do if name1 ~= then v1, v2 = mw.ustring.find(name1, ":") number = mw.ustring.sub(name1, v2+1) name2, _ = mw.ustring.gsub(name1, ":%d+", "") index[i] = tonumber(number) i = i + 1 end end end

    local tableBody= local tableHeader = '

    ' if WDlink_on

    false then tableHeader = tableHeader..'

    ' end tableHeader = tableHeader..getSquadTableColumn(7) .. '
    ' local tableEndText = local tableSize = table.getn(riderNames) local iii = 1 i = 1 while index[i] do tableBody = tableBody.. '' if available_list

    false then tableBody=tableBody.. flags[index[i]]..' '..riderNames[index[i]] else tableBody = tableBody.. riderNames[index[i]] end if WDlink_on

    true then tableBody = tableBody.. ' '.. wdLink(riderIds[index[i]]) end if riderStart[index[i]]~= or riderEnd[index[i]]~= then tableBody=tableBody..'

    ('..riderStart[index[i]]..'–'..riderEnd[index[i]].. riderPosition[index[i]] if riderReason[index[i]] ~= then note = ', '..getSquadTableColumn(4)..'' if wiki

    "ar" then note = '، '..getSquadTableColumn(4)..'' end tableBody = tableBody .. note end tableBody=tableBody .. ')

    ' elseif riderReason[index[i]]~= then tableBody=tableBody.. ' ('..getSquadTableColumn(4)..''.. ')' end tableBody = tableBody.. '' if wiki

    'lv' then local _, _, y1, m1, d1 = string.find(startOfSeason,"(%d+)-(%d+)-0*(%d+)") local _, _, y2, m2, d2 = string.find(riderBirthdays[index[i]],"(%d+)-(%d+)-0*(%d+)") tableBody = tableBody.. frame:expandTemplate.. '' else tableBody = tableBody.. func_date (riderBirthdays[index[i]], 'long') if available_list

    false then tableBody=tableBody..'' else tableBody=tableBody..''.. flags[index[i]].. ' '..pays[i].. '' end end if wiki

    'he' then local isRtl = (mw.ustring.find(riderTeam[index[i]], '\|.*[א-ת]') or (not mw.ustring.find(riderTeam[index[i]], '\|') and mw.ustring.find(riderTeam[index[i]], '[א-ת]'))) if isRtl then tableBody = tableBody.. '' else labelMissing = true -- FIXME: labelMissing is not functional in most languages. once we have infra support for it, move it there tableBody = tableBody.. '' end else tableBody = tableBody.. '' end if riderTeam[index[i]] ~= nil then tableBody = tableBody.. riderTeam[index[i]].. time[index[i]] end tableBody = tableBody..''

    if riderReason[index[i]] ~= then if iii

    1 then tableEndText = tableEndText.. getSquadTableColumn(5)..': '.. riderNames[index[i]].. riderReason[index[i]] else tableEndText = tableEndText.. '

    '.. getSquadTableColumn(5)..': '.. riderNames[index[i]].. riderReason[index[i]] end iii = iii + 1 if riderRef[index[i]] ~= then tableEndText = tableEndText.. frame:extensionTag end tableEndText = tableEndText.. '
    ' end i = i + 1 end

    --if tableEndText ~= then tableEndText = getSquadTableColumn(5)..':

    '.. tableEndText .. '' end

    local borderStyle = 'border:1px solid rgb(200,200,200); padding: 4px' if wiki

    'lv' then borderStyle = 'border:0' end local tableStart = '

    ' local tableEnd = '
    '

    if labelMissing then tableEnd = tableEnd .. getMissingLabelTrackingCategory end

    return tableStart .. tableHeader .. tableBody .. tableFoot .. tableEnd .. tableEndTextend

    --

    I) List of winners

    function p.listofwinnersChamp(frame) local countryflag = false return listofwinners_main(frame, countryflag)end

    function p.listofwinners(frame) local countryflag = true return listofwinners_main(frame, countryflag)end

    function listofwinners_main(frame, countryflag) local rows = frame.args[1] = string.gsub(frame.args[1], "%c", "") local raceID = frame.args[1] local WDlink_on = (wiki

    "mk") or (wiki

    "ja") or (wiki

    "ru") -- WDlink_on is used to decide if a Wikidata logo will be shown local WPcontent =

    local localFrame if string.match(frame:getParent:getTitle, '%P+')

    mw.site.namespaces.Template.name then localFrame = frame:getParent else localFrame = frame end if localFrame.args[1] then localFrame.args[1] = string.gsub(localFrame.args[1], "%c", "") end--[=[ It is possible to give the table listofwinners in the article commands. It could look like this: {{Cycling race/listofwinners|Q18574623 | above row 1: '''[[aaa bbb ccc]] xxx}}"above row x" inserts a new row above row x into the table. Content is what is behind the ":".]=] if localFrame.args[2] then for num, var in pairs(localFrame.args) do if num > 1 and mw.ustring.find(mw.ustring.lower(localFrame.args[num]), 'row') then local _, _, key1, val = mw.ustring.find(localFrame.args[num], "([^:]+)%s*:%s*(%C+)") local _, _, key01, key11, key12 = mw.ustring.find(key1, "(%a+)%s*(%a+)%s*(%d+)") key12 = tonumber(key12) key11 = mw.ustring.lower(key01..key11) if key11

    'aboverow' then WPcontent[key12] = val end end end end

    local parts = mw.wikibase.getAllStatements(raceID, 'P527') -- P527 is 'has part' for _, part in ipairs(parts) do if part.rank ~= 'deprecated' and part.mainsnak.snaktype

    'value' then local partID = part.mainsnak.datavalue.value.id local timeOfRace local p = mw.wikibase.getBestStatements(partID, 'P585') -- P585 is 'point in time' if p[1] and p[1].mainsnak.snaktype

    'value' then timeOfRace = p[1].mainsnak.datavalue.value.time else p = mw.wikibase.getBestStatements(partID, 'P580') -- P580 is 'start time' if p[1] and p[1].mainsnak.snaktype

    'value' then timeOfRace = p[1].mainsnak.datavalue.value.time end end local year = timeOfRace and string.sub(timeOfRace, 2, 5) or '?' local sitelink = mw.wikibase.getSitelink(partID) if sitelink then sitelink = '' .. year .. '' else sitelink = year end if WDlink_on then sitelink = sitelink .. ' ' .. wdLink(partID) end local winners = winner(partID, winners, timeOfRace, countryflag, WDlink_on) rows[#rows+1] = end end table.sort(rows, function(a, b) return a[1] < b[1] end) -- Sort by year local table_first = "

    " if WDlink_on

    false then table_proto = table_proto .. '

    ' end table_proto = table_proto .. headoftableIV(1) .. "
    ".. headoftableIV(2) .. "" .. headoftableIV(3) .. "" .. headoftableIV(4) .. "
    "

    for i, row in ipairs(rows) do if WPcontent[i] then table_center = table_center .. "" .. WPcontent[i] .. "" end table_center = table_center .. row[2] end return table_first .. table_proto .. table_center .. table_lastend

    --

    J) List of stagesfunction p.listofstages(frame) -- WDlink_on is used to decide if a Wikidata logo will be shown local WDlink_on = wiki

    "mk" or wiki

    "ja" local WPcontent = local raceID = frame.args[1]

    local localFrame if string.match(frame:getParent:getTitle, '%P+')

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

    if not WPcontent[key12] then WPcontent[key12] = end if key11

    WProw and key21

    WPcourse then WPcontent[key12][key22] = val end if key11

    WPnew_row and key2

    WPdate then WPcontent[key12]['date'] = val WPcontent[key12]['text'] = WPcontent[key12]['text'] or WPcontent[key12]['icon (new row)'] = WPcontent[key12]['icon (new row)'] or end if key11

    WPnew_row and key2

    WPtext then WPcontent[key12]['text'] = val WPcontent[key12]['date'] = WPcontent[key12]['date'] or WPcontent[key12]['icon (new row)'] = WPcontent[key12]['icon (new row)'] or end if key11

    WPnew_row and key2

    WPicon then val = mw.ustring.gsub(val, "|", "|border|right|20px|", 1) WPcontent[key12]['icon (new row)'] = val WPcontent[key12]['date'] = WPcontent[key12]['date'] or WPcontent[key12]['text'] = WPcontent[key12]['text'] or end if key11

    WProw and key21

    WPwinner and key22

    'a' then WPcontent[key12]['stage winner'] = val end if key11

    WProw and key21

    WPwinner and key22

    'b' then WPcontent[key12]['general winner'] = val end if key11

    WProw and key21

    WPicon then val = mw.ustring.gsub(val, "|", "|border|right|20px|", 1) WPcontent[key12]['icon'] = val end if key11

    WProw and key21

    WPdistance then WPcontent[key12]['distance'] = val end end end end local rows = local stages = mw.wikibase.getBestStatements(raceID, 'P527') -- P527 is 'has part' for _, v in pairs(stages) do if v.mainsnak.snaktype

    'value' then local stageID = v.mainsnak.datavalue.value.id local p = mw.wikibase.getBestStatements(stageID, 'P1545') -- P1545 is 'series ordinal' local sOrdinal = p[1] and p[1].mainsnak.snaktype

    'value' and p[1].mainsnak.datavalue.value or local _, _, sNumber, sLetter = string.find(sOrdinal, '(%d+)(.*)') if not sNumber then sNumber = end if not sLetter then sLetter = end local WDLink = WDlink_on and wdLink(stageID) or local sitelink = mw.wikibase.getSitelink(stageID)

    p = mw.wikibase.getBestStatements(stageID, 'P585') -- P585 is 'point in time' local timeOfRace = p[1] and p[1].mainsnak.snaktype

    'value' and p[1].mainsnak.datavalue.value.time or local _, _, year, month, day = string.find(timeOfRace, "(%d+)-0?(%d+)-0?(%d+)")

    p = mw.wikibase.getBestStatements(stageID, 'P1427') -- P1427 is 'start point' local sPointID = p[1] and p[1].mainsnak.snaktype

    'value' and p[1].mainsnak.datavalue.value.id local sPoint = sPointID and getPlaceLink(sPointID) or p = mw.wikibase.getBestStatements(stageID, 'P1444') -- P1444 is 'destination point' local dPointID = p[1] and p[1].mainsnak.snaktype

    'value' and p[1].mainsnak.datavalue.value.id local dPoint = dPointID and getPlaceLink(dPointID) or local sDistance = getDistance(stageID, false) or local winners = winner(stageID, winners, timeOfRace, true, WDlink_on)

    -- find the type of stage local sType = p = mw.wikibase.getBestStatements(stageID, 'P31') -- P31 is 'instance of' for _,t in pairs(p) do if t.mainsnak.snaktype

    'value' then local iOf = t.mainsnak.datavalue.value['numeric-id'] if iOf

    20646667 then sType = typeofstage('plain stage') break end if iOf

    20646670 then sType = typeofstage('hilly stage') break end if iOf

    20680270 then sType = typeofstage('intermediate stage') break end if iOf

    20646668 then sType = typeofstage('mountain stage') break end if iOf

    485321 then sType = typeofstage('time trial stage', 485321) break end -- prologue if iOf

    2266066 then sType = typeofstage('time trial stage', 2266066) break end -- individual time trial if iOf

    2348250 then sType = typeofstage('time trial stage', 2348250) break end -- team time trial if iOf

    20679712 then sType = typeofstage('uphill time trial stage') break end end end

    local label, section_title if sOrdinal

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

    if day

    "1" and wiki

    "fr" then day = "1er" end if wiki

    "lv" then sLink = sOrdinal end local month = func_month(tonumber(month)) local sDate if wiki

    "br" then sDate = day .. " a viz ".. month elseif wiki

    "ca" or wiki

    "es" then sDate = day .. " de ".. month elseif wiki

    "eo" then sDate = day .. "-a de " .. month elseif wiki

    "eu" then sDate = month .. "k " .. day elseif wiki

    "hu" then sDate = month .. " " .. day .. "." elseif wiki

    "ja" then sDate = month .. day .. "日" elseif wiki

    "de" or wiki

    "da" or wiki

    "fi" or wiki

    "fo" or wiki

    "no" or wiki

    "lv" then sDate = day .. ". " .. month elseif wiki

    "cs" then sDate = day .. ". xg " .. month elseif wiki

    "en" then sDate = month .. " " .. day else sDate = day .. ' ' .. month end

    rows[#rows + 1] = end end

    table.sort(rows, function(a, b) if a[1] ~= b[1] then return a[1] < b[1] end return a[2] < b[2] end)

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

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

    local t = "" .. sLink .. "

     ".. WDLink .. "" .. sDate .. "" .. sPoint if dPoint ~= then t = t .. " – " .. dPoint end t = t .. "" .. sType .. "" .. sDistance .. ""

    if WPc and WPc['stage winner'] then t = t .. "" .. WPc['stage winner'] .. "" else t = t .. "" .. sSWin .. "" end if WPc and WPc['general winner'] then t = t .. "" .. WPc['general winner'] .. "" else t = t .. "" .. sGWin .. "" end if WPc and (WPc['date'] or WPc['text'] or WPc['icon (new row)']) then t = t .. "" if WPc['icon (new row)']

    then t = t .. "" .. WPc['date'] .. "" .. WPc['text'] else t = t .. "" .. WPc['date'] .. "" .. WPc['text'] end t = t .. "" .. WPc['icon (new row)'] .. "" end rows[num] = t end

    return "

    " .. (not WDlink_on and ("")) .. headoftable(1) .. "" .. headoftable(2) .. "".. headoftable(3) .. "type".. headoftable(4) .. "".. headoftable(5) .. "" .. headoftable(6) .. "
    "end

    --Give access to a local variable. Used by other modules. function p.getLocal(name) if name

    'getTeamLinkCat' then return getTeamLinkCat end if name

    'getStatementForTime' then return getStatementForTime endend

    return p

    Notes and References

    1. test