{{i}} Документація модуля[перегляд] [редагувати] [історія] [очистити кеш]
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'
      local alt = 'CMNS:'
    	if ( options['icon_size'] and options['icon_size'] ~= '' ) then
    		icon_size = options['icon_size']
    	end
     if ( options['alt'] and options['alt'] ~= '' ) then
    		alt = options['alt']
    	end
    	commons = '[[File:Commons-logo.svg|' .. icon_size .. '|link=' .. link .. '|alt=' .. alt .. ']] ' .. commons
    end

--[[Text before and after link;
  за відсутності аргументів робимо стандартне посилання на Вікісховище
]]
    if ( options['text_before'] and options['text_before'] ~= '' ) then
    	commons = options['text_before'] .. ' ' .. commons
    else
      commons = '\'\'\' ' .. commons
    end

    if ( options['text_after'] and options['text_after'] ~= '' ) then
      if ( not options['text_before'] and options['text_before'] == '' ) then
       	commons =  commons .. ' \'\'\'' .. options['text_after']
      else
       	commons =  commons .. ' ' .. options['text_after']
      end
    else
      commons = commons .. ' \'\'\' у [[Вікісховище|Вікісховищі]]'
    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

 --[[
  Функция для оформления одного утверждения (statement) для изображения
  Принимает: объект-таблицу утверждение, таблицу параметров,
  объект-функцию оформления внутренних структур утверждения (snak) и
  объект-функцию оформления ссылки на источники (reference)
  Возвращает: строку оформленного текста с заявлением (claim)
]]
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