Перайсці да зместу

Модуль:Wikidata/Software

З Вікіпедыі, свабоднай энцыклапедыі

local p = {}

--Property:P348
function p.formatVersionClaim( context, options, statement )
    local snak = context.formatSnak( options, statement.mainsnak )

	if ( statement.qualifiers ) then
		--Operation system
		if ( statement.qualifiers.P400 ) then
			snak = context.formatSnak( options, statement.qualifiers.P400[1] ) .. ': ' .. snak
		end

		--Name
		if ( statement.qualifiers.P1476 ) then
			snak = snak .. ' «' .. context.formatSnak( options, statement.qualifiers.P1476[1] ) .. '»'
		end

		--Date of release
		if ( statement.qualifiers.P577 ) then
			snak = snak .. ' (' .. context.formatSnak( options, statement.qualifiers.P577[1] ) .. ')'
		elseif ( statement.qualifiers.P585 ) then
			snak = snak .. ' (' .. context.formatSnak( options, statement.qualifiers.P585[1] ) .. ')'
		end
	end

	--References
    if ( options.references ) then
		snak = snak .. context.formatRefs( options, statement );
	end

    return snak
end

--Property:P348
function p.formatVersionProperty( 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 typeFilter = options.property;
	if options.type == 'all' then
		-- нічога не робім
	elseif options.type == 'stable' then
		typeFilter = typeFilter .. '[p548:q12355314,p548:q2804309]'
	elseif options.type == 'unstable' then
		typeFilter = typeFilter .. '[p548][!p548:q12355314][!p548:q15726348][!p548:q2804309]'
	elseif options.type == 'alpha' then
		typeFilter = typeFilter .. '[p548:q2122918]'
	elseif options.type == 'beta' then
		typeFilter = typeFilter .. '[p548:q3295609]'
	elseif options.type == 'rc' then
		typeFilter = typeFilter .. '[p548:q1072356]'
	elseif options.type == 'test' then
		typeFilter = typeFilter .. '[p548][!p548:q2122918][!p548:q3295609][!p548:q1072356][!p548:q12355314][!p548:q15726348][!p548:q2804309]'
	else
		typeFilter = typeFilter .. '[!p548]'
	end

	-- Атрыманне патрэбных сцвярджэнняў
	local WDS = require( 'Module:WikidataSelectors' );
	local claims = WDS.filter( options.entity.claims, typeFilter );

    if claims == nil then
        return ''
    end

	-- Прагляд усіх заяў сцвярджэння з накапленнем аформленых прадвызначаных заяў у табліцы
    local formattedClaims = {}

    for i, claim in ipairs( claims ) do
        local formattedStatement = p.formatVersionClaim( context, 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, options.separator, options.conjunction )
    if out ~= '' then
	    if options.before then
	    	out = options.before .. out
		end
	    if options.after then
	    	out = out .. options.after
		end
	end

    return out
end

--Property:P1195
function p.formatExtension( context, options, value )
	return '<code>.' .. value .. '</code>'
end

return p