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

מאין תקציר עריכה
מ השוואה מול ויקינתונים
שורה 28: שורה 28:
end
end
return isValidDate, res, errors
return isValidDate, res, errors
end
function consistentWithWikidata(localDate, wikidataClaim)
if not wikidataClaim then
return true
end
local iswikidataValid, wikidataDate = pcall(dateParser.newFromWikidataValue, wikidataClaim[1].mainsnak.datavalue.value)
if iswikidataValid and localDate.calendar == wikidataDate.calendar then
if localDate.year ~= wikidataDate.year or
  localDate.month ~= wikidataDate.month or
  localDate.day ~= wikidataDate.day  then
return false
end
end
return true
end
end


שורה 40: שורה 55:
local warnings = {}
local warnings = {}
local dateRangeStr
local dateRangeStr
local wikidataBirth, wikidataDeath
DisplayForAlive = (DisplayForAlive=='כן')
DisplayForAlive = (DisplayForAlive=='כן')
DisplayForDead = (DisplayForDead=='כן')
DisplayForDead = (DisplayForDead=='כן')
שורה 45: שורה 61:
local entity = mw.wikibase.getEntityObject()
local entity = mw.wikibase.getEntityObject()
BirthDateStr = BirthDateStr or (entity and entity.claims and entity.claims['P569'] and entity:formatPropertyValues( 'P569' ).value)
wikidataBirth = entity and entity.claims['P569'] and entity:getBestStatements('P569')
wikidataDeath = entity and entity.claims['P569'] and entity:getBestStatements('P570')
 
BirthDateStr = BirthDateStr or (wikidataBirth and entity:formatPropertyValues( 'P569' ).value)
-- 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 (entity and entity.claims and entity.claims['P570'] and entity:formatPropertyValues( 'P570' ).value)
DeathDateStr = DeathDateStr or (wikidataDeath and entity:formatPropertyValues( 'P570' ).value)
if DeathDateStr =='' then DeathDateStr = nil end
if DeathDateStr =='' then DeathDateStr = nil end
local IsDead = (DeathDateStr~=nil)
local IsDead = (DeathDateStr~=nil)
שורה 58: שורה 77:
return ''
return ''
end
end
 
local isValidDate, BirthDate, errDate = ToDate(frame, BirthDateStr, ApproxDate)
local isValidDate, BirthDate, errDate = ToDate(frame, BirthDateStr, ApproxDate)
if not isValidDate  then
if not isValidDate  then
return errDate
return errDate
end
end
if wikidataBirth and wikidataBirth[1] and wikidataBirth[1].mainsnak  then
--local iswikidataValid, wikidataBirthDate = pcall(dateParser.newFromWikidataValue, wikidataBirth[1].mainsnak)
if not consistentWithWikidata(BirthDate, wikidataBirth) then
table.insert(warnings, '[[קטגוריה:דפים עם שנות חיים שלא תואמים את ויקינתונים]]')
end
end
local DeathDate
local DeathDate
if IsDead then  
if IsDead then  
שורה 69: שורה 95:
return errDate-- invalid death date
return errDate-- invalid death date
end
end
if not consistentWithWikidata(DeathDate, wikidataDeath) then
table.insert(warnings, '[[קטגוריה:דפים עם שנות חיים שלא תואמים את ויקינתונים]]')
end
prefix = 'בגיל '  
prefix = 'בגיל '