{ getLabelWithLink( 'Q953058', 'Kungliga biblioteket', 'LIBRIS'), 'P906', selibrLink, categoryAuthorityControl( 'SELIBR' ) },
{ getLabelWithLink( 'Q2597810', 'Système universitaire de documentation', 'SUDOC'), 'P269', sudocLink, categoryAuthorityControl( 'SUDOC' ) },
{ getLabelWithLink( 'Q54919', 'Virtual International Authority File', 'VIAF'), 'P214', viafLink, categoryAuthorityControl( 'VIAF' ) },
{ getLabelWithLink( 'Q2494649', 'Union List of Artist Names', 'ULAN' ), 'P245', ulanLink, categoryAuthorityControl( 'ULAN' ) },
}  
function getQualifierSingleValue( statement, qualifierName )
if (statement ~= nil
and statement.qualifiers ~= nil
and statement.qualifiers[qualifierName] ~= nil
and statement.qualifiers[qualifierName][0] ~= nil
and statement.qualifiers[qualifierName][0].datavalue ~= nil
and statement.qualifiers[qualifierName][0].datavalue.type ~= nil
and statement.qualifiers[qualifierName][0].datavalue.value ~= nil
) then
local qualifier = statement.qualifiers[qualifierName][0];
if ( qualifier.datavalue.type == "string" ) then
return qualifier.datavalue.value;
end
if ( qualifier.datavalue.type == "wikibase-entityid" ) then
return 'Q' .. qualifier.datavalue.value["numeric-id"];
end
mw.log( 'Unknown qualifier type: ' .. qualifier.datavalue.type )
return qualifier.datavalue.value;
end
return nil;
end  
function getQualifierValues( statement, qualifierName )
local result = {}
if (statement ~= nil
and statement.qualifiers ~= nil
and statement.qualifiers[qualifierName] ~= nil) then
local qualifiers = statement.qualifiers[qualifierName];
for _, qualifier in pairs( qualifiers ) do
if (qualifier.datavalue ~= nil
and qualifier.datavalue.type ~= nil
and qualifier.datavalue.value ~= nil) then  
if ( qualifier.datavalue.type == "string" ) then
result[#result+1] = qualifier.datavalue.value;
elseif ( qualifier.datavalue.type == "wikibase-entityid" ) then
result[#result+1] = 'Q' .. qualifier.datavalue.value["numeric-id"];
else
mw.log( 'Unknown qualifier type: ' .. qualifier.datavalue.type );
result[#result+1] = 'Q' .. qualifier.datavalue.value;
end
end
end
end
return result;
end  
function collectLinks( configuration )  
local moduleLanguages
if ( mw.title.makeTitle( 'Module', 'Languages' ).exists
and mw.title.makeTitle( 'Module', 'Languages/data' ).exists
and mw.title.makeTitle( 'Module', 'Wikidata/Language-codes' ).exists) then
moduleLanguages = require('Module:Languages');
else
moduleLanguages = false;
end  
--Create rows
local elements = {}
local data = {}  
local item = mw.wikibase.getEntity
if item == nil or item.claims == nil then
return elements
end  
if ( item.claims['P553'] ~= nil ) then
local claim = item.claims['P553']
for _, statement in pairs( claim ) do
if (statement ~= nil) then
-- profile ID
local rank = statement.rank or 'normal';
if ( rank ~= 'deprecated' ) then
local itemId = getQualifierSingleValue( statement, 'P554' );
if (itemId ~= nil) then
-- language
local languages = getQualifierValues( statement, 'P407' );
local resourceId = 'Q' .. statement.mainsnak.datavalue.value['numeric-id']
if (data[resourceId] == nil) then
data[resourceId] = {};
end
table.insert( data[resourceId], { itemId = itemId, languages = languages, rank = rank} )
end
end
end
end
end  
if ( item.claims['P1343'] ~= nil ) then
local claim = item.claims['P1343']
for _, statement in pairs( claim ) do
if (statement ~= nil) then
local rank = statement.rank or 'normal';
if ( rank ~= 'deprecated' ) then
local resourceId = 'Q' .. statement.mainsnak.datavalue.value['numeric-id']
local languages = getQualifierValues( statement, 'P407' );  
if ( titleBasedLinks[resourceId] ) then
-- title-based
local title = getQualifierSingleValue( statement, 'P357' );
if (title ~= nil) then
if (data[resourceId] == nil) then
data[resourceId] = {};
end
table.insert( data[resourceId], { itemId = title, languages = languages, rank = rank} );
end
else
-- URL to encyclopedia
local url = getQualifierSingleValue( statement, 'P854' );
if (url ~= nil) then
if (data[resourceId] == nil) then
data[resourceId] = {};
end
table.insert( data[resourceId], { itemId = url, languages = languages, rank = rank} );
end
end
end
end
end
end  
for _, params in pairs( configuration ) do
local resourceId = params[2]  
local claim = item.claims[ resourceId ]
if ( claim ) then
for _, statement in pairs( claim ) do
local rank = statement.rank or 'normal';
if rank ~= 'deprecated' and statement.mainsnak.snaktype ~= 'novalue' then
local itemId = statement.mainsnak.datavalue.value;
local languages = getQualifierValues( statement, 'P407' );
if (data[resourceId] == nil) then
data[resourceId] = {};
end
table.insert( data[resourceId], { itemId = itemId, languages = languages, rank = rank} );
end
end
end
end  
for resourceId, resourceDatas in pairs( data ) do
data[resourceId] = filterByRank( resourceDatas );
end  
local hasNonOptionalLinks = false  
for _, params in pairs( configuration ) do
local resourceLabel = params[1]
local firstChar = mw.ustring.sub( resourceLabel, 1, 1 );
local separateDesign = firstChar == '[' or firstChar == '<';  
local resourceId = params[2]
local optional = params[5] or false;  
local resourceDatas = data[resourceId];
if resourceDatas ~= nil then
if ( not optional ) then
hasNonOptionalLinks = true
end  
local html = '';
if ( separateDesign ) then
html = html .. resourceLabel .. ':&nbsp;';
end
for index, resourceData in pairs(resourceDatas) do
local itemId = resourceData.itemId;
local languages = resourceData.languages;
local link = params[3] ( itemId );
local linkFirstChar;
local interwiki;
if ( link ) then
linkFirstChar = mw.ustring.sub( link, 1, 1 );
interwiki = linkFirstChar == ':'
end  
if ( separateDesign ) then
if ( index ~= 1 ) then
html = html .. ',&nbsp;'
end
if ( link ) then
if ( interwiki ) then
html = html .. * .. itemId .. *;
else
html = html .. '[' .. link .. ' ' .. itemId .. ']';
end
else
html = html .. itemId;
end
else
if ( index ~= 1 ) then
html = html .. ' · '
end
if ( link ) then
if ( interwiki ) then
html = html .. * .. resourceLabel .. *;
else
html = html .. '[' .. link .. ' ' .. resourceLabel .. ']';
end
else
-- it should not happen
html = html .. resourceLabel .. ':&nbsp;' .. itemId;
end  
if ( moduleLanguages ) then
if ( languages ~= nil and #languages > 0 ) then
for langIndex, language in pairs(languages) do
html = html .. '&nbsp;' .. moduleLanguages.getRefHtml( language )
end
end
end
end
end
if ( #params >= 4 and params[4] ) then
html = html .. '[[Category:' .. params[4] .. ']]'
end
table.insert( elements, html )
end
end  
if ( not hasNonOptionalLinks ) then
return {}
end  
return elements
end  
function contains( tableStructure, value )
if ( tableStructure == nil or value == nil) then
return true;
end
for index, line in pairs( tableStructure ) do
if (line == value) then
return true;
end
end
return false;
end  
function filterByRank( resourceDatas )
-- itemId, languages. rank = rank  
local hasPreffered = false;
for index, resourceData in pairs(resourceDatas) do
if ( resourceData.rank == 'preferred' ) then
hasPreffered = true;
end
end  
if (not hasPreffered) then
return resourceDatas;
end  
local result = {};
for index, resourceData in pairs(resourceDatas) do
if ( resourceData.rank == 'preferred' or contains(resourceData.languages, preferredLanguage) ) then
table.insert(result, resourceData);
end
end  
return result;
end  
function p.render
local colorArg = '#CCF';
if ( ~= nil ) then
local parentArgs = :getParent.args
colorArg = parentArgs[templateColorName] or parentArgs["color"] or parentArgs[1] or '#CCF';
local firstChar = mw.ustring.sub( colorArg, 1, 1 );
if ( firstChar ~= '#' ) then
local byTemplate = colorByTitle( , colorArg );
if ( byTemplate ) then
colorArg = byTemplate;
end
end
end  
local navboxData = {
name = 'External links',
navbox,
body,
group .. colorArg .. ';',
};
local rowIndex = 1  
local socialNetworksElements = collectLinks( socialNetworkProperties );
if ( #socialNetworksElements > 0 ) then
navboxData['group' .. rowIndex] = group1Label