Модуль:Wikidata/Awards

Википеди материал

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

local p = {};

function p.formatAwardsProperty( context, options )
	if not context then error( 'context not specified' ); end;
	if not options then error( 'options not specified' ); end;
	if not options.entity then error( 'options.entity missing' ); end;

    local claims = context.selectClaims( options, options.property );
    if claims == nil then
        return ''; --TODO error?
    end

    -- Обход всех заявлений утверждения и с накоплением оформленых предпочтительных 
    -- заявлений в таблице
    local formattedClaims = {};

    for i, claim in ipairs( claims ) do
        local formattedStatement = context.formatStatement( options, claim );
        -- здесь может вернуться либо оформленный текст заявления
        -- либо строка ошибки nil похоже никогда не возвращается
        if formattedStatement then
            formattedStatement = '<span class="wikidata-claim" data-wikidata-property-id="' ..
            	string.upper( options.property ) .. '" data-wikidata-claim-id="' .. claim.id .. '">' ..
            	formattedStatement .. '</span>';
            table.insert( formattedClaims, formattedStatement );
        end
    end

	-- создание текстовой строки со списком оформленых заявлений из таблицы  
    local out = mw.text.listToText( formattedClaims, ';\n* ', ';\n* ' );
    if out ~= '' then
    	out = '* ' .. out;
	end
	out = out .. '.'
    return out
end

function p.formatAwardClaim( context, options, statement )
	local result = '';
	if not statement or statement.mainsnak.snaktype ~= 'value' then
		return result;
	end

	result = result .. context.formatSnak( options, statement.mainsnak, {} );

	if statement.qualifiers and statement.qualifiers.P585 then
		result = result .. ' (' .. context.formatSnak( options, statement.qualifiers.P585[ 1 ] ) .. ')';
	end

    -- TODO: filter only russian text
	if statement.qualifiers and statement.qualifiers.P6208 then
		result = result .. ' — \'\'' .. context.formatSnak( options, statement.qualifiers.P6208[ 1 ] ) .. '\'\'';
	end

	result = result .. context.formatRefs( options, statement );

	return result;
end

function p.formatAwardValue( context, options, statement )
	return context.formatValueDefault( context, options, statement );
end

return p;