יחידה:תבנית מידע/אישיות: הבדלים בין גרסאות בדף

מ תיקון לשלמה גורן כאשר מבקשים לא לציין לידה אין צורך בשאיבה
מ 9 גרסאות של הדף wikipedia:he:יחידה:תבנית_מידע/אישיות יובאו
 
(59 גרסאות ביניים של 11 משתמשים אינן מוצגות)
שורה 3: שורה 3:
local PropertyLink = require('Module:PropertyLink')
local PropertyLink = require('Module:PropertyLink')
local ageModule = require('Module:גיל לערכי אישים')
local ageModule = require('Module:גיל לערכי אישים')
local Date = require('Module:תאריך')
local hebrewDateModule = require('Module:תאריך עברי')
local hebrewDateModule = require('Module:תאריך עברי')
local WikidataCrossValidation = require('Module:WikidataCrossValidation')


--[[ Get general date if known, otherwise guess from hebrew date.
--[[ Get general date if known, otherwise guess from hebrew date.
שורה 11: שורה 13:
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=''} })
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
שורה 18: שורה 20:
end
end


function getEventDetails(generalDate, hebDate, eventPlace, propDate, propPlace, age, usingWikidata)
local function getDeathLabel(deathCause, entityId, gender)
local entityId = mw.wikibase.getEntityIdForCurrentPage()
local result=''
local fromWikidata=nil
entityId = entityId or mw.wikibase.getEntityIdForCurrentPage()
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 = infoObj.args.entityId or mw.wikibase.getEntityIdForCurrentPage()
age = age or ''
age = age or ''
local formattedEvent
local formattedEvent
local placeDate = propDate
if generalDate~=nil and generalDate~='' then
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  
שורה 32: שורה 68:
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


if eventPlace~='' and eventPlace~=nil then
if eventPlace~='' and eventPlace~=nil and eventPlace~='-' then
formattedEvent = formattedEvent..'<br/>' ..eventPlace
formattedEvent = formattedEvent..'<br/>' ..eventPlace
end
end
שורה 47: שורה 91:
end
end


return formattedEvent
return formattedEvent, usingWikidata
end
 
function addMissingImage(infoObj, birthDate, deathDate, gender)
if infoObj.args.image ~= nil and #infoObj.args.image > 0 then return end  -- there is already image
local latestDate = deathDate or birthDate
if latestDate == nil then return end
local dateModule = require('Module:תאריך')
local success, res = pcall(dateModule.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
mw.logObject(matching)
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
end


שורה 55: שורה 167:
local usingDeathWikidata = false
local usingDeathWikidata = false
local birthLabel = 'לידה'
local birthLabel = 'לידה'
local deathLabel = frame.args['תווית-פטירה'] or 'פטירה'  
local deathLabel = 'פטירה'  
-- fill birth/death dates from wikidata is missing
infoObj.isNonPerson = instanceOfViolation(infoObj)
if templateArgs['תאריך לידה']==nil or templateArgs['תאריך לידה']=='' then
templateArgs['תאריך לידה'] = PropertyLink.getProperty( 'P569' )
local wikidataGender = nil
if templateArgs['תאריך לידה'] and #templateArgs['תאריך לידה']>0 then
if not infoObj.isNonPerson then
usingBirthWikidata = true
wikidataGender = PropertyLink.getItem( 'P21', infoObj.args.entityId )
if wikidataGender == nil then
table.insert(infoObj.wikidataCats, '[[קטגוריה:אישים חסרי מגדר בוויקינתונים]]')
else
if (wikidataGender == "Q6581097") then -- male
wikidataGender = 'זכר'
elseif (wikidataGender == "Q2449503") then -- transgender male
wikidataGender = 'זכר'
elseif (wikidataGender == "Q15145778") then -- cisgender male
wikidataGender = 'זכר'
elseif (wikidataGender == "Q6581072") then -- female
wikidataGender = 'נקבה'
elseif (wikidataGender == "Q1052281") then -- transgender female
wikidataGender = 'נקבה'
elseif (wikidataGender == "Q15145779") then -- cisgender female
wikidataGender = 'נקבה'
elseif wikidataGender == 'Q1097630' -- intersex
or wikidataGender == 'Q48270' -- non binary
then wikidataGender = '' -- עד שתחליטו
end
end
end
end
end
if templateArgs['תאריך פטירה']==nil or templateArgs['תאריך פטירה']=='' then
-- fill birth/death dates from wikidata if missing and the person is not a human biblical figure
templateArgs['תאריך פטירה'] = PropertyLink.getProperty( 'P570' )
if PropertyLink.getItem( 'P31', infoObj.args.entityId )~="Q20643955" then
if templateArgs['תאריך פטירה'] and #templateArgs['תאריך פטירה'] >0 then
usingBirthWikidata = fillWikidataParam(templateArgs, 'תאריך לידה', 'P569', infoObj)
usingDeathWikidata = true
usingDeathWikidata = fillWikidataParam(templateArgs, 'תאריך פטירה', 'P570', infoObj)
end
end
end
שורה 77: שורה 207:
local age = nil
local age = nil
if deathDate==nil then
if deathDate==nil then
age = ageModule.ageCalc(birthDate, nil, true, false, true) or ''
age = ageModule.ageCalc(birthDate, nil, true, false, true, nil, wikidataGender) or ''
end
end
local birthDetails = getEventDetails(templateArgs['תאריך לידה'], templateArgs['תאריך לידה עברי'], templateArgs['מקום לידה'], 'P569', 'P19', age, usingBirthWikidata)
local birthDetails, usingBirthWikidataEvent = getEventDetails(templateArgs['תאריך לידה'], templateArgs['תאריך לידה עברי'], templateArgs['מקום לידה'], 'P569', 'P19', age, usingBirthWikidata, infoObj)
table.insert(infoObj.templateStructure, 1, {
table.insert(infoObj.templateStructure, 1, {
label='לידה',
label=birthLabel,
data=birthDetails
data=birthDetails
})
})
else
usingBirthWikidata = usingBirthWikidata or usingBirthWikidataEvent
    if templateArgs['מקום לידה']~= '' and templateArgs['מקום לידה']~=nil and #templateArgs['מקום לידה']>0 then
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, {
table.insert(infoObj.templateStructure, 1, {
    label=birthLabel,
label=birthLabel,
    data= templateArgs['מקום לידה']
data= templateArgs['מקום לידה']
})  
})
  end
end
    end
end
 
deathLabel = getDeathLabel(templateArgs['סיבת המוות'], infoObj.args.entityId, wikidataGender)
if deathDate~=nil then
if deathDate~=nil then
local age =  ageModule.ageCalc(birthDate, deathDate, false, false, true) or ''
local age =  ageModule.ageCalc(birthDate, deathDate, false, false, true) or ''
local deathDetails = getEventDetails(templateArgs['תאריך פטירה'], templateArgs['תאריך פטירה עברי'], templateArgs['מקום פטירה'], 'P570', 'P20', age, usingDeathWikidata)
local deathDetails, usingDeathWikidataEvent = getEventDetails(templateArgs['תאריך פטירה'], templateArgs['תאריך פטירה עברי'], templateArgs['מקום פטירה'], 'P570', 'P20', age, usingDeathWikidata, infoObj)
table.insert(infoObj.templateStructure, 2, {
table.insert(infoObj.templateStructure, 2, {
label=deathLabel,
label=deathLabel,
data=deathDetails
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
שורה 119: שורה 261:
if frame.args['כותרת0'] then
if frame.args['כותרת0'] then
table.insert(infoObj.templateStructure, 1, {
table.insert(infoObj.templateStructure, 1, {
header=frame.args['כותרת0'],
header=1,
data=frame.args['כותרת0'],
rowstyle=frame.args['עיצוב-שורה0'],
rowstyle=frame.args['עיצוב-שורה0'],
rowclass=frame.args['מחלקה-שורה0'],
rowclass=frame.args['מחלקה-שורה0'],
headerstyle=frame.args['כותרת0-עיצוב']
headerstyle=frame.args['כותרת0-עיצוב']
})
})
end
if frame.args['תמונה']~='-' then
addMissingImage(infoObj, birthDate, deathDate, wikidataGender)
end
end
end
end
שורה 129: שורה 276:
function infobox(frame)
function infobox(frame)
local infoObj = Infobox:new()
local infoObj = Infobox:new()
frame.args['תמונה-גודל'] = frame.args['תמונה-גודל']  or '220'
infoObj:parseArgs(frame)
infoObj:parseArgs(frame)