Bu modulun sənədləşdirmə səhifəsi Modul:Wikidata/football/doc səhifəsində yaradıla bilər
local p = {}
local function parseTimeString(t)
if not t then return nil end
local y, m, d = t:match("^([%+%-]?%d+)%-(%d%d)%-(%d%d)")
return y and m and d and tonumber(y) * 10000 + tonumber(m) * 100 + tonumber(d) or nil
end
local function getDateFromSnak(snak)
return parseTimeString(snak and snak.datavalue and snak.datavalue.value and snak.datavalue.value.time)
end
local function selectQualifiedImage(claims, prop, targetDate)
if not claims or not claims[prop] then return nil end
local bestImage = nil
local latestStart = nil
for _, claim in ipairs(claims[prop]) do
local image = claim.mainsnak and claim.mainsnak.datavalue and claim.mainsnak.datavalue.value
if image then
local startTime = claim.qualifiers and claim.qualifiers.P580 and claim.qualifiers.P580[1].datavalue and claim.qualifiers.P580[1].datavalue.value.time
local endTime = claim.qualifiers and claim.qualifiers.P582 and claim.qualifiers.P582[1].datavalue and claim.qualifiers.P582[1].datavalue.value.time
local s = parseTimeString(startTime)
local e = parseTimeString(endTime)
if (not s or targetDate >= s) and (not e or targetDate <= e) then
return image
end
if s and (not latestStart or s > latestStart) then
latestStart = s
bestImage = image
end
end
end
return bestImage
end
function p.formatTeamClaim(context, options, statement)
if not context then error('context is not specified') end
if not options then error('options is not specified') end
if not statement then error('statement is not specified') end
local args = {}
if not statement.qualifiers or not statement.qualifiers['P580'] or not statement.qualifiers['P580'][1] then
return ''
end
local startDate = getDateFromSnak(statement.qualifiers['P580'][1])
local endDate = statement.qualifiers['P582'] and getDateFromSnak(statement.qualifiers['P582'][1]) or nil
local refDate = endDate or startDate
local teamId = statement.mainsnak and statement.mainsnak.datavalue and statement.mainsnak.datavalue.value and statement.mainsnak.datavalue.value.id
if not teamId then return '' end
local teamLabel = context.formatSnak(options, statement.mainsnak)
if not teamLabel then return '' end
local teamEntity = mw.wikibase.getEntity(teamId)
local countryId, flagFile
local categoryText = ''
if teamEntity and teamEntity.claims then
if teamEntity.claims.P17 then
local countrySnak = teamEntity.claims.P17[1].mainsnak
countryId = countrySnak and countrySnak.datavalue and countrySnak.datavalue.value and countrySnak.datavalue.value.id
if countryId then
local countryEntity = mw.wikibase.getEntity(countryId)
if countryEntity and countryEntity.claims then
flagFile = selectQualifiedImage(countryEntity.claims, "P41", refDate)
end
end
end
if teamEntity.claims.P6112 then
for _, claim in ipairs(teamEntity.claims.P6112) do
local catId = claim.mainsnak and claim.mainsnak.datavalue and claim.mainsnak.datavalue.value and claim.mainsnak.datavalue.value.id
if catId then
local catTitle = mw.wikibase.getSitelink(catId, 'azwiki')
if catTitle and mw.ustring.match(catTitle, '^Kateqoriya:') then
categoryText = categoryText .. '[[' .. catTitle .. ']]\n'
end
end
end
end
end
if flagFile then
teamLabel = string.format('[[Fayl:%s|22x20px|border]] %s', flagFile, teamLabel)
end
args['komanda_'] = teamLabel
local params = {
['başlama_'] = 'P580',
['bitmə_'] = 'P582',
['matç sayı_'] = 'P1350',
['qol sayı_'] = 'P1351',
['transfer növü_'] = 'P1642',
}
for k, v in pairs(params) do
if statement.qualifiers and statement.qualifiers[v] then
args[k] = context.formatSnak(options, statement.qualifiers[v][1])
end
end
local res = options.frame:expandTemplate{ title = 'Futbolçu/karyera', args = args }
return res .. categoryText
end
return p