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

מאין תקציר עריכה
מאין תקציר עריכה
שורה 213: שורה 213:
return ''
return ''
end
--[[
This function fills missing parameter using wikidata
]]
function fillMissingParamFromWikidata(missingParam, templateParams, templateArg, frame)
local inWikidata = false
local maintainceCats = nil
if templateParams[missingParam..'-ויקינתונים'] then
templateArg.data = propertyLink.getProperty(templateParams[missingParam..'-ויקינתונים']) or nil
inWikidata = templateArg.data and #(templateArg.data)>0
elseif templateParams[missingParam..'-ויקינתונים-מרובה'] then
templateArg.data = propertyLink.getProperty(templateParams[missingParam..'-ויקינתונים-מרובה'], true) or nil
inWikidata = templateArg.data and #(templateArg.data)>0
elseif templateParams[missingParam..'-ויקינתונים-פשוט'] then
-- use data should be taken from wikidata and link must not be added
local wikidataParamValue = propertyLink.getLabel(templateParams[missingParam..'-ויקינתונים-פשוט'])
if wikidataParamValue and #wikidataParamValue>0 then
templateArg.data = frame:preprocess(mw.ustring.gsub(templateArg.data, '\{\{\{('..missingParam..')\}\}\}', wikidataParamValue))
inWikidata = true
end
elseif missingParam == 'קואורדינטות' then
templateArg.data = frame:expandTemplate{ title = 'קואורדינטות מוויקינתונים', args = { display = 'title,inline' } }
inWikidata = templateArg.data and #(templateArg.data)>0
end
if inWikidata then
local hasData =  #(mw.ustring.gsub(templateArg.data, '%[%[קטגוריה:.-%]%]', ''))>0
if not hasData then
inWikidata = false
maintainceCats = templateArg.data
end
end
return inWikidata, maintainceCats
end
end


שורה 286: שורה 320:
for k,v in pairs(templateStructure) do
for k,v in pairs(templateStructure) do
if v.data then
if v.data then
local m = mw.ustring.match(v.data, '\{\{\{(.-)\}\}\}')
-- remove parameters that were explicitly defined to be removed
-- template isn't full - try to use wikidata to fill it
local ignoreParam = mw.ustring.match(v.data, '^%-$')
if m then
if ignoreParam then
m = mw.uri.decode( m ) -- some templates may add encoding and are preprocessed before
templateStructure[k]=nil
local inWikidata = false
else
if templateParams[m..'-ויקינתונים'] then
-- otherwise if the template isn't full - try to use wikidata to fill it
v.data = propertyLink.getProperty(templateParams[m..'-ויקינתונים']) or nil
local m = mw.ustring.match(v.data, '\{\{\{(.-)\}\}\}')
inWikidata = v.data and #(v.data)>0
if m then
elseif templateParams[m..'-ויקינתונים-מרובה'] then
m = mw.uri.decode( m ) -- some templates may add encoding and are preprocessed before
v.data = propertyLink.getProperty(templateParams[m..'-ויקינתונים-מרובה'], true) or nil
local inWikidata, maintainceCats = fillMissingParamFromWikidata(m, templateParams, v, frame)
inWikidata = v.data and #(v.data)>0
if maintainceCats then
elseif templateParams[m..'-ויקינתונים-פשוט'] then
table.insert(wikidataCats, maintainceCats)
-- use data should be taken from wikidata and link must not be added
local wikidataParamValue = propertyLink.getLabel(templateParams[m..'-ויקינתונים-פשוט'])
if wikidataParamValue and #wikidataParamValue>0 then
v.data = frame:preprocess(mw.ustring.gsub(v.data, '\{\{\{('..m..')\}\}\}', wikidataParamValue))
inWikidata = true
end
end
elseif m == 'קואורדינטות' then
-- if data isn't available remove it
v.data = frame:expandTemplate{ title = 'קואורדינטות מוויקינתונים', args = { display = 'title,inline' } }
if inWikidata then
inWikidata = v.data and #(v.data)>0
args.usingWikidata = true
end
else
if inWikidata then
templateStructure[k]=nil
local hasData = #(mw.ustring.gsub(v.data, '%[%[קטגוריה:.-%]%]', ''))>0
if not hasData then
inWikidata = hasData
table.insert(wikidataCats, v.data)
end
end
end
-- if data isn't available remove it
if inWikidata then
args.usingWikidata = true
else
templateStructure[k]=nil
end
end
end
end
end
end
end
end
-- use wikidata in title
-- use wikidata in title
local m = mw.ustring.match(args.title, '\{\{\{(.-)\|?\}\}\}')
local m = mw.ustring.match(args.title, '\{\{\{(.-)\|?\}\}\}')