Модуль:Wikidata/link
Ладъянъёсты лыдӟон
Набор функций для преобразования ID из свойств Викиданных в работающие ссылки.
Обычно для ссылок используется URL-форматтер из свойства маска URL (P1630), его можно изменить параметром formatter, текст ссылки можно изменить параметром title. Новую функцию имеет смысл создавать, если задачу по изменению ссылки нельзя решить при помощи этих параметров.
p = {}
function p.fromTemplate( frame )
local args = frame.args;
local propertyId = args[1];
local id = args[2];
return p.generateLink( propertyId, id )
end
function p.fromModule( context, options, id )
return p.generateLink( options['property'], id )
end
function p.generateLink( propertyId, id )
if p[propertyId] then
return p[propertyId]( nil, nil, id );
end
local pattern = p.findPattern( propertyId )
if pattern then
return mw.ustring.gsub( '[' .. pattern .. ' $1]', '$1', id ) .. ''
end
return id
end
function p.p163( context, options, id )
return '[[' .. id .. '|Флаг]]';
end
function p.p212( context, options, id )
return '[[Special:Booksources/' .. id .. '|' .. id .. ']]';
end
function p.p237( context, options, id )
return '[[' .. id .. '|Герб]]';
end
function p.p247( context, options, id )
return '[http://nssdc.gsfc.nasa.gov/nmc/spacecraftOrbit.do?id=' .. id .. ' ' .. id .. ']';
end
function p.p267( context, options, id )
local frame = mw.getCurrentFrame()
return frame:expandTemplate{ title = 'АТХ', args = { id } };
end
function p.p296( context, options, id )
return '[http://osm.sbin.ru/esr/esr:' .. id .. ' ' .. id .. ']';
end
function p.p345( context, options, id )
local number = string.sub( id, 3 )
local label = 'ID ' .. number
if string.match( id, '^ch' ) then
return '[[IMDbCharacter:' .. number .. '|' .. label .. ']]'
end
if string.match( id, '^co' ) then
return '[[IMDbCompany:' .. number .. '|' .. label .. ']]'
end
if string.match( id, '^nm' ) then
return '[[IMDbName:' .. number .. '|' .. label .. ']]'
end
if string.match( id, '^tt' ) then
return '[[IMDbTitle:' .. number .. '|' .. label .. ']]'
end
return id;
end
function p.p685( context, options, id )
return '[https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id=' .. id .. ' ' .. id .. ']';
end
function p.p721( context, options, id )
local label = '';
for i = mw.ustring.len( id ), 1, -3 do
if ( i ~= mw.ustring.len( id ) ) then
label = ' ' .. label;
end
if ( i - 2 <= 0 ) then
label = mw.ustring.sub( id, 0, i ) .. label;
else
label = mw.ustring.sub( id, i - 2, i ) .. label;
end
end
return '[http://classif.spb.ru/classificators/view/okt.php?st=A&kr=1&kod=' .. id .. ' ' .. label .. ']';
end
function p.p764( context, options, id )
local label = '';
for i = mw.ustring.len( id ), 1, -3 do
if ( i ~= mw.ustring.len( id ) ) then
label = ' ' .. label;
end
if ( i - 2 <= 0 ) then
label = mw.ustring.sub( id, 0, i ) .. label;
else
label = mw.ustring.sub( id, i - 2, i ) .. label;
end
end
return '[http://classif.spb.ru/classificators/view/tma.php?st=A&kr=1&kod=' .. id .. ' ' .. label .. ']';
end
function p.p957( context, options, id )
return '[[Special:Booksources/' .. id .. '|' .. id .. ']]';
end
function p.p1258( context, options, id )
return '[http://www.rottentomatoes.com/' .. id .. '/ подробнее]';
end
function p.findPattern( property )
local entity = mw.wikibase.getEntity(property:upper())
if entity then
local Statements = entity:getBestStatements('P1630')
for _, statement in pairs(Statements) do
if statement.mainsnak.snaktype == 'value' then
return statement.mainsnak.datavalue.value;
end
end
end
return nil
end
return p;