אונטערשייד צווישן ווערסיעס פון "יחידה:תבנית מידע/אישיות"

פון המכלול
קפיצה לניווט קפיצה לחיפוש
ק (1 רעוויזיע אימפארטירט פון wikipedia:he:יחידה:תבנית_מידע/אישיות)
(אפדעיט)
 
(31 מיטלסטע ווערסיעס פון 3 באַניצער נישט געוויזן.)
שורה 1: שורה 1:
 
local dataTemplateModule = require('Module:תבנית מידע')
local Infobox = require('Module:תבנית מידע').Infobox
local Infobox = dataTemplateModule.Infobox
local BackgroundColors = mw.loadJsonData('Module:תבנית מידע/אישיות/צבע רקע לפי סיווג.json')
local LocationAndCountry = require('Module:LocationAndCountry')
local LocationAndCountry = require('Module:LocationAndCountry')
local PropertyLink = require('Module:PropertyLink')
local PropertyLink = require('Module:PropertyLink')
local ageModule = require('Module:גיל לערכי אישים')
local ageModule = require('Module:עלטער')
local hebrewDateModule = require('Module:תאריך עברי')
local Date = require('Module:דאטום')
local hebrewDateModule = require('Module:אידישע דאטום')
local WikidataCrossValidation = require('Module:WikidataCrossValidation')
local WikidataCrossValidation = require('Module:WikidataCrossValidation')
local siteModule = require('Module:תבנית מידע/אתר')
local TimeRange = require('Module:טווח זמנים')
local gim = require( "Module:גימטריה" )
function count(str, substring)
    local count = 0
    local _, occurrences = string.gsub(str, substring, function()
        count = count + 1
    end)
    return count
end
function enclosed(s)
return mw.ustring.sub(s, 1, 2) == "[[" and mw.ustring.sub(s, -2) == "]]" and count(s, "%[%[") == 1
end


--[[ Get general date if known, otherwise guess from hebrew date.
--[[ Get general date if known, otherwise guess from hebrew date.
שורה 11: שורה 26:
function getSpeculativeDate(generalDate, hebrewDate)
function getSpeculativeDate(generalDate, hebrewDate)
if generalDate == '-' then return nil end
if generalDate == '-' then return nil end
if generalDate~=nil and generalDate~='' then return generalDate end
if generalDate ~= nil and generalDate ~= '' then return generalDate end
if hebrewDate~=nil and hebrewDate~='' then
if hebrewDate ~= nil and hebrewDate ~= '' then
local success, sepcDate = pcall(hebrewDateModule.pick, mw.getCurrentFrame():newChild{ args = {hebrew=hebrewDate, world='', exact='כן' } })
local success, sepcDate = pcall(hebrewDateModule.pick, mw.getCurrentFrame():newChild{ args = {hebrew=hebrewDate, world='', exact='כן' } })
if not success or sepcDate=='' then return nil end
if not success or sepcDate == '' then return nil end
return sepcDate
return sepcDate
end
end
שורה 20: שורה 35:
end
end


local function getDeathLabel(deathCause, entityId)
local function getPencilLink(entityId, prop)
entityId = entityId or mw.wikibase.getEntityIdForCurrentPage()
if not entityId then return '' end
if deathCause == nil and entityId ~= nil then
return string.format(' [[File:Blue pencil RTL.svg|15px|link=https://www.wikidata.org/wiki/%s?uselang=he#%s|עריכת הנתון בוויקינתונים]]', entityId, prop)
end
 
local function getDeathLabel(deathCause, entityId, gender)
local result=''
local fromWikidata=nil
entityId = nil
if ( deathCause == nil or deathCause == '' ) and entityId ~= nil then
local deathCauseWikidata = mw.wikibase.getBestStatements(entityId, 'P1196')
local deathCauseWikidata = mw.wikibase.getBestStatements(entityId, 'P1196')
deathCauseWikidata = deathCauseWikidata and deathCauseWikidata[1] and deathCauseWikidata[1].mainsnak
deathCauseWikidata = deathCauseWikidata and deathCauseWikidata[1] and deathCauseWikidata[1].mainsnak
if deathCauseWikidata then
if deathCauseWikidata then
deathCause = mw.wikibase.renderSnak(deathCauseWikidata)
deathCause = mw.wikibase.renderSnak(deathCauseWikidata)
fromWikidata=true
end
end
end
end
local gender = PropertyLink.getPropertyByOptions( 'P21', entityId )
 
if deathCause and deathCause ~= '' then
if deathCause and deathCause ~= '' then
if deathCause == 'נהרג' or deathCause == 'נהרגה' then
if deathCause == 'נהרג' or deathCause == 'נהרגה' or deathCause == 'מוות בקרב' or deathCause == 'נהרג בקרב' or deathCause == 'נהרגה בקרב' or deathCause == 'תאונה' or deathCause == 'טביעה' then
return (gender=='נקבה' and 'נהרגה') or 'נהרג'
return (gender=='נקבה' and 'נהרגה') or 'נהרג'
elseif deathCause == 'נרצח' or deathCause == 'נרצחה' or deathCause == 'רצח' then
elseif deathCause == 'נעדר' or deathCause == 'נעדרת' then
return (gender=='נקבה' and 'נעדרת') or 'נעדר'
elseif deathCause == 'נרצח' or deathCause == 'נרצחה' or deathCause == 'רצח' or deathCause == 'רצח המוני' or deathCause == 'רעל' then
return (gender=='נקבה' and 'נרצחה') or 'נרצח'
return (gender=='נקבה' and 'נרצחה') or 'נרצח'
        elseif deathCause == 'התאבד' or deathCause == 'התאבדה' or deathCause == 'התאבדות' then
elseif deathCause == 'התאבד' or deathCause == 'התאבדה' or deathCause == 'התאבדות' then
return (gender=='נקבה' and 'התאבדה') or 'התאבד'
return (gender=='נקבה' and 'התאבדה') or 'התאבד'
elseif deathCause == 'הוצא להורג' or deathCause == 'הוצאה להורג' or deathCause == 'עונש מוות' then
elseif deathCause == 'הוצא להורג' or deathCause == 'הוצאה להורג' or deathCause == 'עונש מוות' or deathCause == 'תלייה' then
return 'הוצאה להורג'
return 'הוצאה להורג'
elseif not fromWikidata then result = '[[קאטעגאריע:ערכים עם סיבת מוות שגויה בתבנית]]'
end
end
end
end
return 'פטירה'
return result .. 'פטירה'
end
end


function getEventDetails(generalDate, hebDate, eventPlace, propDate, propPlace, age, usingWikidata, entityId)
function getEventDetails(generalDate, hebDate, eventPlace, propDate, propPlace, age, usingWikidata, infoObj)
entityId = entityId or mw.wikibase.getEntityIdForCurrentPage()
entityId = nil --infoObj.args.entityId or mw.wikibase.getEntityIdForCurrentPage()
age = age or ''
age = age or ''
local formattedEvent
local formattedEvent = ''
if generalDate~=nil and generalDate~='' then
local placeDate = propDate
if generalDate ~= nil and generalDate ~= '' then
local success, placeDateParsed = pcall(Date.newFromWikitext, generalDate)
if success then
placeDate = placeDateParsed
end
formattedEvent = generalDate .. age
formattedEvent = generalDate .. age
if hebDate~=nil and hebDate~='' then  
if hebDate ~= nil and hebDate ~= '' then  
formattedEvent = formattedEvent ..'<br/>' ..hebDate
formattedEvent = formattedEvent .. '<br/>' .. hebDate
end
end
elseif hebDate~=nil and hebDate~='' then
elseif hebDate ~= nil and hebDate ~= '' then
formattedEvent = hebDate .. age
formattedEvent = hebDate .. age
end
end
if (eventPlace == nil or eventPlace == '') and entityId then
if (eventPlace == nil or eventPlace == '') and entityId then
local success, res = pcall(LocationAndCountry.displayFromParams, propPlace, entityId, propDate , 1)
local success, res = pcall(LocationAndCountry.displayFromParams, propPlace, entityId, placeDate , 1)
if success and res and #res>0 then
if success and res and #res > 0 then
usingWikidata = true
usingWikidata = true
eventPlace = res
eventPlace = res
end
else
local pageNs = mw.title.getCurrentTitle().namespace
if pageNs==0 and not infoObj.isNonPerson then
local matching = WikidataCrossValidation.crossValidate(eventPlace, propPlace, entityId)
if matching then
table.insert(infoObj.wikidataCats, WikidataCrossValidation.maintainceCategory(matching, propPlace))
end
end
end
end
end
שורה 71: שורה 109:
if usingWikidata and entityId then
if usingWikidata and entityId then
formattedEvent = formattedEvent .. ' [[File:Blue pencil RTL.svg|15px|link=https://www.wikidata.org/wiki/'..entityId.. '?uselang=yi#P569|עריכת הנתון בוויקינתונים]]'
formattedEvent = formattedEvent .. getPencilLink(entityId, 'P856')
end
end


שורה 77: שורה 115:
end
end


function addMissingImage(infoObj, birthDate, deathDate)
-- Split the comma-separated lists into tables and sort them
if infoObj.args.image ~= nil and #infoObj.args.image > 0 then return end -- there is already image  
local function splitString(inputstr, sep)
local sep, fields = sep or ",", {}
local pattern = string.format("([^%s]+)", sep)
inputstr:gsub(pattern, function(c) fields[#fields + 1] = c end)
return fields
end
 
function addMissingImage(infoObj, birthDate, deathDate, gender)
if infoObj.args.image ~= nil and #infoObj.args.image > 0 then return end -- there is already image  
-- Assuming you have defined deathDate and birthDate earlier
local latestDate = deathDate or birthDate
local latestDate = deathDate or birthDate
if latestDate == nil then return end
if latestDate == nil then return end
local dateModule = require('Module:תאריך')
local success, res = pcall(dateModule.parseDateRange, latestDate, 'raw')
-- Split the comma-separated lists and extract dates
local dateList = splitString(latestDate:gsub(" או ", ","), ",")
if #dateList == 0 then return end
local countSuccess = 0
for i, date in ipairs(dateList) do
local success, DateRes = pcall(Date.newFromWikitext, date)
if success then
dateList[i] = DateRes
countSuccess = countSuccess + 1
end
end
 
if #dateList > 1 and countSuccess == #dateList then
latestDate = dateList[1]
for i, date in ipairs(dateList) do
if i ~= 1 then
local success, DateLeRes = pcall(Date.le, latestDate, date)
if DateLeRes then
latestDate = date
end
end
end
latestDate = os.time(latestDate)
latestDate = os.date("%d %m %Y", latestDate)
end
 
local success, res = pcall(Date.parseDateRange, latestDate, 'raw')
if success==false then return end -- there is no known VALID date
if success==false then return end -- there is no known VALID date
local yearsEstimated = res/(60*60*24*365)
local yearsEstimated = res/(60*60*24*365)
if yearsEstimated>150 then return end  
if yearsEstimated>150 then return end  
if infoObj.args.entityId == nil then
return false -- no wikidata entity
end
local gender = PropertyLink.getPropertyByOptions( 'P21', infoObj.args.entityId )
local frame = mw.getCurrentFrame()
local frame = mw.getCurrentFrame()
infoObj.args.image = frame:expandTemplate{ title = 'קיין בילד', args = { gender, ['יישור'] = 'center' } }
infoObj.args.image = frame:expandTemplate{ title = 'אין תמונה', args = { gender, ['יישור'] = 'מרכז' } }
end
end


שורה 99: שורה 170:
local usingWikidata = false
local usingWikidata = false
if infoObj.args.entityId == nil then
if infoObj.args.entityId == nil then
local matching = WikidataCrossValidation.crossValidate(templateArgs[paramName], property, infoObj.args.entityId )
if matching then
table.insert(infoObj.wikidataCats, WikidataCrossValidation.maintainceCategory(matching, property))
end
return false -- no wikidata entity
return false -- no wikidata entity
end
end
if templateArgs[paramName]==nil or templateArgs[paramName]=='' then
if templateArgs[paramName] == nil or templateArgs[paramName] == '' then
templateArgs[paramName] = PropertyLink.getPropertyByOptions( property, infoObj.args.entityId )
templateArgs[paramName] = PropertyLink.getPropertyByOptions( property, infoObj.args.entityId )
if templateArgs[paramName] and #templateArgs[paramName]>0 then
if templateArgs[paramName] and #templateArgs[paramName] > 0 then
usingWikidata = true
usingWikidata = true
end
end
else
else
local matching = WikidataCrossValidation.crossValidate(templateArgs[paramName], property, infoObj.args.entityId )
local pageNs = mw.title.getCurrentTitle().namespace
if pageNs==0 and not infoObj.isNonPerson then
local matching = WikidataCrossValidation.crossValidate(templateArgs[paramName], property, infoObj.args.entityId )
if matching then
table.insert(infoObj.wikidataCats, WikidataCrossValidation.maintainceCategory(matching, property))
end
end
end
return usingWikidata
end
 
local function instanceOfViolation(infoObj)
local pageNs = mw.title.getCurrentTitle().namespace
if pageNs ~= 0 then
return true
end
local wikidataInstanceOf = nil
if infoObj.args.entityId ~= nil then
wikidataInstanceOf = mw.wikibase.getBestStatements(infoObj.args.entityId, 'P31')
wikidataInstanceOf = wikidataInstanceOf and wikidataInstanceOf[1] and wikidataInstanceOf[1].mainsnak
end
if wikidataInstanceOf == nil then
local matching = WikidataCrossValidation.crossValidate('אדם', 'P31', infoObj.args.entityId )
if matching then
if matching then
table.insert(infoObj.wikidataCats, WikidataCrossValidation.maintainceCategory(matching, property))
table.insert(infoObj.wikidataCats, WikidataCrossValidation.maintainceCategory(matching, 'P31'))
end
else
wikidataInstanceOf = wikidataInstanceOf.datavalue and wikidataInstanceOf.datavalue.value and wikidataInstanceOf.datavalue.value.id
if wikidataInstanceOf ~= 'Q5' then
table.insert(infoObj.wikidataCats, '')
return true
end
end
return false
end
 
local function insertInOrder(templateStructure, row)
local inserted = false
for index, existingRow in ipairs(templateStructure) do
if existingRow.indic and existingRow.indic > row.indic then
table.insert(templateStructure, index, row)
inserted = true
break
end
end
 
if not inserted then
table.insert(templateStructure, row)
end
end
 
function filterMinorPrizes( propertyVals )
local tempVals = {}
    for i, property in ipairs(propertyVals) do
    local propValue = property.mainsnak and property.mainsnak.datavalue
    if propValue and propValue.value then
    local subGroup =  mw.wikibase.getBestStatements(propValue.value['id'], 'P279')
    local isMinor = false
    for _, p in pairs(subGroup) do
    local subGroupId = p.mainsnak and p.mainsnak.datavalue and p.mainsnak.datavalue.value and p.mainsnak.datavalue.value.id
if subGroupId=='Q11415564' then
isMinor = true
end
end
if not isMinor then
table.insert(tempVals, property)
end
end
end
return tempVals
end
 
local function useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, label, propertyIds, paramName, opts)
    opts = opts or {}
    local content = templateArgs[paramName]
 
    if disableWikidataFetch then
        if content == nil or content == '' then return end -- No local content, no display
    end
    if content == '-' then return end -- explicitly suppressed
    local row = { label = label }
    if content and content ~= '' then
        row.data = content
        if opts.image == true then
        row.data = dataTemplateModule.getValueOrWikidataImage({
valueArg=content,
width='180'
})
        end
    else
        local values = {}
        if #propertyIds > 0 and not disableWikidataFetch then
            for _, prop in ipairs(propertyIds) do
                local result = PropertyLink.getPropertyByOptions(prop, entityId, {
        allowMulti = opts.multi or false,
        seperator = opts.sep or ', ',
        ['entity-gender-aware'] = opts.genderAware or false,
        qualifiers = opts.qualifiers,
        ['qualifiers-sep'] = opts.qualSep,
        ['default-value'] = opts.qualDefault,
        ['sort'] = opts.sort,
        ['sort-order'] = opts.sortOrder,
        ['img-width'] = '180px',
        ['filter'] = opts.filter
        })
                if result and result ~= '' then
local cleaned_result = mw.ustring.gsub(result, '%[%[%s*[Cc]ategory:[^%[%]]-%]%]', '')
cleaned_result = mw.ustring.gsub(cleaned_result, '%[%[%s*קאטעגאריע:[^%[%]]-%]%]', '')
                if cleaned_result and cleaned_result ~= '' then
                    local valueWithPencil = result .. (opts.pencil ~= false and getPencilLink(entityId, prop) or '')
                    table.insert(values, valueWithPencil)
                end
            end
            end
        end
       
        if #values == 0 then return end
        row.data = table.concat(values, opts.join or '<br/>')
    end
    row.indic = opts.indic or 700
    insertInOrder(infoObj.templateStructure, row)
end
 
local function isRelogiousLeader(entityId)
local religionLeader = false
if entityId == nil then
return false
end
local religionLeaderQIds ={
--jewish
['Q133485'] = true, -- rav
['Q931732']=true, --posek
--islam
['Q217029'] =true, --kadi
['Q1999841']=true, --faqih
['Q125482']=true, --imam
--christ
['Q152002']=true, -- pastor
['Q49476']=true, -- archbishop
['Q611644']=true, --Catholic bishop
}
local wikidataPosition = mw.wikibase.getBestStatements(entityId, 'P106')
if wikidataPosition then
for _,v in pairs(wikidataPosition) do
if v.mainsnak and v.mainsnak.datavalue and v.mainsnak.datavalue.value.id and religionLeaderQIds[v.mainsnak.datavalue.value.id] then
religionLeader=true
end
end
end
return religionLeader
end
 
local function addAdditionalDetails(frame, infoObj, wikidataGender, disableWikidataFetch)
local parentArgs = frame:getParent().args
local directArgs = frame.args
local templateArgs = setmetatable({}, { __index = function(_, key)
return directArgs[key] ~= nil and directArgs[key] or parentArgs[key]
end })
local entityId = infoObj.args.entityId
-- Determine the correct label for "Known For" based on gender
local knownForLabel = (wikidataGender == 'נקבה' and 'ידועה בשל' or 'ידוע בשל')
 
useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'קבורה', {'P119'}, 'קבורה', {multi=true, pencil=true, indic=5})
useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'תאריך עלייה', {}, 'תאריך עלייה', {indic=10})
-- Full name
local full_name_content =templateArgs['שם מלא']
local birth_name_content = templateArgs['שם לידה']
if full_name_content and full_name_content ~= '-' then
if (birth_name_content and birth_name_content ~= "-" and full_name_content ~= birth_name_content) or (not birth_name_content) then
useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'שם מלא', {}, 'שם מלא', {indic=13})
end
end
useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'שם לידה', {'P1477'}, 'שם לידה', {pencil=true, indic=15})
country_label = templateArgs['סוג ישות'] or 'מדינה'
useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, country_label, {'P27'}, 'מדינה', {pencil=true, indic=20})
useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'לאום', {'P172'}, 'לאום', {pencil=true, indic=22})
useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'וואוין ארט', {'P551'}, 'וואוין ארט', {multi=true, sep='*', join='*', pencil=true, indic=25})
useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'כינוי', {'P1449'}, 'כינוי', {pencil=true, indic=30})
useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'פעילות בולטת', {}, 'פעילות בולטת', {indic=35})
useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, knownForLabel, {}, 'ידוע בשל', {indic=40})
useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'השכלה', {'P69'}, 'השכלה', {multi=true, qualifiers={'P582'}, sort={'P582'}, sortOrder='asc', sep='*', join='*', pencil=true, indic=45})
 
-- Time range
start_args = templateArgs['התחלת פעילות'] or ''
end_args = templateArgs['סיום פעילות'] or ''
if (not disableWikidataFetch) or (start_args ~= '' and end_args ~= '') then
local timeRangeArgs = {
['תאריך התחלה'] = start_args,
['תאריך סיום'] = end_args,
['הצגת הפרשת זמנים'] = 'כן',
['הווה'] = 'הווה,היום',
['טקסט הווה'] = 'הווה',
['טקסט התחלה'] = 'מ-%s',
['טקסט סיום'] = 'עד ל-%s',
['תאריך התחלה-ויקינתונים'] = 'P2031',
['תאריך סיום-ויקינתונים'] = 'P2032',
['גבול תאריך סיום-ויקינתונים'] = 'P570'
}
local timeRange = TimeRange['טווח זמנים'](frame:newChild{ args = timeRangeArgs })
if timeRange and timeRange ~= '' then
insertInOrder(infoObj.templateStructure, {
label = 'תקופת פעילות',
data = timeRange,
indic = 50
})
end
end
useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'עיסוק', {}, 'עיסוק', {indic=55})
useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'מעסיק', {}, 'מעסיק', {indic=60})
useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'תארים', {'P812', 'P811', 'P512', 'P97', 'P2962'}, 'תואר', {multi=true, pencil=true, indic=65})
useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'מפלגה', {'P102'}, 'מפלגה', {multi=true, pencil=true, indic=70})
local religionLeader = isRelogiousLeader(entityId)
--deathCauseWikidata = deathCauseWikidata and deathCauseWikidata[1] and deathCauseWikidata[1].mainsnak
useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch or religionLeader, 'השקפה דתית', {'P140'}, 'השקפה דתית', {pencil=true, indic=75})
 
-- Spouse + Partner
local spouseVal = templateArgs['מאן'] or templateArgs['ווייב'] or ""
if (not disableWikidataFetch) or spouseVal ~= '' then
if spouseVal ~= '-' then
local output = {}
if spouseVal and spouseVal ~= '' then
table.insert(output, spouseVal)
else
for _, prop in ipairs({'P26', 'P451'}) do
local result = PropertyLink.getPropertyByOptions(prop, entityId, {
allowMulti = true,
seperator = '*',
['entity-gender-aware'] = true,
qualifiers = {'P580', 'P582'},
['qualifiers-sep'] = ' – ',
['default-value'] = '?'
})
if result and result ~= '' then
table.insert(output, result .. getPencilLink(entityId, prop))
end
end
end
if #output > 0 then
insertInOrder(infoObj.templateStructure, {
label = ((templateArgs['מאן']) and 'מאן') or ((templateArgs['ווייב']) and 'ווייב') or 'מאן אדער ווייב',
data = table.concat(output, '\n*'),
indic = 80
})
end
end
end
 
useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'קינדער', {'P40'}, 'קינדער', {pencil=true, multi=true, indic=85})
useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'צאל קינדער', {'P1971'}, 'צאל קינדער', {pencil=true, indic=90})
useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'פרסים והוקרה', {'P166'}, 'פרסים והוקרה', {multi=true, sep='*', join='*', pencil=true, indic=95, qualifiers={'P585'}, sortOrder = 'desc', filter = filterMinorPrizes})
 
-- Signature (P109)
useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'חתימה', {'P109'}, 'חתימה', {pencil=true, image=true, indic=100})
 
-- Official website (P856)
local siteInput = templateArgs['אתר אינטרנט'] or ""
if (not disableWikidataFetch) or siteInput ~= "" then
local childFrame = frame:newChild{ args = { ['1'] = siteInput } }
local siteVal = siteModule.site(childFrame)
if siteVal and siteVal ~= '' then
insertInOrder(infoObj.templateStructure, {
label,
data = siteVal,
indic = 300
})
end
end
end
end
return usingWikidata
end
end


function addPersonDetails(frame, infoObj)
function addPersonDetails(frame, infoObj)
local templateArgs = frame:getParent().args
local templateArgs = frame:getParent().args
local args = infoObj.args
local disableWikidataFetch = infoObj.args.title == '-'
local usingBirthWikidata = false
local usingBirthWikidata = false
local usingDeathWikidata = false
local usingDeathWikidata = false
local birthLabel = 'געבורט'
local birthLabel = 'געבורט'
local deathLabel = 'טויט'  
local deathLabel = 'פטירה'  
 
infoObj.isNonPerson = instanceOfViolation(infoObj)
if not disableWikidataFetch then
-- fill birth/death dates from wikidata if missing and the person is not a human biblical figure
--[[
if PropertyLink.getItem('P31', infoObj.args.entityId) ~= "Q20643955" then
usingBirthWikidata = fillWikidataParam(templateArgs, 'תאריך לידה', 'P569', infoObj)
usingDeathWikidata = fillWikidataParam(templateArgs, 'תאריך פטירה', 'P570', infoObj)
end
]]
 
-- יחידה:אידישע דאטום ווערט פארלוירן מיט יארן בעפאר ד'ק"כ
local genBirthDate = templateArgs['תאריך לידה'] or templateArgs['געבורט דאטום']
if genBirthDate == nil and templateArgs['תאריך לידה עברי'] ~= nil then
local l = frame:preprocess(templateArgs['תאריך לידה עברי']) -- preprocess, to handle {{לינק צו אידיש יאר}}
if #mw.text.split(l, '%s' ) == 1 or enclosed(l) then --most probably just year or yearlink
if #mw.text.split(l, '%s' ) > 1 then
l = l:match("%[%[.-|(.*)%]%]") or l:match("%[%[(.-)%]%]") -- try after pipe first, fallback and get the whole if there is no pipe
end
local birthParts = mw.text.split( l, "'", true )
if #birthParts == 1 then
table.insert(birthParts, 1, '') -- אדער אלף החמישי?
end
local BirthDateNum = gim.gimatria(birthParts[1])*1000 + gim.gimatria(birthParts[2]) - 3760
if BirthDateNum < 1 then
genBirthDate = tostring(math.abs(BirthDateNum)) .. " לפנה\"ס"
elseif BirthDateNum < 4120 then
genBirthDate = tostring(BirthDateNum)
end
end
end
local genDeathDate = templateArgs['תאריך פטירה'] or templateArgs['פטירה דאטום']
if genDeathDate == nil and templateArgs['תאריך פטירה עברי'] ~= nil then
local p = frame:preprocess(templateArgs['תאריך פטירה עברי']) -- preprocess, to handle {{לינק צו אידיש יאר}}
if #mw.text.split(p, '%s' ) == 1 or enclosed(p) then --most probably just year or yearlink
if #mw.text.split(p, '%s' ) > 1 then
p = p:match("%[%[.-|(.*)%]%]") or p:match("%[%[(.-)%]%]") -- try after pipe first, fallback and get the whole if there is no pipe
end
local deathParts = mw.text.split( p, "'", true )
if #deathParts == 1 then
table.insert(deathParts, 1, '') -- אדער אלף החמישי?
end
local DeathDateNum = gim.gimatria(deathParts[1])*1000 + gim.gimatria(deathParts[2]) - 3760
if DeathDateNum < 1 then
genDeathDate = tostring(math.abs(DeathDateNum)) .. " לפנה\"ס"
elseif DeathDateNum < 4120 then
genDeathDate = tostring(DeathDateNum)
end
end
end
-- fill birth/death dates from wikidata is missing
local birthDate = getSpeculativeDate(genBirthDate, templateArgs['תאריך לידה עברי'])
usingBirthWikidata = fillWikidataParam(templateArgs, 'תאריך לידה', 'P569', infoObj)
local deathDate = getSpeculativeDate(genDeathDate, templateArgs['תאריך פטירה עברי'])
usingDeathWikidata = fillWikidataParam(templateArgs, 'תאריך פטירה', 'P570', infoObj)
if birthDate ~= nil then
local age = nil
if deathDate == nil and not templateArgs['ללא גיל'] then
age = ageModule.ageCalc(birthDate, nil, true, false, true, nil, wikidataGender) or ''
end
local birthDetails, usingBirthWikidataEvent = getEventDetails(templateArgs['תאריך לידה'] or templateArgs['געבורט דאטום'], templateArgs['תאריך לידה עברי'], templateArgs['מקום לידה'] or templateArgs['געבורט ארט'], 'P569', 'P19', age, usingBirthWikidata, infoObj)
table.insert(infoObj.templateStructure, 1, {
label = birthLabel,
data = birthDetails
})
usingBirthWikidata = usingBirthWikidata or usingBirthWikidataEvent
elseif templateArgs['געבורט ארט'] ~= '-' then
fillWikidataParam(templateArgs, 'געבורט ארט', 'P19', infoObj)
if templateArgs['געבורט ארט'] ~= nil and templateArgs['געבורט ארט'] ~= '' then -- only if we fill the parameter eventually - add to template
table.insert(infoObj.templateStructure, 1, {
label = birthLabel,
data = templateArgs['געבורט ארט']
})
end
end
local birthDate = getSpeculativeDate(templateArgs['תאריך לידה'], templateArgs['תאריך לידה עברי'])
deathLabel = getDeathLabel(templateArgs['סיבת המוות'], infoObj.args.entityId, wikidataGender)
local deathDate = getSpeculativeDate(templateArgs['תאריך פטירה'], templateArgs['תאריך פטירה עברי'])
if deathDate ~= nil then
if birthDate~=nil then
local age = ''
local age = nil
if not templateArgs['ללא גיל'] then
if deathDate==nil then
age = ageModule.ageCalc(birthDate, deathDate, false, false, true) or ''
age = ageModule.ageCalc(birthDate, nil, true, false, true) or ''
end
local deathDetails, usingDeathWikidataEvent = getEventDetails(templateArgs['תאריך פטירה'] or templateArgs['פטירה דאטום'], templateArgs['תאריך פטירה עברי'], templateArgs['מקום פטירה'] or templateArgs['פטירה ארט'], 'P570', 'P20', age, usingDeathWikidata, infoObj)
table.insert(infoObj.templateStructure, 2, {
label=deathLabel,
data=deathDetails
})
usingDeathWikidata = usingDeathWikidata or usingDeathWikidataEvent
elseif templateArgs['פטירה ארט'] ~= '-' then
fillWikidataParam(templateArgs, 'פטירה ארט', 'P20', infoObj)
if templateArgs['פטירה ארט'] ~= nil and templateArgs['פטירה ארט'] ~= '' then -- only if we fill the parameter eventually - add to template
table.insert(infoObj.templateStructure, 2, {
label=deathLabel,
data= templateArgs['פטירה ארט']
})
end
end
end
local birthDetails, usingBirthWikidataEvent = getEventDetails(templateArgs['תאריך לידה'], templateArgs['תאריך לידה עברי'], templateArgs['מקום לידה'], 'P569', 'P19', age, usingBirthWikidata, infoObj.args.entityId)
if infoObj.isSelfUse then
table.insert(infoObj.templateStructure, 1, {
table.insert(infoObj.templateStructure, 1, {
label='געבורט',
label=birthLabel,
data=birthDetails
data='{{{תאריך לידה}}}<br/>{{{געבורט ארט}}}'
})
})
usingBirthWikidata = usingBirthWikidata or usingBirthWikidataEvent
else
    if templateArgs['מקום לידה']~= '-' and templateArgs['מקום לידה']~= '' and  templateArgs['מקום לידה']~=nil and #templateArgs['מקום לידה']>0 then
table.insert(infoObj.templateStructure, 1, {
    label=birthLabel,
    data= templateArgs['מקום לידה']
})
  end
    end
if deathDate~=nil then
deathLabel = getDeathLabel(templateArgs['סיבת המוות'], infoObj.args.entityId)
local age =  ageModule.ageCalc(birthDate, deathDate, false, false, true) or ''
local deathDetails, usingDeathWikidataEvent = getEventDetails(templateArgs['תאריך פטירה'], templateArgs['תאריך פטירה עברי'], templateArgs['מקום פטירה'], 'P570', 'P20', age, usingDeathWikidata, infoObj.args.entityId)
table.insert(infoObj.templateStructure, 2, {
table.insert(infoObj.templateStructure, 2, {
label=deathLabel,
label=deathLabel,
data=deathDetails
data='{{{תאריך פטירה}}}<br/>{{{פטירה ארט}}}'
})
})
usingDeathWikidata = usingDeathWikidata or usingDeathWikidataEvent
end
end
if usingBirthWikidata or usingDeathWikidata then
if infoObj.isSelfUse then
infoObj.args.usingWikidata = true
end
if frame.args['כותרת0'] then
table.insert(infoObj.templateStructure, 1, {
table.insert(infoObj.templateStructure, 1, {
label=birthLabel,
header=1,
data='{{{תאריך לידה}}}<br/>{{{מקום לידה}}}'
data=frame.args['כותרת0'],
rowstyle=frame.args['עיצוב-שורה0'],
rowclass=frame.args['מחלקה-שורה0'],
headerstyle=frame.args['כותרת0-עיצוב']
})
})
table.insert(infoObj.templateStructure, 2, {
end
label=deathLabel,
data='{{{תאריך פטירה}}} <br/>{{{מקום פטירה}}}'
})
end
if usingBirthWikidata or usingDeathWikidata then
--[[
infoObj.args.usingWikidata = true
if frame.args['תמונה'] ~= '-' then
addMissingImage(infoObj, birthDate, deathDate, wikidataGender)
end
]]
end
end
if frame.args['כותרת0'] then
addAdditionalDetails(frame, infoObj, wikidataGender, disableWikidataFetch)
table.insert(infoObj.templateStructure, 1, {
header=1,
data=frame.args['כותרת0'],
rowstyle=frame.args['עיצוב-שורה0'],
rowclass=frame.args['מחלקה-שורה0'],
headerstyle=frame.args['כותרת0-עיצוב']
})
end
 
if frame.args['תמונה']~='-' then
addMissingImage(infoObj, birthDate, deathDate)
end
end
end


function infobox(frame)
function infobox(frame)
local infoObj = Infobox:new()
local infoObj = Infobox:new()
frame.args['תמונה-גודל'] = frame.args['תמונה-גודל'] or '220'
frame.args['תמונה-גודל'] = frame.args['תמונה-גודל'] or '220'
 
local colorKey = frame.args["סיווג"] or frame.args["סוג"] or frame:getParent().args["סיווג"] or frame:getParent().args["סוג"]
local color = BackgroundColors[colorKey] or BackgroundColors["default"] or "#eeeeee"
 
infoObj.args.headerstyle = "background:" .. color .. ";" .. (infoObj.args.headerstyle or "")
local is_white_text = BackgroundColors[colorKey] == '#000000' or BackgroundColors[colorKey] == '#800000'
local header_style = "background:" .. color .. "; border:1px solid #aaaaaa; border-bottom:0px; color:" .. (is_white_text and 'white' or 'black')
frame.args['כותרת-עיצוב'] = header_style .. ";" .. (frame.args['כותרת-עיצוב'] or "")
frame.args['כותרת תבנית-עיצוב'] = header_style .. ";" .. (frame.args['כותרת תבנית-עיצוב'] or "")
frame.args['תת-כותרת תבנית-עיצוב'] = header_style .. ";" .. (frame.args['תת-כותרת תבנית-עיצוב'] or "")
infoObj:parseArgs(frame)
infoObj:parseArgs(frame)
 
if infoObj.args.title~='-' then
addPersonDetails(frame, infoObj)
addPersonDetails(frame, infoObj)
 
end
return infoObj:render()
return infoObj:render()
end
end


return {
return {

יעצטיגע רעוויזיע זינט 03:42, 15 יולי 2025

מען קען שאפן דאקומענטאציע פאר דעם מאדול ביי יחידה:תבנית מידע/אישיות/דאק

local dataTemplateModule = require('Module:תבנית מידע')
local Infobox = dataTemplateModule.Infobox
local BackgroundColors = mw.loadJsonData('Module:תבנית מידע/אישיות/צבע רקע לפי סיווג.json')
local LocationAndCountry = require('Module:LocationAndCountry')
local PropertyLink = require('Module:PropertyLink')
local ageModule = require('Module:עלטער')
local Date = require('Module:דאטום')
local hebrewDateModule = require('Module:אידישע דאטום')
local WikidataCrossValidation = require('Module:WikidataCrossValidation')
local siteModule = require('Module:תבנית מידע/אתר')
local TimeRange = require('Module:טווח זמנים')
local gim = require( "Module:גימטריה" )
function count(str, substring)
    local count = 0
    local _, occurrences = string.gsub(str, substring, function()
        count = count + 1
    end)
    return count
end
function enclosed(s)
	return mw.ustring.sub(s, 1, 2) == "[[" and mw.ustring.sub(s, -2) == "]]" and count(s, "%[%[") == 1
end

--[[ Get general date if known, otherwise guess from hebrew date.
]]
function getSpeculativeDate(generalDate, hebrewDate)
	if generalDate == '-' then return nil end
	if generalDate ~= nil and generalDate ~= '' then return generalDate end
	if hebrewDate ~= nil and hebrewDate ~= '' then
		local success, sepcDate = pcall(hebrewDateModule.pick, mw.getCurrentFrame():newChild{ args = {hebrew=hebrewDate, world='', exact='כן' } })
		if not success or sepcDate == '' then return nil end
		return sepcDate
	end
	return nil
end

local function getPencilLink(entityId, prop)
	if not entityId then return '' end
	return string.format(' [[File:Blue pencil RTL.svg|15px|link=https://www.wikidata.org/wiki/%s?uselang=he#%s|עריכת הנתון בוויקינתונים]]', entityId, prop)
end

local function getDeathLabel(deathCause, entityId, gender)
	local result=''
	local fromWikidata=nil
	entityId = nil
	if ( deathCause == nil or deathCause == '' ) and entityId ~= nil then
		local deathCauseWikidata = mw.wikibase.getBestStatements(entityId, 'P1196')
		deathCauseWikidata = deathCauseWikidata and deathCauseWikidata[1] and deathCauseWikidata[1].mainsnak
		if deathCauseWikidata then
			deathCause = mw.wikibase.renderSnak(deathCauseWikidata)
			fromWikidata=true
		end
	end

	if deathCause and deathCause ~= '' then
		if deathCause == 'נהרג' or deathCause == 'נהרגה' or deathCause == 'מוות בקרב' or deathCause == 'נהרג בקרב' or deathCause == 'נהרגה בקרב' or deathCause == 'תאונה' or deathCause == 'טביעה' then
			return (gender=='נקבה' and 'נהרגה') or 'נהרג'
		elseif deathCause == 'נעדר' or deathCause == 'נעדרת' then
			return (gender=='נקבה' and 'נעדרת') or 'נעדר'
		elseif deathCause == 'נרצח' or deathCause == 'נרצחה' or deathCause == 'רצח' or deathCause == 'רצח המוני' or deathCause == 'רעל' then
			return (gender=='נקבה' and 'נרצחה') or 'נרצח'
		elseif deathCause == 'התאבד' or deathCause == 'התאבדה' or deathCause == 'התאבדות' then
			return (gender=='נקבה' and 'התאבדה') or 'התאבד'
		elseif deathCause == 'הוצא להורג' or deathCause == 'הוצאה להורג' or deathCause == 'עונש מוות' or deathCause == 'תלייה' then
			return 'הוצאה להורג'
		elseif not fromWikidata then result = '[[קאטעגאריע:ערכים עם סיבת מוות שגויה בתבנית]]'
		end
	end
	return result .. 'פטירה'
end

function getEventDetails(generalDate, hebDate, eventPlace, propDate, propPlace, age, usingWikidata, infoObj)
	entityId = nil --infoObj.args.entityId or mw.wikibase.getEntityIdForCurrentPage()
	age = age or ''
	local formattedEvent = ''
	local placeDate = propDate
	if generalDate ~= nil and generalDate ~= '' then
		local success, placeDateParsed = pcall(Date.newFromWikitext, generalDate)
		if success then
			placeDate = placeDateParsed
		end
		formattedEvent = generalDate .. age
		if hebDate ~= nil and hebDate ~= '' then 
			formattedEvent = formattedEvent .. '<br/>' .. hebDate
		end
	elseif hebDate ~= nil and hebDate ~= '' then
		formattedEvent = hebDate .. age
	end
	
	if (eventPlace == nil or eventPlace == '') and entityId then
		local success, res = pcall(LocationAndCountry.displayFromParams, propPlace, entityId, placeDate , 1)
		if success and res and #res > 0 then
			usingWikidata = true
			eventPlace = res
		end
	else
		local pageNs = mw.title.getCurrentTitle().namespace
		if pageNs==0 and not infoObj.isNonPerson then
			local matching = WikidataCrossValidation.crossValidate(eventPlace, propPlace, entityId)
			if matching then
				table.insert(infoObj.wikidataCats, WikidataCrossValidation.maintainceCategory(matching, propPlace))
			end
		end
	end

	if eventPlace~='' and eventPlace~=nil and eventPlace~='-' then
		formattedEvent = formattedEvent..'<br/>' ..eventPlace
	end
	
	if usingWikidata and entityId then
		formattedEvent = formattedEvent .. getPencilLink(entityId, 'P856')
	end

	return formattedEvent, usingWikidata
end

-- Split the comma-separated lists into tables and sort them
local function splitString(inputstr, sep)
	local sep, fields = sep or ",", {}
	local pattern = string.format("([^%s]+)", sep)
	inputstr:gsub(pattern, function(c) fields[#fields + 1] = c end)
	return fields
end

function addMissingImage(infoObj, birthDate, deathDate, gender)
	if infoObj.args.image ~= nil and #infoObj.args.image > 0 then return end -- there is already image 
	
	-- Assuming you have defined deathDate and birthDate earlier
	local latestDate = deathDate or birthDate
	if latestDate == nil then return end
	
	-- Split the comma-separated lists and extract dates
	local dateList = splitString(latestDate:gsub(" או ", ","), ",")
	if #dateList == 0 then return end
	
	local countSuccess = 0
	for i, date in ipairs(dateList) do
		local success, DateRes = pcall(Date.newFromWikitext, date)
		if success then
			dateList[i] = DateRes
			countSuccess = countSuccess + 1
		end
	end

	if #dateList > 1 and countSuccess == #dateList then
		latestDate = dateList[1]
		for i, date in ipairs(dateList) do
			if i ~= 1 then
				local success, DateLeRes = pcall(Date.le, latestDate, date)
				if DateLeRes then
					latestDate = date
				end
			end
		end
		latestDate = os.time(latestDate)
		latestDate = os.date("%d %m %Y", latestDate)
	end

	local success, res = pcall(Date.parseDateRange, latestDate, 'raw')
	
	if success==false then return end -- there is no known VALID date
	local yearsEstimated = res/(60*60*24*365)
	if yearsEstimated>150 then return end 
	
	local frame = mw.getCurrentFrame()
	infoObj.args.image = frame:expandTemplate{ title = 'אין תמונה', args = { gender, ['יישור'] = 'מרכז' } }
end

function fillWikidataParam(templateArgs, paramName, property, infoObj)
	local usingWikidata = false
	if infoObj.args.entityId == nil then
		local matching = WikidataCrossValidation.crossValidate(templateArgs[paramName], property, infoObj.args.entityId )
		if matching then
			table.insert(infoObj.wikidataCats, WikidataCrossValidation.maintainceCategory(matching, property))
		end
		return false -- no wikidata entity
	end
	if templateArgs[paramName] == nil or templateArgs[paramName] == '' then
		templateArgs[paramName] = PropertyLink.getPropertyByOptions( property, infoObj.args.entityId )
		if templateArgs[paramName] and #templateArgs[paramName] > 0 then
			usingWikidata = true
		end
	else
		local pageNs = mw.title.getCurrentTitle().namespace
		if pageNs==0 and not infoObj.isNonPerson then
			local matching = WikidataCrossValidation.crossValidate(templateArgs[paramName], property, infoObj.args.entityId )
			if matching then
				table.insert(infoObj.wikidataCats, WikidataCrossValidation.maintainceCategory(matching, property))
			end
		end
	end
	return usingWikidata
end

local function instanceOfViolation(infoObj)
	local pageNs = mw.title.getCurrentTitle().namespace
	if pageNs ~= 0 then
		return true
	end
	
	local wikidataInstanceOf = nil
	if infoObj.args.entityId ~= nil then
		wikidataInstanceOf = mw.wikibase.getBestStatements(infoObj.args.entityId, 'P31')
		wikidataInstanceOf = wikidataInstanceOf and wikidataInstanceOf[1] and wikidataInstanceOf[1].mainsnak
	end
	
	if wikidataInstanceOf == nil then
		local matching = WikidataCrossValidation.crossValidate('אדם', 'P31', infoObj.args.entityId )
		if matching then
			table.insert(infoObj.wikidataCats, WikidataCrossValidation.maintainceCategory(matching, 'P31'))
		end
	else
		wikidataInstanceOf = wikidataInstanceOf.datavalue and wikidataInstanceOf.datavalue.value and wikidataInstanceOf.datavalue.value.id
		if wikidataInstanceOf ~= 'Q5' then
			table.insert(infoObj.wikidataCats, '')
			return true
		end
	end
	return false
end

local function insertInOrder(templateStructure, row)
	local inserted = false
	for index, existingRow in ipairs(templateStructure) do
		if existingRow.indic and existingRow.indic > row.indic then
			table.insert(templateStructure, index, row)
			inserted = true
			break
		end
	end

	if not inserted then
		table.insert(templateStructure, row)
	end
end

function filterMinorPrizes( propertyVals )
	local tempVals = {}
    for i, property in ipairs(propertyVals) do
    	local propValue = property.mainsnak and property.mainsnak.datavalue
    	if propValue and propValue.value then
    		local subGroup =  mw.wikibase.getBestStatements(propValue.value['id'], 'P279')
    		local isMinor = false
    		for _, p in pairs(subGroup) do
    			local subGroupId = p.mainsnak and p.mainsnak.datavalue and p.mainsnak.datavalue.value and p.mainsnak.datavalue.value.id
				if subGroupId=='Q11415564' then
					isMinor = true
				end
			end
			if not isMinor then
				table.insert(tempVals, property)
			end
		end
	end
	return tempVals
end

local function useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, label, propertyIds, paramName, opts)
	    opts = opts or {}
	    local content = templateArgs[paramName]

	    if disableWikidataFetch then
	        if content == nil or content == '' then return end -- No local content, no display
	    end
		
	    if content == '-' then return end -- explicitly suppressed
	
	    local row = { label = label }
	    if content and content ~= '' then
	        row.data = content
	        if opts.image == true then
	        	row.data = dataTemplateModule.getValueOrWikidataImage({
					valueArg=content,
					width='180'
				})
	        end
	    else
	        local values = {}
	        if #propertyIds > 0 and not disableWikidataFetch then
	            for _, prop in ipairs(propertyIds) do
	                local result = PropertyLink.getPropertyByOptions(prop, entityId, {
	        allowMulti = opts.multi or false,
	        seperator = opts.sep or ', ',
	        ['entity-gender-aware'] = opts.genderAware or false,
	        qualifiers = opts.qualifiers,
	        ['qualifiers-sep'] = opts.qualSep,
	        ['default-value'] = opts.qualDefault,
	        ['sort'] = opts.sort,
	        ['sort-order'] = opts.sortOrder,
	        ['img-width'] = '180px',
	        ['filter'] = opts.filter
	        })
	                if result and result ~= '' then
						local cleaned_result = mw.ustring.gsub(result, '%[%[%s*[Cc]ategory:[^%[%]]-%]%]', '')
						cleaned_result = mw.ustring.gsub(cleaned_result, '%[%[%s*קאטעגאריע:[^%[%]]-%]%]', '')
		                if cleaned_result and cleaned_result ~= '' then
		                    local valueWithPencil = result .. (opts.pencil ~= false and getPencilLink(entityId, prop) or '')
		                    table.insert(values, valueWithPencil)
		                end
		            end
	            end
	        end
	        
	        if #values == 0 then return end
	        row.data = table.concat(values, opts.join or '<br/>')
	    end
	
	    row.indic = opts.indic or 700
	    insertInOrder(infoObj.templateStructure, row)
end

local function isRelogiousLeader(entityId)
	local religionLeader = false
	if entityId == nil then
		return false
	end
	local religionLeaderQIds ={
		--jewish
		['Q133485'] = true, -- rav
		['Q931732']=true, --posek
		--islam
		['Q217029'] =true, --kadi
		['Q1999841']=true, --faqih
		['Q125482']=true, --imam
		--christ
		['Q152002']=true, -- pastor
		['Q49476']=true, -- archbishop
		['Q611644']=true, --Catholic bishop
	}
	local wikidataPosition = mw.wikibase.getBestStatements(entityId, 'P106')
	if wikidataPosition then
		for _,v in pairs(wikidataPosition) do
			if v.mainsnak and v.mainsnak.datavalue and v.mainsnak.datavalue.value.id and religionLeaderQIds[v.mainsnak.datavalue.value.id] then
				religionLeader=true
			end
		end
	end
	return religionLeader
end

local function addAdditionalDetails(frame, infoObj, wikidataGender, disableWikidataFetch)
	local parentArgs = frame:getParent().args
	local directArgs = frame.args
	local templateArgs = setmetatable({}, { __index = function(_, key)
		return directArgs[key] ~= nil and directArgs[key] or parentArgs[key]
	end })
	local entityId = infoObj.args.entityId
	-- Determine the correct label for "Known For" based on gender
	local knownForLabel = (wikidataGender == 'נקבה' and 'ידועה בשל' or 'ידוע בשל')

	useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'קבורה', {'P119'}, 'קבורה', {multi=true, pencil=true, indic=5})
	useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'תאריך עלייה', {}, 'תאריך עלייה', {indic=10})
	
	-- Full name
	local full_name_content =templateArgs['שם מלא']
	local birth_name_content = templateArgs['שם לידה']
	
	if full_name_content and full_name_content ~= '-' then
		if (birth_name_content and birth_name_content ~= "-" and full_name_content ~= birth_name_content) or (not birth_name_content) then
			useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'שם מלא', {}, 'שם מלא', {indic=13})
		end
	end
	
	useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'שם לידה', {'P1477'}, 'שם לידה', {pencil=true, indic=15})
	
	country_label = templateArgs['סוג ישות'] or 'מדינה'
	
	useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, country_label, {'P27'}, 'מדינה', {pencil=true, indic=20})
	useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'לאום', {'P172'}, 'לאום', {pencil=true, indic=22})
	
	useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'וואוין ארט', {'P551'}, 'וואוין ארט', {multi=true, sep='*', join='*', pencil=true, indic=25})
	
	useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'כינוי', {'P1449'}, 'כינוי', {pencil=true, indic=30})
	useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'פעילות בולטת', {}, 'פעילות בולטת', {indic=35})
	useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, knownForLabel, {}, 'ידוע בשל', {indic=40})
	useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'השכלה', {'P69'}, 'השכלה', {multi=true, qualifiers={'P582'}, sort={'P582'}, sortOrder='asc', sep='*', join='*', pencil=true, indic=45})

	-- Time range
	start_args = templateArgs['התחלת פעילות'] or ''
	end_args = templateArgs['סיום פעילות'] or ''
	if (not disableWikidataFetch) or (start_args ~= '' and end_args ~= '') then
		local timeRangeArgs = {
			['תאריך התחלה'] = start_args,
			['תאריך סיום'] = end_args,
			['הצגת הפרשת זמנים'] = 'כן',
			['הווה'] = 'הווה,היום',
			['טקסט הווה'] = 'הווה',
			['טקסט התחלה'] = 'מ-%s',
			['טקסט סיום'] = 'עד ל-%s',
			['תאריך התחלה-ויקינתונים'] = 'P2031',
			['תאריך סיום-ויקינתונים'] = 'P2032',
			['גבול תאריך סיום-ויקינתונים'] = 'P570'
		}
		
		local timeRange = TimeRange['טווח זמנים'](frame:newChild{ args = timeRangeArgs })
		if timeRange and timeRange ~= '' then
			insertInOrder(infoObj.templateStructure, {
				label = 'תקופת פעילות',
				data = timeRange,
				indic = 50
			})
		end
	end
	
	useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'עיסוק', {}, 'עיסוק', {indic=55})
	useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'מעסיק', {}, 'מעסיק', {indic=60})
	useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'תארים', {'P812', 'P811', 'P512', 'P97', 'P2962'}, 'תואר', {multi=true, pencil=true, indic=65})
	useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'מפלגה', {'P102'}, 'מפלגה', {multi=true, pencil=true, indic=70})
	local religionLeader = isRelogiousLeader(entityId)
	
	--deathCauseWikidata = deathCauseWikidata and deathCauseWikidata[1] and deathCauseWikidata[1].mainsnak
	useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch or religionLeader, 'השקפה דתית', {'P140'}, 'השקפה דתית', {pencil=true, indic=75})

	-- Spouse + Partner
	local spouseVal = templateArgs['מאן'] or templateArgs['ווייב'] or ""
	if (not disableWikidataFetch) or spouseVal ~= '' then
		if spouseVal ~= '-' then
			local output = {}
			if spouseVal and spouseVal ~= '' then
				table.insert(output, spouseVal)
			else
				for _, prop in ipairs({'P26', 'P451'}) do
					local result = PropertyLink.getPropertyByOptions(prop, entityId, {
						allowMulti = true,
						seperator = '*',
						['entity-gender-aware'] = true,
						qualifiers = {'P580', 'P582'},
						['qualifiers-sep'] = ' – ',
						['default-value'] = '?'
					})
					if result and result ~= '' then
						table.insert(output, result .. getPencilLink(entityId, prop))
					end
				end
			end
			if #output > 0 then
				insertInOrder(infoObj.templateStructure, {
					label = ((templateArgs['מאן']) and 'מאן') or ((templateArgs['ווייב']) and 'ווייב') or 'מאן אדער ווייב',
					data = table.concat(output, '\n*'),
					indic = 80
				})
			end
		end
	end

	useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'קינדער', {'P40'}, 'קינדער', {pencil=true, multi=true, indic=85})
	useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'צאל קינדער', {'P1971'}, 'צאל קינדער', {pencil=true, indic=90})
	useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'פרסים והוקרה', {'P166'}, 'פרסים והוקרה', {multi=true, sep='*', join='*', pencil=true, indic=95, qualifiers={'P585'}, sortOrder = 'desc', filter = filterMinorPrizes})

	-- Signature (P109)
	useArgsOrWikidata(templateArgs, infoObj, disableWikidataFetch, 'חתימה', {'P109'}, 'חתימה', {pencil=true, image=true, indic=100})

	-- Official website (P856)
	local siteInput = templateArgs['אתר אינטרנט'] or ""
	if (not disableWikidataFetch) or siteInput ~= "" then
		local childFrame = frame:newChild{ args = { ['1'] = siteInput } }
		local siteVal = siteModule.site(childFrame)
		if siteVal and siteVal ~= '' then
			insertInOrder(infoObj.templateStructure, {
				label,
				data = siteVal,
				indic = 300
			})
		end
	end
end

function addPersonDetails(frame, infoObj)
	local templateArgs = frame:getParent().args
	local args = infoObj.args
	local disableWikidataFetch = infoObj.args.title == '-' 
	local usingBirthWikidata = false
	local usingDeathWikidata = false
	local birthLabel = 'געבורט'
	local deathLabel = 'פטירה' 

	infoObj.isNonPerson = instanceOfViolation(infoObj)
		
	if not disableWikidataFetch then
		-- fill birth/death dates from wikidata if missing and the person is not a human biblical figure
		--[[
		if PropertyLink.getItem('P31', infoObj.args.entityId) ~= "Q20643955" then
			usingBirthWikidata = fillWikidataParam(templateArgs, 'תאריך לידה', 'P569', infoObj)
			usingDeathWikidata = fillWikidataParam(templateArgs, 'תאריך פטירה', 'P570', infoObj)
		end
		]]

	-- יחידה:אידישע דאטום ווערט פארלוירן מיט יארן בעפאר ד'ק"כ
	local genBirthDate = templateArgs['תאריך לידה'] or templateArgs['געבורט דאטום']
	if genBirthDate == nil and templateArgs['תאריך לידה עברי'] ~= nil then
		local l = frame:preprocess(templateArgs['תאריך לידה עברי']) -- preprocess, to handle {{לינק צו אידיש יאר}}
		if #mw.text.split(l, '%s' ) == 1 or enclosed(l) then --most probably just year or yearlink
			if #mw.text.split(l, '%s' ) > 1 then
				l = l:match("%[%[.-|(.*)%]%]") or l:match("%[%[(.-)%]%]") -- try after pipe first, fallback and get the whole if there is no pipe
			end
			local birthParts = mw.text.split( l, "'", true )
			if #birthParts == 1 then
				table.insert(birthParts, 1, '') -- אדער אלף החמישי?
			end
			local BirthDateNum = gim.gimatria(birthParts[1])*1000 + gim.gimatria(birthParts[2]) - 3760
			if BirthDateNum < 1 then
				genBirthDate = tostring(math.abs(BirthDateNum)) .. " לפנה\"ס"
			elseif BirthDateNum < 4120 then
				genBirthDate = tostring(BirthDateNum)
			end
		end
	end
	local genDeathDate = templateArgs['תאריך פטירה'] or templateArgs['פטירה דאטום']
	if genDeathDate == nil and templateArgs['תאריך פטירה עברי'] ~= nil then
		local p = frame:preprocess(templateArgs['תאריך פטירה עברי']) -- preprocess, to handle {{לינק צו אידיש יאר}}
		if #mw.text.split(p, '%s' ) == 1 or enclosed(p) then --most probably just year or yearlink
			if #mw.text.split(p, '%s' ) > 1 then
				p = p:match("%[%[.-|(.*)%]%]") or p:match("%[%[(.-)%]%]") -- try after pipe first, fallback and get the whole if there is no pipe
			end
			local deathParts = mw.text.split( p, "'", true )
			if #deathParts == 1 then
				table.insert(deathParts, 1, '') -- אדער אלף החמישי?
			end
			local DeathDateNum = gim.gimatria(deathParts[1])*1000 + gim.gimatria(deathParts[2]) - 3760
			if DeathDateNum < 1 then
				genDeathDate = tostring(math.abs(DeathDateNum)) .. " לפנה\"ס"
			elseif DeathDateNum < 4120 then
				genDeathDate = tostring(DeathDateNum)
			end
		end
	end
	
	local birthDate = getSpeculativeDate(genBirthDate, templateArgs['תאריך לידה עברי'])
	local deathDate = getSpeculativeDate(genDeathDate, templateArgs['תאריך פטירה עברי'])
		
		if birthDate ~= nil then
			local age = nil
			if deathDate == nil and not templateArgs['ללא גיל'] then
				age = ageModule.ageCalc(birthDate, nil, true, false, true, nil, wikidataGender) or ''
			end
			local birthDetails, usingBirthWikidataEvent = getEventDetails(templateArgs['תאריך לידה'] or templateArgs['געבורט דאטום'], templateArgs['תאריך לידה עברי'], templateArgs['מקום לידה'] or templateArgs['געבורט ארט'], 'P569', 'P19', age, usingBirthWikidata, infoObj)
			table.insert(infoObj.templateStructure, 1, {
				label = birthLabel,
				data = birthDetails
			})
			usingBirthWikidata = usingBirthWikidata or usingBirthWikidataEvent
		elseif templateArgs['געבורט ארט'] ~= '-' then
			fillWikidataParam(templateArgs, 'געבורט ארט', 'P19', infoObj)
			if templateArgs['געבורט ארט'] ~= nil and templateArgs['געבורט ארט'] ~= '' then -- only if we fill the parameter eventually - add to template
				table.insert(infoObj.templateStructure, 1, {
					label = birthLabel,
					data = templateArgs['געבורט ארט']
				})
			end
		end
	
		deathLabel = getDeathLabel(templateArgs['סיבת המוות'], infoObj.args.entityId, wikidataGender)
		if deathDate ~= nil then
	
			local age = ''
			if not templateArgs['ללא גיל'] then
				age = ageModule.ageCalc(birthDate, deathDate, false, false, true) or ''
			end
			local deathDetails, usingDeathWikidataEvent = getEventDetails(templateArgs['תאריך פטירה'] or templateArgs['פטירה דאטום'], templateArgs['תאריך פטירה עברי'], templateArgs['מקום פטירה'] or templateArgs['פטירה ארט'], 'P570', 'P20', age, usingDeathWikidata, infoObj)
				table.insert(infoObj.templateStructure, 2, {
				label=deathLabel,
				data=deathDetails
			})
			usingDeathWikidata = usingDeathWikidata or usingDeathWikidataEvent
		elseif templateArgs['פטירה ארט'] ~= '-' then
			fillWikidataParam(templateArgs, 'פטירה ארט', 'P20', infoObj)
			if templateArgs['פטירה ארט'] ~= nil and templateArgs['פטירה ארט'] ~= '' then -- only if we fill the parameter eventually - add to template
				table.insert(infoObj.templateStructure, 2, {
					label=deathLabel,
					data= templateArgs['פטירה ארט']
				})
			end
		end
	
		if infoObj.isSelfUse then
			table.insert(infoObj.templateStructure, 1, {
				label=birthLabel,
				data='{{{תאריך לידה}}}<br/>{{{געבורט ארט}}}'
			})
			table.insert(infoObj.templateStructure, 2, {
				label=deathLabel,
				data='{{{תאריך פטירה}}}<br/>{{{פטירה ארט}}}'
			})
		end	
		
		if usingBirthWikidata or usingDeathWikidata then
			infoObj.args.usingWikidata = true
		end
		
		if frame.args['כותרת0'] then
			table.insert(infoObj.templateStructure, 1, {
				header=1,
				data=frame.args['כותרת0'],
				rowstyle=frame.args['עיצוב-שורה0'],
				rowclass=frame.args['מחלקה-שורה0'],
				headerstyle=frame.args['כותרת0-עיצוב']
			})
		end
	
		--[[
		if frame.args['תמונה'] ~= '-' then
			addMissingImage(infoObj, birthDate, deathDate, wikidataGender)
		end
		]]
	end
	
	addAdditionalDetails(frame, infoObj, wikidataGender, disableWikidataFetch)
end

function infobox(frame)
	local infoObj = Infobox:new()
	frame.args['תמונה-גודל'] = frame.args['תמונה-גודל'] or '220'

	local colorKey = frame.args["סיווג"] or frame.args["סוג"] or frame:getParent().args["סיווג"] or frame:getParent().args["סוג"]
	local color = BackgroundColors[colorKey] or BackgroundColors["default"] or "#eeeeee"

	infoObj.args.headerstyle = "background:" .. color .. ";" .. (infoObj.args.headerstyle or "")
	
	local is_white_text = BackgroundColors[colorKey] == '#000000' or BackgroundColors[colorKey] == '#800000'
	
	local header_style = "background:" .. color .. "; border:1px solid #aaaaaa; border-bottom:0px; color:" .. (is_white_text and 'white' or 'black')
	
	frame.args['כותרת-עיצוב'] = header_style .. ";" .. (frame.args['כותרת-עיצוב'] or "")
	frame.args['כותרת תבנית-עיצוב'] = header_style .. ";" .. (frame.args['כותרת תבנית-עיצוב'] or "")
	frame.args['תת-כותרת תבנית-עיצוב'] = header_style .. ";" .. (frame.args['תת-כותרת תבנית-עיצוב'] or "")
	
	infoObj:parseArgs(frame)

	addPersonDetails(frame, infoObj)

	return infoObj:render()
end

return 	{
	['מידע']=infobox,
	['addPersonDetails'] = addPersonDetails
}