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

אין תקציר עריכה
מ 5 גרסאות של הדף wikipedia:he:יחידה:גיל_לערכי_אישים יובאו
 
(30 גרסאות ביניים של 10 משתמשים אינן מוצגות)
שורה 9: שורה 9:
local isValidDate, res = pcall(dateParser.newFromWikitext, Date)
local isValidDate, res = pcall(dateParser.newFromWikitext, Date)
local errors = ''
local errors = ''
if not isValidDate then
if isValidDate and dateParser.age(res).year<0 then
-- invalid date
-- date is in the future
errors = frame:expandTemplate{ title = 'גיל לערכי אישים/בעיה', args = {
['מקורב']=ApproxDate,
['נוסף']=Date,
['מחרוזת']=Date
} }
-- validate
elseif dateParser.age(res)<0 then  
isValidDate = false
isValidDate = false
local title = mw.title.getCurrentTitle()
local title = mw.title.getCurrentTitle()
if title.namespace==0 then
if title.namespace==0 then
errors = Errors['future-date']-- date is in the future
errors = Errors['future-date']
else
else
errors = '<!--' .. Errors['future-date'] .. '-->'
errors = '<!--' .. Errors['future-date'] .. '-->'
end
end
elseif not isValidDate or res.precision < dateParser.PRECISION.YEAR then
-- date is either invalid or is imprecise
isValidDate = false -- mark as invalid anyway, even if "only" imprecise
errors = frame:expandTemplate{ title = 'גיל לערכי אישים/בעיה', args = {
['מקורב']=ApproxDate,
['נוסף']=Date,
['מחרוזת']=Date
} }
end
end
return isValidDate, res, errors
return isValidDate, res, errors
שורה 56: שורה 56:
end
end


function ageCalc(frame)
function ageCalcFromFrame(frame)
local args = Arguments.getArgs(frame, { ['trim'] = true, ['removeBlanks'] = true })
local args = Arguments.getArgs(frame, { ['trim'] = true, ['removeBlanks'] = true })
--local age_string = args['מציין']
local BirthDateStr = args['תאריך לידה']
local BirthDateStr = args['תאריך לידה']
local DeathDateStr = args['תאריך פטירה']
local DeathDateStr = args['תאריך פטירה']
שורה 64: שורה 65:
local Brackets = args['סוגריים']
local Brackets = args['סוגריים']
local ApproxDate = args['מקורב']
local ApproxDate = args['מקורב']
DisplayForAlive = (DisplayForAlive=='כן')
DisplayForDead = (DisplayForDead=='כן')
Brackets = (Brackets~='לא')
return ageCalc(BirthDateStr, DeathDateStr, DisplayForAlive, DisplayForDead, Brackets, ApproxDate)
end
function ageCalc(BirthDateStr, DeathDateStr, DisplayForAlive, DisplayForDead, Brackets, ApproxDate, gender)
local frame = mw.getCurrentFrame()
local warnings = {}
local warnings = {}
local dateRangeStr
local dateRangeStr
local wikidataBirth, wikidataDeath
local wikidataBirth, wikidataDeath
DisplayForAlive = (DisplayForAlive=='כן')
if BirthDateStr == '' then BirthDateStr = nil end
DisplayForDead = (DisplayForDead=='כן')
if DeathDateStr == '' then DeathDateStr = nil end
Brackets = (Brackets~='לא')
local entityId = mw.wikibase.getEntityIdForCurrentPage()
wikidataBirth = entityId and mw.wikibase.getBestStatements( entityId, 'P569' )
local entity = mw.wikibase.getEntityObject()
wikidataDeath = entityId and wikidataBirth and mw.wikibase.getBestStatements( entityId, 'P570' )
wikidataBirth = entity and entity.claims and entity.claims['P569'] and entity:getBestStatements('P569')
wikidataDeath = entity and entity.claims and entity.claims['P569'] and entity:getBestStatements('P570')


BirthDateStr = BirthDateStr or (wikidataBirth and entity:formatPropertyValues( 'P569' ).value)
BirthDateStr = BirthDateStr or ((wikidataBirth and #wikidataBirth>0 and mw.wikibase.renderSnak( wikidataBirth[1].mainsnak ) or nil))
-- validate dates are valid
-- validate dates are valid
if not BirthDateStr then
if not BirthDateStr then
return -- missing date, nothing to do
return -- missing date, nothing to do
end
end
DeathDateStr = DeathDateStr or (wikidataDeath and entity:formatPropertyValues( 'P570' ).value)
DeathDateStr = DeathDateStr or ((wikidataDeath and #wikidataDeath>0 and mw.wikibase.renderSnak( wikidataDeath[1].mainsnak ) or nil))
if DeathDateStr =='' then DeathDateStr = nil end
if DeathDateStr =='' then DeathDateStr = nil end
local IsDead = (DeathDateStr~=nil)
local IsDead = (DeathDateStr~=nil)
שורה 98: שורה 106:
end
end
end
end
-- skip age calculation if we dont have enough precision
if BirthDate.precision < dateParser.PRECISION.YEAR then return nil end
local DeathDate
local DeathDate
שורה 112: שורה 123:
else
else
prefix = frame:expandTemplate{ title = 'לפי מגדר/בדוק', args = { 'בן&nbsp;', 'בת&nbsp;' } }
if gender == nil and entityId~=nil then
local PropertyLink = require('Module:PropertyLink')
gender = PropertyLink.getItem( 'P21', entityId )
if (gender == "Q6581097") then -- male
gender = 'זכר'
elseif (gender == "Q2449503") then -- transgender male
gender = 'זכר'
elseif (gender == "Q15145778") then -- cisgender male
gender = 'זכר'
elseif (gender == "Q6581072") then -- female
gender = 'נקבה'
elseif (gender == "Q1052281") then -- transgender female
gender = 'נקבה'
elseif (gender == "Q15145779") then -- cisgender female
gender = 'נקבה'
end
end
prefix = 'גיל:&nbsp;'
if gender == 'נקבה' then
prefix = 'בת&nbsp;'
elseif gender == 'זכר' then
prefix = 'בן&nbsp;'
end
end
end
-- skip age calculation if we dont have enough precision
if DeathDate and DeathDate.precision and DeathDate.precision < dateParser.PRECISION.YEAR then return nil end
local success, Age = pcall(dateParser.age, BirthDate , DeathDate)
local success, AgeYears = pcall(dateParser.age, BirthDate , DeathDate)
if success then
if success then
if AgeYears == 1 then
AgeYears = Age.year
result = prefix..'שנה'
if Age.year <= 0 then
elseif AgeYears == 2 then
if Age.month == 1 then
result = prefix..'שנתיים'
result = prefix..'חודש'
elseif Age.month == 2 then
result  = prefix..'חודשיים'
else
result = prefix..tostring(Age.month)..' חודשים'
end
if Age.day > 0 then
if Age.day == 1 then
result = result..' ויום'
elseif Age.day == 2 then
result = result..' ויומיים'
else
result = result..'  ו־'..tostring(Age.day)..' ימים'
end
end
elseif Age.year < 3 then
if Age.year == 1 then
result = prefix..'שנה'
elseif Age.year == 2 then
result = prefix..'שנתיים'
end
if Age.month == 0 then
if Age.day > 0 then
if Age.day == 1 then
result = result..' ויום'
elseif Age.day == 2 then
result = result..' ויומיים'
else
result = result..'  ו־'..tostring(Age.day)..' ימים'
end
end
elseif Age.month == 1 then
result = result..' וחודש'
elseif Age.month == 2 then
result  = result..' וחודשיים'
else
result = result..' ו־'..tostring(Age.month)..' חודשים'
end
else
else
result = prefix..tostring(AgeYears)
result = prefix..tostring(Age.year)
end
end
if BirthDate.precision < dateParser.PRECISION.MONTH or (DeathDate and DeathDate.precision < dateParser.PRECISION.MONTH) then
if BirthDate.precision < dateParser.PRECISION.MONTH or (DeathDate and DeathDate.precision < dateParser.PRECISION.MONTH) then
שורה 130: שורה 205:
end
end
if AgeYears > 139 then  
-- ignore warning in specific template
table.insert(warnings, Errors['future-date'])
local noAgeWarning = false
elseif AgeYears>109 then  
if mw.getCurrentFrame():getParent():getTitle() == 'תבנית:אישיות תנ"כית' or mw.getCurrentFrame():getParent():getTitle() == 'תבנית:בעל חיים מפורסם' then
table.insert(warnings, '[[קטגוריה:אישים שהגיעו לגיל 110]]')
noAgeWarning = true
elseif AgeYears>100 then
end
table.insert(warnings, '[[קטגוריה:אישים שהגיעו לגיל מאה]]')
local title = mw.title.getCurrentTitle()
-- ignore warning in other namespace except the main NS
if title.namespace==0 and not noAgeWarning then
if AgeYears > 139 then  
local instanceOf = entityId and mw.wikibase.getBestStatements( entityId, 'P31' )
local isHuman = instanceOf and instanceOf[1].mainsnak and instanceOf[1].mainsnak.datavalue.value.id=='Q5'
if isHuman then
table.insert(warnings, Errors['future-date'])
end
elseif AgeYears>109 then  
table.insert(warnings, '[[קטגוריה:אישים שהגיעו לגיל 110]]')
elseif AgeYears>99 then
table.insert(warnings, '[[קטגוריה:אישים שהגיעו לגיל מאה]]')
end
end
end
else
else
שורה 144: שורה 232:
} }
} }
end
end
 
if mw.title.getCurrentTitle()["nsText"] == "" then
warnings = table.concat( warnings, '')
warnings = table.concat( warnings, '')
if #warnings > 0 then
else
warnings = string.format('%s ', warnings)
warnings = ""
end
end
if Brackets then
if Brackets then
result = string.format(' (%s)', result)
result = string.format(' (%s)', result)
end
end
return string.format('%s <span style="white-space: nowrap;">%s</span>', warnings, result)
return string.format('%s<span style="white-space: nowrap;">%s</span>', warnings, result)
end
end




return {
return {
['גיל'] = ageCalc
['גיל'] = ageCalcFromFrame,
ageCalc = ageCalc
}
}