Bu modulun sənədləşdirmə səhifəsi Modul:Wikidata/positions/doc səhifəsində yaradıla bilər
local p = {}
local function getDateNumber(snak)
if not snak or not snak.datavalue or not snak.datavalue.value then
return -999999999
end
local time = snak.datavalue.value.time
if not time then
return -999999999
end
local year, month, day = time:match("^([%+%-]?%d+)%-(%d%d)%-(%d%d)")
if year and month and day then
return tonumber(year) * 10000 + tonumber(month) * 100 + tonumber(day)
end
return -999999999
end
function p.formatPositionClaims(context, options)
local statements = context.selectClaims(options, options.property)
if not statements or #statements == 0 then
return ""
end
-- Group claims by their displayed (trimmed) label.
local grouped = {}
for _, statement in ipairs(statements) do
local mainsnak = statement.mainsnak
if mainsnak and mainsnak.datavalue and mainsnak.datavalue.value then
local rawLabel = context.formatSnak(options, mainsnak) or ""
rawLabel = mw.text.trim(rawLabel)
if rawLabel ~= "" then
grouped[rawLabel] = grouped[rawLabel] or {}
table.insert(grouped[rawLabel], statement)
end
end
end
local groupsArray = {}
for label, groupStatements in pairs(grouped) do
table.sort(groupStatements, function(a, b)
local aStart = (a.qualifiers and a.qualifiers.P580) and getDateNumber(a.qualifiers.P580[1]) or -999999999
local bStart = (b.qualifiers and b.qualifiers.P580) and getDateNumber(b.qualifiers.P580[1]) or -999999999
return aStart > bStart
end)
local latest = -999999999
if groupStatements[1] and groupStatements[1].qualifiers and groupStatements[1].qualifiers.P580 then
latest = getDateNumber(groupStatements[1].qualifiers.P580[1])
end
table.insert(groupsArray, { label = label, statements = groupStatements, latest = latest })
end
table.sort(groupsArray, function(a, b)
return a.latest > b.latest
end)
local results = {}
for _, groupInfo in ipairs(groupsArray) do
local groupStatements = groupInfo.statements
local formattedLabel = '<span class="ts-wikidata-positions-uppercasefirst">' .. groupInfo.label .. '</span>'
local firstStmt = groupStatements[1]
if firstStmt.qualifiers and firstStmt.qualifiers.P642 then
local orgs = {}
for _, snak in ipairs(firstStmt.qualifiers.P642) do
local orgName = context.formatSnak(options, snak)
if orgName and orgName ~= "" then
table.insert(orgs, orgName)
end
end
if #orgs > 0 then
formattedLabel = formattedLabel .. " (" .. mw.text.listToText(orgs) .. ")"
end
end
local args = {}
args["vəzifə_"] = formattedLabel
local dateIndex = 1
for _, st in ipairs(groupStatements) do
if st.qualifiers then
local suffix = (dateIndex == 1) and "" or tostring(dateIndex)
-- Process start and end dates (P580 and P582)
local startVal = ""
local endVal = ""
if st.qualifiers["P580"] then
startVal = context.formatSnak(options, st.qualifiers["P580"][1]) or ""
end
if st.qualifiers["P582"] then
endVal = context.formatSnak(options, st.qualifiers["P582"][1]) or ""
end
args["başlanğıc_" .. suffix] = startVal
args["son_" .. suffix] = endVal
local evv = ""
local sonrak = ""
local sec = ""
if st.qualifiers["P1365"] then
evv = context.formatSnak(options, st.qualifiers["P1365"][1]) or ""
end
if st.qualifiers["P1366"] then
sonrak = context.formatSnak(options, st.qualifiers["P1366"][1]) or ""
end
if st.qualifiers["P768"] then
sec = context.formatSnak(options, st.qualifiers["P768"][1]) or ""
end
args["əvvəlki_" .. suffix] = evv
args["sonrakı_" .. suffix] = sonrak
args["seçki dairəsi_" .. suffix] = sec
dateIndex = dateIndex + 1
end
end
local res = options.frame:extensionTag("templatestyles", "", {
src = "Şablon:Wikidata/positions/styles.css"
})
res = res .. options.frame:expandTemplate{
title = "Vəzifəli şəxs/vəzifə",
args = args
}
table.insert(results, res)
end
return table.concat(results, "\n")
end
return p