יחידה:תבנית מידע: הבדלים בין גרסאות בדף
מאין תקציר עריכה |
מאין תקציר עריכה |
||
| שורה 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 | -- 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 ignoreParam then | |||
m = mw. | templateStructure[k]=nil | ||
else | |||
-- otherwise if the template isn't full - try to use wikidata to fill it | |||
local m = mw.ustring.match(v.data, '\{\{\{(.-)\}\}\}') | |||
if m then | |||
m = mw.uri.decode( m ) -- some templates may add encoding and are preprocessed before | |||
local inWikidata, maintainceCats = fillMissingParamFromWikidata(m, templateParams, v, frame) | |||
if maintainceCats then | |||
table.insert(wikidataCats, maintainceCats) | |||
local | |||
if | |||
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 | ||
end | |||
-- use wikidata in title | -- use wikidata in title | ||
local m = mw.ustring.match(args.title, '\{\{\{(.-)\|?\}\}\}') | local m = mw.ustring.match(args.title, '\{\{\{(.-)\|?\}\}\}') | ||