יחידה:תבנית מידע/אישיות: הבדלים בין גרסאות בדף
מראה
מאין תקציר עריכה |
מאין תקציר עריכה |
||
| שורה 3: | שורה 3: | ||
local PropertyLink = require('Module:PropertyLink') | local PropertyLink = require('Module:PropertyLink') | ||
local ageModule = require('Module:גיל לערכי אישים') | local ageModule = require('Module:גיל לערכי אישים') | ||
local hebrewDateModule = require('Module:תאריך עברי') | |||
function getEventDetails( | --[[ 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=''} }) | |||
if not success or sepcDate=='' then return nil end | |||
return sepcDate | |||
end | |||
return nil | |||
end | |||
function getEventDetails(generalDate, hebDate, eventPlace, propDate, propPlace, age, usingWikidata) | |||
local entityId = mw.wikibase.getEntityIdForCurrentPage() | local entityId = mw.wikibase.getEntityIdForCurrentPage() | ||
age = age or '' | age = age or '' | ||
local formattedEvent = | local formattedEvent | ||
if generalDate~=nil and generalDate~='' then | |||
formattedEvent = generalDate .. age | |||
if hebDate~=nil and hebDate~='' then | |||
formattedEvent = formattedEvent ..'<br/>' ..hebDate | |||
end | |||
elseif hebDate~=nil and hebDate~='' then | |||
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, propDate , 1) | ||
| שורה 51: | שורה 70: | ||
end | end | ||
end | end | ||
local birthDate = getSpeculativeDate(templateArgs['תאריך לידה'], templateArgs['תאריך לידה עברי']) | |||
local deathDate = getSpeculativeDate(templateArgs['תאריך פטירה'], templateArgs['תאריך פטירה עברי']) | |||
if birthDate~=nil then | |||
local age = nil | local age = nil | ||
if deathDate==nil then | |||
if | |||
age = ageModule.ageCalc(birthDate, nil, true, false, true) or '' | age = ageModule.ageCalc(birthDate, nil, true, false, true) or '' | ||
end | end | ||
| שורה 76: | שורה 96: | ||
end | end | ||
if | 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 = getEventDetails(templateArgs['תאריך פטירה'], templateArgs['תאריך פטירה עברי'], templateArgs['מקום פטירה'], 'P570', 'P20', age, usingDeathWikidata) | ||
גרסה מ־08:13, 12 במאי 2018
יחידה זו מרחיבה את יחידה:תבנית מידע עבור תבניות מידע של אישים. היחידה כוללת תמיכה אוטומטית בפרמטרים האופיינים לאישים כדוגמת תאריכים ומקומות של לידה/פטירה, יחד עם ציון גיל.
local Infobox = require('Module:תבנית מידע').Infobox
local LocationAndCountry = require('Module:LocationAndCountry')
local PropertyLink = require('Module:PropertyLink')
local ageModule = require('Module:גיל לערכי אישים')
local hebrewDateModule = require('Module:תאריך עברי')
--[[ 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=''} })
if not success or sepcDate=='' then return nil end
return sepcDate
end
return nil
end
function getEventDetails(generalDate, hebDate, eventPlace, propDate, propPlace, age, usingWikidata)
local entityId = mw.wikibase.getEntityIdForCurrentPage()
age = age or ''
local formattedEvent
if generalDate~=nil and generalDate~='' then
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, propDate , 1)
if success and res and #res>0 then
usingWikidata = true
eventPlace = res
end
end
if eventPlace~='' and eventPlace~=nil then
formattedEvent = formattedEvent..'<br/>' ..eventPlace
end
if usingWikidata and entityId then
formattedEvent = formattedEvent .. ' [[File:Blue pencil RTL.svg|15px|link=https://www.wikidata.org/wiki/'..entityId.. '?uselang=he#P569|עריכת הנתון בוויקינתונים]]'
end
return formattedEvent
end
function addPersonDetails(frame, infoObj)
local templateArgs = frame:getParent().args
local usingBirthWikidata = false
local usingDeathWikidata = false
local birthLabel = 'לידה'
local deathLabel = frame.args['תווית-פטירה'] or 'פטירה'
-- fill birth/death dates from wikidata is missing
if templateArgs['תאריך לידה']==nil or templateArgs['תאריך לידה']=='' then
templateArgs['תאריך לידה'] = PropertyLink.getProperty( 'P569' )
if templateArgs['תאריך לידה'] and #templateArgs['תאריך לידה']>0 then
usingBirthWikidata = true
end
end
if templateArgs['תאריך פטירה']==nil or templateArgs['תאריך פטירה']=='' then
templateArgs['תאריך פטירה'] = PropertyLink.getProperty( 'P570' )
if templateArgs['תאריך פטירה'] and #templateArgs['תאריך פטירה'] >0 then
usingDeathWikidata = true
end
end
local birthDate = getSpeculativeDate(templateArgs['תאריך לידה'], templateArgs['תאריך לידה עברי'])
local deathDate = getSpeculativeDate(templateArgs['תאריך פטירה'], templateArgs['תאריך פטירה עברי'])
if birthDate~=nil then
local age = nil
if deathDate==nil then
age = ageModule.ageCalc(birthDate, nil, true, false, true) or ''
end
local birthDetails = getEventDetails(templateArgs['תאריך לידה'], templateArgs['תאריך לידה עברי'], templateArgs['מקום לידה'], 'P569', 'P19', age, usingBirthWikidata)
table.insert(infoObj.templateStructure, 1, {
label='לידה',
data=birthDetails
})
else
if templateArgs['מקום לידה']==nil or templateArgs['מקום לידה']=='' then
templateArgs['מקום לידה'] = PropertyLink.getProperty( 'P19' )
end
if templateArgs['מקום לידה']~= '' and templateArgs['מקום לידה']~=nil and #templateArgs['מקום לידה']>0 then
table.insert(infoObj.templateStructure, 1, {
label=birthLabel,
data= templateArgs['מקום לידה']
})
end
end
if deathDate~=nil then
local age = ageModule.ageCalc(birthDate, deathDate, false, false, true) or ''
local deathDetails = getEventDetails(templateArgs['תאריך פטירה'], templateArgs['תאריך פטירה עברי'], templateArgs['מקום פטירה'], 'P570', 'P20', age, usingDeathWikidata)
table.insert(infoObj.templateStructure, 2, {
label=deathLabel,
data=deathDetails
})
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=frame.args['כותרת0'],
rowstyle=frame.args['עיצוב-שורה0'],
rowclass=frame.args['מחלקה-שורה0'],
headerstyle=frame.args['כותרת0-עיצוב']
})
end
end
function infobox(frame)
local infoObj = Infobox:new()
infoObj:parseArgs(frame)
if infoObj.args.title~='-' then
addPersonDetails(frame, infoObj)
end
return infoObj:render()
end
return {
['מידע']=infobox,
['addPersonDetails'] = addPersonDetails
}