יחידה:טווח זמנים: הבדלים בין גרסאות בדף
מראה
מאין תקציר עריכה |
מאין תקציר עריכה |
||
| שורה 4: | שורה 4: | ||
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 end | if parameter~=nil then return parameter, false end | ||
local wikidataVal = mw.wikibase.getBestStatements( entityId, property ) | local wikidataVal = mw.wikibase.getBestStatements( entityId, property ) | ||
if #wikidataVal > 0 then | if #wikidataVal > 0 then | ||
local propValue = wikidataVal[1].mainsnak | local propValue = wikidataVal[1].mainsnak | ||
return mw.wikibase.renderSnak( propValue ) | return mw.wikibase.renderSnak( propValue ) , true | ||
end | end | ||
return nil | return nil, false | ||
end | end | ||
| שורה 24: | שורה 24: | ||
local wikidataStartDate = args['תאריך התחלה-ויקינתונים'] or 'P580' | local wikidataStartDate = args['תאריך התחלה-ויקינתונים'] or 'P580' | ||
local wikidataEndDate = args['תאריך סיום-ויקינתונים'] or 'P582' | local wikidataEndDate = args['תאריך סיום-ויקינתונים'] or 'P582' | ||
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 | ||
| שורה 31: | שורה 32: | ||
-- 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: כן. | ||
local showTimeDiff = args['הצגת הפרשת זמנים'] | local showTimeDiff = args['הצגת הפרשת זמנים'] | ||
local usingWikidata = false | |||
if entityId~=nil then | if entityId~=nil then | ||
-- todo: support different fallbacks for properties | -- todo: support different fallbacks for properties | ||
startDate = WikidataSimpleFill(startDate, entityId, wikidataStartDate ) | local usingWikidataStartDate = false | ||
endDate = WikidataSimpleFill(endDate, entityId, wikidataEndDate ) | local usingWikidataEndDate = false | ||
local usingWikidataPointInTime = false | |||
local usingWikidataDuration = false | |||
startDate, usingWikidataStartDate = WikidataSimpleFill(startDate, entityId, wikidataStartDate ) | |||
endDate, usingWikidataEndDate = WikidataSimpleFill(endDate, entityId, wikidataEndDate ) | |||
usingWikidata = usingWikidata or usingWikidataStartDate or usingWikidataEndDate | |||
if startDate == nil and endDate == nil then | if startDate == nil and endDate == nil then | ||
pointInTime = WikidataSimpleFill(pointInTime, entityId, 'P585' ) | pointInTime, usingWikidataPointInTime = WikidataSimpleFill(pointInTime, entityId, 'P585' ) | ||
usingWikidata = usingWikidata or usingWikidataPointInTime | |||
end | end | ||
if showTimeDiff == 'כן' then | if showTimeDiff == 'כן' then | ||
duration = WikidataSimpleFill(duration, entityId, 'P2047' ) | duration, usingWikidataDuration = WikidataSimpleFill(duration, entityId, 'P2047' ) | ||
if usingWikidataDuration then | |||
-- workaround for T261543 | |||
duration = mw.ustring.gsub( duration, '(%d+) יממה', '%1 ימים' ) | |||
end | |||
usingWikidata = usingWikidata or usingWikidataDuration | |||
end | end | ||
end | end | ||
| שורה 59: | שורה 73: | ||
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 return end -- ignore only end date | ||
res = mw.ustring.format(onlyEndDateText, endDate) | |||
elseif startDate ~= nil and endDate==nil then | elseif startDate ~= nil and endDate==nil then | ||
if ongoingEvent == 'כן' then | if ongoingEvent == 'כן' then | ||
| שורה 83: | שורה 97: | ||
if showTimeDiff == 'כן' and duration~=nil and duration~='' then | if showTimeDiff == 'כן' and duration~=nil and duration~='' then | ||
res = mw.ustring.format('%s (%s)', res, duration) | res = mw.ustring.format('%s (%s)', res, duration) | ||
end | |||
if showEditWikidata and usingWikidata and res~=nil and res~='' and entityId~=nil then | |||
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) | |||
end | end | ||
return res | return res | ||
גרסה מ־08:58, 29 באוגוסט 2020
ניתן ליצור תיעוד על היחידה הזאת בדף יחידה:טווח זמנים/תיעוד
local Date = require('Module:תאריך')
local Arguments = require( "Module:Arguments" )
local function WikidataSimpleFill(parameter, entityId, property)
-- this doesnt handle unkown values, multi value etc
if parameter~=nil then return parameter, false end
local wikidataVal = mw.wikibase.getBestStatements( entityId, property )
if #wikidataVal > 0 then
local propValue = wikidataVal[1].mainsnak
return mw.wikibase.renderSnak( propValue ) , true
end
return nil, false
end
function render(frame)
local args = Arguments.getArgs(frame, { ['trim'] = true, ['removeBlanks'] = true })
local res = ''
local entityId = args['qid'] or mw.wikibase.getEntityIdForCurrentPage()
local pointInTime = args['נקודת זמן']
local startDate = args['תאריך התחלה']
local endDate = args['תאריך סיום']
local wikidataStartDate = args['תאריך התחלה-ויקינתונים'] or 'P580'
local wikidataEndDate = args['תאריך סיום-ויקינתונים'] or 'P582'
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
local onlyEndDateText = args['טקסט סיום']
local duration = args['משך'] --P2047
-- Whether to show time diff between start and end day when applicable. Example: כן.
local showTimeDiff = args['הצגת הפרשת זמנים']
local usingWikidata = false
if entityId~=nil then
-- todo: support different fallbacks for properties
local usingWikidataStartDate = false
local usingWikidataEndDate = false
local usingWikidataPointInTime = false
local usingWikidataDuration = false
startDate, usingWikidataStartDate = WikidataSimpleFill(startDate, entityId, wikidataStartDate )
endDate, usingWikidataEndDate = WikidataSimpleFill(endDate, entityId, wikidataEndDate )
usingWikidata = usingWikidata or usingWikidataStartDate or usingWikidataEndDate
if startDate == nil and endDate == nil then
pointInTime, usingWikidataPointInTime = WikidataSimpleFill(pointInTime, entityId, 'P585' )
usingWikidata = usingWikidata or usingWikidataPointInTime
end
if showTimeDiff == 'כן' then
duration, usingWikidataDuration = WikidataSimpleFill(duration, entityId, 'P2047' )
if usingWikidataDuration then
-- workaround for T261543
duration = mw.ustring.gsub( duration, '(%d+) יממה', '%1 ימים' )
end
usingWikidata = usingWikidata or usingWikidataDuration
end
end
-- Whether the event still continues. this will show <START>-present. Example: כן
local ongoingEvent = args['נמשך']
local diffFormat = 'auto' -- TODO: better handling for different scales
-- simple case of single point in time
if pointInTime~=nil or startDate==endDate then
if pointInTime == nil and startDate==endDate then
pointInTime = startDate
end
res = pointInTime
else -- date ranges
if startDate == nil and endDate~=nil then
if onlyEndDateText == nil then return end -- ignore only end date
res = mw.ustring.format(onlyEndDateText, endDate)
elseif startDate ~= nil and endDate==nil then
if ongoingEvent == 'כן' then
res = mw.ustring.format('%s - הווה', startDate)
-- 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 = startDate
end
elseif startDate~=nil and endDate~=nil then
res = mw.ustring.format('%s - %s', startDate, endDate)
if showTimeDiff == 'כן' and duration==nil then
local success, automaicDuration = pcall(Date.parseDateRange, dateRange, diffFormat, true)
if success then duration = automaicDuration end
end
end
end
-- append the duration
if showTimeDiff == 'כן' and duration~=nil and duration~='' then
res = mw.ustring.format('%s (%s)', res, duration)
end
if showEditWikidata and usingWikidata and res~=nil and res~='' and entityId~=nil then
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)
end
return res
end
return {
['טווח זמנים']=render
}