Модуль:Wikidata/Software
< Модуль:Wikidata
Версия от 15:45, 28 марта 2018; Alexandre (обсуждение | вклад) (Новая страница: «local p = {} --Property:P348 function p.formatVersionClaim( context, options, statement ) local snak = context.formatSnak( options, statement.mainsnak ) if…»)
Для документации этого модуля может быть создана страница Модуль:Wikidata/Software/doc
local p = {} --Property:P348 function p.formatVersionClaim( context, options, statement ) local snak = context.formatSnak( options, statement.mainsnak ) if ( statement.qualifiers ) then --Operation system/Platform if ( statement.qualifiers.P306 ) then snak = context.formatSnak( options, statement.qualifiers.P306[1] ) .. ': ' .. snak elseif ( 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,p548:q15726348,p548:q20631656]' elseif options.type == 'unstable' then typeFilter = typeFilter .. '[p548][!p548:q12355314][!p548:q15726348][!p548:q2804309][!p548:q20631656]' 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][!p548:q20631656]' 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 ) local dot = '' if string.sub( value, 1, 1 ) ~= '.' then dot = '.' end return '<code>' .. dot .. value .. '</code>' end return p