מייבאים כמותיים, בדוקי עריכות אוטומטית, ביוראקראטן, אינטערפעיס רעדאקטארן, emailconfirmed, אינטערפעיס אדמיניסטראַטאָרן, מנטרים, סיסאפן, צוות טכני, מייבאים, מעדכנים, אספקלריה רעדאקטארן
102,362
רעדאגירונגען
(אויסקרויזן וויקידאטא) |
(באהאנדלען אויך {{לינק צו אידיש יאר}}) |
||
| (25 מיטלסטע ווערסיעס פון 2 באַניצער נישט געוויזן.) | |||
| שורה 1: | שורה 1: | ||
local dateParser = require( "Module: | local dateParser = require( "Module:דאטום" ) | ||
local Arguments = require( "Module:Arguments" ) | local Arguments = require( "Module:Arguments" ) | ||
local gim = require( "Module:גימטריה" ) | |||
local Errors = { | local Errors = { | ||
['future-date'] = '[[קאטעגאריע: | ['future-date'] = '[[קאטעגאריע:אומריכטיגע לעבן דאטומען]]' | ||
} | } | ||
function count(str, substring) | |||
local count = 0 | |||
local _, occurrences = string.gsub(str, substring, function() | |||
count = count + 1 | |||
end) | |||
return count | |||
end | |||
function ToDate(frame, Date, ApproxDate) | function ToDate(frame, Date, ApproxDate) | ||
local isValidDate, res = pcall(dateParser.newFromWikitext, Date) | local isValidDate, res = pcall(dateParser.newFromWikitext, Date) | ||
local errors = '' | local errors = '' | ||
if | if isValidDate and dateParser.age(res).year<0 then | ||
-- date is in the future | |||
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'] | 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 | ||
| שורה 59: | שורה 68: | ||
local args = Arguments.getArgs(frame, { ['trim'] = true, ['removeBlanks'] = true }) | local args = Arguments.getArgs(frame, { ['trim'] = true, ['removeBlanks'] = true }) | ||
--local age_string = args['מציין'] | --local age_string = args['מציין'] | ||
local BirthDateStr = args['געבורט דאטום'] | local BirthDateStr = args['געבורט דאטום'] or args['תאריך לידה עברי'] | ||
local DeathDateStr = args['פטירה | local l = frame:preprocess(args['תאריך לידה עברי']) -- preprocess, to handle {{לינק צו אידיש יאר}} | ||
if args['געבורט דאטום'] == nil and (#mw.text.split(l, '%s' ) == 1 or count(l, "%[%[") == 1) then --most probably just year or yearlink | |||
if #mw.text.split(l, '%s' ) > 1 then | |||
l = l:match("%[%[.-|(.*)%]%]") | |||
end | |||
local birthParts = mw.text.split( l, "'", true ) | |||
local BirthDateNum = gim.gimatria(birthParts[1])*1000 + gim.gimatria(birthParts[2]) - 3760 | |||
if BirthDateNum < 1 then | |||
BirthDateStr = tostring(math.abs(BirthDateNum)) .. " לפנה\"ס" | |||
else | |||
BirthDateStr = tostring(BirthDateNum) | |||
end | |||
end | |||
--error(BirthDateStr) | |||
local DeathDateStr = args['פטירה דאטום'] or args['תאריך פטירה עברי'] | |||
local p = frame:preprocess(args['תאריך פטירה עברי']) | |||
if args['פטירה דאטום'] == nil and (#mw.text.split(p, '%s' ) == 1 or count(p, "%[%[") == 1) then --most probably just year or yearlink | |||
if #mw.text.split(p, '%s' ) > 1 then | |||
p = p:match("%[%[.-|(.*)%]%]") | |||
end | |||
local deathParts = mw.text.split( p, "'", true ) | |||
local DeathDateNum = gim.gimatria(deathParts[1])*1000 + gim.gimatria(deathParts[2]) - 3760 | |||
if DeathDateNum < 1 then | |||
DeathDateStr = tostring(math.abs(DeathDateNum)) .. " לפנה\"ס" | |||
else | |||
DeathDateStr = tostring(DeathDateNum) | |||
end | |||
end | |||
local DisplayForAlive = args['הצג אם בחיים'] | local DisplayForAlive = args['הצג אם בחיים'] | ||
local DisplayForDead = args['הצג אם נפטר'] | local DisplayForDead = args['הצג אם נפטר'] | ||
| שורה 72: | שורה 108: | ||
end | end | ||
function ageCalc(BirthDateStr, DeathDateStr, DisplayForAlive, DisplayForDead, Brackets, ApproxDate) | function ageCalc(BirthDateStr, DeathDateStr, DisplayForAlive, DisplayForDead, Brackets, ApproxDate, gender) | ||
local frame = mw.getCurrentFrame() | local frame = mw.getCurrentFrame() | ||
local warnings = {} | local warnings = {} | ||
| שורה 79: | שורה 115: | ||
if BirthDateStr == '' then BirthDateStr = nil end | if BirthDateStr == '' then BirthDateStr = nil end | ||
if DeathDateStr == '' then DeathDateStr = nil end | if DeathDateStr == '' then DeathDateStr = nil end | ||
wikidataBirth = entityId and mw.wikibase.getBestStatements( entityId, 'P569' ) | wikidataBirth = entityId and mw.wikibase.getBestStatements( entityId, 'P569' ) | ||
wikidataDeath = entityId and wikidataBirth and mw.wikibase.getBestStatements( entityId, 'P570' ) | wikidataDeath = entityId and wikidataBirth and mw.wikibase.getBestStatements( entityId, 'P570' ) | ||
| שורה 106: | שורה 141: | ||
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 | ||
| שורה 117: | שורה 155: | ||
table.insert(warnings, '[[קאטעגאריע:דפים עם שנות חיים שלא תואמים את ויקינתונים]]') | table.insert(warnings, '[[קאטעגאריע:דפים עם שנות חיים שלא תואמים את ויקינתונים]]') | ||
end | end | ||
prefix = 'אלט ' | prefix = 'אלט: ' | ||
else | else | ||
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 = 'יארגאנג: ' | |||
if gender == 'נקבה' then | |||
prefix = 'בת ' | |||
elseif gender == 'זכר' then | |||
prefix = 'בן ' | |||
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) | |||
if success then | if success then | ||
if | AgeYears = Age.year | ||
result = prefix..'שנה' | if Age.year <= 0 then | ||
if Age.month == 1 then | |||
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( | 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 | ||
| שורה 143: | שורה 240: | ||
end | end | ||
-- ignore warning in specific template | |||
local noAgeWarning = false | |||
if mw.getCurrentFrame():getParent():getTitle() == 'מוסטער:תנ"ך פערזענליכקייט' or mw.getCurrentFrame():getParent():getTitle() == 'מוסטער:בעל חיים מפורסם' then | |||
noAgeWarning = true | |||
end | |||
local title = mw.title.getCurrentTitle() | local title = mw.title.getCurrentTitle() | ||
-- ignore warning in other namespace except the main NS | -- ignore warning in other namespace except the main NS | ||
if title.namespace==0 then | if title.namespace==0 and not noAgeWarning then | ||
if AgeYears > 139 then | if AgeYears > 139 then | ||
table.insert(warnings, Errors['future-date']) | 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 | elseif AgeYears>109 then | ||
table.insert(warnings, '[[קאטעגאריע: | table.insert(warnings, '[[קאטעגאריע:מענטשן וואס זענען אנגעקומען צו די 110]]') | ||
elseif AgeYears>99 then | elseif AgeYears>99 then | ||
table.insert(warnings, '[[קאטעגאריע:הונדערט | table.insert(warnings, '[[קאטעגאריע:מענטשן וואס זענען אנגעקומען צו די הונדערט]]') | ||
end | end | ||
end | end | ||
רעדאגירונגען