אונטערשייד צווישן ווערסיעס פון "יחידה:טווח זמנים"

אפדעיט
אין תקציר עריכה
(אפדעיט)
 
(10 מיטלסטע ווערסיעס פון 2 באַניצער נישט געוויזן.)
שורה 1: שורה 1:
local Date = require('Module:דאטום')
local Date = require('Module:דאטום')
local HDate = require('Module:אידישע דאטום')
local Arguments = require( "Module:Arguments" )
local Arguments = require( "Module:Arguments" )
--[[
Assuming a string representng a date is passed, this function tries to determine
whether the date is Hebrew
]]
local function isHDate(str)
  -- quick heuristic: date without numeric digit is probably hebrew
  if string.match(str, "%d") then
    return false
  else
    return true
  end
end


local function WikidataSimpleFill(parameter, entityId, property)  
local function WikidataSimpleFill(parameter, entityId, property)  
-- this doesnt handle unkown values, multi value etc
-- this doesnt handle unkown values, multi value etc
if parameter~=nil then return parameter, false end
if parameter~=nil and parameter~="" then return parameter, false end
return nil, false
return nil, false
end
--[[
This function fills missing parameter using wikidata
]]
function crossValidateWikidata(missingParam, templateParams, templateArg, frame, entityId)
local WikidataCrossValidation = require('Module:WikidataCrossValidation')
local matching = nil
local propertyName
if entityId == nil or missingParam==nil  then
return nil
end
if templateParams[missingParam..'-ויקינתונים'] then
propertyName = templateParams[missingParam..'-ויקינתונים']
if mw.ustring.find(propertyName, ',')~=nil then return end
matching = WikidataCrossValidation.crossValidate(templateArg, propertyName, entityId)
end
if matching then
return WikidataCrossValidation.maintainceCategory(matching, propertyName)
end
end
end


שורה 11: שורה 47:
local args = Arguments.getArgs(frame, { ['trim'] = true, ['removeBlanks'] = true })
local args = Arguments.getArgs(frame, { ['trim'] = true, ['removeBlanks'] = true })
local res = ''
local res = ''
local maintainceCategory = ''
local entityId = args['qid']
local entityId = args['qid']
if (entityId == '-' or entityId=='') then entityId = nil end
if (entityId == '-' or entityId=='') then entityId = nil end
local pointInTime = args['נקודת זמן']
local pointInTime = args['נקודת זמן']
local startDate = args['תאריך התחלה']
local startDate = args['תאריך התחלה']
local HStartDate
if startDate ~= nil and isHDate(startDate) then
HStartDate = startDate
local success, sepcDate = pcall(HDate.pick, mw.getCurrentFrame():newChild{ args = {hebrew=startDate, world='', exact='כן' } })
if success and sepcDate ~= '' then
    startDate = sepcDate
end
end
local endDate = args['תאריך סיום']
local endDate = args['תאריך סיום']
local HEndDate
if endDate ~= nil and isHDate(endDate) then
HEndDate = endDate
local success, sepcDate = pcall(HDate.pick, mw.getCurrentFrame():newChild{ args = {hebrew=endDate, world='', exact='כן' } })
if success and sepcDate ~= '' then
    endDate = sepcDate
end
end
local wikidataStartDate = args['תאריך התחלה-ויקינתונים'] or 'P580'
local wikidataStartDate = args['תאריך התחלה-ויקינתונים'] or 'P580'
local wikidataEndDate = args['תאריך סיום-ויקינתונים'] or 'P582'
local wikidataEndDate = args['תאריך סיום-ויקינתונים'] or 'P582'
local wikidataEndDateLimit = args['גבול תאריך סיום-ויקינתונים']
local showEditWikidata = true
local showEditWikidata = true
 
-- text to show if we have only end date. Example: "Last even - %s" where %s is time. nil - will not show end date
-- text to show if we have only end date. Example: "Last even - %s" where %s is time. nil - will not show end date
local onlyEndDateText = args['טקסט סיום']
local onlyEndDateText = args['טקסט סיום']
-- text to show if we have only start date. Example: "First even - %s" where %s is time. nil - will not show end date
local onlyStartDateText = args['טקסט התחלה']
 
local duration = args['משך'] --P2047
local duration = args['משך'] --P2047
-- Whether to show time diff between start and end day when applicable. Example: כן.
-- Whether to show time diff between start and end day when applicable. Example: כן.
שורה 33: שורה 88:
if  entityId~=nil then
if  entityId~=nil then
local crossValBegin = crossValidateWikidata('תאריך התחלה', frame.args, startDate, frame, entityId)
if crossValBegin~=nil then maintainceCategory = maintainceCategory ..crossValBegin end
local crossvalEnd = crossValidateWikidata('תאריך סיום', frame.args, endDate, frame, entityId)
if crossvalEnd~=nil then maintainceCategory= maintainceCategory ..crossvalEnd end
-- todo: support different fallbacks for properties
-- todo: support different fallbacks for properties
local usingWikidataStartDate = false
local usingWikidataStartDate = false
שורה 39: שורה 100:
local usingWikidataDuration = false
local usingWikidataDuration = false
wikidataStartDate = mw.text.split( wikidataStartDate, ' *, *', false )
wikidataStartDate = mw.text.split( wikidataStartDate, ' *, *', false )
wikidataEndDate = mw.text.split( wikidataEndDate, ' *, *', false )
wikidataEndDate = mw.text.split( wikidataEndDate, ' *, *', false )
שורה 46: שורה 108:
for _, wikidataEndProp in pairs(wikidataEndDate) do
for _, wikidataEndProp in pairs(wikidataEndDate) do
endDate, usingWikidataEndDate = WikidataSimpleFill(endDate, entityId, wikidataEndProp )
endDate, usingWikidataEndDate = WikidataSimpleFill(endDate, entityId, wikidataEndProp )
end
-- if only start date available, we will add prefix prefixStartOnly otherwise will bound the end
if onlyStartDateText==nil and (endDate == '' or endDate == nil) and wikidataEndDateLimit~=nil and wikidataEndDateLimit~='' then
-- fallback
endDate, usingWikidataEndDate = WikidataSimpleFill(endDate, entityId, wikidataEndDateLimit )
end
end
שורה 96: שורה 164:
else -- date ranges
else -- date ranges
if startDate == nil and endDate~=nil  then
if startDate == nil and endDate~=nil  then
if onlyEndDateText == nil then return end -- ignore only end date
if onlyEndDateText == nil then
res = mw.ustring.format(onlyEndDateText, endDate)
elseif startDate ~= nil and (endDate==nil or (ongoingEvent and endDate~=nil))  then
if ongoingEvent then
dateFormat = '%s–%s'
dateFormat = '%s–%s'
if mw.ustring.match(startDate, ' ') or (endDate and mw.ustring.match(endDate, ' ')) then
if mw.ustring.match(endDate, ' ') then
dateFormat = '%s – %s'
dateFormat = '%s – %s'
end
end
res = mw.ustring.format(dateFormat, startDate, endDate or 'הווה')
res = mw.ustring.format(dateFormat, '?', endDate)
-- try to fallback to automatic duration if duration is not available
else
if showTimeDiff == 'כן' and duration==nil then
res = mw.ustring.format(onlyEndDateText, endDate)
local success, automaicDuration = pcall(Date.parseDateRange, startDate, diffFormat, true)
end
if success then duration = automaicDuration end
elseif startDate ~= nil and (endDate==nil or (ongoingEvent and endDate~=nil))  then
if onlyStartDateText then
res = mw.ustring.format(onlyStartDateText, startDate)
else
if ongoingEvent then
dateFormat = '%s–%s'
if mw.ustring.match(startDate, ' ') or (endDate and mw.ustring.match(endDate, ' ')) then
dateFormat = '%s – %s'
end
res = mw.ustring.format(dateFormat, HStartDate or startDate, HEndDate or endDate or 'הווה')
-- try to fallback to automatic duration if duration is not available
if showTimeDiff == 'כן' and duration==nil then
local success, automaicDuration = pcall(Date.parseDateRange, startDate, diffFormat, true)
if success then duration = automaicDuration end
end
else
res = HStartDate or startDate
end
end
else
res = startDate
end
end
elseif startDate~=nil and endDate~=nil  then
elseif startDate~=nil and endDate~=nil  then
שורה 118: שורה 197:
dateFormat = '%s – %s'
dateFormat = '%s – %s'
end
end
res = mw.ustring.format(dateFormat, startDate, endDate)
res = mw.ustring.format(dateFormat, HStartDate or startDate, HEndDate or endDate)
if showTimeDiff == 'כן' and duration==nil then
if showTimeDiff == 'כן' and duration==nil then
local success, automaicDuration = pcall(Date.parseDateRange, res, diffFormat, true)
local success, automaicDuration = pcall(Date.parseDateRange, startDate .. '-' .. endDate, diffFormat, true)
if success then duration = automaicDuration end
if success then duration = automaicDuration end
end
end
שורה 134: שורה 213:
local link = mw.title.makeTitle( 0, entityId, '', 'wikidata' ):fullUrl('uselang=he')
local link = mw.title.makeTitle( 0, entityId, '', 'wikidata' ):fullUrl('uselang=he')
res = res .. mw.ustring.format(' [[File:Blue pencil RTL.svg|15px|link=%s|עריכת הנתון בוויקינתונים]]', link)
res = res .. mw.ustring.format(' [[File:Blue pencil RTL.svg|15px|link=%s|עריכת הנתון בוויקינתונים]]', link)
end
if maintainceCategory~=nil and res~=nil then
res = res..maintainceCategory
end
end
return res
return res
end
end