Modul:Wikidata: Versiyalar orasidagi farq
Qiyofa
Tahrir izohi yoʻq Teglar: Qaytarildi Ziyosfera Admin Panel [1.0] |
avtomatik tuzatish xatosi: enwiki versiyasi bilan almashtirilgani bekor qilindi Teglar: Bekor qilindi Ziyosfera Admin Panel [1.0] |
||
| Qator 2: | Qator 2: | ||
-- modules reading Wikidata degrade to nil instead of erroring. Auto-added on import. | -- modules reading Wikidata degrade to nil instead of erroring. Auto-added on import. | ||
if not mw.wikibase then mw.wikibase = setmetatable({}, { __index = function() return function() return nil end end }) end | if not mw.wikibase then mw.wikibase = setmetatable({}, { __index = function() return function() return nil end end }) end | ||
-- | local i18n = { | ||
["errors"] = { | |||
["property-param-not-provided"] = "Xossa koʻrsatkichi berilmagan", | |||
["entity-not-found"] = "Obyekt topilmadi.", | |||
["unknown-claim-type"] = "Noma’lum da’vo turi.", | |||
["unknown-snak-type"] = "Noma’lum snek turi.", | |||
["unknown-datavalue-type"] = "Nomaʼlum maʼlumotlar qiymati turi.", | |||
["unknown-entity-type"] = "Nomaʼlum obyekt turi.", | |||
["unknown-property-module"] = "Siz ham property-moduleni, ham property-functionni oʻrnatishingiz kerak.", | |||
["unknown-claim-module"] = "Siz ham claim-moduleni, ham claim-functionni oʻrnatishingiz kerak.", | |||
["unknown-value-module"] = "Siz ham value-moduleni, ham value-functionni oʻrnatishingiz kerak.", | |||
["property-module-not-found"] = "Xossalarni koʻrsatish uchun modul topilmadi", | |||
["property-function-not-found"] = "Xossalarni koʻrsatish uchun funksiya topilmadi", | |||
["claim-module-not-found"] = "Tasdiqni koʻrsatish uchun modul topilmadi.", | |||
["claim-function-not-found"] = "Tasdiqni koʻrsatish uchun funksiya topilmadi.", | |||
["value-module-not-found"] = "Qiymatni koʻrsatish uchun modul topilmadi.", | |||
["value-function-not-found"] = "Qiymatni koʻrsatish uchun funksiya topilmadi." | |||
}, | |||
["somevalue"] = "''nomaʼlum''", | |||
["novalue"] = "", | |||
["approximate"] = '<span style="border-bottom: 1px dotted; cursor: help;" title="около, приблизительно">прибл. </span>', | |||
["presumably"] = '<span style="border-bottom: 1px dotted; cursor: help;" title="предположительно">предп. </span>', | |||
} | |||
local | -- settings, may differ from project to project | ||
local | local categoryLinksToEntitiesWithMissingLabel = ''; | ||
local categoryLocalValuePresent = '[[Turkum:ZiyoSfera:Vikimaʼlumotlarda qayta aniqlash maqolalari]]'; | |||
local outputReferences = true; | |||
-- sources that shall be omitted if any preffered sources exists | |||
local deprecatedSources = { | |||
Q36578 = true, -- Gemeinsame Normdatei | |||
Q63056 = true, -- Find a Grave | |||
Q15222191 = true, -- BNF | |||
}; | |||
local preferredSources = { | |||
Q5375741 = true, -- Encyclopædia Britannica Online | |||
Q17378135 = true, -- Great Soviet Encyclopedia (1969—1978) | |||
}; | |||
local | local moduleSources = require('Module:Sources') | ||
local p = {} | |||
local | |||
{ | |||
} | |||
-- Wikibase mavjud bo‘lmagan vikilarda modul skript xatosi bermasligi uchun | |||
-- barcha Wikibase chaqiruvlari xavfsiz yordamchi funksiyalar orqali bajariladi. | |||
local function hasWikibase() | |||
return mw.wikibase ~= nil | |||
end | end | ||
local function safeGetEntityObject( entityId ) | |||
if not hasWikibase() then | |||
return nil | |||
local function | |||
if | |||
end | end | ||
local getter = mw.wikibase.getEntityObject or mw.wikibase.getEntity | |||
if type( getter ) ~= 'function' then | |||
return nil | |||
local | |||
end | end | ||
local ok, entity | |||
if | if entityId and entityId ~= '' then | ||
ok, entity = pcall( getter, entityId ) | |||
else | else | ||
ok, entity = pcall( getter ) | |||
end | end | ||
if ok then | |||
if | return entity | ||
end | end | ||
return nil | |||
end | |||
local function safeWikibaseLabel( entityId ) | |||
if | if not hasWikibase() or type( mw.wikibase.label ) ~= 'function' then | ||
return nil | |||
return | |||
end | end | ||
local ok, label = pcall( mw.wikibase.label, entityId ) | |||
local | if ok then | ||
return label | |||
if | |||
return | |||
end | end | ||
return nil | |||
end | end | ||
local function safeWikibaseSitelink( entityId ) | |||
if not hasWikibase() or type( mw.wikibase.sitelink ) ~= 'function' then | |||
return nil | |||
local function | end | ||
if not | |||
local ok, sitelink = pcall( mw.wikibase.sitelink, entityId ) | |||
local | if ok then | ||
return sitelink | |||
end | end | ||
return nil | |||
return | |||
end | end | ||
local function | local function safePropertyParserFunction( frame, propertyId ) | ||
if not frame or not propertyId or propertyId == '' then | |||
return '' | |||
end | |||
local ok, value = pcall( function() | |||
return frame:callParserFunction( '#property', propertyId ) | |||
end ) | |||
end | |||
if ok and value then | |||
return value | |||
return | |||
end | end | ||
return '' | |||
end | |||
local formatDatavalue, formatEntityId, formatRefs, formatSnak, formatStatement, formatStatementDefault, formatProperty, getSourcingCircumstances, loadCacheSafe, throwError, toBoolean; | |||
local function copyTo( obj, target ) | |||
for k, v in pairs( obj ) do | |||
target[k] = v | |||
end | end | ||
return target; | |||
end | end | ||
local function | local function loadCacheSafe( entityId ) | ||
local status, result = pcall( function() return mw.loadData( 'Module:WikidataCache/' .. entityId ) end ); | |||
if ( status == true ) then | |||
return result; | |||
end | end | ||
return nil; | |||
end | |||
local function parseISO8601(str) | |||
if 'table' == type(str) then | |||
if str.args and str.args[1] then | |||
str = '' .. str.args[1] | |||
else | else | ||
return | return 'unknown argument type: ' .. type( str ) .. ': ' .. table.tostring( str ) | ||
end | end | ||
end | end | ||
local Y, M, D = (function(str) | |||
local pattern = "(%-?%d+)%-(%d+)%-(%d+)T" | |||
local Y, M, D = mw.ustring.match( str, pattern ) | |||
return tonumber(Y), tonumber(M), tonumber(D) | |||
end) (str); | |||
local h, m, s = (function(str) | |||
local pattern = "T(%d+):(%d+):(%d+)%Z"; | |||
local H, M, S = mw.ustring.match( str, pattern); | |||
return tonumber(H), tonumber(M), tonumber(S); | |||
end) (str); | |||
local oh,om = ( function(str) | |||
if str:sub(-1)=="Z" then return 0,0 end; -- ends with Z, Zulu time | |||
-- matches ±hh:mm, ±hhmm or ±hh; else returns nils | |||
local pattern = "([-+])(%d%d):?(%d?%d?)$"; | |||
local sign, oh, om = mw.ustring.match( str, pattern); | |||
sign, oh, om = sign or "+", oh or "00", om or "00"; | |||
return tonumber(sign .. oh), tonumber(sign .. om); | |||
end )(str) | |||
return tonumber(os.time({year=Y, month=M, day=D, hour=(h+oh), min=(m+om), sec=s})) * 1000; | |||
end | end | ||
local function | local function toBoolean( valueToParse, defaultValue ) | ||
if ( valueToParse ) then | |||
if valueToParse == '' or valueToParse == 'false' or valueToParse == '0' then | |||
return false | |||
end | |||
return true | |||
end | |||
return defaultValue; | |||
end | end | ||
local function getEntityFromId( id ) | |||
if id and id ~= '' then | |||
local cached = loadCacheSafe( id ); | |||
if ( cached ) then | |||
return cached; | |||
end | |||
return safeGetEntityObject( id ) | |||
end | |||
local entity = safeGetEntityObject(); | |||
if ( entity and entity.id ) then | |||
local cached = loadCacheSafe( entity.id ); | |||
if ( cached ) then | |||
return cached; | |||
end | |||
end | end | ||
return entity; | |||
end | end | ||
local function | |||
local function throwError( key ) | |||
error( i18n.errors[key] ); | |||
end | end | ||
local function | |||
local function getEntityIdFromValue( value ) | |||
local prefix = '' | |||
if value['entity-type'] == 'item' then | |||
prefix = 'Q' | |||
elseif value['entity-type'] == 'property' then | |||
prefix = 'P' | |||
else | |||
throwError( 'unknown-entity-type' ) | |||
end | |||
return prefix .. value['numeric-id'] | |||
end | end | ||
local function | |||
local function getUserFunction( options, prefix, defaultFunction ) | |||
if options[ prefix .. '-module' ] or options[ prefix .. '-function' ] then | |||
if not options[ prefix .. '-module' ] or not options[ prefix .. '-function' ] then | |||
throwError( 'unknown-' .. prefix .. '-module' ); | |||
end | |||
local formatter = require ('Module:' .. options[ prefix .. '-module' ]); | |||
if formatter == nil then | |||
throwError( prefix .. '-module-not-found' ) | |||
end | |||
local fun = formatter[ options[ prefix .. '-function' ] ] | |||
if fun == nil then | |||
throwError( prefix .. '-function-not-found' ) | |||
end | |||
return fun; | |||
end | |||
return defaultFunction; | |||
end | end | ||
local function | |||
local function selectClaims( context, options, propertySelector ) | |||
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 propertySelector ) then error( 'propertySelector not specified'); end; | |||
local WDS = require('Module:WikidataSelectors') | |||
result = WDS.filter(options.entity.claims, propertySelector) | |||
if ( not result or #result == 0 ) then | |||
return nil; | |||
end | |||
if options.limit and options.limit ~= '' and options.limit ~= '-' then | |||
local limit = tonumber( options.limit, 10 ); | |||
while #result > limit do | |||
table.remove( result ); | |||
end | end | ||
end | end | ||
return result; | |||
end | end | ||
local function | |||
local function formatProperty( options ) | |||
-- Получение сущности по идентификатору | |||
local entity = getEntityFromId( options.entityId ) | |||
if not entity then | |||
return -- throwError( 'entity-not-found' ) | |||
return | end | ||
-- проверка на присутсвие у сущности заявлений (claim) | |||
-- подробнее о заявлениях см. d:Викиданные:Глоссарий | |||
if (entity.claims == nil) then | |||
return '' --TODO error? | |||
end | |||
-- improve options | |||
options.frame = g_frame; | |||
options.entity = entity; | |||
options.extends = function( self, newOptions ) | |||
return copyTo( newOptions, copyTo( self, {} ) ) | |||
end | end | ||
if ( options.i18n ) then | |||
if | options.i18n = copyTo( options.i18n, copyTo( i18n, {} ) ); | ||
else | else | ||
options.i18n = i18n; | |||
end | end | ||
end | -- create context | ||
local context = { formatSnak = formatSnak, formatPropertyDefault = formatPropertyDefault, formatStatementDefault = formatStatementDefault } | |||
context.formatProperty = function( options ) | |||
local func = getUserFunction( options, 'property', context.formatPropertyDefault ); | |||
return func( context, options ) | |||
if | end; | ||
context.formatStatement = function( options, statement ) return formatStatement( context, options, statement ) end; | |||
context.formatSnak = function( options, snak, circumstances ) return formatSnak( context, options, snak, circumstances ) end; | |||
context.formatRefs = function( options, statement ) return formatRefs( context, options, statement ) end; | |||
context.parseTimeFromSnak = function( snak ) | |||
if ( snak and snak.datavalue and snak.datavalue.value and snak.datavalue.value.time ) then | |||
local timeISO6801 = tostring( snak.datavalue.value.time ) | |||
return parseISO8601( timeISO6801 ); | |||
end | |||
return nil; | return nil; | ||
end | end | ||
context.getSourcingCircumstances = function( statement ) return getSourcingCircumstances( statement ) end; | |||
context.selectClaims = function( options, propertyId ) return selectClaims( context, options, propertyId ) end; | |||
return context.formatProperty( options ); | |||
end | end | ||
function formatPropertyDefault( 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; | |||
if | local claims = context.selectClaims( options, options.property ); | ||
if (claims == nil) then | |||
return '' --TODO error? | |||
end | |||
local formattedClaims = {} | |||
for i, claim in ipairs(claims) do | |||
end | local formattedStatement = context.formatStatement( options, claim ) | ||
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 | |||
return mw.text.listToText( formattedClaims, options.separator, options.conjunction ) | |||
end | end | ||
function formatStatement( context, options, statement ) | |||
if ( not statement ) then | |||
error( 'statement is not specified or nil' ); | |||
if | |||
end | end | ||
if not statement.type or statement.type ~= 'statement' then | |||
throwError( 'unknown-claim-type' ) | |||
end | |||
local functionToCall = getUserFunction( options, 'claim', context.formatStatementDefault ); | |||
return functionToCall( context, options, statement ); | |||
end | end | ||
function getSourcingCircumstances( statement ) | |||
if (not statement) then error('statement is not specified') end; | |||
local circumstances = {}; | |||
if ( statement.qualifiers | |||
and statement.qualifiers.P1480 ) then | |||
local | for i, qualifier in pairs( statement.qualifiers.P1480 ) do | ||
if ( qualifier | |||
and qualifier.datavalue | |||
and qualifier.datavalue.type == 'wikibase-entityid' | |||
and qualifier.datavalue.value | |||
and qualifier.datavalue.value["entity-type"] == 'item' ) then | |||
local circumstance = 'Q' .. qualifier.datavalue.value["numeric-id"]; | |||
if ( 'Q18086598' == circumstance ) then | |||
circumstances.approximate = true; | |||
end | end | ||
if ( 'Q18122778' == circumstance ) then | |||
circumstances.presumably = true; | |||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
return circumstances; | |||
end | end | ||
function formatStatementDefault( context, options, statement ) | |||
if (not context) then error('context is not specified') end; | |||
if (not options) then error('options is not specified') end; | |||
if not | if (not statement) then error('statement is not specified') end; | ||
if | |||
end | |||
local circumstances = context.getSourcingCircumstances( statement ); | |||
local | |||
if ( options.references ) then | |||
return context.formatSnak( options, statement.mainsnak, circumstances ) .. context.formatRefs( options, statement ); | |||
else | |||
return context.formatSnak( options, statement.mainsnak, circumstances ); | |||
end | |||
end | end | ||
function formatSnak( context, options, snak, circumstances ) | |||
circumstances = circumstances or {}; | |||
local hash = ''; | |||
local mainSnakClass = ''; | |||
if ( snak.hash ) then | |||
hash = ' data-wikidata-hash="' .. snak.hash .. '"'; | |||
local | |||
local | |||
if ( | |||
else | else | ||
mainSnakClass = ' wikidata-main-snak'; | |||
end | end | ||
- | local before = '<span class="wikidata-snak ' .. mainSnakClass .. '"' .. hash .. '>' | ||
local after = '</span>' | |||
if snak.snaktype == 'somevalue' then | |||
return before .. options.i18n['somevalue'] .. after; | |||
elseif snak.snaktype == 'novalue' then | |||
return before .. options.i18n['novalue'] .. after; | |||
elseif snak.snaktype == 'value' then | |||
if ( circumstances.presumably ) then | |||
before = before .. options.i18n.presumably; | |||
end | |||
if ( circumstances.approximate ) then | |||
before = before .. options.i18n.approximate; | |||
end | end | ||
return before .. formatDatavalue( context, options, snak.datavalue ) .. after; | |||
else | |||
throwError( 'unknown-snak-type' ); | |||
end | |||
end | end | ||
function formatGlobeCoordinate( value, options ) | |||
-- проверка на требование в параметрах вызова на возврат сырого значения | |||
if options['subvalue'] == 'latitude' then -- широты | |||
return value['latitude'] | |||
elseif options['subvalue'] == 'longitude' then -- долготы | |||
return value['longitude'] | |||
else | |||
-- в противном случае формируются параметры для вызова шаблона {{coord}} | |||
-- нужно дописать в документации шаблона, что он отсюда вызывается, и что | |||
-- любое изменние его парамеров должно быть согласовано с кодом тут | |||
local eps = 0.0000001 -- < 1/360000 | |||
local globe = '' -- TODO | |||
local lat = {} | |||
lat['abs'] = math.abs(value['latitude']) | |||
lat['ns'] = value['latitude'] >= 0 and 'N' or 'S' | |||
lat['d'] = math.floor(lat['abs'] + eps) | |||
lat['m'] = math.floor((lat['abs'] - lat['d']) * 60 + eps) | |||
lat['s'] = math.max(0, ((lat['abs'] - lat['d']) * 60 - lat['m']) * 60) | |||
local lon = {} | |||
lon['abs'] = math.abs(value['longitude']) | |||
lon['ew'] = value['longitude'] >= 0 and 'E' or 'W' | |||
lon['d'] = math.floor(lon['abs'] + eps) | |||
lon['m'] = math.floor((lon['abs'] - lon['d']) * 60 + eps) | |||
lon['s'] = math.max(0, ((lon['abs'] - lon['d']) * 60 - lon['m']) * 60) | |||
local coord = '{{coord' | |||
if (value['precision'] == nil) or (value['precision'] < 1/60) then -- по умолчанию с точностью до секунды | |||
coord = coord .. '|' .. lat['d'] .. '|' .. lat['m'] .. '|' .. lat['s'] .. '|' .. lat['ns'] | |||
coord = coord .. '|' .. lon['d'] .. '|' .. lon['m'] .. '|' .. lon['s'] .. '|' .. lon['ew'] | |||
elseif value['precision'] < 1 then | |||
coord = coord .. '|' .. lat['d'] .. '|' .. lat['m'] .. '|' .. lat['ns'] | |||
coord = coord .. '|' .. lon['d'] .. '|' .. lon['m'] .. '|' .. lon['ew'] | |||
else | |||
coord = coord .. '|' .. lat['d'] .. '|' .. lat['ns'] | |||
coord = coord .. '|' .. lon['d'] .. '|' .. lon['ew'] | |||
end | |||
coord = coord .. '|globe:' .. globe | |||
if options['display'] then | |||
coord = coord .. '|display=' .. options.display | |||
else | |||
coord = coord .. '|display=title' | |||
end | |||
coord = coord .. '}}' | |||
return g_frame:preprocess(coord) | |||
end | |||
end | |||
local function getDefaultValueFunction( datavalue ) | |||
if datavalue.type == 'wikibase-entityid' then | |||
return function( context, options, value ) return formatEntityId( getEntityIdFromValue( value ), options ) end; | |||
elseif datavalue.type == 'string' then | |||
return function( context, options, value ) return value end; | |||
elseif datavalue.type == 'monolingualtext' then | |||
return function( context, options, value ) | |||
if ( options.monolingualLangTemplate == 'lang' ) then | |||
return options.frame:expandTemplate{ title = 'lang-' .. value.language, args = { value.text } }; | |||
elseif ( options.monolingualLangTemplate == 'ref' ) then | |||
return '<span class="lang" lang="' .. value.language .. '">' .. value.text .. '</span>' .. options.frame:expandTemplate{ title = 'ref-' .. value.language }; | |||
else | |||
return '<span class="lang" lang="' .. value.language .. '">' .. value.text .. '</span>'; | |||
end | |||
end; | |||
elseif datavalue.type == 'globecoordinate' then | |||
-- geografik koordinatalar | |||
return function( context, options, value ) return formatGlobeCoordinate( value, options ) end; | |||
elseif datavalue.type == 'quantity' then | |||
return function( context, options, value ) | |||
local amount = string.gsub(value['amount'], '^%+', '') | |||
local lang = mw.language.new( 'ru' ) | |||
return lang:formatNum( tonumber( amount ) ) | |||
end; | |||
elseif datavalue.type == 'time' then | |||
return function( context, options, value ) | |||
local moduleDate = require('Module:Wikidata/date') | |||
return moduleDate.formatDate( context, options, value ); | |||
end; | |||
else | |||
throwError( 'unknown-datavalue-type' ) | |||
end | |||
end | |||
function formatDatavalue( context, options, datavalue ) | |||
if ( not context ) then error( 'context not specified' ); end; | |||
if ( not options ) then error( 'options not specified' ); end; | |||
if (not | if ( not datavalue ) then error( 'datavalue not specified' ); end; | ||
if ( not datavalue.value ) then error( 'datavalue.value is missng' ); end; | |||
context.formatValueDefault = getDefaultValueFunction( datavalue ); | |||
local functionToCall = getUserFunction( options, 'value', context.formatValueDefault ); | |||
return functionToCall( context, options, datavalue.value ); | |||
end | end | ||
-- | -- | ||
local simpleReplaces = { | |||
Q30 = '[[AQSh]]', | |||
Q148 = '[[Xitoy Xalq Respublikasi|Xitoy]]', | |||
Q183 = '[[Germaniya]]', | |||
Q258 = '[[JAR]]', | |||
Q423 = '[[Koreya Xalq Demokratik Respublikasi|KXDR]]', | |||
Q2184 = '[[Rossiya Sovet Federativ Sotsialistik Respublikasi|Rossiya SFSR]]', | |||
Q2895 = '[[Belorussiya Sovet Sotsialistik Respublikasi|Belorus SSR]]', | |||
Q15180 = '[[Sovet Sotsialistik Respublikalari Ittifoqi|SSSR]]', | |||
Q16957 = '[[Germaniya Demokratik Respublikasi|GDR]]', | |||
Q130229 = '[[Gruziya Sovet Sotsialistik Respublikasi|Gruziya SSR]]', | |||
Q130280 = '[[Estoniya Sovet Sotsialistik Respublikasi|Estoniya SSR]]', | |||
Q131337 = '[[Ozarbayjon Sovet Sotsialistik Respublikasi|Ozarbayjon SSR]]', | |||
Q132856 = '[[Armaniston Sovet Sotsialistik Respublikasi|Armaniston SSR]]', | |||
Q133356 = '[[Ukraina Sovet Sotsialistik Respublikasi|Ukraina SSR]]', | |||
Q168811 = '[[Qozogʻiston Sovet Sotsialistik Respublikasi|Qozogʻiston SSR]]', | |||
Q170895 = '[[Moldova Sovet Sotsialistik Respublikasi|Moldova SSR]]', | |||
Q173761 = '[[Litva Sovet Sotsialistik Respublikasi|Litva SSR]]', | |||
Q192180 = '[[Latviya Sovet Sotsialistik Respublikasi|Latviya SSR]]', | |||
Q199707 = '[[Turkmaniston Sovet Sotsialistik Respublikasi|Turkmaniston SSR]]', | |||
Q199711 = '[[Tojikiston Sovet Sotsialistik Respublikasi|Tojikiston SSR]]', | |||
Q484578 = '[[Oʻzbekiston Sovet Sotsialistik Respublikasi|Oʻzbekiston SSR]]', | |||
} | |||
function formatEntityId( entityId, options ) | |||
-- получение локализованного названия | |||
local label = nil; | |||
if ( options.text and options.text ~= '' ) then | |||
label = options.text | |||
else | |||
if ( simpleReplaces[entityId] ) then | |||
return simpleReplaces[entityId]; | |||
end | end | ||
label = safeWikibaseLabel( entityId ); | |||
end | |||
-- получение ссылки по идентификатору | |||
local link = safeWikibaseSitelink( entityId ) | |||
end | if link then | ||
if label then | |||
return '[[' .. link .. '|' .. label .. ']]' | |||
else | |||
return '[[' .. link .. ']]' | |||
end | |||
end | |||
-- | if label then | ||
return 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 | end | ||
--[[ | |||
Функция для оформления утверждений (statement) | |||
Подробнее о утверждениях см. d:Wikidata:Glossary/ru | |||
Принимает: таблицу параметров | |||
Возвращает: строку оформленного текста, предназначенного для отображения в статье | |||
]] | |||
-- устаревшее имя, не использовать | |||
function p.formatStatements( frame ) | |||
return p.formatProperty( frame ); | |||
end | |||
function p.formatProperty( frame ) | |||
local args = frame.args | |||
local plain = toBoolean( frame.args.plain, false ); | |||
frame.args.nocat = toBoolean( frame.args.nocat, false ); | |||
frame.args.references = toBoolean( frame.args.references, true ); | |||
if not frame.args.property then | |||
throwError( 'property-param-not-provided' ) | |||
end | |||
p_frame = frame | |||
while p_frame do | |||
if p_frame:getTitle() == mw.site.namespaces[10].name .. ':Wikidata' then | |||
copyTo( p_frame.args, args, true ); | |||
end | |||
if p_frame.args and p_frame.args.from and p_frame.args.from ~= '' then | |||
args.entityId = p_frame.args.from; | |||
end | end | ||
p_frame = p_frame:getParent(); | |||
end | end | ||
local propertyValue = safePropertyParserFunction( frame, frame.args.property ) | |||
if frame.args.value and frame.args.value ~= '' then | |||
end | if plain or frame.args.nocat or propertyValue == '' then | ||
return frame.args.value | |||
else | |||
return args.value .. categoryLocalValuePresent; | |||
end | |||
end | |||
if ( plain ) then | |||
return propertyValue; | |||
end | |||
g_frame = frame | |||
return formatProperty( frame.args ) | |||
end | |||
function formatRefs( context, options, statement ) | |||
end | if ( not context ) then error( 'context not specified' ); end; | ||
end | if ( not options ) then error( 'options not specified' ); end; | ||
if ( not options.entity ) then error( 'options.entity missing' ); end; | |||
if ( not statement ) then error( 'statement not specified' ); end; | |||
if ( not outputReferences ) then | |||
return ''; | |||
if | |||
return | |||
end | end | ||
local result = ''; | |||
local | if ( statement.references ) then | ||
local allReferences = statement.references; | |||
local hasPreferred = false; | |||
local | for _, reference in pairs( statement.references ) do | ||
if ( reference.snaks | |||
and reference.snaks.P248 | |||
and reference.snaks.P248[1] | |||
and reference.snaks.P248[1].datavalue | |||
and reference.snaks.P248[1].datavalue.value["numeric-id"] ) then | |||
local entityId = "Q" .. reference.snaks.P248[1].datavalue.value["numeric-id"]; | |||
if ( preferredSources[entityId] ) then | |||
hasPreferred = true; | |||
end | |||
end | |||
end | end | ||
for _, reference in pairs( statement.references ) do | |||
local display = true; | |||
if ( hasPreferred ) then | |||
if ( reference.snaks | |||
and reference.snaks.P248 | |||
and reference.snaks.P248[1] | |||
and reference.snaks.P248[1].datavalue | |||
and reference.snaks.P248[1].datavalue.value["numeric-id"] ) then | |||
local entityId = "Q" .. reference.snaks.P248[1].datavalue.value["numeric-id"]; | |||
if ( deprecatedSources[entityId] ) then | |||
display = false; | |||
end | |||
end | |||
end | |||
if ( display ) then | |||
result = result .. moduleSources.renderReference( g_frame, options.entity, reference ); | |||
end | |||
end | end | ||
end | end | ||
return result | |||
end | end | ||
return p | return p | ||
2026-yil 20-avgust, 10:13 dagi (joriy) koʻrinishi
Bu modul uchun Modul:Wikidata/doc nomli hujjat sahifasini yaratishingiz mumkin
-- [zs-wikibase-guard] Ziyosfera has no Wikibase client; stub mw.wikibase so
-- modules reading Wikidata degrade to nil instead of erroring. Auto-added on import.
if not mw.wikibase then mw.wikibase = setmetatable({}, { __index = function() return function() return nil end end }) end
local i18n = {
["errors"] = {
["property-param-not-provided"] = "Xossa koʻrsatkichi berilmagan",
["entity-not-found"] = "Obyekt topilmadi.",
["unknown-claim-type"] = "Noma’lum da’vo turi.",
["unknown-snak-type"] = "Noma’lum snek turi.",
["unknown-datavalue-type"] = "Nomaʼlum maʼlumotlar qiymati turi.",
["unknown-entity-type"] = "Nomaʼlum obyekt turi.",
["unknown-property-module"] = "Siz ham property-moduleni, ham property-functionni oʻrnatishingiz kerak.",
["unknown-claim-module"] = "Siz ham claim-moduleni, ham claim-functionni oʻrnatishingiz kerak.",
["unknown-value-module"] = "Siz ham value-moduleni, ham value-functionni oʻrnatishingiz kerak.",
["property-module-not-found"] = "Xossalarni koʻrsatish uchun modul topilmadi",
["property-function-not-found"] = "Xossalarni koʻrsatish uchun funksiya topilmadi",
["claim-module-not-found"] = "Tasdiqni koʻrsatish uchun modul topilmadi.",
["claim-function-not-found"] = "Tasdiqni koʻrsatish uchun funksiya topilmadi.",
["value-module-not-found"] = "Qiymatni koʻrsatish uchun modul topilmadi.",
["value-function-not-found"] = "Qiymatni koʻrsatish uchun funksiya topilmadi."
},
["somevalue"] = "''nomaʼlum''",
["novalue"] = "",
["approximate"] = '<span style="border-bottom: 1px dotted; cursor: help;" title="около, приблизительно">прибл. </span>',
["presumably"] = '<span style="border-bottom: 1px dotted; cursor: help;" title="предположительно">предп. </span>',
}
-- settings, may differ from project to project
local categoryLinksToEntitiesWithMissingLabel = '';
local categoryLocalValuePresent = '[[Turkum:ZiyoSfera:Vikimaʼlumotlarda qayta aniqlash maqolalari]]';
local outputReferences = true;
-- sources that shall be omitted if any preffered sources exists
local deprecatedSources = {
Q36578 = true, -- Gemeinsame Normdatei
Q63056 = true, -- Find a Grave
Q15222191 = true, -- BNF
};
local preferredSources = {
Q5375741 = true, -- Encyclopædia Britannica Online
Q17378135 = true, -- Great Soviet Encyclopedia (1969—1978)
};
local moduleSources = require('Module:Sources')
local p = {}
-- Wikibase mavjud bo‘lmagan vikilarda modul skript xatosi bermasligi uchun
-- barcha Wikibase chaqiruvlari xavfsiz yordamchi funksiyalar orqali bajariladi.
local function hasWikibase()
return mw.wikibase ~= nil
end
local function safeGetEntityObject( entityId )
if not hasWikibase() then
return nil
end
local getter = mw.wikibase.getEntityObject or mw.wikibase.getEntity
if type( getter ) ~= 'function' then
return nil
end
local ok, entity
if entityId and entityId ~= '' then
ok, entity = pcall( getter, entityId )
else
ok, entity = pcall( getter )
end
if ok then
return entity
end
return nil
end
local function safeWikibaseLabel( entityId )
if not hasWikibase() or type( mw.wikibase.label ) ~= 'function' then
return nil
end
local ok, label = pcall( mw.wikibase.label, entityId )
if ok then
return label
end
return nil
end
local function safeWikibaseSitelink( entityId )
if not hasWikibase() or type( mw.wikibase.sitelink ) ~= 'function' then
return nil
end
local ok, sitelink = pcall( mw.wikibase.sitelink, entityId )
if ok then
return sitelink
end
return nil
end
local function safePropertyParserFunction( frame, propertyId )
if not frame or not propertyId or propertyId == '' then
return ''
end
local ok, value = pcall( function()
return frame:callParserFunction( '#property', propertyId )
end )
if ok and value then
return value
end
return ''
end
local formatDatavalue, formatEntityId, formatRefs, formatSnak, formatStatement, formatStatementDefault, formatProperty, getSourcingCircumstances, loadCacheSafe, throwError, toBoolean;
local function copyTo( obj, target )
for k, v in pairs( obj ) do
target[k] = v
end
return target;
end
local function loadCacheSafe( entityId )
local status, result = pcall( function() return mw.loadData( 'Module:WikidataCache/' .. entityId ) end );
if ( status == true ) then
return result;
end
return nil;
end
local function parseISO8601(str)
if 'table' == type(str) then
if str.args and str.args[1] then
str = '' .. str.args[1]
else
return 'unknown argument type: ' .. type( str ) .. ': ' .. table.tostring( str )
end
end
local Y, M, D = (function(str)
local pattern = "(%-?%d+)%-(%d+)%-(%d+)T"
local Y, M, D = mw.ustring.match( str, pattern )
return tonumber(Y), tonumber(M), tonumber(D)
end) (str);
local h, m, s = (function(str)
local pattern = "T(%d+):(%d+):(%d+)%Z";
local H, M, S = mw.ustring.match( str, pattern);
return tonumber(H), tonumber(M), tonumber(S);
end) (str);
local oh,om = ( function(str)
if str:sub(-1)=="Z" then return 0,0 end; -- ends with Z, Zulu time
-- matches ±hh:mm, ±hhmm or ±hh; else returns nils
local pattern = "([-+])(%d%d):?(%d?%d?)$";
local sign, oh, om = mw.ustring.match( str, pattern);
sign, oh, om = sign or "+", oh or "00", om or "00";
return tonumber(sign .. oh), tonumber(sign .. om);
end )(str)
return tonumber(os.time({year=Y, month=M, day=D, hour=(h+oh), min=(m+om), sec=s})) * 1000;
end
local function toBoolean( valueToParse, defaultValue )
if ( valueToParse ) then
if valueToParse == '' or valueToParse == 'false' or valueToParse == '0' then
return false
end
return true
end
return defaultValue;
end
local function getEntityFromId( id )
if id and id ~= '' then
local cached = loadCacheSafe( id );
if ( cached ) then
return cached;
end
return safeGetEntityObject( id )
end
local entity = safeGetEntityObject();
if ( entity and entity.id ) then
local cached = loadCacheSafe( entity.id );
if ( cached ) then
return cached;
end
end
return entity;
end
local function throwError( key )
error( i18n.errors[key] );
end
local function getEntityIdFromValue( value )
local prefix = ''
if value['entity-type'] == 'item' then
prefix = 'Q'
elseif value['entity-type'] == 'property' then
prefix = 'P'
else
throwError( 'unknown-entity-type' )
end
return prefix .. value['numeric-id']
end
local function getUserFunction( options, prefix, defaultFunction )
if options[ prefix .. '-module' ] or options[ prefix .. '-function' ] then
if not options[ prefix .. '-module' ] or not options[ prefix .. '-function' ] then
throwError( 'unknown-' .. prefix .. '-module' );
end
local formatter = require ('Module:' .. options[ prefix .. '-module' ]);
if formatter == nil then
throwError( prefix .. '-module-not-found' )
end
local fun = formatter[ options[ prefix .. '-function' ] ]
if fun == nil then
throwError( prefix .. '-function-not-found' )
end
return fun;
end
return defaultFunction;
end
local function selectClaims( context, options, propertySelector )
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 propertySelector ) then error( 'propertySelector not specified'); end;
local WDS = require('Module:WikidataSelectors')
result = WDS.filter(options.entity.claims, propertySelector)
if ( not result or #result == 0 ) then
return nil;
end
if options.limit and options.limit ~= '' and options.limit ~= '-' then
local limit = tonumber( options.limit, 10 );
while #result > limit do
table.remove( result );
end
end
return result;
end
local function formatProperty( options )
-- Получение сущности по идентификатору
local entity = getEntityFromId( options.entityId )
if not entity then
return -- throwError( 'entity-not-found' )
end
-- проверка на присутсвие у сущности заявлений (claim)
-- подробнее о заявлениях см. d:Викиданные:Глоссарий
if (entity.claims == nil) then
return '' --TODO error?
end
-- improve options
options.frame = g_frame;
options.entity = entity;
options.extends = function( self, newOptions )
return copyTo( newOptions, copyTo( self, {} ) )
end
if ( options.i18n ) then
options.i18n = copyTo( options.i18n, copyTo( i18n, {} ) );
else
options.i18n = i18n;
end
-- create context
local context = { formatSnak = formatSnak, formatPropertyDefault = formatPropertyDefault, formatStatementDefault = formatStatementDefault }
context.formatProperty = function( options )
local func = getUserFunction( options, 'property', context.formatPropertyDefault );
return func( context, options )
end;
context.formatStatement = function( options, statement ) return formatStatement( context, options, statement ) end;
context.formatSnak = function( options, snak, circumstances ) return formatSnak( context, options, snak, circumstances ) end;
context.formatRefs = function( options, statement ) return formatRefs( context, options, statement ) end;
context.parseTimeFromSnak = function( snak )
if ( snak and snak.datavalue and snak.datavalue.value and snak.datavalue.value.time ) then
local timeISO6801 = tostring( snak.datavalue.value.time )
return parseISO8601( timeISO6801 );
end
return nil;
end
context.getSourcingCircumstances = function( statement ) return getSourcingCircumstances( statement ) end;
context.selectClaims = function( options, propertyId ) return selectClaims( context, options, propertyId ) end;
return context.formatProperty( options );
end
function formatPropertyDefault( 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 claims = context.selectClaims( options, options.property );
if (claims == nil) then
return '' --TODO error?
end
local formattedClaims = {}
for i, claim in ipairs(claims) do
local formattedStatement = context.formatStatement( options, claim )
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
return mw.text.listToText( formattedClaims, options.separator, options.conjunction )
end
function formatStatement( context, options, statement )
if ( not statement ) then
error( 'statement is not specified or nil' );
end
if not statement.type or statement.type ~= 'statement' then
throwError( 'unknown-claim-type' )
end
local functionToCall = getUserFunction( options, 'claim', context.formatStatementDefault );
return functionToCall( context, options, statement );
end
function getSourcingCircumstances( statement )
if (not statement) then error('statement is not specified') end;
local circumstances = {};
if ( statement.qualifiers
and statement.qualifiers.P1480 ) then
for i, qualifier in pairs( statement.qualifiers.P1480 ) do
if ( qualifier
and qualifier.datavalue
and qualifier.datavalue.type == 'wikibase-entityid'
and qualifier.datavalue.value
and qualifier.datavalue.value["entity-type"] == 'item' ) then
local circumstance = 'Q' .. qualifier.datavalue.value["numeric-id"];
if ( 'Q18086598' == circumstance ) then
circumstances.approximate = true;
end
if ( 'Q18122778' == circumstance ) then
circumstances.presumably = true;
end
end
end
end
return circumstances;
end
function formatStatementDefault( context, options, statement )
if (not context) then error('context is not specified') end;
if (not options) then error('options is not specified') end;
if (not statement) then error('statement is not specified') end;
local circumstances = context.getSourcingCircumstances( statement );
if ( options.references ) then
return context.formatSnak( options, statement.mainsnak, circumstances ) .. context.formatRefs( options, statement );
else
return context.formatSnak( options, statement.mainsnak, circumstances );
end
end
function formatSnak( context, options, snak, circumstances )
circumstances = circumstances or {};
local hash = '';
local mainSnakClass = '';
if ( snak.hash ) then
hash = ' data-wikidata-hash="' .. snak.hash .. '"';
else
mainSnakClass = ' wikidata-main-snak';
end
local before = '<span class="wikidata-snak ' .. mainSnakClass .. '"' .. hash .. '>'
local after = '</span>'
if snak.snaktype == 'somevalue' then
return before .. options.i18n['somevalue'] .. after;
elseif snak.snaktype == 'novalue' then
return before .. options.i18n['novalue'] .. after;
elseif snak.snaktype == 'value' then
if ( circumstances.presumably ) then
before = before .. options.i18n.presumably;
end
if ( circumstances.approximate ) then
before = before .. options.i18n.approximate;
end
return before .. formatDatavalue( context, options, snak.datavalue ) .. after;
else
throwError( 'unknown-snak-type' );
end
end
function formatGlobeCoordinate( value, options )
-- проверка на требование в параметрах вызова на возврат сырого значения
if options['subvalue'] == 'latitude' then -- широты
return value['latitude']
elseif options['subvalue'] == 'longitude' then -- долготы
return value['longitude']
else
-- в противном случае формируются параметры для вызова шаблона {{coord}}
-- нужно дописать в документации шаблона, что он отсюда вызывается, и что
-- любое изменние его парамеров должно быть согласовано с кодом тут
local eps = 0.0000001 -- < 1/360000
local globe = '' -- TODO
local lat = {}
lat['abs'] = math.abs(value['latitude'])
lat['ns'] = value['latitude'] >= 0 and 'N' or 'S'
lat['d'] = math.floor(lat['abs'] + eps)
lat['m'] = math.floor((lat['abs'] - lat['d']) * 60 + eps)
lat['s'] = math.max(0, ((lat['abs'] - lat['d']) * 60 - lat['m']) * 60)
local lon = {}
lon['abs'] = math.abs(value['longitude'])
lon['ew'] = value['longitude'] >= 0 and 'E' or 'W'
lon['d'] = math.floor(lon['abs'] + eps)
lon['m'] = math.floor((lon['abs'] - lon['d']) * 60 + eps)
lon['s'] = math.max(0, ((lon['abs'] - lon['d']) * 60 - lon['m']) * 60)
local coord = '{{coord'
if (value['precision'] == nil) or (value['precision'] < 1/60) then -- по умолчанию с точностью до секунды
coord = coord .. '|' .. lat['d'] .. '|' .. lat['m'] .. '|' .. lat['s'] .. '|' .. lat['ns']
coord = coord .. '|' .. lon['d'] .. '|' .. lon['m'] .. '|' .. lon['s'] .. '|' .. lon['ew']
elseif value['precision'] < 1 then
coord = coord .. '|' .. lat['d'] .. '|' .. lat['m'] .. '|' .. lat['ns']
coord = coord .. '|' .. lon['d'] .. '|' .. lon['m'] .. '|' .. lon['ew']
else
coord = coord .. '|' .. lat['d'] .. '|' .. lat['ns']
coord = coord .. '|' .. lon['d'] .. '|' .. lon['ew']
end
coord = coord .. '|globe:' .. globe
if options['display'] then
coord = coord .. '|display=' .. options.display
else
coord = coord .. '|display=title'
end
coord = coord .. '}}'
return g_frame:preprocess(coord)
end
end
local function getDefaultValueFunction( datavalue )
if datavalue.type == 'wikibase-entityid' then
return function( context, options, value ) return formatEntityId( getEntityIdFromValue( value ), options ) end;
elseif datavalue.type == 'string' then
return function( context, options, value ) return value end;
elseif datavalue.type == 'monolingualtext' then
return function( context, options, value )
if ( options.monolingualLangTemplate == 'lang' ) then
return options.frame:expandTemplate{ title = 'lang-' .. value.language, args = { value.text } };
elseif ( options.monolingualLangTemplate == 'ref' ) then
return '<span class="lang" lang="' .. value.language .. '">' .. value.text .. '</span>' .. options.frame:expandTemplate{ title = 'ref-' .. value.language };
else
return '<span class="lang" lang="' .. value.language .. '">' .. value.text .. '</span>';
end
end;
elseif datavalue.type == 'globecoordinate' then
-- geografik koordinatalar
return function( context, options, value ) return formatGlobeCoordinate( value, options ) end;
elseif datavalue.type == 'quantity' then
return function( context, options, value )
local amount = string.gsub(value['amount'], '^%+', '')
local lang = mw.language.new( 'ru' )
return lang:formatNum( tonumber( amount ) )
end;
elseif datavalue.type == 'time' then
return function( context, options, value )
local moduleDate = require('Module:Wikidata/date')
return moduleDate.formatDate( context, options, value );
end;
else
throwError( 'unknown-datavalue-type' )
end
end
function formatDatavalue( context, options, datavalue )
if ( not context ) then error( 'context not specified' ); end;
if ( not options ) then error( 'options not specified' ); end;
if ( not datavalue ) then error( 'datavalue not specified' ); end;
if ( not datavalue.value ) then error( 'datavalue.value is missng' ); end;
context.formatValueDefault = getDefaultValueFunction( datavalue );
local functionToCall = getUserFunction( options, 'value', context.formatValueDefault );
return functionToCall( context, options, datavalue.value );
end
--
local simpleReplaces = {
Q30 = '[[AQSh]]',
Q148 = '[[Xitoy Xalq Respublikasi|Xitoy]]',
Q183 = '[[Germaniya]]',
Q258 = '[[JAR]]',
Q423 = '[[Koreya Xalq Demokratik Respublikasi|KXDR]]',
Q2184 = '[[Rossiya Sovet Federativ Sotsialistik Respublikasi|Rossiya SFSR]]',
Q2895 = '[[Belorussiya Sovet Sotsialistik Respublikasi|Belorus SSR]]',
Q15180 = '[[Sovet Sotsialistik Respublikalari Ittifoqi|SSSR]]',
Q16957 = '[[Germaniya Demokratik Respublikasi|GDR]]',
Q130229 = '[[Gruziya Sovet Sotsialistik Respublikasi|Gruziya SSR]]',
Q130280 = '[[Estoniya Sovet Sotsialistik Respublikasi|Estoniya SSR]]',
Q131337 = '[[Ozarbayjon Sovet Sotsialistik Respublikasi|Ozarbayjon SSR]]',
Q132856 = '[[Armaniston Sovet Sotsialistik Respublikasi|Armaniston SSR]]',
Q133356 = '[[Ukraina Sovet Sotsialistik Respublikasi|Ukraina SSR]]',
Q168811 = '[[Qozogʻiston Sovet Sotsialistik Respublikasi|Qozogʻiston SSR]]',
Q170895 = '[[Moldova Sovet Sotsialistik Respublikasi|Moldova SSR]]',
Q173761 = '[[Litva Sovet Sotsialistik Respublikasi|Litva SSR]]',
Q192180 = '[[Latviya Sovet Sotsialistik Respublikasi|Latviya SSR]]',
Q199707 = '[[Turkmaniston Sovet Sotsialistik Respublikasi|Turkmaniston SSR]]',
Q199711 = '[[Tojikiston Sovet Sotsialistik Respublikasi|Tojikiston SSR]]',
Q484578 = '[[Oʻzbekiston Sovet Sotsialistik Respublikasi|Oʻzbekiston SSR]]',
}
function formatEntityId( entityId, options )
-- получение локализованного названия
local label = nil;
if ( options.text and options.text ~= '' ) then
label = options.text
else
if ( simpleReplaces[entityId] ) then
return simpleReplaces[entityId];
end
label = safeWikibaseLabel( entityId );
end
-- получение ссылки по идентификатору
local link = safeWikibaseSitelink( entityId )
if link then
if label then
return '[[' .. link .. '|' .. label .. ']]'
else
return '[[' .. link .. ']]'
end
end
if label then
return 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
--[[
Функция для оформления утверждений (statement)
Подробнее о утверждениях см. d:Wikidata:Glossary/ru
Принимает: таблицу параметров
Возвращает: строку оформленного текста, предназначенного для отображения в статье
]]
-- устаревшее имя, не использовать
function p.formatStatements( frame )
return p.formatProperty( frame );
end
function p.formatProperty( frame )
local args = frame.args
local plain = toBoolean( frame.args.plain, false );
frame.args.nocat = toBoolean( frame.args.nocat, false );
frame.args.references = toBoolean( frame.args.references, true );
if not frame.args.property then
throwError( 'property-param-not-provided' )
end
p_frame = frame
while p_frame do
if p_frame:getTitle() == mw.site.namespaces[10].name .. ':Wikidata' then
copyTo( p_frame.args, args, true );
end
if p_frame.args and p_frame.args.from and p_frame.args.from ~= '' then
args.entityId = p_frame.args.from;
end
p_frame = p_frame:getParent();
end
local propertyValue = safePropertyParserFunction( frame, frame.args.property )
if frame.args.value and frame.args.value ~= '' then
if plain or frame.args.nocat or propertyValue == '' then
return frame.args.value
else
return args.value .. categoryLocalValuePresent;
end
end
if ( plain ) then
return propertyValue;
end
g_frame = frame
return formatProperty( frame.args )
end
function formatRefs( 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 missing' ); end;
if ( not statement ) then error( 'statement not specified' ); end;
if ( not outputReferences ) then
return '';
end
local result = '';
if ( statement.references ) then
local allReferences = statement.references;
local hasPreferred = false;
for _, reference in pairs( statement.references ) do
if ( reference.snaks
and reference.snaks.P248
and reference.snaks.P248[1]
and reference.snaks.P248[1].datavalue
and reference.snaks.P248[1].datavalue.value["numeric-id"] ) then
local entityId = "Q" .. reference.snaks.P248[1].datavalue.value["numeric-id"];
if ( preferredSources[entityId] ) then
hasPreferred = true;
end
end
end
for _, reference in pairs( statement.references ) do
local display = true;
if ( hasPreferred ) then
if ( reference.snaks
and reference.snaks.P248
and reference.snaks.P248[1]
and reference.snaks.P248[1].datavalue
and reference.snaks.P248[1].datavalue.value["numeric-id"] ) then
local entityId = "Q" .. reference.snaks.P248[1].datavalue.value["numeric-id"];
if ( deprecatedSources[entityId] ) then
display = false;
end
end
end
if ( display ) then
result = result .. moduleSources.renderReference( g_frame, options.entity, reference );
end
end
end
return result
end
return p