Перейти к содержимому страницы
Открыть меню
Переключить меню настроек
Открыть персональное меню
Вы не представились системе
Ваш IP-адрес будет виден всем, если вы внесёте какие-либо изменения.

Модуль:Награда

Материал из вики «Вече»
Версия от 08:43, 27 августа 2026; wp>ru.wikipedia (Импорт из русской Википедии, версия 154722546)
(разн.) ← Предыдущая версия | Текущая версия (разн.) | Следующая версия → (разн.)

Для документации этого модуля может быть создана страница Модуль:Награда/doc

-- Общий модуль для шаблонов наград

local p = {}
local mw = require('mw')

function p.render(frame)
    local args = frame:getParent().args
    local element = args['элемент'] or args['element'] or args['e'] or args[1] or ""
    local file = args['файл'] or args['file'] or ""
    local size = args['размер'] or args['size'] or ""
    local link = args['ссылка'] or args['link'] or ""
    local title = args['заголовок'] or args['название'] or args['title'] or ""
    local category = args['категория'] or args['category'] or ""
    local border = args['рамка'] or args['border'] or ""
    local date = args['дата'] or args['date'] or args[2] or ""
	local yesno = require('Module:Yesno')
	local nocat = yesno(args['nocat'])
    
    local image = file
    local imageType = ""
    if image == "" and element ~= "" then
        local p2910 = mw.wikibase.getBestStatements(element, 'P2910')
        local p2425 = mw.wikibase.getBestStatements(element, 'P2425')
        if p2910 and #p2910 > 0 then
            image = p2910[1].mainsnak.datavalue.value
            imageType = "P2910"
        elseif p2425 and #p2425 > 0 then
            image = p2425[1].mainsnak.datavalue.value
            imageType = "P2425"
        end
    end

    if size == "" then
        if imageType == "P2910" then
            size = "40x40px"
        elseif imageType == "P2425" then
            size = "x17px"
        else
            size = "x17px"
        end
    end

    local wikilink = ""
    if link ~= "" then
        wikilink = link
    elseif element ~= "" then
        wikilink = mw.wikibase.getSitelink(element) or ("d:" .. element)
    end
    
    local label = title ~= "" and title or (link ~= "" and link or (element ~= "" and mw.wikibase.getLabelByLang(element, 'ru') or ""))
    if date ~= "" and image ~= "" then
        label = label .. " — " .. date
    end

    local output
    if image ~= "" then
        output = '[[Файл:' .. image ..
                 (border == "+" and "|border" or "") ..
                 "|" .. size ..
                 (wikilink ~= "" and ("|link=" .. wikilink) or "") ..
                 (label ~= "" and "|" .. label or "") ..
                 ']]'
    else
        output = '[[' .. wikilink .. '|' .. label .. ']]'
        if date ~= "" then
            output = output .. ' <span style="font-size:95%;">(' .. date .. ')</span>'
        end
    end

    if element ~= "" then
        output = '<span data-wikidata-value-id="' .. element .. '">' .. output .. '</span>'
    end

    if date ~= "" then
        output = output .. '<span class="noprint" style="display:none" data-wikidata-qualifier-id="P585">' .. date .. '</span>'
    end

    if mw.title.getCurrentTitle().namespace == 0 and not nocat then
        if category ~= "" then
            output = output .. '[[Категория:' .. category .. ']]'
        elseif element ~= "" then
            local cat = mw.wikibase.getBestStatements(element, 'P2517')
            if cat and #cat > 0 then
                local catQ = cat[1].mainsnak.datavalue.value
                if type(catQ) == "table" then
                    catQ = catQ.id
                end
                local catSitelink = mw.wikibase.getSitelink(catQ)
                if catSitelink and catSitelink ~= "" then
                    output = output .. '[[' .. catSitelink .. ']]'
                end
            end
        end
    end

    return output
end

return p