בדוקי עריכות אוטומטית, אינטערפעיס רעדאקטארן, אינטערפעיס אדמיניסטראַטאָרן, סיסאפן, מייבאים, מעדכנים, מייבא, אספקלריה רעדאקטארן
46,368
רעדאגירונגען
ק (rv) |
(אפדעיט) |
||
| (18 מיטלסטע ווערסיעס פון 5 באַניצער נישט געוויזן.) | |||
| שורה 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 | ||
local | return nil, false | ||
if | 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 | end | ||
| שורה 16: | שורה 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: כן. | ||
| שורה 38: | שורה 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 | ||
| שורה 44: | שורה 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 ) | ||
| שורה 51: | שורה 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 | ||
| שורה 80: | שורה 143: | ||
-- set default ongoingEvent as false | -- set default ongoingEvent as false | ||
ongoingEvent = false | ongoingEvent = false | ||
for v in string.gmatch(endDateOngoingEvent, "[^, | for v in string.gmatch(endDateOngoingEvent, "[^,]+") do | ||
if v == endDate then | if v:match('^%s*(.-)%s*$') == endDate then | ||
-- set as true if end date specific that match endDateOngoingEvent | -- set as true if end date specific that match endDateOngoingEvent | ||
ongoingEvent = true | ongoingEvent = true | ||
| שורה 101: | שורה 164: | ||
else -- date ranges | else -- date ranges | ||
if startDate == nil and endDate~=nil then | if startDate == nil and endDate~=nil then | ||
if onlyEndDateText == nil | if onlyEndDateText == nil then | ||
dateFormat = '%s–%s' | dateFormat = '%s–%s' | ||
if | 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) | ||
else | |||
res = mw.ustring.format(onlyEndDateText, endDate) | |||
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 | ||
end | end | ||
elseif startDate~=nil and endDate~=nil then | elseif startDate~=nil and endDate~=nil then | ||
| שורה 123: | שורה 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, | local success, automaicDuration = pcall(Date.parseDateRange, startDate .. '-' .. endDate, diffFormat, true) | ||
if success then duration = automaicDuration end | if success then duration = automaicDuration end | ||
end | end | ||
| שורה 132: | שורה 206: | ||
-- append the duration | -- append the duration | ||
if showTimeDiff == 'כן' and duration~=nil and duration~='' then | if showTimeDiff == 'כן' and duration~=nil and duration~='' and res~=nil then | ||
res = mw.ustring.format(dateRangeDiffFormat, res, duration) | res = mw.ustring.format(dateRangeDiffFormat, res, duration) | ||
end | end | ||
| שורה 139: | שורה 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 | ||
רעדאגירונגען