Модуль:Wikidata2: юрамалар арасында аерма
Контент бетерелгән Контент өстәлгән
кТөзәтмә аңлатмасы юк |
к Ilnur efende үзгәртүләре (бәхәс) Takhirgeran Umar юрамасына кадәр кире кайтарылды Тамга: кире кайтару |
||
Юл номеры - 3:
local outputReferences = true;
-- sources that shall be omitted if any
local deprecatedSources = {
Q36578 = true, -- Gemeinsame Normdatei
Q63056 = true, -- Find a Grave
Q15222191 = true, -- BNF
};
local preferredSources = {
Q17378135 = true, -- Great Soviet Encyclopedia (1969—1978)
};
Строка 52 ⟶ 51 :
local function getConfig( section, code )
if config == nil then
config = require( 'Module:
end;
if not config then
Строка 139 ⟶ 138 :
if ( precision == 12 ) then
return { tonumber(os.time( {year=s.year, month=s.month, day=s.day, hour=s.hour, min=0, sec=0} )) * 1000,
tonumber(os.time( {year=s.year, month=s.month, day=s.day, hour=s.hour, min=59, sec=58} )) * 1000 +
end
Строка 169 ⟶ 168 :
end
return defaultValue;
end
Строка 386 ⟶ 366 :
Возвращает: текстовую метку элемента, язык метки
]]
if (type(entityId) ~= 'string') then error('type of entityId argument expected string, but was ' .. type(entityId)); end
if not entityId then
Строка 429 ⟶ 409 :
return label, langCode;
end
Строка 548 ⟶ 484 :
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;
if options.property then -- TODO: Почему тут может не быть property?
claims = context.selectClaims( options, options.property );
end
if claims == nil then
return '' --TODO error?
end
-- Обход всех заявлений утверждения и с накоплением оформленых предпочтительных
-- заявлений в таблице
local formattedClaims = {}
for i, claim in ipairs(claims) do
local formattedStatement = context.formatStatement( options, claim )
-- здесь может вернуться либо оформленный текст заявления, либо строка ошибки, либо nil
if ( formattedStatement and 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
-- создание текстовой строки со списком оформленых заявлений из таблицы
local out = mw.text.listToText( formattedClaims, options.separator, options.conjunction )
if out ~= '' then
if options.before then
out = options.before .. out
end
if options.after then
out = out .. options.after
end
end
return out
end
Строка 580 ⟶ 556 :
and qualifier.datavalue.value
and qualifier.datavalue.value['entity-type'] == 'item' ) then
if ( 'Q5727902' == circumstance ) then
circumstances.circa = true;
end
if ( 'Q18122778' == circumstance ) then
circumstances.presumably = true;
end
end
end
Строка 607 ⟶ 589 :
if ( options.qualifier and statement.qualifiers and statement.qualifiers[ options.qualifier ] ) then
local qualifierValues = {};
for _, qualifierSnak in pairs( statement.qualifiers[ options.qualifier ] ) do
local snakValue = context.formatSnak(
if snakValue and snakValue ~= '' then
table.insert( qualifierValues,
end
end
if (
result = result .. ' (' .. table.concat( qualifierValues, ', ' ) .. ')';
end
end
Строка 666 ⟶ 642 :
elseif snak.snaktype == 'value' then
result = formatDatavalue( context, options, snak.datavalue, snak.datatype );
if ( circumstances.circa ) then
result = options.i18n.circa .. result;
end
else
Строка 688 ⟶ 666 :
Возвращает: строку оформленного текста
]]
-- проверка на требование в параметрах вызова на возврат сырого значения
if options['subvalue'] == 'latitude' then -- широты
Строка 702 ⟶ 680 :
-- нужно дописать в документации шаблона, что он отсюда вызывается, и что
-- любое изменние его парамеров должно быть согласовано с кодом тут
local eps = 0.0000001 -- < 1/360000
local globe = options.globe or ''
if globe == '' and value['globe'] then
globes = require( 'Module:
globe = globes[value['globe']] or ''
end
local
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 + eps)
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 + eps)
-- TODO: round seconds with precision
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['type'] and options['type'] ~= '' then
coord = coord .. '|type=' .. options.type
end
if options['display'] and options['display'] ~= '' then
coord = coord .. '|display=' .. options.display
else
coord = coord .. '|display=title'
end
coord = coord .. '}}'
return g_frame:preprocess(coord)
end
end
Строка 730 ⟶ 733 :
Возвращает: строку оформленного текста
]]
local image = value;
Строка 740 ⟶ 743 :
end
if caption ~= '' then
caption =
end
if not string.find( value, '[%[%]%{%}]
image = '[[File:' .. value .. '|frameless';
if options[ 'border' ] and options[ 'border' ] ~= '' then
Строка 770 ⟶ 771 :
if caption ~= '' then
image = image .. '<br>' .. caption;
end
else
image = image .. caption .. getCategoryByCode( 'media-contains-markup' );
end
return image
end
Строка 795 ⟶ 786 :
@return string Formatted string.
]]
return options.frame:extensionTag{ name = 'math', content = value };
end
Строка 838 ⟶ 829 :
if formatter and formatter ~= '' then
local link = mw.ustring.gsub( mw.ustring.gsub( formatter, '$1', value ), ' ', '%%20' )
local title = options.title
Строка 870 ⟶ 859 :
local mult = 10^sigfig;
number = math.floor( number * mult + 0.5 ) / mult;
return string.gsub( lang:formatNum( number ), '^-', '−' );
end
Строка 877 ⟶ 867 :
local diff = tonumber( value.upperBound ) - tonumber( amount )
if diff > 0 then -- временная провека, пока у большинства значений не будет убрано ±0
out = out .. ' ± ' .. formatNum( diff )
end
end
Строка 907 ⟶ 883 :
unitEntity.claims.P2370[1].mainsnak.snaktype == 'value' and
not value.upperBound and
options.siConversion
then
conversionToSIunit = string.gsub( unitEntity.claims.P2370[1].mainsnak.datavalue.value.amount, '^%+', '' );
Строка 1015 ⟶ 991 :
-- Media
return function( context, options, value )
if ( not options.caption
and ( not options.
for i, qualifier in pairs( options.qualifiers.P2096 ) do
if ( qualifier
Строка 1090 ⟶ 1061 :
elseif datavalue.type == 'time' then
return function( context, options, value )
local moduleDate = require( 'Module:
return moduleDate.formatDate( context, options, value );
end;
Строка 1148 ⟶ 1119 :
link = ':' .. link
end
if label
local a = link == label and ('[[' .. link .. ']]') or '[[' .. link .. '|' .. label .. ']]';
if ( contentLanguageCode ~= labelLanguageCode ) then
Строка 1165 ⟶ 1136 :
local title = mw.title.new( label );
if title and not title.exists and options.frame then
local templateText = "{{Универсальная карточка|" .. entityId .. "}}%0A'''" .. label .. "''' — %0A%0A== Примечания ==%0A{{примечания}}%0A";
local templateText = templateText .. "[[Категория:Википедия:Связать с элементом Викиданных|" .. entityId .. "]]";
local preloadUrl = tostring( mw.uri.canonicalUrl( label, 'action=edit&preload=Ш:Preload/Викиданные&preloadparams[]=' .. templateText ));
local redLink = options.frame:expandTemplate{ title='цветная ссылка', args = { '#0645AD', preloadUrl, label }};
return '<span class="plainlinks">' .. redLink .. '</span><sup>[[:d:' .. entityId .. '|[d]]]</sup>' .. category;
end
Строка 1191 ⟶ 1165 :
]]
function p.extractCategory( context, options, value )
local wbStatus, entity = pcall( mw.wikibase.getEntity, value.id )
local category = ''
if ( options.category ) then
if ( claims ) then
if ( claim.mainsnak
and claim.mainsnak
and claim.mainsnak.datavalue
and claim.mainsnak.datavalue.type == 'wikibase-entityid' ) then
local catEntityId = claim.mainsnak.datavalue.value.id;
local wbStatus, catEntity = pcall( mw.wikibase.getEntity, catEntityId );
if ( wbStatus == true and
if catEntity:getSitelink() then
category = '[[' .. catEntity:getSitelink() .. ']]';
end
end
end
end
end
end
return category;
end
--[[
Функция для оформления утверждений (statement)
Строка 1302 ⟶ 1273 :
throwError( 'property-param-not-provided' )
end
local propertyId = mw.language.getContentLanguage():ucfirst( string.gsub( args.property, '%[.*$', '' ) )
args = getPropertyParams( propertyId, nil, args );
local datatype = args.datatype;
Строка 1318 ⟶ 1280 :
p_frame = frame
while p_frame do
if p_frame:getTitle() == mw.site.namespaces[10].name .. ':
copyTo( p_frame.args, args, true );
end
Строка 1375 ⟶ 1337 :
value = value .. getCategoryByCode( 'value-contains-table' )
else
-- значений с блочными тегами остаются блоком, текст встраиваем в строку
if ( string.match( value, '\n' )
or string.
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
end
end
Строка 1429 ⟶ 1400 :
local allReferences = statement.references;
local
local displayCount = 0;
for _, reference in pairs( statement.references ) do
Строка 1438 ⟶ 1409 :
and reference.snaks.P248[1].datavalue.value.id ) then
local entityId = reference.snaks.P248[1].datavalue.value.id;
if (
end
end
Строка 1446 ⟶ 1417 :
for _, reference in pairs( statement.references ) do
local display = true;
if (
if ( reference.snaks
and reference.snaks.P248
Строка 1457 ⟶ 1428 :
end
end
end
if ( display == true ) then
if ( displayCount > 2 ) then
if ( options.entity and options.property ) then
table.remove( references );
local moreReferences = '<sup>[[d:' .. options.entity.id .. '#' .. string.upper( options.property ) .. '|[…]]]</sup>';
table.insert( references, moreReferences );
end
break;
end;
local refText = moduleSources.renderReference( g_frame, options.entity, reference );
if ( refText ~= '' ) then
|