local p = local wiki, onwikidatawiki = string.match(mw.site.server, "%a+")if wiki
--
-- 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 "--
--
-- 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)
true and type(translations.lang_priority)
local textalign = "left"local floattable = "left"local floatinfobox = "right"if wiki
"fa" or wiki
"he" then textalign = "right" floattable = "right" floatinfobox = "left"end
--
'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
function fooB (mode, entity_var, property, var1, var2, ref, var3) --Obsolete local snak if mode
function fooC (mode, entity_var, property, var1, quali, var2) --Obsolete local snak if mode
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
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
nilendlocal function qualifiers(statement, PID) return nextQualifier, statement.qualifiers and statement.qualifiers[PID] or, 0end
--
--
--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
9 then -- precision is years start = string.sub(start, 1, 5) -- Cut of everything after year elseif startPrecision
'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
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 = 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
'long' then starttime = lang:formatDate("j F Y", sTime) else starttime = lang:formatDate("j M Y", sTime) end elseif m ~= m2 then if mode
if 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
"es" or 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
"da" 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
"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
"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
"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
"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
"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
"ca" or wiki
"ast" then endtime = lang:formatDate("j", eTime) .." de ".. lang:formatDate("F", eTime) .." de ".. lang:formatDate("Y", eTime) elseif wiki
"de" or wiki
"fi" or wiki
"no" then endtime = lang:formatDate("j. F Y", eTime) elseif wiki
"eo" then endtime = lang:formatDate("j", eTime) .."-a de ".. lang:formatDate("F Y", eTime) elseif wiki
"fi" then endtime = lang:formatDate('j F"ta" Y', 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
"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
--
-- 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
'00' and d
'00' and d
'01' and d
true and property
'table' then test=true end end) if test
lang_module then zaehler = number break end end -- for number in pairs if lang_WD
"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
'00' and d
'00' and d
'01' and d
true and property
'table' then test=true end end) if test
lang_module then zaehler = number break end end -- for number in pairs if lang_WD
"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
'00' and d
'00' and d
'01' and d
true and property
'table' then test=true end end) if test
lang_module then zaehler = number break end end -- for number in pairs if lang_WD
"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
--
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
local function getRiderLink(riderID) local sitelink = wikibase.getSitelink(riderID) if sitelink then if wiki
'value' then local c = p27[1].mainsnak.datavalue.value['numeric-id'] if c
184 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
-- No label in the local language. Try other languages, but don't link. if wiki
--Get the name of a country local function getCountryName(countryID) local name = if available_list then name = translations.list(countryID) end if name
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
'Q20738667' then countryID = firstValue(teamID, 'P17', 'id') -- P17 is country end if countryID and (catID
'Q20738667') then -- It is a national cycling team name = getCountryName(countryID) if catID
'fr' then s = ' espoirs' elseif wiki
'ar' then s = ' تحت 23' elseif wiki
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
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 -- 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
'ar') then refDate = '، ' .. refDate else refDate = ', ' .. refDate end end if ref.P813 and ref.P813[1] and ref.P813[1].snaktype
"de" then refRetrieved = ", (abgerufen am " .. 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)
"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 wikifunction 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
'en' then black_list= end if wiki
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' and caption.datavalue.value.language
--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
local function getPlaceLink(placeID) local link local sitelink = wikibase.getSitelink(placeID) if sitelink then 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
--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 = '
◀ ' .. year .. '' else previousText = '◀ ' .. year end end if nextID then local year = getYear(nextID) local link = wikibase.getSitelink(nextID) if link then nextText = '' .. year .. ' ▶' else nextText = year .. ' ▶' end end local direction = contentLanguage:getDir return "--
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]
"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
true and (b
184 or b
232) then link = "" .. Label .. "" end end elseif Label ~= then if 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)
then link = entity:getLabel('fr') or entity:getLabel('en') or entity:getLabel('de') or if wiki
nil
if arg[1]
true then local a2, b2 = timeStartEnd('Q'..b1, 'P1448', 'text', arg[2]) if a2
true then official_name = b end
if available_lang_priority
true then a, b = timeStartEnd(Qnumber, 'P1448', 'text', arg[2]) --officialName(entity) if a
true then official_name = b end end end
if Sitelink ~= nil then if official_name
"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
nil or official_name
"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 then if official_name ~= then link = official_name else link = entity:getLabel end if link
-- mw.log('Sitelink=', Sitelink, 'Sitelink2=', Sitelink2, 'official_name=', official_name) end -- end arg[1] if arg[1]
"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
'race' then -- for infobox "Competitions" local a, b = pcall(fooA, 'numeric-id', entity, 'P31', 1) if a
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
else if Sitelink ~= nil then link = "".. Sitelink.. "" else link = Label end end end if arg[1]
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]
true then entity = mw.wikibase.getEntity('Q'..b1) local a2, b2 = timeStartEnd_entity(entity, 'P1448', 'text', arg[2]) if a2
Sitelink2 = entity:getSitelink -- link to WParticle end if a
if available_lang_priority
true then a, b = timeStartEnd_entity(entity, 'P1448', 'text', arg[2]) --officialName(entity) if a
true then official_name = b end end end
if Sitelink ~= nil then if official_name
"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
nil then link = "".. mw.text.trim(mw.ustring.gsub(Sitelink2,"%b","").. ' ').. "" else if wiki
if Sitelink
nil then if official_name ~= then link = official_name else link = entity:getLabel end if link
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
"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, 'team', timeofrace) else return WPlink(q_number, 'team', timeofrace) end end end if command
"t" then return WPlink(q_number, 'team', timeofrace) end if command
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
20738667 then -- Q20738667 = national cycling team U23 if wiki
'mk' then s = ' под 23 години' elseif wiki
'es' then s = ' sub-23' elseif wiki
true and (b
23726798) then s = end -- Q1194951 = national sports team, Q23726798 = national cycling team
a, b = timeStartEnd(riderID, "P27", 'numeric-id', startOfSeason) if a
nil then team = nationality.. s else team = "".. nationality.. s.. '' end end
a, b = timeStartEnd(riderID, "P17", 'numeric-id', startOfSeason) if a
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
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 ref2 = b ref2b= entity.claims[property][var1].references[1].snaks['P1476'][1].datavalue.value.language or if ref2b
true then local _, _, year, m, d = string.find(b,"(%d+)-(%d+)-(%d+)") if d ~= '00' and m ~= '00' then if wiki
"ar" then ref3 = '، ' .. lang:formatDate("j F Y", 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
"de" then ref3 = ', ' .. lang:formatDate("F Y", year..'-'..m..'-'..d) elseif wiki
"en" then ref3 =', ' .. lang:formatDate("Y F", year..'-'..m..'-'..d)..'.' elseif wiki
true then if wiki
"ar" then ref4 = " تاريخ الوصول " .. lang:formatDate("j F Y", 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
--
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
"" or not s.item then return "" end if s.error_message
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 .. ' |
--
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
'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[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
--
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' 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.P828[1].datavalue.value.id -- P828 is 'has cause' wCriterion = q.P1013 and q.P1013[1].snaktype
'value' and iOf.mainsnak.datavalue.value['numeric-id']
then winners[wOf] = riderLink else winners[wOf] = winners[wOf] .. '
' .. riderLink end end end end end endend
local function getKm(wiki) local km if wiki
"mk" 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
'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
'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
"da" then kmh = 'km/t' elseif wiki
"nl" then kmh = 'km/u' elseif wiki
"mk" 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
'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
'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
"ca" then if b
2 then str = b.."n" elseif b
4 then str = b.."t" else str = b.."è" end elseif wiki
1 then str="1st" elseif b
3 then str="3rd" else str=b.."th" end elseif wiki
'm' or gender
'f' then str = b..".ª" else str = b.."." end elseif wiki
1 then if gender
'f' or gender
"nl" then str=b.."e" elseif wiki
"eo" then str=b.."-a" elseif wiki
'm' or 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
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 and m
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
--
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
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
'hilly stage' then return "" end if x
'mountain stage' then return "" end if x
'rest day' then return "" end if x
2348250 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
-- fr: étape, étape if wiki
"lb" then if b
"1" then word1 = "1re "..word else word1 = a.."e "..word end -- table text = étape, étape, if a
"1" then word1 = "1re "..b.." "..word else word1 = a.."e "..b.." "..word end -- table text = étape, étape, if a
"de" or wiki
"fo" or wiki
"ca" 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
--
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
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
--
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 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])
if frame.args[5] ~= nil then if tonumber(frame.args[5])
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])
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
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
"ar" and calendarID
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
outputtable[1]=dateOfRace outputtable[2]='
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
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
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
'0' then stagenumber= victories_translate(wiki,9) else if stagenumber
local comma = ", " 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
"lb" or wiki
"es" or wiki
"de" or wiki
"fo" or wiki
"ru" or wiki
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
0 then local p2561 = wikibase.getBestStatements(instanceOf, 'P2561') --name for championship if p2561[1] and p2561[1].mainsnak.snaktype
nil then --if label
'value' then label = "blibli" end --p1448[1].mainsnak.datavalue.value.text end --end if label
nil then --only if no link to the race direct Sitelink=wikibase.getSitelink(instanceOf) end if Sitelink
'champ' then --only for champ local p361=wikibase.getBestStatements(instanceOf, 'P361') if p361[1] and p361[1].mainsnak.snaktype
'2' then if functionName~=nil then --calendar=nil if wiki
'stage' then --how to write "stage, " is concentrated in one function local commatable=commastage(stageID, label) prefix= commatable[1] postfix=commatable[2] end
if Sitelink
nil then return prefix..wikibase.label(entityID)..postfix else return prefix..label..postfix end else if label
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
displayed_class[i] then display=true break end end end --is it a championship? for i=1,#class_champ do if entityID
nil then for i=1,#class_2x do -- #class = number of elements in class if entityID
nil then for i=1,#class_without2x do if entityID
nil then entity_type = 'nada' end--to allow display of race without class... end if display
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
nil or inputtable[1]
nil then --bypass if stage inputtable=fn_getclassinfo(instanceOf,displayed_class) if inputtable[1]
'nada' then --no display="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
true then if classID
'Q23005603' then --1WWT 2WWT clear displayedCircuitID = 'Q21075974' elseif 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
local function fn_rider(entityID,dateOfRace,displayteam,only_winner) local winRows = local win, winners =, if 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
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 .. '
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
local p527 = wikibase.getBestStatements(calendarID, s.property) -- P27 is country of citizenship if p527[1] and p527[1].mainsnak.snaktype
----- 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 = '
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
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
for key, v in pairs(UCI) do if calendarID
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
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
nil then tBody='
--
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
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 = '
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
--
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
a1, b1 = pcall(fooA, 'numeric-id', entity, 'P31', 1) -- If stage is a "stage" or a timetrial stage if a1
if t_g.is_a
'Q2348250' or t_g.is_a
a1, b1 = pcall(fooA, 'value', entity, 'P18', 1) -- picture, legende if a1
"" 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
-- Function that give the starting place of a race a1, b1, c1 = pcall(fooA, 'numeric-id', entity, 'P1427', 1) if a1
"" then i = 1 while a1
'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
"" then i = 1 while a1
'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
"" then i = 1 while a1
'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
"" and t_g.nr_participants_end
true and c1
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"]
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
a1, b1 = pcall(fooA, 'value', entity, 'P242', 1) -- locator map image if a1
"" then t_g.map = b1 end a1, b1 = pcall(fooA, 'value', entity, 'P2713', 1) -- sectional view if a1
"" then t_g.sectional_view = b1 end
a1, b1 = pcall(fooA, 'numeric-id', entity, 'P155', 1) if a1
"" then t_g.previous = "Q"..b1 a2, b2 = pcall(fooA, 'value', mw.wikibase.getEntity(t_g.previous), 'P1545', 1) if a2
true and t_g.next
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 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
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
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
27104271 and t_s.classement_annex.equipe_points[1]
20882922 and t_s.classement_annex.equipe[1]
a1, b1 = pcall(fooA, 'numeric-id', mw.wikibase.getEntityObject('Q'..id), 'P21', 1) -- detect gender if a1
6581097 then t_s[t_P642[qual][1]][t_P642[qual][2]][3] = 'm' -- men elseif b1
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
2 or rank
or t_s.results[order[rank]][10]
and t_s.results[order[rank]][6]
and t_s.results[order[rank]][6]
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
6581097 then t_s.results[order[rank]][3] = 'm' -- men elseif b1
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
2 or rank
or t_s.classement_gen[order[rank]][10]
and t_s.classement_gen[order[rank]][6]
and t_s.classement_gen[order[rank]][6]
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
6581097 then t_s.classement_gen[order[rank]][3] = 'm' -- men elseif b1
local a, b local span1, span2 = "
◀ ", " ▶"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
"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 = 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
"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 = end
if t_g.course
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
true then t_g.course = t_g.course .. ', '.. WPlink('Q'..b2,'pure') if wiki
local entity_race = mw.wikibase.getEntity('Q'..b2) a3, b3 = pcall(fooA, 'numeric-id', entity_race, 'P31', 1) if a3
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
'Q20646670' then return " " end if x
'Q20646668' then return " " end if x
'Q2348250' 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
'no' or wiki
tab = "
" tab = tab .. "
| " .. t_g.icon .. " |
if t_g.picture ~= "" then tab = tab .. "
for _, value_order in ipairs(t_s.order) do if t_s[value_order].show
".. 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) 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.. " |
"..t_s[value_order][value][9] .. " | |
if t_g.map ~= "" then tab = tab .. "
prevNextLine = "
local s = "d:Wikidata:WikiProject Cycling/Documentation/stageinfobox" tab = tab .. "
--
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
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
return '
' .. text .. getHeader(oldCatID, count) .. '
|
--
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
'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)
'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+')
if localFrame.args.country ~= nil then -- switch country column on or off in the article 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
'true' then -- parameter newline in WP article is 'true' tableStyle = "border:1px solid rgb(200,200,200)" tableNewline = '
' end if localFrame.args.newline
'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 .. ' |
--
function p.infobox(frame) localframe = frame -- If true, winners will have Wikidata logos with link to Wikidata local WDlink_on = (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+')
local name, dateOfRace, class local icon = (firstValue(entityID, 'P641', 'numeric-id')
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
1) and "1re " or (nr .. "e ") elseif wiki
"ru" then nr = nr .. "-й " 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
"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
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
"http://www.wikidata.org/entity/Q4916" then cost = cost .. ' €' elseif unit
local tab if wiki
" .. "
| " .. icon .. " |
if others[1].content then -- picture tab = tab .. "
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 .. " " end end if winRows ~= then tab = tab .. "" .. v.name .. " " .. v.content .. "
if others[3].content then -- map tab = tab .. "
--
local function trans(date, month, day) if date ~= then local _, _, y, m, d = string.find(date, "(%d+)-(%d+)-(%d+)") if m
'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
3 and names~= then _, _, a, b, c = mw.ustring.find(names, "(%S+)%s+(%S+)%s+(%S+)") if wiki
v then names = b..' '..c..' '..a..":"..i done = true break end end end if wiki
v then names = b..' '..c..' '..a..":"..i done = true break end end end if wiki
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
'notransl' then --or (wiki~='lv' and wiki~='mk' and wiki~='ru' and wiki~='ja') then for _,v in ipairs(name_parts) do if b
2 then names = b..' '..c..' '..a..":"..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
v then names = c..' '..d..' '..a..' '..b..":"..i done = true break end end for _,v in ipairs(name_parts_mk) do if b
'lv' then for _,v in ipairs(name_parts_lv) do if c
v then names = b..' '..c..' '..d..' '..a..":"..i done = true break end end end if wiki
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 = c..' '..d..' '..a..' '..b..":"..i done = true break end end for _,v in ipairs(name_parts) do if b
'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 = 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+')
"lv" 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
"ja" 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
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
'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
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
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["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
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
b then -- print riderStart[i], riderEnd[i], riderPosition[i], riderReason[i] if riderReason[i]
then pcall(function riderReason[i] = 'Q'.. v.qualifiers["P1642"][1].datavalue.value['numeric-id'] end) end if riderReason[i]
'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) and ((y1
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]
stagiaire = pcall(function stagiaire = v.qualifiers["P39"][1].datavalue.value['numeric-id'] end) if v.mainsnak.datavalue.value['numeric-id'] ~= b and stagiaire
local a, b = timeStartEnd(riderIds[i], 'P27', 'numeric-id', startOfSeason) if a then flags[i] = flag('Q' .. b, startOfSeason) if available_list
'function' then pays[i] = translations.list('Q'..b) if pays[i]
i = i + 1 end end)
-- sorting names after surname if sort
local tableBody= local tableHeader = '
' if WDlink_on false then tableHeader = tableHeader..'' end tableHeader = tableHeader..getSquadTableColumn(7) .. ' |
---|
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 wikifalse then tableBody=tableBody..'' else tableBody=tableBody..'
if riderReason[index[i]] ~= then if iii
--if tableEndText ~= then tableEndText = getSquadTableColumn(5)..':
'.. tableEndText .. '' endlocal borderStyle = 'border:1px solid rgb(200,200,200); padding: 4px' if wiki
' local tableEnd = ' |
if labelMissing then tableEnd = tableEnd .. getMissingLabelTrackingCategory end
return tableStart .. tableHeader .. tableBody .. tableFoot .. tableEnd .. tableEndTextend
--
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
"ja") or (wiki
local localFrame if string.match(frame:getParent:getTitle, '%P+')
'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 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
" 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 .. "
--
"mk" or wiki
local localFrame if string.match(frame:getParent:getTitle, '%P+')
if not WPcontent[key12] then WPcontent[key12] = end if key11
WPcourse then WPcontent[key12][key22] = val end if key11
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
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
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
WPwinner and key22
WProw and key21
'b' then WPcontent[key12]['general winner'] = val end if key11
WPicon then val = mw.ustring.gsub(val, "|", "|border|right|20px|", 1) WPcontent[key12]['icon'] = val end if key11
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' 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
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 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
20646667 then sType = typeofstage('plain stage') break end if iOf
20680270 then sType = typeofstage('intermediate stage') break end if iOf
485321 then sType = typeofstage('time trial stage', 485321) break end -- prologue if iOf
2348250 then sType = typeofstage('time trial stage', 2348250) break end -- team time trial if iOf
local label, section_title if sOrdinal
if day
"fr" then day = "1er" end if wiki
"br" then sDate = day .. " a viz ".. month elseif wiki
"es" then sDate = day .. " de ".. month elseif wiki
"eu" then sDate = month .. "k " .. day elseif wiki
"ja" then sDate = month .. day .. "日" elseif wiki
"da" or wiki
"fo" or wiki
"lv" then sDate = day .. ". " .. 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 = "
if WPc and WPc['stage winner'] then t = t .. "
return "
" .. (not WDlink_on and ("")) .. headoftable(1) .. " | " .. headoftable(2) .. " | ".. headoftable(3) .. " | type | ".. headoftable(4) .. " | ".. headoftable(5) .. " | " .. headoftable(6) .. " |
---|
--Give access to a local variable. Used by other modules. function p.getLocal(name) if name
'getStatementForTime' then return getStatementForTime endend
return p