Modul:InfoboxPolitician
Documentația acestui modul poate fi creată la Modul:InfoboxPolitician/doc
local p = {}
local infobox = require('Modul:InfoboxBiography')
local wikidata = require('Modul:Wikidata')
local infoboxImage = require('Modul:InfoboxImage').InfoboxImage
local bda = require('Modul:BirthDateAndAge')
local lc = require('Modul:LocationAndCountry')
local SeparatedEntries = require('Modul:Separated entries')
local join = SeparatedEntries._main
local DateUtils = require('Modul:DateUtils')
local StringUtils = require('Modul:StringUtils')
local TableTools = require('Modul:TableTools')
local Set = require('Modul:Set')
local wdLinker = require('Modul:EditAtWikidata')
local getArgs = require('Modul:Arguments').getArgs
local collapsibleList = require('Modul:Collapsible list').display
local printTimestampForClaim = require('Modul:WikidataUtils/Time/Interval').printTimestampForClaim
local _br_ = tostring(mw.html.create('br'))
local nbsp = mw.text.decode(' ', true)
local function smallTextInBrackets(text)
return tostring(mw.html.create('small'):wikitext(StringUtils._encloseString(text, '(', ')')))
end
local function extractDataAndNumberFromMultiParam(argName, paramNames)
local actualParamName = nil
local actualParamNumber
local prevParamName = nil
for paramIndex = 1, #paramNames do
local nlStart, nlEnd = mw.ustring.find(argName, paramNames[paramIndex])
if nlStart == 1 then
actualParamName = mw.ustring.sub(argName, 1, nlEnd)
local presumedIndex = mw.ustring.find(argName, "%d+$") or (1 + #(paramNames[paramIndex]))
local indexStr = mw.text.trim(mw.ustring.sub(argName, presumedIndex, #argName) or "")
local headingUnderscores = mw.ustring.match(indexStr, '^_+')
if headingUnderscores then
indexStr = mw.ustring.sub(indexStr, #headingUnderscores)
end
if indexStr == "" then
actualParamNumber = 1
elseif mw.ustring.match(indexStr, "^%d+$") then
actualParamNumber = 1 + tonumber(indexStr)
else
actualParamName = prevParamName
end
prevParamName = actualParamName
end
end
if not actualParamName then return nil, nil end
return actualParamName, actualParamNumber
end
local function extractQualifierShortNames(claim, qualifierId)
if claim == nil or claim.qualifiers == nil or qualifierId == nil or claim.qualifiers[qualifierId] == nil then return {} end
local nameList = {}
if claim.qualifiers and claim.qualifiers[qualifierId] then
for qualIdx,qualifier in ipairs(claim.qualifiers[qualifierId]) do
local name = nil
if qualifier.datatype == 'wikibase-item' and qualifier.datavalue and qualifier.datavalue.type == 'wikibase-entityid' then
local QID = StringUtils._prependIfMissing(tostring(qualifier.datavalue.value['numeric-id']), 'Q')
name = wikidata.findOneValueNoRef('P1813', QID) -- short name
local link = nil
if name == nil then
link = wikidata.printSnak(qualifier)
else
link = wikidata.findLinkToItemWithCallback(QID, false, nil, function() return name end)
end
link = link .. wikidata.outputReferences(qualifier)
table.insert(nameList, link)
end
end
end
return nameList
end
local function makeListCollapsibleIfTwoLarge(list, label, limit)
if #list < limit then
return SeparatedEntries.br(list)
else
return collapsibleList(true, 'border:none; padding:0;', '', tostring(#list) .. ' ' .. label, 'text-align: left;', list)
end
end
local function computeArguments(origArgs)
local processedArgs = {}
local functii = {}
local embedded = {}
for argK, argV in pairs(origArgs) do
if argV ~= nil and mw.ustring.len(mw.text.trim(argV)) > 0 then
processedArgs[argK] = mw.text.trim(argV)
end
end
local q = origArgs.q or mw.wikibase.getEntityIdForCurrentPage()
local fem = wikidata.isFemale(q)
for argK, argV in pairs(processedArgs) do
local presumedFunctionParamName, presumedFunctionParamNumber = extractDataAndNumberFromMultiParam(argK, {"functia", "funcție", "office"})
if presumedFunctionParamName and presumedFunctionParamNumber and type(presumedFunctionParamNumber) == 'number' then
if not functii[presumedFunctionParamNumber] then functii[presumedFunctionParamNumber] = {} end
functii[presumedFunctionParamNumber].denumire = argV
end
local presumedOrderParamName, presumedOrderParamNumber = extractDataAndNumberFromMultiParam(argK, {"ordine", "order"})
if presumedOrderParamName and presumedOrderParamNumber and type(presumedOrderParamNumber) == 'number' then
if not functii[presumedOrderParamNumber] then functii[presumedOrderParamNumber] = {} end
functii[presumedOrderParamNumber].ordine = argV
end
local presumedNomParamName, presumedNomParamNumber = extractDataAndNumberFromMultiParam(argK, {"nominalizat", "candidat", "nominee", "candidate"})
if presumedNomParamName and presumedNomParamNumber and type(presumedNomParamNumber) == 'number' then
if not functii[presumedNomParamNumber] then functii[presumedNomParamNumber] = {} end
functii[presumedNomParamNumber].nom = argV
end
local presumedStartParamName, presumedStartParamNumber = extractDataAndNumberFromMultiParam(argK, {"inceput", "început", "term_start"})
if presumedStartParamName and presumedStartParamNumber and type(presumedStartParamNumber) == 'number' then
if not functii[presumedStartParamNumber] then functii[presumedStartParamNumber] = {} end
functii[presumedStartParamNumber].startTime = argV
end
local presumedEndParamName, presumedEndParamNumber = extractDataAndNumberFromMultiParam(argK, {"sfarsit", "sfârșit", "term_end"})
if presumedEndParamName and presumedEndParamNumber and type(presumedEndParamNumber) == 'number' then
if not functii[presumedEndParamNumber] then functii[presumedEndParamNumber] = {} end
functii[presumedEndParamNumber].endTime = argV
end
local presumedVpParamName, presumedVpParamNumber = extractDataAndNumberFromMultiParam(argK, {"vice_presedinte", "vice_președinte", "vicepreședinte", "vicepresedinte", "vicepresident"})
if presumedVpParamName and presumedVpParamNumber and type(presumedVpParamNumber) == 'number' then
if not functii[presumedVpParamNumber] then functii[presumedVpParamNumber] = {} end
functii[presumedVpParamNumber].vp = argV
end
local presumedVpmParamName, presumedVpmParamNumber = extractDataAndNumberFromMultiParam(argK, {"vice_prim_ministru", "viceprimeminister"})
if presumedVpmParamName and presumedVpmParamNumber and type(presumedVpmParamNumber) == 'number' then
if not functii[presumedVpmParamNumber] then functii[presumedVpmParamNumber] = {} end
functii[presumedVpmParamNumber].vpm = argV
end
local presumedDptyParamName, presumedDptyParamNumber = extractDataAndNumberFromMultiParam(argK, {"deputy", "deputat", "loctiitor", "locțiitor"})
if presumedDptyParamName and presumedDptyParamNumber and type(presumedDptyParamNumber) == 'number' then
if not functii[presumedDptyParamNumber] then functii[presumedDptyParamNumber] = {} end
functii[presumedDptyParamNumber].deputy = argV
end
local presumedPresParamName, presumedPresParamNumber = extractDataAndNumberFromMultiParam(argK, {"presedinte", "președinte", "president"})
if presumedPresParamName and presumedPresParamNumber and type(presumedPresParamNumber) == 'number' then
if not functii[presumedPresParamNumber] then functii[presumedPresParamNumber] = {} end
functii[presumedPresParamNumber].president = argV
end
local presumedPmParamName, presumedPmParamNumber = extractDataAndNumberFromMultiParam(argK, {"primministru", "prim_ministru", "primeminister"})
if presumedPmParamName and presumedPmParamNumber and type(presumedPmParamNumber) == 'number' then
if not functii[presumedPmParamNumber] then functii[presumedPmParamNumber] = {} end
functii[presumedPmParamNumber].pm = argV
end
local presumedMnrchParamName, presumedMnrchParamNumber = extractDataAndNumberFromMultiParam(argK, {"monarh", "monarch"})
if presumedMnrchParamName and presumedMnrchParamNumber and type(presumedMnrchParamNumber) == 'number' then
if not functii[presumedMnrchParamNumber] then functii[presumedMnrchParamNumber] = {} end
functii[presumedMnrchParamNumber].monarch = argV
end
local presumedPredParamName, presumedPredParamNumber = extractDataAndNumberFromMultiParam(argK, {"predecesor", "predecessor"})
if presumedPredParamName and presumedPredParamNumber and type(presumedPredParamNumber) == 'number' then
if not functii[presumedPredParamNumber] then functii[presumedPredParamNumber] = {} end
functii[presumedPredParamNumber].pred = argV
end
local presumedSuccParamName, presumedSuccParamNumber = extractDataAndNumberFromMultiParam(argK, {"succesor", "successor"})
if presumedSuccParamName and presumedSuccParamNumber and type(presumedSuccParamNumber) == 'number' then
if not functii[presumedSuccParamNumber] then functii[presumedSuccParamNumber] = {} end
functii[presumedSuccParamNumber].succ = argV
end
local presumedCircParamName, presumedCircParamNumber = extractDataAndNumberFromMultiParam(argK, {"circumscriptia", "circumscripția"})
if presumedCircParamName and presumedCircParamNumber and type(presumedCircParamNumber) == 'number' then
if not functii[presumedCircParamNumber] then functii[presumedCircParamNumber] = {} end
functii[presumedCircParamNumber].circumscription = argV
end
local presumedEmbeddedParamName, presumedEmbeddedParamNumber = extractDataAndNumberFromMultiParam(argK, {"embedded"})
if presumedEmbeddedParamName and presumedEmbeddedParamNumber and type(presumedEmbeddedParamNumber) == 'number' then
embedded[presumedEmbeddedParamNumber] = argV
end
end
if table.maxn(functii) == 0 then
local wikidataPositions = wikidata.findSortedClaimsForProperty(q, 'P39')
if wikidataPositions then
for psnIdx = 1,#wikidataPositions do
if wikidata.isClaimTrue(wikidataPositions[psnIdx]) and wikidata.hasValueSnak(wikidataPositions[psnIdx]) then
local posn = {}
posn.q = StringUtils._prependIfMissing(wikidataPositions[psnIdx].mainsnak.datavalue.value['numeric-id'], 'Q')
local orderValues = wikidata.findQualifierValueListForClaim(wikidataPositions[psnIdx], 'P1545')
posn.orders = {}
if orderValues then
for _,eachRawOrder in ipairs(orderValues) do
if eachRawOrder and mw.text.trim(eachRawOrder) ~= '' then
if eachRawOrder == '1' then table.insert(posn.orders, 'primul')
else table.insert(posn.orders, 'al ' .. eachRawOrder .. '-lea')
end
end
end
end
local roPosnLabel = mw.wikibase.getLabelByLang(posn.q, 'ro')
if roPosnLabel and #posn.orders == 0 then roPosnLabel = StringUtils._capitalize({roPosnLabel}) end
local posnTitleParts = {}
if wikidataPositions[psnIdx].qualifiers and wikidataPositions[psnIdx].qualifiers['P642'] then
table.insert(posnTitleParts, roPosnLabel or wikidata.findNativeOrEnglishLabel(posn.q, #posnTitleParts == 0))
table.insert(posnTitleParts, 'în')
table.insert(posnTitleParts, table.concat(wikidata.findQualifierValueListForClaim(wikidataPositions[psnIdx], 'P642'), ', '))
else
table.insert(posnTitleParts,
(mw.wikibase.sitelink(posn.q) or wikidata.loadOneValueInChain({posn.q, 'P2354'}))
and wikidata.findLinkToItem(posn.q, #posn.orders == 0, fem, false)
or roPosnLabel or wikidata.findNativeOrEnglishLabel(posn.q, #posn.orders == 0))
end
table.insert(posnTitleParts, wdLinker.displayMessage('P39', q))
posn.denumire = table.concat(posnTitleParts, ' ')
for _,startTimeQual in ipairs(wikidataPositions[psnIdx].qualifiers and wikidataPositions[psnIdx].qualifiers['P580'] or {}) do
if (wikidata.isValueSnak(startTimeQual)) then
posn.startTime = DateUtils.extractDateFromWikidataSnak(startTimeQual)
end
end
for _,endTimeQual in ipairs(wikidataPositions[psnIdx].qualifiers and wikidataPositions[psnIdx].qualifiers['P582'] or {}) do
if (wikidata.isValueSnak(endTimeQual)) then
posn.endTime = DateUtils.extractDateFromWikidataSnak(endTimeQual)
if posn.endTime.precision == 9 then
posn.endTime.month = 12
posn.endTime.day = 31
elseif posn.endTime.precision == 10 then
posn.endTime = DateUtils.addDaysToDate({day = 1, month = 1 + (posn.endTime.month % 12), year = (posn.endTime.month < 12) and posn.endTime.year or (posn.endTime.year + 1) }, -1)
posn.endTime.precision = 10
end
end
end
posn.refs = wikidata.getReferences(wikidataPositions[psnIdx])
posn.legislatures = wikidata.findQualifierValueListForClaim(wikidataPositions[psnIdx], 'P2937')
posn.parlGroups = wikidata.findQualifierValueListForClaim(wikidataPositions[psnIdx], 'P4100')
posn.elections = wikidata.findQualifierValueListForClaim(wikidataPositions[psnIdx], 'P2715')
posn.predecessors = wikidata.findQualifierValueListForClaim(wikidataPositions[psnIdx], 'P1365')
posn.successors = wikidata.findQualifierValueListForClaim(wikidataPositions[psnIdx], 'P1366')
posn.circumscription = table.concat(extractQualifierShortNames(wikidataPositions[psnIdx], 'P768'), tostring(mw.html.create('br')))
posn.headsofstate = wikidata.findQualifierValueListForClaim(wikidataPositions[psnIdx], 'P35')
posn.cabinets = wikidata.findQualifierValueListForClaim(wikidataPositions[psnIdx], 'P5054')
table.insert(functii, posn)
end
end
local foldedPositions = { }
for psnIdx,psn in ipairs(functii) do
local foldedPosition = { q = psn.q, posns = {}, denumire = psn.denumire, refs = {}, isnew = true }
for foldedPsnIdx,foldedPsn in ipairs(foldedPositions) do
if foldedPsn.q == functii[psnIdx].q then
foldedPosition = foldedPsn
break
end
end
psn.denumire = nil
table.insert(foldedPosition.posns, psn)
if foldedPosition.isnew then
foldedPosition.isnew = false
table.insert(foldedPositions, foldedPosition)
end
end
for foldedPsnIdx,foldedPsn in ipairs(foldedPositions) do
table.sort(foldedPsn.posns, function(a, b) return DateUtils.compare(a.startTime, b.startTime) < 0 end)
local mergedPsns = { foldedPsn.posns[1] }
for psnIdx = 2,#foldedPsn.posns do
local mergedPsnIdx = 1
local merged = false
while mergedPsnIdx <= #mergedPsns do
local eachMergedPsn = mergedPsns[mergedPsnIdx]
if eachMergedPsn.circumscription == foldedPsn.posns[psnIdx].circumscription and
DateUtils.compare(DateUtils.addDaysToDate(eachMergedPsn.endTime, 7), foldedPsn.posns[psnIdx].startTime) > -1 then
eachMergedPsn.endTime = foldedPsn.posns[psnIdx].endTime
for hash,cargs in pairs(foldedPsn.posns[psnIdx].refs) do
eachMergedPsn[hash] = eachMergedPsn[hash] or cargs
end
Set.union(eachMergedPsn.refs, foldedPsn.posns[psnIdx].refs)
eachMergedPsn.orders = Set.valueUnion(eachMergedPsn.orders, foldedPsn.posns[psnIdx].orders)
eachMergedPsn.parlGroups = Set.valueUnion(eachMergedPsn.parlGroups, foldedPsn.posns[psnIdx].parlGroups)
eachMergedPsn.elections = Set.valueUnion(eachMergedPsn.elections, foldedPsn.posns[psnIdx].elections)
eachMergedPsn.legislatures = Set.valueUnion(eachMergedPsn.legislatures, foldedPsn.posns[psnIdx].legislatures)
eachMergedPsn.successors = foldedPsn.posns[psnIdx].successors
eachMergedPsn.headsofstate = Set.valueUnion(eachMergedPsn.headsofstate, foldedPsn.posns[psnIdx].headsofstate)
eachMergedPsn.cabinets = Set.valueUnion(eachMergedPsn.cabinets, foldedPsn.posns[psnIdx].cabinets)
merged = true
break
end
mergedPsnIdx = mergedPsnIdx + 1
end
if not merged then
table.insert(mergedPsns, foldedPsn.posns[psnIdx])
end
end
table.sort(mergedPsns, function(a, b) return DateUtils.compare(a.startTime, b.startTime) > 0 end)
foldedPsn.posns = mergedPsns
end
functii = {}
for _,eachFoldedPosn in ipairs(foldedPositions) do
local firstPosn = {}
firstPosn.denumire = eachFoldedPosn.denumire
if eachFoldedPosn.posns[1].orders and #eachFoldedPosn.posns[1].orders > 0 then
eachFoldedPosn.posns[1].orders.conjunction = ' și '
eachFoldedPosn.posns[1].orders.separator = ', '
firstPosn.denumire = StringUtils._capitalize(join(eachFoldedPosn.posns[1].orders)) .. ' ' .. firstPosn.denumire
end
local crtPosn = firstPosn
for _,eachPosn in ipairs(eachFoldedPosn.posns) do
crtPosn.startTime = DateUtils.formatDate(eachPosn.startTime)
crtPosn.startTimeRaw = eachPosn.startTime
crtPosn.endTime = DateUtils.formatDate(eachPosn.endTime)
crtPosn.endTimeRaw = eachPosn.endTime
crtPosn.legislature = makeListCollapsibleIfTwoLarge(eachPosn.legislatures, 'legislaturi', 3)
crtPosn.pred = SeparatedEntries.br(eachPosn.predecessors)
crtPosn.succ = SeparatedEntries.br(eachPosn.successors)
crtPosn.headofstate = makeListCollapsibleIfTwoLarge(eachPosn.headsofstate, 'șefi de stat', 3)
crtPosn.circumscription = eachPosn.circumscription
crtPosn.cabinet = makeListCollapsibleIfTwoLarge(eachPosn.cabinets, 'cabinete', 3)
crtPosn.parlGroup = makeListCollapsibleIfTwoLarge(eachPosn.parlGroups, 'grupuri parlamentare', 3)
crtPosn.election = makeListCollapsibleIfTwoLarge(eachPosn.elections, 'scrutinuri', 3)
crtPosn.refs = wikidata.printFirstReferences(eachPosn.refs, 4)
table.insert(functii, crtPosn)
crtPosn = {}
end
end
end
end
local childMode = (processedArgs['embed'] == 'yes' or processedArgs['embed'] == 'da')
local mainMode = not childMode
local computedArgs = { }
computedArgs.q = q
computedArgs.aboveclass = origArgs['aboveclass'] or 'biografii'
computedArgs['culoare cadru'] = origArgs['culoare cadru'] or 'E6E6FA'
computedArgs['culoare text'] = origArgs['culoare text'] or '000'
computedArgs['headerstyle'] = 'border-top-style: solid; border-color:#aaa; border-top-width: 1px; padding-top: 3px; padding-bottom: 3px'
computedArgs['subheader1'] = origArgs['subheader']
computedArgs.embed = childMode and 'yes' or 'no'
computedArgs.doc = origArgs['doc'] or 'Infocaseta Om politic'
computedArgs.wikidata = 'y'
computedArgs['name'] = processedArgs['nume'] or processedArgs['name'] or (mainMode and (StringUtils._emptyToNil({wikidata.findLabel(q)}) or mw.title.getCurrentTitle().text))
computedArgs.default_title = 'Cariera politică'
computedArgs.parent_colspan = processedArgs['parent_colspan'] or '2'
local imageTitle = processedArgs['imagine'] or processedArgs['image']
local imageCaption = processedArgs['caption'] or processedArgs['descriere'] or processedArgs['comentariu'] or processedArgs['Descriere']
local imageSize = processedArgs['dimensiune_imagine'] or processedArgs['imagesize'] or processedArgs['image_size'] or processedArgs['mărime']
local smallImageTitle = processedArgs['imagine_mică'] or processedArgs['smallimage']
local wdImageName, wdImageCaption
if imageTitle == nil then
wdImageTitle, wdImageCaption = wikidata.findImageAndCaption()
imageTitle = wdImageName
imageCaption = wdImageCaption
end
if imageTitle and imageTitle ~= '' then computedArgs.image = infoboxImage{image=imageTitle, size = imageSize, sizedefault = frameless, suppressplaceholder='yes'}
elseif smallImageTitle then computedArgs.image = '[[Fișier:' .. smallImageTitle .. ']]' end
computedArgs.caption = imageCaption
local crtLineIndex = 1
if origArgs['extra_header'] then
local extraDataIdxes = TableTools.affixNums(origArgs, 'extra_data')
if #extraDataIdxes > 0 then
computedArgs['header' .. tostring(crtLineIndex)] = origArgs['extra_header']
crtLineIndex = crtLineIndex + 1
for _,eachExtraDataIdx in ipairs(extraDataIdxes) do
computedArgs['data' .. tostring(crtLineIndex)] = origArgs['extra_data' .. tostring(eachExtraDataIdx)]
computedArgs['label' .. tostring(crtLineIndex)] = origArgs['extra_label' .. tostring(eachExtraDataIdx)]
crtLineIndex = crtLineIndex + 1
end
end
end
local prevPosition = nil
for functionIdx = 1,table.maxn(functii) do
if functii[functionIdx] then
if functii[functionIdx].denumire or functii[functionIdx].ordine then
if prevPosition == nil or prevPosition.denumire == nil or prevPosition.denumire ~= functii[functionIdx].denumire then
computedArgs['header' .. tostring(crtLineIndex)] = (functii[functionIdx].ordine or '') .. ' ' .. (functii[functionIdx].denumire or '')
crtLineIndex = crtLineIndex + 1
end
end
if functii[functionIdx].nom then
computedArgs['label' .. tostring(crtLineIndex)] = 'Candidat'
computedArgs['data' .. tostring(crtLineIndex)] = functii[functionIdx].nom
crtLineIndex = crtLineIndex + 1
end
if functii[functionIdx].startTime and functii[functionIdx].endTime then
computedArgs['data' .. tostring(crtLineIndex)] = "'''În funcție'''<br/>" .. functii[functionIdx].startTime .. ' – ' .. functii[functionIdx].endTime .. (functii[functionIdx].refs or '')
crtLineIndex = crtLineIndex + 1
elseif functii[functionIdx].startTime then
local startDate = functii[functionIdx].startTimeRaw or DateUtils.parseDate(mw.ustring.gsub(mw.ustring.gsub(functii[functionIdx].startTime, "%[%[", ""), "%]%]", ""))
if startDate and DateUtils.compare(os.date('*t'), startDate) < 0 then
computedArgs['data' .. tostring(crtLineIndex)] = 'Va prelua funcția'
else
computedArgs['data' .. tostring(crtLineIndex)] = 'Deținător actual'
end
computedArgs['style' .. tostring(crtLineIndex)] = 'background-color: #eeeeff;'
crtLineIndex = crtLineIndex + 1
computedArgs['data' .. tostring(crtLineIndex)] = "'''Funcție asumată'''<br/>" .. functii[functionIdx].startTime .. (functii[functionIdx].refs or '')
crtLineIndex = crtLineIndex + 1
end
if functii[functionIdx].vp then
computedArgs['label' .. tostring(crtLineIndex)] = 'Vicepreședinte'
computedArgs['data' .. tostring(crtLineIndex)] = functii[functionIdx].vp
crtLineIndex = crtLineIndex + 1
end
if functii[functionIdx].vpm then
computedArgs['label' .. tostring(crtLineIndex)] = 'Viceprim-ministru'
computedArgs['data' .. tostring(crtLineIndex)] = functii[functionIdx].vpm
crtLineIndex = crtLineIndex + 1
end
if functii[functionIdx].deputy then
computedArgs['label' .. tostring(crtLineIndex)] = 'Locțiitor'
computedArgs['data' .. tostring(crtLineIndex)] = functii[functionIdx].deputy
crtLineIndex = crtLineIndex + 1
end
if functii[functionIdx].president then
computedArgs['label' .. tostring(crtLineIndex)] = 'Președinte'
computedArgs['data' .. tostring(crtLineIndex)] = functii[functionIdx].president
crtLineIndex = crtLineIndex + 1
end
if functii[functionIdx].pm then
computedArgs['label' .. tostring(crtLineIndex)] = 'Prim-ministru'
computedArgs['data' .. tostring(crtLineIndex)] = functii[functionIdx].pm
crtLineIndex = crtLineIndex + 1
end
if functii[functionIdx].monarch then
computedArgs['label' .. tostring(crtLineIndex)] = 'Monarh'
computedArgs['data' .. tostring(crtLineIndex)] = functii[functionIdx].monarch
crtLineIndex = crtLineIndex + 1
end
if functii[functionIdx].headofstate then
computedArgs['label' .. tostring(crtLineIndex)] = 'Șef al statului'
computedArgs['data' .. tostring(crtLineIndex)] = functii[functionIdx].headofstate
crtLineIndex = crtLineIndex + 1
end
if functii[functionIdx].cabinet then
computedArgs['label' .. tostring(crtLineIndex)] = 'Guvern'
computedArgs['data' .. tostring(crtLineIndex)] = functii[functionIdx].cabinet
crtLineIndex = crtLineIndex + 1
end
if functii[functionIdx].pred then
computedArgs['label' .. tostring(crtLineIndex)] = 'Precedat de'
computedArgs['data' .. tostring(crtLineIndex)] = functii[functionIdx].pred
crtLineIndex = crtLineIndex + 1
end
if functii[functionIdx].succ then
computedArgs['label' .. tostring(crtLineIndex)] = 'Succedat de'
computedArgs['data' .. tostring(crtLineIndex)] = functii[functionIdx].succ
crtLineIndex = crtLineIndex + 1
end
if functii[functionIdx].circumscription then
computedArgs['label' .. tostring(crtLineIndex)] = 'Circumscripția'
computedArgs['data' .. tostring(crtLineIndex)] = functii[functionIdx].circumscription
crtLineIndex = crtLineIndex + 1
end
if functii[functionIdx].legislature then
computedArgs['label' .. tostring(crtLineIndex)] = 'Legislatură'
computedArgs['data' .. tostring(crtLineIndex)] = functii[functionIdx].legislature
crtLineIndex = crtLineIndex + 1
end
if functii[functionIdx].parlGroup then
computedArgs['label' .. tostring(crtLineIndex)] = 'Grup parlamentar'
computedArgs['data' .. tostring(crtLineIndex)] = functii[functionIdx].parlGroup
crtLineIndex = crtLineIndex + 1
end
if functii[functionIdx].election then
computedArgs['label' .. tostring(crtLineIndex)] = fem and 'Aleasă în' or 'Ales în'
computedArgs['data' .. tostring(crtLineIndex)] = functii[functionIdx].election
crtLineIndex = crtLineIndex + 1
end
prevPosition = functii[functionIdx]
end
end
if table.maxn(functii) > 0 then
computedArgs['data' .. tostring(crtLineIndex)] = tostring(mw.html.create('hr'))
crtLineIndex = crtLineIndex + 1
end
local wikidataGender = wikidata.findOneValueNoRef('P21', q)
local gender = nil
if wikidataGender then
if mw.ustring.find(wikidataGender, 'femeie') then gender = 'f'
else gender = 'm' end
end
computedArgs['birth_date'] = processedArgs['data_nasterii'] or processedArgs['data_nașterii'] or processedArgs['birth_date']
computedArgs['birth_name'] = processedArgs['nume_la_naștere'] or processedArgs['birth_name'] or processedArgs['birthname']
computedArgs['death_date'] = processedArgs['data_decesului'] or processedArgs['death_date']
computedArgs['birth_place'] = processedArgs['locul_nasterii'] or processedArgs['locul_nașterii'] or processedArgs['birth_place']
computedArgs['death_place'] = processedArgs['locul_decesului'] or processedArgs['death_place']
local awards = processedArgs['premii'] or processedArgs['awards']
if awards == nil then
if processedArgs['ordine și medalii românești'] and processedArgs['ordine și medalii străine'] then
awards = table.concat({processedArgs['ordine și medalii românești'], processedArgs['ordine și medalii străine']}, tostring(mw.html.create('br')))
else if processedArgs['ordine și medalii românești'] then
awards = processedArgs['ordine și medalii românești']
else if processedArgs['ordine și medalii străine'] then awards = processedArgs['ordine și medalii străine'] end
end
end
end
if mainMode and awards == nil then
local wikidataAwards = wikidata.findClaimsForProperty(nil, 'P166')
if wikidataAwards and #wikidataAwards > 0 then
local awardsList = {}
for _idx,eachClaim in ipairs(wikidataAwards) do
if _idx < 10 and eachClaim.mainsnak.snaktype == 'value' then
local award = wikidata.printSnak(eachClaim.mainsnak) .. wikidata.outputReferences(eachClaim.mainsnak)
local fromList = {}
if eachClaim.qualifiers then
for _,eachQualProp in ipairs({'P1027', 'P642'}) do
if eachClaim.qualifiers[eachQualProp] then
for _,eachQual in ipairs(eachClaim.qualifiers[eachQualProp]) do
table.insert(fromList, wikidata.printSnak(eachQual))
end
end
end
if #fromList > 0 then
award = award .. ' de la ' .. table.concat(fromList, ', ')
end
end
local awardTimestamp = printTimestampForClaim(eachClaim)
if awardTimestamp and mw.ustring.len(mw.text.trim(awardTimestamp)) > 2 then
award = award .. nbsp .. smallTextInBrackets(awardTimestamp)
end
table.insert(awardsList, award)
end
end
local lineBr = tostring(mw.html.create('br'))
awards = table.concat(awardsList, lineBr)
if #wikidataAwards > 10 then
awards = awards .. lineBr .. wdLinker.displayMessageWithCustomText('P166', q, tostring(mw.html.create('small'):wikitext('...mai multe...')))
end
end
end
if awards then
computedArgs['label' .. tostring(crtLineIndex)] = 'Premii'
computedArgs['data' .. tostring(crtLineIndex)] = awards
crtLineIndex = crtLineIndex + 1
end
local parties = processedArgs['partid'] or processedArgs['party']
if parties == nil then
local wikidataParties = wikidata.findSortedClaimsForProperty(nil, 'P102')
if wikidataParties and #wikidataParties > 0 then
local partiesList = {}
for partyIdx=1,#wikidataParties do
local crtEntry = ''
if wikidataParties[partyIdx].mainsnak.snaktype == 'value' then
crtEntry = wikidata.findLinkToItemWithCallback(wikidataParties[partyIdx].mainsnak.datavalue.value['numeric-id'], true, function(entityObject)
local entityObjectQId = entityObject and StringUtils._prependIfMissing(tostring(entityObject.id), 'Q')
local returnValueCandidate = nil
if entityObject and entityObject.claims and entityObject.claims['P1813'] and #(entityObject.claims['P1813']) > 0 then
local inPartyEndDate = nil
if wikidataParties[partyIdx].qualifiers and wikidataParties[partyIdx].qualifiers['P582'] and wikidataParties[partyIdx].qualifiers['P582'][1] then
inPartyEndDate = DateUtils.extractDateFromWikidataSnak(wikidataParties[partyIdx].qualifiers['P582'][1])
end
local returnValueRank = mw.wikibase.entity.claimRanks.RANK_DEPRECATED --initial rank is lowest, so that practically anything is accepted here
local returnValueEndDate = inPartyEndDate and {year = 1, month = 1, day = 1} or os.date('*t')
for _,eachPartyShortNameClaim in ipairs(entityObject.claims['P1813']) do
if eachPartyShortNameClaim.type == 'statement' and eachPartyShortNameClaim.mainsnak.snaktype == 'value' and eachPartyShortNameClaim.mainsnak.datavalue.value.language == 'ro' then
local namingEndDate = {} -- empty date
if eachPartyShortNameClaim.qualifiers and eachPartyShortNameClaim.qualifiers['P582'] and #(eachPartyShortNameClaim.qualifiers['P582']) > 0 then
namingEndDate = DateUtils.extractDateFromWikidataSnak(eachPartyShortNameClaim.qualifiers['P582'][1])
end
if inPartyEndDate == nil then
--in this case, we don't have a time reference to get the party name, so we get the best we've got: the most recent among those with the highest rank
local candidateRank = mw.wikibase.entity.claimRanks['RANK_' .. mw.ustring.upper(eachPartyShortNameClaim.rank)]
if candidateRank > returnValueRank then
--we found a candidate with a better rank
returnValueCandidate = eachPartyShortNameClaim.mainsnak.datavalue.value.text
returnValueEndDate = namingEndDate
returnValueRank = candidateRank
elseif candidateRank == returnValueRank then
--same rank, we now care about which is more recent
if returnValueEndDate ~= nil then
if DateUtils.compare(namingEndDate, returnValueEndDate) > 0 then
--the naming end date is more recent than the end date of the candidate return value
returnValueCandidate = eachPartyShortNameClaim.mainsnak.datavalue.value.text
returnValueEndDate = namingEndDate
--else not interested: examined date is older than what we already have
end
--else not interested: we have one value without end date, which means it's current
end
--else not interested: lower rank
end
else
--in this case, we want the one with the oldest end date, but newer than the time reference
if namingEndDate and DateUtils.compare(namingEndDate, inPartyEndDate) >= 0 then
-- the naming end date is more recent than the time reference
if DateUtils.compare(namingEndDate, returnValueEndDate) < 0 then
--the naming end date is older than the current candidate return value
returnValueCandidate = eachPartyShortNameClaim.mainsnak.datavalue.value.text
returnValueEndDate = namingEndDate
--else not interested: we have a candidate that is already closer to the time reference than this one
end
--else not interested: either not dated or ended before the time reference
end
end
--else not interested: unknown or no value, or foreign language
end
end --for
if not returnValueCandidate then returnValueCandidate = wikidata.findOneValue('P1813', entityObjectQId) end
end
return returnValueCandidate
end)
elseif wikidataParties[partyIdx].mainsnak == 'novalue' then
crtEntry = "''Niciunul''"
end
crtEntry = crtEntry .. nbsp .. smallTextInBrackets(printTimestampForClaim(wikidataParties[partyIdx]))
if crtEntry ~= '' then table.insert(partiesList, crtEntry) end
end
parties = table.concat(partiesList, tostring(mw.html.create('br')))
if #partiesList > 0 then parties = parties .. ' ' .. wdLinker.displayMessage('P102', q) end
end
end
if parties then
computedArgs['label' .. tostring(crtLineIndex)] = 'Partid politic'
computedArgs['data' .. tostring(crtLineIndex)] = parties
crtLineIndex = crtLineIndex + 1
end
local ideology = wikidata._getValueListWithSeparator({_br_, 'P1142'})
if ideology and ideology ~= '' then
computedArgs['label' .. tostring(crtLineIndex)] = 'Ideologie'
computedArgs['data' .. tostring(crtLineIndex)] = StringUtils._appendToString({
ideology,
wdLinker.displayMessage('P1142', q)
})
crtLineIndex = crtLineIndex + 1
end
computedArgs['label' .. tostring(crtLineIndex)] = 'Alte afilieri'
computedArgs['data' .. tostring(crtLineIndex)] = processedArgs['alte afilieri'] or processedArgs['otherparty']
crtLineIndex = crtLineIndex + 1
computedArgs['label' .. tostring(crtLineIndex)] = 'Grup europarlamentar'
computedArgs['data' .. tostring(crtLineIndex)] = processedArgs['grup_europarlamentar']
crtLineIndex = crtLineIndex + 1
computedArgs['label' .. tostring(crtLineIndex)] = 'Rezidență'
computedArgs['data' .. tostring(crtLineIndex)] = processedArgs['rezidenta'] or processedArgs['rezidență'] or processedArgs['residence']
crtLineIndex = crtLineIndex + 1
computedArgs['spouse'] = processedArgs['sot'] or processedArgs['soț'] or processedArgs['spouse'] or processedArgs['sotia'] or processedArgs['soție']
computedArgs['partener'] = processedArgs['partener'] or processedArgs['parteneră']
computedArgs['children'] = processedArgs['copii'] or processedArgs['children']
computedArgs['parents'] = processedArgs['părinți'] or processedArgs['parents']
computedArgs['siblings'] = processedArgs['frati'] or processedArgs['frați']
computedArgs['avere'] = processedArgs['avere'] or processedArgs['net_worth']
local alma_mater = processedArgs['alma_mater']
if mainMode and alma_mater == nil then
local wikidataAlmaMater = wikidata.findValueListWithQualifiersInBrackets(nil, 'P69', false, {'$P512', '$P812', '$P582'}, {' în ', ', '})
if wikidataAlmaMater then alma_mater = table.concat(wikidataAlmaMater, tostring(mw.html.create('br'))) end
end
if alma_mater then
computedArgs['label' .. tostring(crtLineIndex)] = '[[Alma mater]]'
computedArgs['data' .. tostring(crtLineIndex)] = alma_mater
crtLineIndex = crtLineIndex + 1
end
computedArgs['label' .. tostring(crtLineIndex)] = 'Cunoscut' .. (gender == nil and '(ă)' or gender == 'f' and 'ă' or '') .. ' pentru'
computedArgs['data' .. tostring(crtLineIndex)] = processedArgs['cunoscut_pentru']
crtLineIndex = crtLineIndex + 1
computedArgs['label' .. tostring(crtLineIndex)] = 'Societăți'
computedArgs['data' .. tostring(crtLineIndex)] = processedArgs['societăți']
crtLineIndex = crtLineIndex + 1
computedArgs['label' .. tostring(crtLineIndex)] = 'Organizații'
computedArgs['data' .. tostring(crtLineIndex)] = processedArgs['organizații']
crtLineIndex = crtLineIndex + 1
computedArgs['occupation'] = processedArgs['ocupatia'] or processedArgs['ocupație'] or processedArgs['occupation']
computedArgs['label' .. tostring(crtLineIndex)] = 'Profesie'
computedArgs['data' .. tostring(crtLineIndex)] = processedArgs['profesia'] or processedArgs['profesie'] or processedArgs['profession']
crtLineIndex = crtLineIndex + 1
computedArgs['nationality'] = processedArgs['nationalitatea'] or processedArgs['naționalitate'] or processedArgs['nationality']
computedArgs['ethnicity'] = processedArgs['etnie'] or processedArgs['ethnicity']
computedArgs['citizenship'] = processedArgs['cetatenie'] or processedArgs['cetățenie'] or processedArgs['citizenship']
computedArgs['religion'] = processedArgs['religie'] or processedArgs['religia'] or processedArgs['confesiune'] or processedArgs['religion']
computedArgs['signature'] = processedArgs['semnătură'] or processedArgs['semnatura'] or processedArgs['signature']
crtLineIndex = crtLineIndex + 1
computedArgs['data' .. tostring(crtLineIndex)] = processedArgs['note'] or processedArgs['footnotes']
crtLineIndex = crtLineIndex + 1
for embeddedIdx = 1, table.maxn(embedded) do
if embedded[embeddedIdx] then
computedArgs['data' .. tostring(crtLineIndex)] = embedded[embeddedIdx]
crtLineIndex = crtLineIndex + 1
end
end
return computedArgs
end
p.show = function(frame)
local infoboxArguments = computeArguments(getArgs(frame))
return infobox.displayInfoboxFromArgs(infoboxArguments)
end
p.fromArray = computeArguments
return p