Modul:Multiple images from Wikidata
Aspect
Documentația acestui modul poate fi creată la Modul:Multiple images from Wikidata/doc
local multiImages = require('Modul:Multiple image').render
local getArgs = require('Modul:Arguments').getArgs
local illWd = require('Modul:Ill-wd').fromArgs
local TableTools = require('Modul:TableTools')
local join = require('Modul:Separated entries')._main
local p = {}
local function extractOneClaim(q, propId)
local claims = wikidata.findBestClaimsForProperty(q, propId)
local array = {}
if claims then
for _,eachClaim in ipairs(claims) do
if eachClaim.type == 'statement' and eachClaim.mainsnak.snaktype == 'value' then
return eachClaim
end
end
end
return nil
end
function p.fromArgs(q, props, captionTemplates)
local images = {}
local captions = { separator = ', ', conjunction = ' și '}
for propIdx=1,#props do
local eachProp = props[propIdx]
local propClaim = extractOneClaim(q, eachProp)
local imageClaim
if propClaim then
imageClaim = extractOneClaim(propClaim.mainsnak.datavalue.value.id, 'P18')
end
if imageClaim then
table.insert(images, imageClaim.mainsnak.datavalue.value)
local crtCaptionTemplate = captionTemplates[propIdx]
if not crtCaptionTemplate then crtCaptionTemplate = captionTemplates[1 + (propIdx % #captionTemplates)] end
local expandedCaptionTemplate = nil
if crtCaptionTemplate then
expandedCaptionTemplate = mw.ustring.sub(crtCaptionTemplate, '___', illWd(propClaim.mainsnak.datavalue.value.id))
table.insert(captions, expandedCaptionTemplate)
end
end
end
captions = TableTools.removeDuplicates(captions)
-- TODO: compute args
return multiImages()
end
function p.fromArray(array)
if not array or not array.props then return nil end
local props = mw.text.split(array.props, ',')
for propIdx = 1,#props do
props[propIdx] = mw.text.trim(props[propIdx])
end
local captionTemplates = ''
if array.captionTemplates then
-- TODO: parse templates
end
return p.fromArgs(array.q, props, array.captionTemplate)
end
function p.fromFrame(frame)
return p.fromArray(getArgs(frame))
end
return p