Модуль:Wikidata/media

Материал из Энциклопедии Гитармага
< Модуль:Wikidata
Версия от 15:52, 19 апреля 2016; Admin (обсуждение | вклад) (Новая страница: «local p = {} function p.formatCommonsCategory( context, options, value ) local link = 'commons:Category:' .. value local title = value if ( options['…»)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Для документации этого модуля может быть создана страница Модуль: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 .. ' \'\'\' на [[Викисклад]]е'
    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

return p