Модуль:Wikidata/link

Материал из Энциклопедии Гитармага
Перейти к: навигация, поиск

Предназначен для преобразования ID из свойств Викиданных в работающие ссылки. Работает совместно с {{Wikidata/link}}.

Если для свойства не прописана функция для форматирования, используется форматтер из свойства d:Property:P1630.


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.p231( context, options, id )
	return '[http://www.chemnet.com/cas/supplier.cgi?exact=dict&terms=' .. 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.p377( context, options, id )
	return '[http://www.n2yo.com/satellite/?s=' .. id .. ' ' .. id .. ']';
end

function p.p492( context, options, id )
	return '[http://omim.org/entry/' .. id .. ' ' .. id .. ']';
end

function p.p493( context, options, id )
	return '[http://www.icd9data.com/getICD9Code.ashx?icd9=' .. id .. ' ' .. id .. ']';
end

function p.p494( context, options, id )
	return '[http://apps.who.int/classifications/icd10/browse/2010/en#/' .. id .. ' ' .. id .. ']';
end

function p.p557( context, options, id )
	return '[http://www.diseasesdatabase.com/ddb' .. id .. '.htm ' .. id .. ']';
end

function p.p563( context, options, id )
	return '[http://www.progenetix.org/cgi-bin/subsets.cgi?project=progenetix&subsetType=ICDM&ICDMcodes_m=' .. id .. ' ' .. id .. ']';
end

function p.p604( context, options, id )
	return '[https://www.nlm.nih.gov/medlineplus/ency/article/' .. id .. '.htm ' .. id .. ']';
end

function p.p661( context, options, id )
	return '[//www.chemspider.com/Chemical-Structure.' .. id .. '.html ' .. id .. ']';
end

function p.p662( context, options, id )
	return '[http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=' .. id .. ' ' .. id .. ']';
end

function p.p685( context, options, id )
	return '[http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id=' .. id .. ' ' .. id .. ']';
end

function p.p715( context, options, id )
	return '[http://www.drugbank.ca/drugs/DB' .. 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.p815( context, options, id )
	return '[http://www.itis.gov/servlet/SingleRpt/SingleRpt?search_topic=TSN&search_value=' .. id .. ' ' .. id .. ']';
end

function p.p830( context, options, id )
	return '[http://www.eol.org/pages/' .. id .. ' ' .. id .. ']';
end

function p.p842( context, options, id )
        return '[http://fossilworks.org/bridge.pl?a=taxonInfo&taxon_no=' .. id .. ' ' .. id .. ']';
end

function p.p884( context, options, id )
	return '[http://vwo.osm.rambler.ru/?page=findname&name=' .. id .. ' ' .. id .. ']';
end

function p.p957( context, options, id )
	return '[[Special:Booksources/' .. id .. '|' .. id .. ']]';
end

function p.p961( context, options, id )
	return '[http://www.ipni.org/ipni/idPlantNameSearch.do?id=' .. id .. ' ' .. id .. ']';
end

function p.p962( context, options, id )
	return '[http://www.mycobank.org/Biolomics.aspx?Table=Mycobank&MycoBankNr_=' .. id .. ' ' .. id .. ']';
end

function p.p959( context, options, id )
	return '[http://www.bucknell.edu/msw3/browse.asp?id=' .. id .. ' ' .. id .. ']';
end

function p.p1070( context, options, id )
	return '[http://www.theplantlist.org/tpl1.1/record/' .. id .. ' ' .. id .. ']';
end

function p.p1077( context, options, id )
	return '[http://dovidnyk.in.ua/directories/koatuu/search=' .. id .. ' ' .. id .. ']';
end

function p.p1146( context, options, id )
	return '[http://www.iaaf.org/athletes/athlete=' .. id .. '/ ' .. id .. ']';
end

function p.p1258( context, options, id )
	return '[http://www.rottentomatoes.com/' .. id .. '/ подробнее]';
end

function p.p1483( context, options, id )
	return '[http://kulturnoe-nasledie.ru/monuments.php?id=' .. id .. ' ' .. id .. ']';
end

function p.p1883( context, options, id )
	return '[http://declarator.org/person/' .. id .. '/ ' .. 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;