Модуль:Wikidata2/Medals

Модульдә аерым буләк мәгънәләре (Калып:WD property) һәм үзлекне бизәү функцияләре тупланган.

Модульнең функцияләрен туры итеп чакырып булмый - алар туры килгән калыплардан (һәм шул калыплардан гына, башка калыпларга аларны кертергә кирәк түгел) аргументлар итеп тапшырыла.


local WDS = require( 'Module:Wikidata2Selectors' )local moduleDate = require( 'Module:Wikidata2/date' )local p = {}--Get string with dates from qualifiers tablefunction datesFromQualifier( context, options, qualifierId )local dates = {}local qualifiers = options.qualifiers[qualifierId]if qualifiers thenfor _, qualifier in pairs( qualifiers ) dolocal dateValue = moduleDate.formatDate( context, options, qualifier.datavalue.value )if dateValue thentable.insert( dates, dateValue )endendendreturn table.concat( dates, ', ' )end--Property:P166function p.formatMedalValue( context, options, statement )local entityId = statement.idif not entityId thenreturn statementendlocal label = mw.wikibase.label( entityId )local image = nillocal entity = mw.wikibase.getEntity( entityId )local size = 'x17px'-- получение изображения планки из элементаlocal ribbonImageClaims = WDS.filter( entity.claims, 'p2425' )if ribbonImageClaims and #ribbonImageClaims thenfor i, claim in pairs( ribbonImageClaims ) doif claim.type == 'statement' and claim.mainsnak.snaktype == 'value' thenimage = claim.mainsnak.datavalue.valuebreakendendend-- получение иконки из элементаif not image thenlocal imageClaims = WDS.filter( entity.claims, 'p2910' )if imageClaims and #imageClaims thenfor i, claim in pairs( imageClaims ) doif claim.type == 'statement' and claim.mainsnak.snaktype == 'value' thenimage = claim.mainsnak.datavalue.valuesize = '40x40px'breakendendendend-- получение категорииlocal recipientCategoryClaims = WDS.filter( entity.claims, 'p2517' )local recipientCategory = ''if recipientCategoryClaims and #recipientCategoryClaims thenfor i, claim in pairs( recipientCategoryClaims ) doif claim.type == 'statement' and claim.mainsnak.snaktype == 'value' thenlocal categoryLink = mw.wikibase.sitelink( claim.mainsnak.datavalue.value.id )if categoryLink thenrecipientCategory = recipientCategory .. '[[' .. categoryLink .. ']]'endendendendlocal dates = ''if options.qualifiers thenmw.logObject( options.qualifiers )local startDates = {}dates = datesFromQualifier( context, options, 'P580' )if dates ~= '' thenlocal endDates = datesFromQualifier( context, options, 'P582' )if endDates and endDates ~= '' thendates = dates .. ' — ' .. endDatesendelsedates = datesFromQualifier( context, options, 'P585' )endend-- получение ссылки по идентификатору и вывод планкиif image thenlocal link = mw.wikibase.sitelink( entityId )local out = '[[File:' .. image .. '|border|' .. size .. '|link='-- получение ссылки из родительского элемента-- для степеней обычно только одна общая статьяif not link thenlocal partOfClaims = WDS.filter( entity.claims, 'p361' ) -- часть отif not partOfClaims or #partOfClaims == 0 thenpartOfClaims = WDS.filter( entity.claims, 'p279' ) -- подкласс отendif partOfClaims and #partOfClaims thenfor i, claim in pairs( partOfClaims ) doif claim.type == 'statement' and claim.mainsnak.snaktype == 'value' thenlink = mw.wikibase.sitelink( claim.mainsnak.datavalue.value.id )if link thenbreak;endendendendendif link thenout = out .. linkelseout = out .. 'd:' .. entityIdendif label thenout = out .. '|' .. labelendout = out .. ']]'out = out .. recipientCategoryreturn outendlocal out = context.formatValueDefault( context, options, statement )if out and out ~= '' thenif dates ~= '' thenout = out .. ' (' .. dates .. ')'endreturn '<p style="text-align:left>' .. out .. recipientCategory .. '</p>'endreturn ''endreturn p;