Modul:NameAndImage
Aspect

Afișează numele unei entități (cu link) având în stânga un simbol asociat acestuia. Numele este identificat prin ID-ul itemului de Wikidata, iar proprietatea prin codul de la Wikidata al proprietății. Procedând așa, se garantează că linkul va duce mereu către articolul corect, iar numele și imaginea vor fi unice și actuale, fără a mai face vreo modificare în urma redenumirii.
local getArgs = require('Modul:Arguments').getArgs
local wikidata = require('Modul:Wikidata')
local StringUtils = require('Modul:StringUtils')
local join = require('Modul:Separated entries')._main
local libUtils = require('libraryUtil')
local p = {}
local maxSize = { }
maxSize['P94'] = '23x23'
maxSize['P41'] = '23x23'
p._nameAndImageFromOneOfProps = function(entityId, imagePropIds)
libUtils.checkTypeForNamedArg('_nameAndImage', 'imagePropIds', imagePropIds, 'table', false)
libUtils.checkTypeForNamedArg('_nameAndImage', 'entityId', entityId, 'string', true)
local articleLink = wikidata.findLinkToItem(entityId, false)
local imageName = nil
local maxSizeOfImage = nil
for _idx, eachPropId in pairs(imagePropIds) do
local eachImageName = wikidata.findOneValueNoRef(imagePropId, entityId)
if imageName == nil and eachImageName and mw.text.trim(eachImageName) ~= '' then
imageName = eachImageName
maxSizeOfImage = StringUtils.appendIfMissing({maxSize[imagePropId] or '23x23', 'px'})
end
end
local imageLink = ''
if imageName and mw.text.trim(imageName) ~= '' then
imageLink = '[[Fișier:' .. imageName .. '|' .. maxSizeOfImage .. ']]'
end
return mw.text.trim(join({imageLink, articleLink, separator = ' '}))
end
p._nameAndImage = function(entityId, imagePropId)
libUtils.checkTypeForNamedArg('_nameAndImage', 'imagePropId', imagePropId, 'string', false)
libUtils.checkTypeForNamedArg('_nameAndImage', 'entityId', entityId, 'string', true)
return p._nameAndImageFromOneOfProps(entityId, {imagePropId})
end
p.nameAndImage = function(frame)
local args = getArgs(frame)
local entityId = args[1]
local propId = args[2]
return p._nameAndImage()
end
p.nameAndCoatOfArms = function(frame)
local args = getArgs(frame)
local entityId = args[1]
return p._nameAndImage(entityId, 'P94')
end
p.nameAndFlag = function(frame)
local args = getArgs(frame)
local entityId = args[1]
return p._nameAndImage(entityId, 'P41')
end
return p