Модуль:Wikidata/item
Поделись знанием:
Для документации этого модуля может быть создана страница Модуль:Wikidata/item/doc
local WDS = require('Module:WikidataSelectors') local p = {} local categoryLinksToEntitiesWithMissingLabel = '[[Категория:Википедия:Статьи со ссылками на элементы Викиданных без русской подписи]]'; local function getGenderLabelForEntityId( entityId, isFemale ) if not isFemale then return mw.wikibase.label( entityId ); end local entity = mw.wikibase.getEntity( entityId ); if not entity.claims['P2521'] then return entity:getLabel(); end local femLabels = WDS.filterByLanguage( WDS.filterByRank( entity.claims.P2521, 'deprecated', true ), 'ru' ); if femLabels ~= nil and femLabels[1] and femLabels[1].mainsnak and femLabels[1].mainsnak.datavalue and femLabels[1].mainsnak.datavalue.value and femLabels[1].mainsnak.datavalue.value.text then return femLabels[1].mainsnak.datavalue.value.text; end return entity:getLabel(); end local function formatGenderLabelForEntityId( entityId, isFemale ) local label = getGenderLabelForEntityId( entityId, isFemale ); -- получение ссылки по идентификатору local link = mw.wikibase.sitelink( entityId ) if link then return label and '[[' .. link .. '|' .. label .. ']]' or '[[' .. link .. ']]' end if label then -- will be replaced by link to Reasonator by Gadget return '[[:d:' .. entityId .. '|' .. label .. ']]' end -- сообщение об отсутвии локализованного названия -- not good, but better than nothing return '[[:d:' .. entityId .. '|' .. entityId .. ']]<span style="border-bottom: 1px dotted; cursor: help; white-space: nowrap" title="В Викиданных нет русской подписи к элементу. Вы можете помочь, указав русский вариант подписи.">?</span>' .. categoryLinksToEntitiesWithMissingLabel; end function p.formatEntityWithGenderClaim( context, options, statement ) 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 is missing'); end; if ( not statement ) then error( 'statement not specified'); end; local isFemale = options.entity.claims['P21'] and options.entity.claims['P21'][1] and options.entity.claims['P21'][1].mainsnak and options.entity.claims['P21'][1].mainsnak.datavalue and options.entity.claims['P21'][1].mainsnak.datavalue.value and options.entity.claims['P21'][1].mainsnak.datavalue.value["numeric-id"] == 6581072 local snak = statement.mainsnak; if snak and snak.datavalue and snak.datavalue.value and snak.datavalue.value['numeric-id'] then local entityId = 'Q' .. snak.datavalue.value['numeric-id']; return formatGenderLabelForEntityId( entityId, isFemale ); end return context.formatSnak( options, snak ) end return p