Модуль:Wikidata/item
Для документации этого модуля может быть создана страница Модуль:Wikidata/item/doc
local WDS = require( 'Module:WikidataSelectors' );local p = {};local categoryLinksToEntitiesWithMissingLabel = '[[Категори:Википедия:Статьи со ссылками на элементы Викиданных без чувашской подписи]]';local function getGenderLabelForEntityId( entityId, gender )local genderPropertyIdif gender == 1 thengenderPropertyId = 'P3321'elseif gender == 2 thengenderPropertyId = 'P2521'elsereturn mw.wikibase.label( entityId )endlocal genderLabels = mw.wikibase.getAllStatements( entityId, genderPropertyId )if genderLabels thengenderLabels = WDS.filterByLanguage( WDS.filterByRank( genderLabels, 'deprecated', true ), 'cv' );endif genderLabels andgenderLabels[ 1 ] andgenderLabels[ 1 ].mainsnak andgenderLabels[ 1 ].mainsnak.datatype == 'monolingualtext'thenreturn genderLabels[ 1 ].mainsnak.datavalue.value.text;endreturn mw.wikibase.label( entityId )end local function formatOccupationLinkForEntityId( entityId, gender )local label = getGenderLabelForEntityId( entityId, gender );-- first try to link to occupation article local link = mw.wikibase.sitelink( entityId ) if link and not label then label = link end -- if we don't have article for occupation, try to link to field of occupation if not link then local fooEntity = mw.wikibase.getEntity( entityId ); if fooEntity and fooEntity.claims and fooEntity.claims.P425 then fooEntity = WDS.filterByRank( fooEntity.claims.P425, 'deprecated', true );if fooEntity ~= nil and fooEntity[1] and fooEntity[1].mainsnak and fooEntity[1].mainsnak.datavalue and fooEntity[1].mainsnak.datavalue.value and fooEntity[1].mainsnak.datavalue.value.id thenlink = mw.wikibase.sitelink( fooEntity[1].mainsnak.datavalue.value.id );endendend-- no article about occupation or field, link to wikidata if not link then link = ':d:' .. entityIdend if label then return '[[' .. link .. '|' .. label .. ']]' end -- сообщение об отсутвии локализованного названия -- not good, but better than nothing return '[[' .. link .. '|' .. entityId .. ']]<span style="border-bottom: 1px dotted; cursor: help; white-space: nowrap" title="В Викиданных нет чувашской подписи к элементу. Вы можете помочь, указав чувашский вариант подписи.">?</span>' .. categoryLinksToEntitiesWithMissingLabel;endfunction 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 gender = 0 -- per [[ISO/IEC 5218]]if 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 then local genderId = options.entity.claims.P21[1].mainsnak.datavalue.value.id if genderId == 'Q6581097' or genderId == 'Q2449503' or genderId == 'Q44148' then gender = 1 elseif genderId == 'Q6581072' or genderId == 'Q1052281' or genderId == 'Q43445' then gender = 2end endlocal snak = statement.mainsnak;if snak and snak.datavalue and snak.datavalue.value and snak.datavalue.value.id thenlocal entityId = snak.datavalue.value.id;local value = formatOccupationLinkForEntityId( entityId, gender )return context.wrapSnak( value, snak.hash )endreturn context.formatSnak( options, snak )endfunction p.applyDefaultTemplate( context, options, statement )local snak = context.formatSnak( options, statement.mainsnak ) if ( statement.qualifiers and statement.qualifiers.P249 and statement.qualifiers.P249[1].snaktype == 'value') then snak = statement.qualifiers.P249[1].datavalue.value entityId = statement.mainsnak.datavalue.value.idwbStatus, entity = pcall( mw.wikibase.getEntity, entityId );if ( entity.claims and entity.claims.P1424 ) thenwbStatus, template = pcall( mw.wikibase.getEntity, entity.claims.P1424[1].mainsnak.datavalue.value.id )if template:getSitelink( ) thensnak = options.frame:preprocess( string.gsub( template:getSitelink( ), 'Шаблон:', '{{' ) .. '|' .. statement.qualifiers.P249[1].datavalue.value .. '}}' )endend end--Referencesif ( options.references and snak ) then snak = snak .. context.formatRefs( options, statement ); end return snakendfunction p.formatCategoryOnly( context, options, value )return context.extractCategory( options, value )end return p
🔥 Top keywords: Тĕп страницаМария-Антуанетта.neМари-Агнес Штрак-ЦиммерманВикипеди:Википеди çинченВикипеди:ПорталИншааллахИккĕмĕш Тĕнче вăрçиПулăшу:ТупмаллиВикипеди:Википеди ăшлăхĕПельш Валдис ЭйженовичВикипеди:ХыпарсемДрозд Максим ГеоргиевичВикипедиЯтарлă:Свежие правкиВикипеди:КанашлуTelegram (мессенджер)Чăваш чĕлхиШупашкарСӳтсе явасси:Тĕп страницаВилĕмМишина Ксения АлександровнаÇеçпĕл МишшиИндиЛазерМаксимилиан КрахШаблон:Cite webКузнецова Екатерина ОлеговнаMail.ruЯтарлă:ПоискЯковлев Иван ЯковлевичТопинамбурАдюков Виталий ИвановичАслă БританиАмерикăри Пĕрлешĕннĕ ШтатсемВаккатХăнарТӗнчери патшалӑхсен списокӗЕгипет