Модуль:Wikidata2: юрамалар арасында аерма

Контент бетерелгән Контент өстәлгән
Marat-avgust (бәхәс | кертем)
Төзәтмә аңлатмасы юк
Marat-avgust (бәхәс | кертем)
Төзәтмә аңлатмасы юк
Юл номеры - 17:
["value-function-not-found"] = "Функция для отображения значения не найдена."
},
["somevalue"] = "''билгесезнеизвестно''",
["novalue"] = "",
["circa"] = '<span style="border-bottom: 1px dotted; cursor: help;" title="якынчаоколо, приблизительно">якприбл. </span>',
["presumably"] = '<span style="border-bottom: 1px dotted; cursor: help;" title="предположительно">предп. </span>',
}
Юл номеры - 43:
-- Ссылки на используемые модули, которые потребуются в 99% случаев загрузки страниц (чтобы иметь на виду при переименовании)
local moduleSources = require( 'Module:Sources' )
local WDS = require( 'Module:WikidataSelectors' );
 
-- Константы
Строка 51 ⟶ 52 :
local formatDatavalue, formatEntityId, formatRefs, formatSnak, formatStatement,
formatStatementDefault, formatProperty, getSourcingCircumstances,
getPropertyDatatype, getPropertyParams, loadCacheSafe, throwError, toBoolean;
 
local function copyTo( obj, target )
Строка 58 ⟶ 59 :
end
return target;
end
 
local function loadCacheSafe( entityId )
-- TODO: Вернуть mw.loadData()
local status, result = pcall( function() return require( 'Module:WikidataCache/' .. entityId ) end );
if ( status == true ) then
return result;
end
return nil;
end
 
Строка 170 ⟶ 162 :
local function getEntityFromId( id )
if id then
local cached = loadCacheSafe( id );
if ( cached ) then
return cached;
end
return mw.wikibase.getEntityObject( id )
end
local entity =return mw.wikibase.getEntityObject();
if ( entity ) then
local cached = loadCacheSafe( entity.id );
if ( cached ) then
return cached;
end
end
return entity;
end
 
Строка 240 ⟶ 221 :
-- Выбирает свойства по property id, дополнительно фильтруя их по рангу
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;
 
result = WDS.filter( options.entity.claims, propertySelector );
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
 
--[[
Функция для получения значения свойства элемента в заданный момент времени.
 
Принимает: контекст, элемент, временные границы, таблица ID свойства
Возвращает: таблицу соответствующих значений свойства
]]
local function getPropertyInBoundaries( context, entity, boundaries, propertyIds )
local results = {};
 
if not propertyIds or #propertyIds == 0 then
return results;
end
 
if entity.claims then
for _, propertyId in ipairs( propertyIds ) do
local filteredClaims = WDS.filter( entity.claims, propertyId .. '[rank:preferred, rank:normal]' );
if filteredClaims then
for _, claim in pairs( filteredClaims ) do
if not boundaries or not propertyIds or #propertyIds == 0 then
table.insert( results, claim.mainsnak );
else
local startBoundaries = getTimeBoundariesFromQualifiers( context, claim, 'P580' );
local endBoundaries = getTimeBoundariesFromQualifiers( context, claim, 'P582' );
if ( (startBoundaries == nil or ( startBoundaries[2] <= boundaries[1]))
and (endBoundaries == nil or ( endBoundaries[1] >= boundaries[2]))) then
table.insert( results, claim.mainsnak );
end
end
end
end
 
if #results > 0 then
break;
end
end
end
 
return results;
end
 
--[[
Функция для получения метки элемента в заданный момент времени.
 
Принимает: контекст, элемент, временные границы
Возвращает: текстовую метку элемента, язык метки
]]
function getLabelWithLang( context, options, entity, boundaries, propertyIds )
if not entity then
return nil;
end
 
local lang = mw.language.getContentLanguage();
local langCode = lang:getCode();
 
-- name from label
local label = nil;
if ( options.text and options.text ~= '' ) then
label = options.text;
else
label, langCode = entity:getLabelWithLang();
if not langCode then
return nil;
end
if not propertyIds then
propertyIds = {
'P1813[language:' .. langCode .. ']',
'P1448[language:' .. langCode .. ']',
'P1705[language:' .. langCode .. ']'
};
end
-- name from properties
local results = getPropertyInBoundaries( context, entity, boundaries, propertyIds );
for _, result in pairs( results ) do
if result.datavalue and result.datavalue.value then
if result.datavalue.type == 'monolingualtext' and result.datavalue.value.text then
label = result.datavalue.value.text;
lang = result.datavalue.value.language;
break;
elseif result.datavalue.type == 'string' then
label = result.datavalue.value;
break;
end
end
end
end
 
return label, langCode;
end
 
Строка 273 ⟶ 354 :
return '' --TODO error?
end
 
-- проброс всех параметров из шаблона {wikidata}
local p_frame = g_frame:getParent();
if p_frame and p_frame:getTitle() == mw.site.namespaces[10].name .. ':Wikidata' then
copyTo( p_frame.args, options );
end
 
-- improve options
Строка 641 ⟶ 716 :
end
 
if valueoptions.unit and string.match( valueoptions.unit, ~= 'http://www.wikidata.org/entity/' ) then
if options.unit ~= '-' then
out = out .. ' ' .. options.unit
end
elseif value.unit and string.match( value.unit, 'http://www.wikidata.org/entity/' ) then
local unitEntityId = string.gsub( value.unit, 'http://www.wikidata.org/entity/', '' );
local unitEntity = mw.wikibase.getEntity( unitEntityId );
if unitEntity then
local writingSystemElementId = 'Q8209';
-- name from label
local langElementId = 'Q7737';
-- TODO: lang:getFallbackLanguages()
local label = getLabelWithLang( context, options, unitEntity, nil;, {
'P558[P282:' .. writingSystemElementId .. ', P407:' .. langElementId .. ']',
if unitEntity.labels then
'P558[!P282][!P407]'
if unitEntity.labels[langCode] and unitEntity.labels[langCode].value then
} );
label = unitEntity.labels[langCode].value;
elseif unitEntity.labels.en and unitEntity.labels.en.value then
label = unitEntity.labels.en.value;
end
end
-- name from properties
if unitEntity.claims and unitEntity.claims.P558 then
local writingSystemElementId = 'Q8209';
local langElementId = 'Q7737';
local labelFilter = 'P558[P282:' .. writingSystemElementId .. ', P407:' .. langElementId .. ']';
local WDS = require( 'Module:WikidataSelectors' );
local labelClaims = WDS.filter( unitEntity.claims, labelFilter );
for r, claim in pairs( labelClaims ) do
if claim.mainsnak
and claim.mainsnak.datavalue
and claim.mainsnak.datavalue.type == 'string'
and claim.mainsnak.datavalue.value ~= '' then
label = claim.mainsnak.datavalue.value;
break;
end
end
end
out = out .. '  ' .. label;
end
end
Строка 704 ⟶ 761 :
if datavalue.type == 'wikibase-entityid' then
-- Entity ID
return function( context, options, value ) return formatEntityId( context, options, getEntityIdFromValue( value ), options ) end;
elseif datavalue.type == 'string' then
-- String
Строка 787 ⟶ 844 :
return functionToCall( context, options, datavalue.value );
end
 
-- Небольшой словарь упрощенного отображения (TODO: надо сделать расширенный с учётом даты)
local simpleReplaces = {}
 
--[[
Строка 797 ⟶ 851 :
Возвращает: строку оформленного текста
]]
function formatEntityId( entityIdcontext, options, entityId )
-- получение локализованного названия
local entity = mw.wikibase.getEntity( entityId )
local label = nil;
local label, labelLanguageCode = contentLanguageCode;getLabelWithLang( context, options, entity )
if ( options.text and options.text ~= '' ) then
label = options.text
else
if ( simpleReplaces[entityId] ) then
return simpleReplaces[entityId];
end
label, lang = mw.wikibase.getLabelWithLang( entityId );
end
 
-- получение ссылки по идентификатору
Строка 938 ⟶ 984 :
local datatype = getPropertyDatatype( propertyId );
args = getPropertyParams( propertyId, datatype, args );
 
-- проброс всех параметров из шаблона {wikidata}
local p_frame = frame:getParent();
if p_frame and p_frame:getTitle() == mw.site.namespaces[10].name .. ':Wikidata' then
copyTo( p_frame.args, args );
end
 
args.nocat = toBoolean( args.nocat, false );
Строка 956 ⟶ 1008 :
 
-- обработчики по типу значения
local wrapperExtraArgs = ''
if args['value-module'] and args['value-function'] and not string.find( value, '[%[%]%{%}]' ) then
local func = getUserFunction( args, 'value' );
Строка 962 ⟶ 1015 :
value = formatCommonsMedia( value, args );
elseif datatype == 'external-id' and not string.find( value, '[%[%]%{%}]' ) then
wrapperExtraArgs = wrapperExtraArgs .. ' data-wikidata-external-id="' .. mw.text.encode( value ).. '"';
value = formatExternalId( value, args );
elseif datatype == 'url' then
Строка 983 ⟶ 1037 :
or string.match( value, '<t[dhr][ >]' )
or string.match( value, '<div[ >]' ) ) then
value = '<div class="no-wikidata" ' .. wrapperExtraArgs
.. ' data-wikidata-property-id="' .. propertyId .. '">\n'
.. value .. '</div>'
else
value = '<span class="no-wikidata" ' .. wrapperExtraArgs
.. ' data-wikidata-property-id="' .. propertyId .. '">'
.. value .. '</span>'
end