Module:Wikidata/media
Documentation for this module may be created at Module:Wikidata/media/doc
local p = {}
function p.formatCommonsCategory( context, options, value )
local link = 'commons:Category:' .. value
local title = value
if ( options['text'] and options['text'] ~= '' ) then
title = options['text']
end
commons = '[[' .. link .. '|' .. title .. ']]'
--Commons icon
if ( not options['icon'] or options['icon'] ~= '-' ) then
local icon_size = '15px'
if ( options['icon_size'] and options['icon_size'] ~= '' ) then
icon_size = options['icon_size']
end
commons = '[[File:Commons-logo.svg|' .. icon_size .. '|link=' .. link .. ']] ' .. commons
end
--Text before and after link
if ( options['text_before'] and options['text_before'] ~= '' ) then
if ( options['text_before'] ~= '-' ) then
commons = options['text_before'] .. ' ' .. commons
end
else
commons = '\'\'\' ' .. commons
end
if ( options['text_after'] and options['text_after'] ~= '' ) then
if ( options['text_after'] ~= '-' ) then
commons = commons .. ' ' .. options['text_after']
end
else
commons = commons .. ' \'\'\' на [[Wikipiklan]]е'
end
return commons
end
function p.formatImage( context, options, value )
local image = '[[File:' .. value
if options['border'] and options['border'] ~= '' then
image = image .. '|border'
end
if options['size'] and options['size'] ~= '' then
image = image .. '|' .. options['size']
end
if options['alt'] and options['alt'] ~= '' then
image = image .. '|' .. options['alt']
end
image = image .. ']]'
return image
end
--[[
ʻO ka hana no ka hanaʻana i kahi'ōlelo ('ōlelo) no ke kiʻi
ʻAeʻia: kahi pane pāʻokoʻa, papa hoʻonohonoho,
keʻona hana o nāʻenehana hoʻonā i loko (snak) a
papa mea manao i maopopo nä haumäna i kumu (kūmole)
Hoʻi: he kaula o kikokikona palapala i hoakaka (kuleana)
]]
function p.formatImageClaim( context, options, statement )
local snak = statement.mainsnak
local hash = ''
local mainSnakClass = ''
if ( snak.hash ) then
hash = ' data-wikidata-hash="' .. snak.hash .. '"'
else
mainSnakClass = ' wikidata-main-snak';
end
local before = '<span class="wikidata-snak ' .. mainSnakClass .. '"' .. hash .. '>'
local after = '</span>'
if snak.snaktype ~= 'value' then
return ''
end
--Image legend
local legend = ''
if ( statement.qualifiers and statement.qualifiers.P2096 ) then
local langCode = mw.language.getContentLanguage():getCode()
mw.logObject( statement.qualifiers.P2096 )
mw.logObject( langCode )
for k, qualifier in pairs ( statement.qualifiers.P2096 ) do
if qualifier.snaktype == 'value'
and qualifier.datavalue.value.language == langCode
then
legend = '<br>' .. qualifier.datavalue.value.text
break
end
end
end
return p.formatImage( context, options, snak.datavalue.value ) .. legend
end
return p