Модуль:External links: відмінності між версіями

Матеріал з Вікіпедії — вільної енциклопедії.
Перейти до навігації Перейти до пошуку
[перевірена версія][перевірена версія]
Вилучено вміст Додано вміст
Немає опису редагування
Немає опису редагування
Рядок 431: Рядок 431:
{ getLabelWithoutLink( 'Q4043924', 'Megogo' ), 'P2826', MegogoIDLink, categoryExternalLink( 'Megogo' ) },
{ getLabelWithoutLink( 'Q4043924', 'Megogo' ), 'P2826', MegogoIDLink, categoryExternalLink( 'Megogo' ) },
{ getLabelWithoutLink( 'Q150248', 'Metacritic' ), 'P1712', metacriticLink, categoryExternalLink( 'Metacritic' ) },
{ getLabelWithoutLink( 'Q150248', 'Metacritic' ), 'P1712', metacriticLink, categoryExternalLink( 'Metacritic' ) },
{ getLabelWithoutLink( 'Q2158761', 'MovieMeter' ), 'P1969', function(id) return 'https://www.moviemeter.nl/director/' .. id end, categoryExternalLink( 'MovieMeter' ) },
{ getLabelWithoutLink( 'Q2158761', 'MovieMeter' ), 'P1970', function(id) return 'https://www.moviemeter.nl/film/' .. id end, categoryExternalLink( 'MovieMeter' ) },
{ getLabelWithoutLink( 'Q2158761', 'MovieMeter' ), 'P1970', function(id) return 'https://www.moviemeter.nl/film/' .. id end, categoryExternalLink( 'MovieMeter' ) },
{ getLabelWithoutLink( 'Q2158761', 'MovieMeter' ), 'P9463', function(id) return 'https://www.moviemeter.nl/site/zoeken/' .. id end, categoryExternalLink( 'MovieMeter' ) },
{ getLabelWithoutLink( 'Q2158761', 'MovieMeter' ), 'P9463', function(id) return 'https://www.moviemeter.nl/site/zoeken/' .. id end, categoryExternalLink( 'MovieMeter' ) },
{ getLabelWithoutLink( 'Q1951172', 'Moviepilot' ), 'P5786', function(id) return 'https://www.moviepilot.de/movies/' .. id end, categoryExternalLink( 'Moviepilot' ) },
{ getLabelWithoutLink( 'Q1951172', 'Moviepilot' ), 'P5786', function(id) return 'https://www.moviepilot.de/movies/' .. id end, categoryExternalLink( 'Moviepilot' ) },
{ getLabelWithoutLink( 'Q3841788', 'MYmovies' ), 'P4779', function(id) return 'http://www.mymovies.it/biografia/?a=' .. id end, categoryExternalLink( 'MYmovies' ) },
{ getLabelWithoutLink( 'Q3841788', 'MYmovies' ), 'P4779', function(id) return 'http://www.mymovies.it/biografia/?a=' .. id end, categoryExternalLink( 'MYmovies' ) },

Версія за 15:51, 20 квітня 2021

{{i}} Документація модуля[перегляд] [редагувати] [історія] [очистити кеш]

Цей модуль Lua використовується в шаблоні {{Бібліоінформація}} (обг. · викор. · ред.) (перенаправлення -{{External links}} (обг. · викор. · ред.)), і, можливо, деяких інших. Зазвичай його функції не повинні викликатися з інших шаблонів Вікіпедії.

Категорії спостереження

див. пояснення нижче на підсторінці спільної документації. Категорія:Вікіпедія:Шаблон «Бібліоінформація» пустий (7117) Категорія:Вікіпедія:Статті з посиланнями на Вікісховище (17 064)

Ви на сторінці модуля {{Модуль:External links}} (обг. · викор. · ред.). Спільна із шаблоном {{Бібліоінформація}} (обг. · викор. · ред.) документація, що наведена нижче, знаходиться на підсторінці спільної документації «Шаблон:Бібліоінформація/документація».:


Шаблон автоматично підставляє посилання на соціальні мережі, служби фото і відеохостингу, а також дані нормативного контролю, які визначені для поточного Елемента на Вікіданих.

Єдиним аргументом є «color», який дозволяє модифікувати колір групових заголовків для отриманої навігаційної таблиці.

{{Бібліоінформація}}
{{Бібліоінформація|#CCF}}
{{Бібліоінформація|колір=#CCF}}
{{Бібліоінформація|color=#CCF}}


Для додавання, редагування та видалення посилань в шаблоні без переходу на сайт Вікіданих існує спеціальний гаджет.

Розміщення на сторінці

Шаблон розміщується наприкінці основного вмісту сторінки (зазвичай — це безпосередньо після списку посилань розділу «== Посилання ==», до категорій; до інших навігаційних шаблонів, так як додає посилання на поточну тему в інших джерелах: соцмережах, медіахостінгах, словниках-енциклопедіях, тематичних сайтах. За ним розташовуються «блочні» навігаційні шаблони, тобто внутрішні посилання Вікіпедії, на дотичні вікі-статті-сторінки. Принцип — спочатку посилання на саме цю тему в інших (будь-яких) джерелах, а потім — навігація по темах Вікіпедії — а саме, К:Навігаційні шаблони (115). Шаблон бажано розміщувати до інших навігаційних шаблонів, щоб він візуально йшов одразу після розділу «Посилання», якщо такий є.

Редагування

Всі значення беруться з Вікіданих, для їх зміни необхідно змінити інформацію на Вікіданих.

  • На сторінці цільової статті в лівому бічному меню знайдіть посилання «Елемент Вікіданих» і перейдіть по ньому (якщо посилання немає, то потрібно створити новий елемент і пов'язати його з існуючою статтею)
  • На сторінці, що з'явилася знайдіть розділ «Твердження»
  • На таблиці нижче знайдіть сайт, посилання на який Ви хочете додати. Якщо в таблиці рядок «Вікідані» має вигляд «P553/P554/Q219523», то робите наступне:
    • Створюєте нове твердження (кнопка «[додати]»).
    • Назва нової властивості: «соціальна мережа, в якій має акаунт»
    • Значення нової властивості: тип соціальної мережі, профіль в якій Ви хочете додати в список посилань. Наприклад, «Q918: X».
    • Натискаєте «Зберегти», і, після збереження, на кнопку «Редагувати» (вона з'явиться праворуч від назви соц. мережі)
    • Натискаєте «уточнити» — це додасть поля для додавання уточнення
    • У полі «Властивість» вказуєте «адресу в соціальних медіа»
    • У полі, що з'явиться після цього, вказуєте адресу в Twitter, наприклад, «myaccount»
    • Натискаєте «Зберегти». Вітаємо, Ви додали посилання на акаунт Twitter'а.
  • Якщо в таблиці рядок «Вікідані» має вигляд «P549», то робите наступне:
    • Створюєте нове твердження (кнопка «[додати]»).
    • Назва нової властивості: «P549: ідентифікатор MGP» (з'явиться назва сайту)
    • Як значення властивості вказуєте цифрове або цифро-літерне ID акаунта на сайті. Наприклад, якщо для сайту «Родовід» посилання виглядає як http://ru.rodovid.org/wk/Person:57500, причому останні цифри змінюються від людини до людини, значить саме «57500» і є ID акаунта і саме його потрібно вказувати як значення властивості.
    • Натискаєте «Зберегти». Вітаємо, Ви додали посилання на сайт.

Список посилань, що додаються

Категорії спостереження

Так як шаблон фактично тільки викликає модуль, то наступні категорії є категоріями спостереження «{{Модуль:External links}} (обг. · викор. · ред.)»:

Див. також

Цей модуль містить код, запозичений з модуля «External links» російської Вікіпедії.

Переклад
-- Localizable part
-- Please, note, that labels to various sites and cataloges are taken from Wikidata (i.e. Wikidata label)

local linksPrefix = ''
local project = 'Вікіпедія'
local categoryTemplateEmpty = project .. ':Шаблон «Бібліоінформація» пустий'
local categoryWithWikimediaCommons = project .. ':Статті з посиланнями на Вікісховище'
local templateLink = 'Перегляд цього шаблону|link=Template:Бібліоінформація'

local group1Label = '[[' .. linksPrefix .. 'Соціальна мережа|У соціальних мережах]]'
local group2Label = 'Тексти творів'
local group3Label = 'Фото, відео та аудіо'
local group4Label = 'Тематичні сайти'
local group5Label = 'Словники та енциклопедії'
local group6Label = '[[' .. linksPrefix .. 'Нормативний контроль|Нормативний контроль]]'

-- The language codes that should be always displayed even if they have normal rank and claim with another language and prefferered rank exists
local preferredLanguage = 'Q8798'; -- ukrainian

function categoryAuthorityControl( code )
	return false; --project .. ':Статті, що містять ' .. code .. ' код'
end
function categoryExternalLink( code )
	return false; --project .. ':Статті з зовнішнім посиланням:' .. code
end

local templateColorName = 'колір';
-- some project have "named" colors, defined by templates
function colorByTitle( frame, colorTitle )
	local templateName = 'Колір/' .. colorTitle;
	local templateTitle = mw.title.makeTitle( 'Template', templateName );
	if ( templateTitle == nil or not templateTitle.exists ) then
		return false;
	end
	return frame:expandTemplate{ title = templateName };
end

local dictionaries = {
	{ id = 'Q19217220',		title = 'Березіна',							project = 'ukwikisource',	projectCode = 's:'	},
	{ id = 'Q4086271',		title = 'Біблійска',						project = 'ukwikisource',	projectCode = 's:'	},
	{ id = 'P1296',			title = 'Велика каталонська',				linkF = function ( id ) 	return 'http://www.enciclopedia.cat/enciclopèdies/gran-enciclopèdia-catalana/EC-GEC-' .. id .. '.xml' end	},
    { id = 'Q20078554',		title = 'Велика радянська (1 вид.)',		project = 'ukwikisource',	projectCode = 's:'	},
--	{ id = 'Q17378135',		title = 'Велика радянська',					},
    { id = 'Q4091878',		title = 'Велика Южакова',					project = 'ukwikisource',	projectCode = 's:'	},
    { id = 'Q602358',		title = 'Брокгауза і Єфрона',				project = 'ukwikisource',	projectCode = 's:'	},
	{ id = 'P1648',			title = 'Валлійський біографічний',		    linkF = function ( id ) 	return 'http://yba.llgc.org.uk/en/' .. id .. '.html' end,													},
    { id = 'Q4114391',		title = 'Військова',						project = 'ukwikisource',	projectCode = 's:'	},
	{ id = 'P5357',			title = 'Енциклопедія наукової фантастики',	linkF = function ( id ) 	return 'http://www.sf-encyclopedia.com/entry/' .. id end	},
	{ id = 'P4613',			title = 'Енциклопедія сучасної України',    linkF = function ( id ) 	return 'http://esu.com.ua/search_articles.php?id=' .. id end	},
    { id = 'Q4173137',		title = 'Єврейська Брокгауза і Єфрона',		project = 'ukwikisource',	projectCode = 's:'	},
	{ id = 'Q4091875',		title = 'Кирила та Мефодія',				},
	{ id = 'P1438',			title = 'Коротка єврейська',				linkF = function ( id )		return 'https://eleven.co.il/article/' .. id end,														},
	{ id = 'Q4239850',		title = 'Коротка літературна'				},
	{ id = 'Q2627728',		title = 'Кругосвіт'							},
	{ id = 'Q17329836',		title = 'Ларуса',							},
	{ id = 'Q17290934',		title = 'Лентапедія',						project = 'ukwikisource',	projectCode = 's:'	},
	{ id = 'Q4263804',		title = 'Літературна',						},
    { id = 'Q19180675',		title = 'Малий Брокгауза і Єфрона',			project = 'ukwikisource',	projectCode = 's:'	},
    { id = 'Q19190511',		title = 'Новий',							project = 'ukwikisource',	projectCode = 's:'	},
	{ id = 'Q2498180',		title = 'Православна',						},
    { id = 'Q19211082',		title = 'Православна богословська',		    project = 'ukwikisource',	projectCode = 's:'	},
    { id = 'Q1960551',		title = 'Російський біографічний',			project = 'ukwikisource',	projectCode = 's:'	},
   	{ id = 'P8144',	    	title = 'Тернопільська енциклопедія',		linkF = function ( id ) return 'https://ternopedia.te.ua/index.php?curid=' .. id end	},
    { id = 'Q20078551',		title = 'Технічна (1 вид.)',					project = 'ukwikisource',	projectCode = 's:'	},
    { id = 'Q1970746',		title = 'Тлумачний',							project = 'ukwikisource',	projectCode = 's:'	},
    { id = 'Q590208',		title = 'Allgemeine Deutsche Biographie',		project = 'dewikisource',	projectCode = 's:de:'	},
    { id = 'Q19077875',		title = 'American Cycl. (1879)',				project = 'enwikisource',	projectCode = 's:en:'	},
    { id = 'Q19037977',		title = 'American Med. Biogr. (1920)',			project = 'enwikisource',	projectCode = 's:en:'	},
    { id = 'Q12912667',		title = 'Appletons\' (1887—1901)',				project = 'enwikisource',	projectCode = 's:en:'	},
    { id = 'P2581',			title = 'BabelNet',					            linkF = function ( id ) return 'https://babelnet.org/synset?word=bn:'.. id end, },
    { id = 'Q20096917',		title = 'Britannica (9-th)',					project = 'enwikisource',	projectCode = 's:en:'	},
    { id = 'Q867541',		title = 'Britannica (11-th)',					project = 'enwikisource',	projectCode = 's:en:'	},
    { id = 'Q15987490',		title = 'Britannica (12-th)',					project = 'enwikisource',	projectCode = 's:en:'	},
	{ id = 'P1417',			title = 'Britannica (онлайн)',					linkF = function ( id ) return 'http://britannica.com/'.. id end, },
    { id = 'Q302556',		title = 'Catholic (1907—13)',					project = 'enwikisource',	projectCode = 's:en:'	},
	{ id = 'P3219',			title = 'Encyclopædia Universalis',	           	linkF = function ( id ) return 'https://www.universalis.fr/encyclopedie/' .. id .. '/' end, },
    { id = 'Q20089963',		title = 'New International',					project = 'enwikisource',	projectCode = 's:en:'	},
	{ id = 'P3365',			title = 'Treccani',	           			    	linkF = function ( id ) return 'http://www.treccani.it/enciclopedia/'.. id end, },
	{ id = 'P4124',			title = 'Who′s Who in France',	           		linkF = function ( id ) return 'https://www.whoswho.fr/bio/'.. id end, },	
	{ id = 'P4223',			title = 'Італійська енциклопедія',	           	linkF = function ( id ) return 'http://www.treccani.it/enciclopedia/' .. id .. '_(Enciclopedia-Italiana)/' end, },
	{ id = 'P1415',			title = 'Оксфордський біографічний',			linkF = function ( id ) return 'http://www.oxforddnb.com/index/' .. id .. '/' end,													},
	{ id = 'P902',			title = 'Швейцарський історичний',				linkF = function ( id ) return 'http://www.hls-dhs-dss.ch/textes/f/F' .. id .. '.php'	end,										},
	{ id = 'P886',			title = 'Швейцарський історичний (online)',	    linkF = function ( id ) return 'http://www.e-lir.ch/e-LIR___Lexicon.' .. id .. '.450.0.html'	end,								},
}


-- feed free to correct labels and categories, or add/remove sources here
local dictionaryProperties = {
}

-- Non-localizable part (not need to localize )
local moduleNavbox = require('Module:Navbox')

local titleBasedLinks = { ['Q602358'] = true, ['Q17290934'] = true, ['Q1960551'] = true }

local p = {}

function link( url )
	return url
end

function aniDBLink( id )
  local pos,_ = id:find("/")
  local type = id:sub(1,pos-1)
  local number = id:sub(pos+1)
  local urltype =''
  if type == "anime" then urltype = "a"
  elseif type == "creator" then urltype = "creator"
  elseif type == "character" then urltype = "char"
  else
   return ""
  end
  return "http://anidb.net/perl-bin/animedb.pl?show=" ..type .. "&" .. urltype .. "id=" .. number
end

function allocineFilmLink( id )		return 'http://www.allocine.fr/film/fichefilm_gen_cfilm=' .. id .. '.html'	end
function allocinePersonneLink( id )	return 'http://www.allocine.fr/personne/fichepersonne_gen_cpersonne=' .. id .. '.html'	end
function allocineSeriesLink( id )	return 'http://www.allocine.fr/series/ficheserie_gen_cserie=' .. id .. '.html'	end

function animenewsnetworkLink( id )
    if string.match( id, '^anime\/' ) then
		return 'http://www.animenewsnetwork.com/encyclopedia/anime.php?id=' .. mw.ustring.sub( id, 7 )
	end
    if string.match( id, '^company\/' ) then
		return 'http://www.animenewsnetwork.com/encyclopedia/company.php?id=' .. mw.ustring.sub( id, 9 )
	end
    if string.match( id, '^manga\/' ) then
		return 'http://www.animenewsnetwork.com/encyclopedia/manga.php?id=' .. mw.ustring.sub( id, 7 )
	end
    if string.match( id, '^people\/' ) then
		return 'http://www.animenewsnetwork.com/encyclopedia/people.php?id=' .. mw.ustring.sub( id, 8 )
	end
    if string.match( id, '^releases\/' ) then
		return 'http://www.animenewsnetwork.com/encyclopedia/releases.php?id=' .. mw.ustring.sub( id, 10 )
	end
	return false
end

function bavLink( id )		return 'http://viaf.org/processed/BAV%7C' .. id	end
function bibsysLink( id )	return 'http://ask.bibsys.no/ask/action/result?cmd=&kilde=biblio&cql=bs.autid+%3D+' .. id .. '&feltselect=bs.autid'	end
function bncLink( id )		return 'http://cantic.bnc.cat/registres/CUCId/' .. id	end
function bneLink( id )		return 'http://catalogo.bne.es/uhtbin/authoritybrowse.cgi?action=display&authority_id=' .. id	end
function bnfLink( id )		return 'http://catalogue.bnf.fr/ark:/12148/cb' .. id	end
function boxofficemojoLink( id )	return 'http://www.boxofficemojo.com/movies/?id=' .. id .. '.htm'	end
function bpnLink( id )		return 'http://www.biografischportaal.nl/persoon/' .. id	end
function calisLink( id )	return 'http://opac.calis.edu.cn/aopac/ajsp/detail.jsp?actionfrom=1&actl=CAL++' .. id	end
function cbdbLink( id )		return 'http://db1.ihp.sinica.edu.tw/cbdbc/cbdbkmeng?~~AAA' .. id	end
function ciniiLink( id )	return 'http://ci.nii.ac.jp/author/' .. id	end
function conorLink( id )	return 'http://www.cobiss.si/scripts/cobiss?command=DISPLAY&base=CONOR&rid=' .. id	end
function chitalnyaRuLink( id )	return 'http://www.chitalnya.ru/users/' .. id .. '/'	end
function commonsWikimediaLink( id )	return ':commons:Category:' .. id	end
function egaxaLink( id )	return 'http://viaf.org/processed/EGAXA%7Cvtls' .. id	end


function fanLibRuLink( id )
	local firstChar = mw.ustring.sub( id, 1, 1 )
    return 'http://fan.lib.ru/' .. firstChar .. '/' .. id .. '/'
end

function flickrLink( id )		return 'https://www.flickr.com/' .. id	end
function findagraveLink( id )	return 'http://www.findagrave.com/cgi-bin/fg.cgi?page=gr&GRid=' .. id	end
function genealogyAsmLink( id )	return 'http://www.genealogy.ams.org/id.php?id=' .. id	end
function gndLink( id )			return 'http://d-nb.info/gnd/' .. id	end
function ibdbPersonLink( id )	return 'http://www.ibdb.com/person.php?id=' .. id	end
function ibdbProductionLink( id )	return 'http://www.ibdb.com/production.php?id=' .. id	end
function ibdbShowLink( id )		return 'http://www.ibdb.com/show.php?id=' .. id	end
function ibdbVenueLink( id )	return 'http://www.ibdb.com/venue.php?id=' .. id	end
function isfdbAuthorLink( id )	return 'http://www.isfdb.org/cgi-bin/ea.cgi?' .. id	end
function isfdbPublicationLink( id )	return 'http://www.isfdb.org/cgi-bin/pl.cgi?' .. id	end
function isfdbSeriesLink( id )	return 'http://www.isfdb.org/cgi-bin/pe.cgi?' .. id	end
function isfdbPublisherLink( id )	return 'http://www.isfdb.org/cgi-bin/publisher.cgi?' .. id	end
function isfdbTitleLink( id )	return 'http://www.isfdb.org/cgi-bin/title.cgi?' .. id	end

function MegogoIDLink( id )		return 'http://megogo.net/ua/view/' .. id	end
function imslpLink( id )		return 'http://imslp.org/wiki/' .. id	end

function imdbLink( id )
	if string.match( id, '^ch' ) then
		return 'http://www.imdb.com/character/' .. id
    end
    if string.match( id, '^co' ) then
		return 'http://www.imdb.com/company/' .. id
    end
    if string.match( id, '^ev' ) then
		return 'http://www.imdb.com/event/' .. id
    end
    if string.match( id, '^nm' ) then
		return 'http://www.imdb.com/name/' .. id
    end
    if string.match( id, '^ni' ) then
		return 'http://www.imdb.com/news/' .. id		
    end
    if string.match( id, '^tt' ) then
		return 'http://www.imdb.com/title/' .. id
    end

	return false
end

function isniLink( id )
	id = id:gsub( '[ %-]', '' ):upper()
    return 'http://isni-url.oclc.nl/isni/' .. id
end

function lccnLink( id )		return 'http://id.loc.gov/authorities/' .. id	end
function lastfmLink( id )	return 'http://www.last.fm/ru/music/' .. id	end

function iccuLink( id )
	id = id:gsub( '\\\\', '%5C' ):upper()
	return 'http://opac.sbn.it/opacsbn/opac/iccu/scheda_authority.jsp?bid=' .. id
end

function instagramLink( id )	return 'https://www.instagram.com/' .. id	end
function lnbLink( id )			return 'http://viaf.org/processed/LNB%7CLNC10-' .. id	end
function merimeeLink( id )		return false	end
function mixcloudLink( id )		return 'https://mixcloud.com/' .. id .. '/'	end
function musicBrainzArtistLink( id )		return 'https://musicbrainz.org/artist/' .. id	end
function musicBrainzReleazeGroupLink( id )	return 'https://musicbrainz.org/release-group/' .. id	end
function musicBrainzWorkLink( id )			return 'https://musicbrainz.org/work/' .. id	end
function discogsLink( id )	return 'http://www.discogs.com/artist/' .. id	end
function nclLink( id )		return 'http://aleweb.ncl.edu.tw/F/?func=accref&acc_sequence=' .. id	end
function ndlLink( id )		return 'http://id.ndl.go.jp/auth/ndlna/' .. id	end
function nlcLink( id )		return false	end
function nliLink( id )		return 'http://a20.libnet.ac.il/F?func=find-b&REQUEST=' .. id .. '&find_code=SYS&local_base=NNL10'	end
function nkcLink( id )		return 'http://aut.nkp.cz/' .. id	end
function nlaLink( id )	 	return 'http://nla.gov.au/anbd.aut-an' .. id end
function nlrLink( id )		return 'http://alephnew.bibnat.ro:8991/F?func=find-b&request=' .. id .. '000354872&find_code=SYS&adjacent=Y&local_base=NLR10' end
function nszlLink( id )		return 'http://viaf.org/processed/NSZL%7C' .. id	end
function nskLink( id )		return 'http://viaf.org/processed/NSK%7C' .. id	end
function ntaLink( id )		return 'http://opc4.kb.nl/PPN?PPN=' .. id	end
function nukatLink( id )	return 'http://viaf.org/processed/NUKAT%7C' .. id	end


function orcidLink( id )
	id = id:gsub( '[ %-]', '' ):upper()
    return 'http://orcid.org/' .. id
end


function ptbnpLink( id )		return 'http://viaf.org/processed/PTBNP%7C' .. id	end
function rkdArtistsLink( id )	return 'http://www.rkd.nl/rkddb/dispatcher.aspx?action=search&database=ChoiceArtists&search=priref=' .. id	end
function rkdImagesLink( id )	return 'https://rkd.nl/nl/explore/images/' .. id	end
function ridLink( id )			return 'http://www.researcherid.com/rid/' .. id	end
function rodovidLink( id )		return 'http://uk.rodovid.org/wk/Person:' .. id	end
function allmovieLink( id )		return 'http://allmovie.com/movie/v' .. id	end
function metacriticLink( id )	return 'http://www.metacritic.com/' .. id	end
function rslLink( id )			return 'http://aleph.rsl.ru/F?func=find-b&find_code=SYS&adjacent=Y&local_base=RSL11&request=' .. id	end

function rutubeLink( id )
    if string.match( id, '^%d+$' ) then
    	return 'http://rutube.ru/video/persion/' .. id .. '/'
    end
	return 'http://' .. id .. '.rutube.ru/'
end

function samlibRuLink( id )
	local firstChar = mw.ustring.sub( id, 1, 1 )
    return 'http://samlib.ru/' .. firstChar .. '/' .. id .. '/'
end

function scopusLink( id )		return 'http://www.scopus.com/authid/detail.url?authorId=' .. id	end
function googlescholarLink( id )	return 'https://scholar.google.com.ua/citations?user=' .. id	end
function selibrLink( id )		return 'http://libris.kb.se/auth/' .. id	end
function soundcloudLink( id )	return 'http://soundcloud.com/' .. id .. '/'	end
function stihiRuLink( id )		return 'http://stihi.ru/avtor/' .. id end
function sudocLink( id )		return 'http://www.idref.fr/' .. id	end
function ulanLink( id )			return 'http://www.getty.edu/vow/ULANFullDisplay?find=&role=&nation=&subjectid=' .. id	end
function vimeoLink( id )		return 'https://vimeo.com/' .. id	end
function viafLink( id )			return 'http://viaf.org/viaf/' .. id	end
function youtubeLink( id )		return 'https://www.youtube.com/user/' .. id	end
function youtubeLinkLong( id )	return 'https://www.youtube.com/channel/' .. id	end

function getLabelWithoutLink( id, defaultLabel )
	return mw.wikibase.label( id ) or defaultLabel;
end

function getLabelWithLink( id, defaultTitle, label )
	local link = mw.wikibase.sitelink( id );
	if ( link ~= nil ) then
		return '[[' .. link .. '|' .. label .. ']]';
	end
	local title = mw.wikibase.label( id ) or defaultTitle;
	return '<span title="' .. title .. '" style="border-bottom: 1px dotted; cursor: help;">' .. label .. '</span>'
end

local socialNetworkProperties = {
    { getLabelWithoutLink( 'Q219523', 'Живий Журнал'),		'P3258',		function( id ) return 'http://' .. id .. '.livejournal.com/' end,				categoryExternalLink( 'Живий Журнал' ) },
    { getLabelWithoutLink( 'Q219523', 'Живий Журнал'),		'Q219523',		function( id ) return 'http://' .. id .. '.livejournal.com/' end,				categoryExternalLink( 'Живий Журнал' ) },
    { getLabelWithoutLink( 'Q171186', 'Blogger'),   		'Q171186',		function( id ) return 'http://' .. id .. '.blogspot.com' end,					categoryExternalLink( 'Blogger' ) },
    { getLabelWithoutLink( 'Q4037665', 'Dudu'),    			'Q4037665',		function( id ) return 'http://dudu.com/' .. id end,								categoryExternalLink( 'Dudu' ) },
    { getLabelWithoutLink( 'Q355', 'Facebook'), 		   	'P2013',		function( id ) return 'https://www.facebook.com/' .. id end,					categoryExternalLink( 'Facebook' ) },
    { getLabelWithoutLink( 'Q355', 'Facebook'), 		   	'Q355',			function( id ) return 'https://www.facebook.com/' .. id end,					categoryExternalLink( 'Facebook' ) },
    { getLabelWithoutLink( 'Q356', 'Google+'),				'Q356',			function( id ) return 'https://plus.google.com/' .. id .. '/posts' end,			categoryExternalLink( 'Google+' ) },
    { getLabelWithoutLink( 'Q356', 'Google+'),				'P2847',		function( id ) return 'https://plus.google.com/' .. id .. '/posts' end,			categoryExternalLink( 'Google+' ) },
    { getLabelWithoutLink( 'Q213660', 'LinkedIn'),   		'P6634',		function( id ) return 'https://www.linkedin.com/in/' .. id end,					categoryExternalLink( 'LinkedIn' ) },
    { getLabelWithoutLink( 'Q4043051', 'LiveInternet'),		'Q4043051',		function( id ) return 'http://www.liveinternet.ru/users/' .. id end,			categoryExternalLink( 'LiveInternet' ) },
    { getLabelWithoutLink( 'Q40629', 'MySpace'),			'P3265',		function( id ) return 'https://myspace.com/' .. id end,							categoryExternalLink( 'MySpace' ) },
    { getLabelWithoutLink( 'Q40629', 'MySpace'),			'Q40629',		function( id ) return 'https://myspace.com/' .. id end,							categoryExternalLink( 'MySpace' ) },
    { getLabelWithoutLink( 'Q17144398', 'QRoom'),			'Q17144398',	function( id ) return 'http://qroom.ru/' .. id end,								categoryExternalLink( 'QRoom' ) },
    { getLabelWithoutLink( 'Q92526', 'Weibo'),				'P3579',		function( id ) return 'https://weibo.com/' .. id end,							categoryExternalLink( 'Weibo' ) },
    { getLabelWithoutLink( 'Q92526', 'Weibo'),				'Q92526',		function( id ) return 'https://weibo.com/' .. id end,							categoryExternalLink( 'Weibo' ) },
    { getLabelWithoutLink( 'Q384060', 'Tumblr'),			'Q384060',		function( id ) return 'http://' .. id .. '.tumblr.com/' end,					categoryExternalLink( 'Tumblr' ) },
    { getLabelWithoutLink( 'Q15616276', 'Telegram'),		'P3789',		function( id ) return 'https://t.me/' .. id end,								categoryExternalLink( 'Telegram' ) },
    { getLabelWithoutLink( 'Q15616276', 'Telegram'),		'Q15616276',	function( id ) return 'https://t.me/' .. id end,								categoryExternalLink( 'Telegram' ) },
    { getLabelWithoutLink( 'Q918', 'Twitter'),				'P2002',		function( id ) return 'https://twitter.com/' .. id end,							categoryExternalLink( 'Twitter' ) },
    { getLabelWithoutLink( 'Q918', 'Twitter'),				'Q918',			function( id ) return 'https://twitter.com/' .. id end,							categoryExternalLink( 'Twitter' ) },
    { getLabelWithoutLink( 'Q116933', 'ВКонтакті'),   		'P3185',		function( id ) return 'https://vk.com/' .. id end,								categoryExternalLink( 'ВКонтакті' ) },
    { getLabelWithoutLink( 'Q116933', 'ВКонтакті'),   		'Q116933',		function( id ) return 'https://vk.com/' .. id end,								categoryExternalLink( 'ВКонтакті' ) },
    { getLabelWithoutLink( 'Q4101720', 'В колі друзів'),	'Q4101720',		function( id ) return 'http://' .. id .. '.vkrugudruzei.ru/' end,				categoryExternalLink( 'В колі друзів' ) },
    { getLabelWithoutLink( 'Q4299813', 'Моє коло'),			'Q4299813',		function( id ) return 'http://' .. id .. '.moikrug.ru/' end,					categoryExternalLink( 'Моє коло' ) },
    { getLabelWithoutLink( 'Q4299858', 'Мой мир'),			'Q4299858',		function( id ) return 'http://my.mail.ru/' .. id end,							categoryExternalLink( 'Мой мир' ) },
    { getLabelWithoutLink( 'Q1123836', 'Odnoklassniki'),	'P5163',		function( id ) return 'https://ok' .. '.ru/' .. id end,	categoryExternalLink( 'Odnoklassniki' ) },
    { getLabelWithoutLink( 'Q17195318', 'Спрашивай.Ру'),	'Q17195318',	function( id ) return 'http://sprashivai.ru/' .. id end,						categoryExternalLink( 'Спрашивай.Ру' ) }
}

local textsProperties = {
    { getLabelWithoutLink( 'Q17254543', 'Изба-читальня'),		'Q17254543',	chitalnyaRuLink,	categoryExternalLink( 'Изба-читальня' ) },
    { getLabelWithoutLink( 'Q17195344', 'Журнал «Самиздат»'),	'Q17195344',	samlibRuLink,		categoryExternalLink( 'Самиздат' ) },
    { getLabelWithoutLink( 'Q4380129', 'Проза.ру'),				'Q4380129',		function( id )		return 'http://proza.ru/avtor/' .. id end,		categoryExternalLink( 'Проза.ру' ) },
    { getLabelWithoutLink( 'Q4442644', 'Стихи.ру'),				'Q4442644',		stihiRuLink,		categoryExternalLink( 'Стихи.ру' ) },
    { getLabelWithoutLink( 'Q17300505', 'Lib.Ru/Фантастика'),	'Q17300505',	fanLibRuLink,		categoryExternalLink( 'Lib.Ru/Фантастика' ) },
}

local contentHostingProperties = {
    { getLabelWithoutLink( 'Q565', 'Wikimedia Commons' ),	'P373',			commonsWikimediaLink,	categoryWithWikimediaCommons,			true	},
    { getLabelWithoutLink( 'Q103204', 'Flickr' ),			'P3267',		flickrLink,				categoryExternalLink( 'Flickr' ),		false	},
    { getLabelWithoutLink( 'Q103204', 'Flickr' ),			'Q103204',		flickrLink,				categoryExternalLink( 'Flickr' ),		false	},
    { getLabelWithoutLink( 'Q209330', 'Instagram' ),		'Q209330',		instagramLink,			categoryExternalLink( 'Instagram' ),	false	},
    { getLabelWithoutLink( 'Q9589', 'iTunes' ),				'P2281',	    function(id)	return 'https://itunes.apple.com/us/album/' .. id end,	categoryExternalLink( 'iTunes' ) },
    { getLabelWithoutLink( 'Q209330', 'Instagram' ),		'P2003',		instagramLink,			categoryExternalLink( 'Instagram' ),	false	},
    { getLabelWithoutLink( 'Q183718', 'Last.fm' ),			'P3192',		lastfmLink,				categoryExternalLink( 'Last.fm' ),		false	},
    { getLabelWithoutLink( 'Q183718', 'Last.fm' ),			'Q183718',		lastfmLink,				categoryExternalLink( 'Last.fm' ),		false	},
    { getLabelWithoutLink( 'Q6883832', 'Mixcloud' ),		'Q6883832',		mixcloudLink,			categoryExternalLink( 'Mixcloud' ),		false	},
    { getLabelWithoutLink( 'Q17117201', 'PROMODJ' ),		'Q17117201',	function(id)	return 'http://promodj.com/' .. id	end,		categoryExternalLink( 'PROMODJ' ),		false	},
    { getLabelWithoutLink( 'Q372827', 'Rutube' ),			'Q372827',		rutubeLink,				categoryExternalLink( 'Rutube' ),		false	},
    { getLabelWithoutLink( 'Q568769', 'SoundCloud' ),		'P3040',		soundcloudLink,			categoryExternalLink( 'SoundCloud' ),	false	},
    { getLabelWithoutLink( 'Q568769', 'SoundCloud' ),		'Q568769',		soundcloudLink,			categoryExternalLink( 'SoundCloud' ),	false	},
    { getLabelWithoutLink( 'Q156376', 'Vimeo' ),			'P4015',		vimeoLink,				categoryExternalLink( 'Vimeo' ),		false	},
    { getLabelWithoutLink( 'Q156376', 'Vimeo' ),			'Q156376',		vimeoLink,				categoryExternalLink( 'Vimeo' ),		false	},
    { getLabelWithoutLink( 'Q866', 'YouTube' ),				'Q866',			youtubeLink,			categoryExternalLink( 'YouTube' ),		false	},
    { getLabelWithoutLink( 'Q866', 'YouTube' ),				'P2397',		youtubeLinkLong,			categoryExternalLink( 'YouTube' ),		false	},
}

local labelAllocine = getLabelWithoutLink( 'Q31165', 'AlloCiné' );
local labelIBDb = getLabelWithoutLink( 'Q31964', 'Internet Broadway Database' );
local labelISFDb = getLabelWithoutLink( 'Q2629164', 'Internet Speculative Fiction Database' );
local labelMusicBrainz = getLabelWithoutLink( 'Q14005', 'MusicBrainz' );
local labelEncyclopaediaMetallum = getLabelWithoutLink( 'Q938726', 'Encyclopaedia Metallum' );

local themeProfilesProperties = {
	-- science
	{ getLabelWithoutLink( 'Q829984', 'Mathematics Genealogy Project' ),	'P549',		genealogyAsmLink,				categoryExternalLink( 'Математична генеалогія' ) },
	{ getLabelWithoutLink( 'Q1373513', 'Notable Names Database' ),			'P1263',	function(id) return 'http://nndb.com/people/' .. id end,						categoryExternalLink( 'NNDB' ) },
	{ getLabelWithoutLink( 'Q51044', 'ORCID' ),								'P496',		orcidLink,						categoryExternalLink( 'ORCID' ) },
	{ getLabelWithoutLink( 'Q7315186', 'ResearcherID' ),					'P1053',	ridLink,						categoryExternalLink( 'ResearcherID' ) },
	{ getLabelWithoutLink( 'Q371467', 'Scopus' ),							'P1153',	scopusLink,						categoryExternalLink( 'Scopus' ) },
	{ getLabelWithoutLink( 'Q494817', 'Google Scholar' ),					'P1960',	googlescholarLink,				categoryExternalLink( 'Google Scholar' ) },
	{ getLabelWithoutLink( 'Q18241050', 'zbMATH' ),							'P1556',	function(id) return 'https://www.zbmath.org/authors/?q=ai:' .. id end,							categoryExternalLink( 'zbMATH' ) },
	{ getLabelWithoutLink( 'Q557919', 'MedlinePlus' ),						'P604',		function(id) return 'https://medlineplus.gov/ency/article/' .. id .. '.htm'	end,				categoryExternalLink( 'MedlinePlus' ) },
	{ getLabelWithoutLink( 'Q305913', 'eMedicine' ),						'P673',		function(id) return 'http://emedicine.medscape.com/article/' .. id .. '-overview'	end,		categoryExternalLink( 'eMedicine' ) },
	{ getLabelWithoutLink( 'Q3048291', 'GeneReviews' ),						'P668',		function(id) return 'https://www.ncbi.nlm.nih.gov/books/' .. id	end,							categoryExternalLink( 'GeneReviews' ) },
	{ getLabelWithoutLink( 'Q47517289', 'GARD' ),							'P4317',	function(id) return 'https://rarediseases.info.nih.gov/diseases/' .. id .. '/index'	end,		categoryExternalLink( 'GARD') },
	{ getLabelWithoutLink( 'Q1515833', 'Orphanet' ),						'P1550',	function(id) return 'http://www.orpha.net/consor/cgi-bin/OC_Exp.php?lng=EN&Expert=' .. id	end,	categoryExternalLink( 'Orphanet' ) },
	-- audio and video
	{ getLabelWithoutLink( 'Q7713473', 'AFI' ),                	            'P3593',	function(id) return 'http://www.afi.com/members/catalog/DetailView.aspx?s=&Movie=' .. id end,	categoryExternalLink( 'AFI' ) },
	{ getLabelWithoutLink( 'Q477809', 'AllMovie' ),							'P1562',	function(id) return 'http://www.allmovie.com/movie/' .. id end,									categoryExternalLink( 'AllMovie' ) },
	{ getLabelWithoutLink( 'Q477809', 'AllMovie' ),							'P2019',	function(id) return 'http://www.allmovie.com/artist/' .. id end,		categoryExternalLink( 'AllMovie' ) },
	{ getLabelWithoutLink( 'Q31181', 'AllMusic' ),							'P1728',	function(id) return 'http://www.allmusic.com/artist/' .. id end,		categoryExternalLink( 'AllMusic' ) },
	{ getLabelWithoutLink( 'Q31181', 'AllMusic' ),							'P1729',	function(id) return 'http://www.allmusic.com/album/' .. id end,			categoryExternalLink( 'AllMusic' ) },
	{ getLabelWithoutLink( 'Q31181', 'AllMusic' ),							'P1730',	function(id) return 'http://www.allmusic.com/song/' .. id end,			categoryExternalLink( 'AllMusic' ) },
	{ getLabelWithoutLink( 'Q31181', 'AllMusic' ),							'P1994',	function(id) return 'http://www.allmusic.com/composition/' .. id end,	categoryExternalLink( 'AllMusic' ) },
	{ labelAllocine,												    	'P1265',	allocineFilmLink,				categoryExternalLink( 'AlloCiné' ) },
	{ labelAllocine,														'P1266',	allocinePersonneLink,			categoryExternalLink( 'AlloCiné' ) },
	{ labelAllocine,														'P1267',	allocineSeriesLink,				categoryExternalLink( 'AlloCiné' ) },
	{ getLabelWithoutLink( 'Q3626651', 'ANICA' ),							            'P6151',	function(id) return 'http://www.archiviodelcinemaitaliano.it/index.php/scheda.html?codice=' .. id end, categoryExternalLink( 'ANICA' ) },
	{ getLabelWithoutLink( 'Q220509', 'Anime News Network' ),							'P1984',	function(id) return 'https://www.animenewsnetwork.com/encyclopedia/manga.php?id=' .. id end, categoryExternalLink( 'Anime News Network' ) },
    { getLabelWithoutLink( 'Q56193019', 'AniDB' ),                                      'P5646',    function(id) return 'https://anidb.net/perl-bin/animedb.pl?show=anime&aid=' .. id end, categoryExternalLink( 'AniDB' ) },
    { getLabelWithoutLink( 'Q56193019', 'AniDB' ),                                      'P5648',    function(id) return 'https://anidb.net/perl-bin/animedb.pl?show=character&charid=' .. id end, categoryExternalLink( 'AniDB' ) },
    { getLabelWithoutLink( 'Q56193019', 'AniDB' ),                                      'P5649',    function(id) return 'https://anidb.net/perl-bin/animedb.pl?show=creator&creatorid=' .. id end, categoryExternalLink( 'AniDB' ) },
    { getLabelWithoutLink( 'Q545966', 'Bandcamp' ),                                     'P3283',    function(id) return 'https://' .. id .. '.bandcamp.com' end, categoryExternalLink( 'Bandcamp' ) },
    { getLabelWithoutLink( 'Q260528', 'BFI' ),                                          'P2703',    function(id) return 'http://collections-search.bfi.org.uk/web/Details/ChoiceFilmWorks/' .. id end, categoryExternalLink( 'BFI' ) },
    { getLabelWithoutLink( 'Q260528', 'BFI' ),                                          'P4326',    function(id) return 'https://filmography.bfi.org.uk/person/' .. id end, categoryExternalLink( 'BFI' ) },
    { getLabelWithoutLink( 'Q260528', 'BFI' ),                                          'P4438',    function(id) return 'http://www.bfi.org.uk/films-tv-people/' .. id end, categoryExternalLink( 'BFI' ) },
    { getLabelWithoutLink( 'Q245966', 'BND' ),                                          'P5691',    function(id) return 'http://purl.pt/' .. id end, categoryExternalLink( 'BND' ) },
    { getLabelWithoutLink( 'Q223142', 'Box Office Mojo' ),							    'P1237',	boxofficemojoLink,				categoryExternalLink( 'Box Office Mojo' ) },
    { getLabelWithoutLink( 'Q16539867', 'Ciné-Ressources' ),                            'P3203',    function(id) return 'http://cinema.encyclopedie.films.bifi.fr/index.php?pk=' .. id end, categoryExternalLink( 'Ciné-Ressources' ) },
    { getLabelWithoutLink( 'Q16539867', 'Ciné-Ressources' ),                            'P3204',    function(id) return 'http://cinema.encyclopedie.personnalites.bifi.fr/index.php?pk=' .. id end, categoryExternalLink( 'Ciné-Ressources' ) },
    { getLabelWithoutLink( 'Q1674691', 'Cinema of Israel' ),                            'P3445',    function(id) return 'http://www.cinemaofisrael.co.il/?p=' .. id end, categoryExternalLink( 'Cinema of Israel' ) },
    { getLabelWithoutLink( 'Q30055831', 'Cineuropa' ),                                  'P5791',    function(id) return 'http://www.cineuropa.org/en/film/' .. id end, categoryExternalLink( 'Cineuropa' ) },
    { getLabelWithoutLink( 'Q30055831', 'Cineuropa' ),                                  'P6083',    function(id) return 'https://cineuropa.org/filmography/' .. id end, categoryExternalLink( 'Cineuropa' ) },
	{ getLabelWithoutLink( 'Q504063', 'Discogs' ),										'P1953',	function(id) return 'http://www.discogs.com/artist/' .. id end,				categoryExternalLink( 'Discogs' ) },
 	{ getLabelWithoutLink( 'Q504063', 'Discogs' ),										'P1954',	function(id) return 'http://www.discogs.com/master/' .. id end,				categoryExternalLink( 'Discogs' ) },
 	{ getLabelWithoutLink( 'Q504063', 'Discogs' ),										'P1955',	function(id) return 'http://www.discogs.com/label/' .. id end,				categoryExternalLink( 'Discogs' ) },
 	{ getLabelWithoutLink( 'Q504063', 'Discogs' ),										'P2206',	function(id) return 'http://www.discogs.com/release/' .. id end,			categoryExternalLink( 'Discogs' ) },
	{ getLabelWithoutLink( 'Q2638147', 'FilmAffinity' ),								'P480',		function(id) return 'http://www.filmaffinity.com/en/film' .. id .. '.html' end,	categoryExternalLink( 'FilmAffinity' ) },
    { getLabelWithoutLink( 'Q16323348', 'Danmarks Nationalfilmografi' ), 		        'P1804',	function(id) return 'http://www.dfi.dk/faktaomfilm/film/da/' .. id .. '.aspx' end,	categoryExternalLink( 'DNF' ) },
    { getLabelWithoutLink( 'Q16323348', 'Danmarks Nationalfilmografi' ), 	            'P2626',	function(id) return 'http://www.dfi.dk/FaktaOmFilm/Nationalfilmografien/nfperson.aspx?id=' .. id end,	categoryExternalLink( 'DNF' ) },
    { getLabelWithoutLink( 'Q5159753', 'Danskefilm' ),             	                    'P3785',	function(id) return 'https://www.danskefilm.dk/film.php?id=' .. id end,	categoryExternalLink( 'Danskefilm.dk' ) },
    { getLabelWithoutLink( 'Q5159753', 'Danskefilm' ),             	                    'P4021',	function(id) return 'https://www.danskefilm.dk/tegnefilm.php?id=' .. id end,	categoryExternalLink( 'Danskefilm.dk' ) },
    { getLabelWithoutLink( 'Q5159753', 'Danskefilm' ), 	                                'P3786',	function(id) return 'https://www.danskefilm.dk/skuespiller.php?id=' .. id end,	categoryExternalLink( 'Danskefilm.dk' ) },
    { getLabelWithoutLink( 'Q1204237', 'Deutsche Synchronkartei' ),   	                'P3844',	function(id) return 'https://www.synchronkartei.de/film/' .. id end,	categoryExternalLink( 'Deutsche Synchronkartei' ) },
    { getLabelWithoutLink( 'Q1204237', 'Deutsche Synchronkartei' ), 	                'P4332',	function(id) return 'https://www.synchronkartei.de/darsteller/' .. id end,	categoryExternalLink( 'Deutsche Synchronkartei' ) },
   	{ getLabelWithoutLink( 'Q96747621', 'DzygaMDB'),							        'P9229',	function(id) return 'https://dzygamdb.com/uk/persons/' .. id end,	        categoryExternalLink( 'DzygaMDB' ) },
   	{ getLabelWithoutLink( 'Q96747621', 'DzygaMDB'),							        'P9461',	function(id) return 'https://dzygamdb.com/uk/site/films-single/' .. id end,	categoryExternalLink( 'DzygaMDB' ) },   
    { getLabelWithoutLink( 'Q15672050', 'FilmPolski'),                           		'P3495',	function(id) return 'http://www.filmpolski.pl/fp/index.php/' .. id end ,	categoryExternalLink( 'Filmpolski' ) },
	{ getLabelWithoutLink( 'Q15706812', 'Filmportal' ),                        		    'P2639',	function(id) return 'http://www.filmportal.de/film/' .. '' .. id end ,	    categoryExternalLink( 'Filmportal' ) },
	{ getLabelWithoutLink( 'Q28944146', 'FilmTV.it' ),                        		    'P5253',	function(id) return 'https://www.filmtv.it/film/' .. id end ,	            categoryExternalLink( 'FilmTV.it' ) },
	{ getLabelWithoutLink( 'Q28944146', 'FilmTV.it' ),                        		    'P5254',	function(id) return 'https://www.filmtv.it/persona/' .. id end ,	        categoryExternalLink( 'FilmTV.it' ) },
	{ getLabelWithoutLink( 'Q28944146', 'FilmTV.it' ),                        		    'P5255',	function(id) return 'https://www.filmtv.it/serie-tv/' .. id end ,	        categoryExternalLink( 'FilmTV.it' ) },
	{ getLabelWithoutLink( 'Q2090445', 'Filmweb' ),                        		        'P3995',	function(id) return 'http://www.filmweb.pl/' .. id end ,	                categoryExternalLink( 'Filmweb' ) },
	{ getLabelWithoutLink( 'Q2090445', 'Filmweb' ),                        		        'P5032',	function(id) return 'http://www.filmweb.pl/film?Id=' .. id end ,	        categoryExternalLink( 'Filmweb' ) },
	{ getLabelWithoutLink( 'Q2090445', 'Filmweb' ),                        		        'P5033',	function(id) return 'http://www.filmweb.pl/person?Id=' .. id end ,	        categoryExternalLink( 'Filmweb' ) },
	{ getLabelWithoutLink( 'Q5918374', 'ICAA' ),                        		        'P5128',	function(id) return 'http://infoicaa.mecd.es/CatalogoICAA/Peliculas/Detalle?pelicula=' .. id end ,	categoryExternalLink( 'Каталог фільмів ICAA' ) },
	{ labelEncyclopaediaMetallum,														'P1952',	function(id) return 'http://www.metal-archives.com/bands//' .. id end,	    categoryExternalLink( 'Encyclopaedia Metallum' ) },
	{ labelEncyclopaediaMetallum,														'P1989',	function(id) return 'http://www.metal-archives.com/artists//' .. id end,	categoryExternalLink( 'Encyclopaedia Metallum' ) },
    { getLabelWithoutLink( 'Q461', 'Internet Archive'),	                	            'P724',     function(id) return 'https://archive.org/details/' .. id end,           categoryExternalLink( 'Internet Archive' ) },
	{ labelIBDb,																		'P1217',	ibdbVenueLink,					categoryExternalLink( 'IBDb' ) },
	{ labelIBDb,																		'P1218',	ibdbProductionLink,				categoryExternalLink( 'IBDb' ) },
	{ labelIBDb,																		'P1219',	ibdbShowLink,					categoryExternalLink( 'IBDb' ) },
	{ labelIBDb,																		'P1220',	ibdbPersonLink,					categoryExternalLink( 'IBDb' ) },
	{ getLabelWithoutLink( 'Q37312', 'Internet Movie Database' ),						'P345',		imdbLink,						categoryExternalLink( 'IMDb' ) },
	{ getLabelWithoutLink( 'Q9589', 'iTunes' ),						                    'P2850',	function(id) return 'https://itunes.apple.com/us/artist/' .. id end,	categoryExternalLink( 'iTunes' ) },
    { getLabelWithoutLink( 'Q1320308', 'Japanese Movie Database'),	                	'P2400',    function(id) return 'http://www.jmdb.ne.jp/' .. id .. '.htm' end,           categoryExternalLink( 'JMDb' ) },
    { getLabelWithoutLink( 'Q1320308', 'Japanese Movie Database'),	                	'P3703',    function(id) return 'http://www.jmdb.ne.jp/person/p' .. id .. '.htm' end,    categoryExternalLink( 'JMDb' ) },    
	{ getLabelWithoutLink( 'Q11296881', 'KINENOTE', '' ),								'P2508',	function(id) return 'http://www.kinenote.com/main/public/cinema/detail.aspx?cinema_id=' .. id end, categoryExternalLink( 'KINENOTE' ) },
	{ getLabelWithoutLink( 'Q11296881', 'KINENOTE', '' ),								'P3305',	function(id) return 'http://www.kinenote.com/main/public/cinema/person.aspx?person_id=' .. id end, categoryExternalLink( 'KINENOTE' ) },
	{ getLabelWithoutLink( 'Q12071437', 'Kino-teatr.ua'),							    'P5311',	function(id) return 'http://kino-teatr.ua/uk/main/film/film_id/' .. id .. '.phtml' end,	    categoryExternalLink( 'Kino-teatr.ua' ) },
	{ getLabelWithoutLink( 'Q12071437', 'Kino-teatr.ua'),							    'P5312',	function(id) return 'http://kino-teatr.ua/uk/main/person/person_id/' .. id .. '.phtml' end,	    categoryExternalLink( 'Kino-teatr.ua' ) },
	{ getLabelWithoutLink( 'Q47085761', 'LUMIERE' ),						            'P4282',	function(id) return 'http://lumiere.obs.coe.int/web/film_info/?id=' .. id end,	    categoryExternalLink( 'LUMIERE' ) },
	{ getLabelWithoutLink( 'Q47085761', 'LUMIERE' ),						            'P4283',	function(id) return 'http://lumiere.obs.coe.int/web/director_info/?lum_id=' .. id end,	categoryExternalLink( 'LUMIERE' ) },
	{ getLabelWithoutLink( 'Q4043924', 'Megogo' ),						                'P2826',	MegogoIDLink,						categoryExternalLink( 'Megogo' ) },
	{ getLabelWithoutLink( 'Q150248', 'Metacritic' ),							    	'P1712',	metacriticLink,			        	categoryExternalLink( 'Metacritic' ) },
	{ getLabelWithoutLink( 'Q2158761', 'MovieMeter' ),							    	'P1969',	function(id) return 'https://www.moviemeter.nl/director/' .. id end,        categoryExternalLink( 'MovieMeter' ) },
	{ getLabelWithoutLink( 'Q2158761', 'MovieMeter' ),							    	'P1970',	function(id) return 'https://www.moviemeter.nl/film/' .. id end,			categoryExternalLink( 'MovieMeter' ) },
	{ getLabelWithoutLink( 'Q2158761', 'MovieMeter' ),							    	'P9463',	function(id) return 'https://www.moviemeter.nl/site/zoeken/' .. id end,		categoryExternalLink( 'MovieMeter' ) },
	{ getLabelWithoutLink( 'Q1951172', 'Moviepilot' ),							    	'P5786',	function(id) return 'https://www.moviepilot.de/movies/' .. id end,			categoryExternalLink( 'Moviepilot' ) },
	{ getLabelWithoutLink( 'Q3841788', 'MYmovies' ),							    	'P4779',	function(id) return 'http://www.mymovies.it/biografia/?a=' .. id end,		categoryExternalLink( 'MYmovies' ) },
	{ getLabelWithoutLink( 'Q3841788', 'MYmovies' ),							    	'P4780',	function(id) return 'http://www.mymovies.it/dizionario/recensione.asp?id=' .. id end,			categoryExternalLink( 'MYmovies' ) },
	{ getLabelWithoutLink( 'Q3841788', 'MYmovies' ),							    	'P4781',	function(id) return 'http://www.mymovies.it/biografia/?r=' .. id end,		categoryExternalLink( 'MYmovies' ) },
	{ getLabelWithoutLink( 'Q3841788', 'MYmovies' ),							    	'P4785',	function(id) return 'http://www.mymovies.it/biografia/?s=' .. id end,		categoryExternalLink( 'MYmovies' ) },
    { getLabelWithoutLink( 'Q907311', 'Netflix'),	                    	            'P1874',	function(id) return 'https://www.netflix.com/title/' .. id end,             categoryExternalLink( 'Netflix' ) },
	{ getLabelWithoutLink( 'Q27653527', 'OMDb' ),							      	    'P3302',	function(id) return 'https://www.omdb.org/movie/' .. id	end,			    categoryExternalLink( 'OMDb' ) },
	{ getLabelWithoutLink( 'Q27653527', 'OMDb' ),							      	    'P5534',	function(id) return 'https://www.omdb.org/person/' .. id	end,			categoryExternalLink( 'OMDb' ) },
    { getLabelWithoutLink( 'Q1669874', 'Online-Filmdatenbank'),	                    	'P3138',	function(id) return 'https://ssl.ofdb.de/film/' .. id .. ',' end,           categoryExternalLink( 'OFDb' ) },
	{ getLabelWithoutLink( 'Q1201876', 'Open Library' ),								'P648',	    function(id) return 'https://openlibrary.org/works/' .. id	end,			categoryExternalLink( 'Open Library' ) },
	{ getLabelWithoutLink( 'Q105584', 'Rotten Tomatoes' ),								'P1258',	function(id) return 'http://www.rottentomatoes.com/' .. id	end,			categoryExternalLink( 'Rotten Tomatoes' ) },
    { getLabelWithoutLink( 'Q54933170', 'Silent Era'),  	                            'P5338',    function(id) return 'http://www.silentera.com/PSFL/data/' .. id .. '.html' end, categoryExternalLink( 'Silent Era' ) },
    { getLabelWithoutLink( 'Q3938001', 'Cinematografo.it'),  	                        'P4768',    function(id) return 'https://www.cinematografo.it/pls/cinematografo/consultazione.redirect?ida=' .. id end, categoryExternalLink( 'Cinematografo.it' ) },
    { getLabelWithoutLink( 'Q3938001', 'Cinematografo.it'),  	                        'P4786',    function(id) return 'https://www.cinematografo.it/pls/cinematografo/consultazione.redirect?sch=' .. id end, categoryExternalLink( 'Cinematografo.it' ) },
    { getLabelWithoutLink( 'Q12334769', 'Scope'),  	                                    'P2518',    function(id) return 'http://www.scope.dk/film.php?id=' .. id end, categoryExternalLink( 'Scope' ) },
    { getLabelWithoutLink( 'Q12334769', 'Scope'),  	                                    'P2519',    function(id) return 'http://www.scope.dk/person.php?id=' .. id end, categoryExternalLink( 'Scope' ) },
    { getLabelWithoutLink( 'Q1139587', 'Swedish Film Database'),  	                    'P2334',    function(id) return 'http://www.sfi.se/sv/svensk-filmdatabas/Item/?type=MOVIE&itemid=' .. id end, categoryExternalLink( 'SFDb' ) },
    { getLabelWithoutLink( 'Q1139587', 'Swedish Film Database'),  	                    'P2168',    function(id) return 'http://www.svenskfilmdatabas.se/sv/item/?type=person&itemid=' .. id end, categoryExternalLink( 'SFDb' ) },
    { getLabelWithoutLink( 'Q2372943', 'Swiss Films'),  	                            'P6474',    function(id) return 'https://www.swissfilms.ch/de/film_search/filmdetails/-/id_film/' .. id end, categoryExternalLink( 'Swiss Films' ) },
    { getLabelWithoutLink( 'Q749719', 'Turner Classic Movies' ),                        'P2631',    function(id) return 'http://tcmdb.com/title/title.jsp?stid=' .. id end,                      categoryExternalLink( 'TCM' ) },
    { getLabelWithoutLink( 'Q749719', 'Turner Classic Movies' ),                        'P3056',    function(id) return 'http://tcmdb.com/participant/participant.jsp?participantId=' .. id end, categoryExternalLink( 'TCM' ) },
    { getLabelWithoutLink( 'Q20828898', 'TMDb' ),                                       'P4947',    function(id) return 'https://www.themoviedb.org/movie/' .. id end, categoryExternalLink( 'TMDb' ) },
    { getLabelWithoutLink( 'Q20828898', 'TMDb' ),                                       'P4983',    function(id) return 'https://www.themoviedb.org/tv/' .. id end, categoryExternalLink( 'TMDb' ) },
    { getLabelWithoutLink( 'Q20828898', 'TMDb' ),                                       'P4985',    function(id) return 'https://www.themoviedb.org/person/' .. id end, categoryExternalLink( 'TMDb' ) },
    { getLabelWithoutLink( 'Q1516429', 'Unifrance' ),                                   'P3961',    function(id) return 'http://www.unifrance.org/film/' .. id end, categoryExternalLink( 'Unifrance' ) },
    { getLabelWithoutLink( 'Q1516429', 'Unifrance' ),                                   'P3980',    function(id) return 'http://www.unifrance.org/annuaires/personne/' .. id end, categoryExternalLink( 'Unifrance' ) },
    { getLabelWithoutLink( 'Q1516429', 'Unifrance' ),                                   'P3979',    function(id) return 'http://www.unifrance.org/annuaires/societe/' .. id end, categoryExternalLink( 'Unifrance' ) },
    { getLabelWithoutLink( 'Q3561957', 'ČSFD' ),                                        'P2529',    function(id) return 'http://www.csfd.cz/film/' .. id ..'/prehled/' end, categoryExternalLink( 'ČSFD' ) },
    { getLabelWithoutLink( 'Q3561957', 'ČSFD' ),                                        'P2605',    function(id) return 'http://www.csfd.cz/tvurce/' .. id ..'/' end, categoryExternalLink( 'ČSFD' ) },	
	{ getLabelWithoutLink( 'Q523660', 'International Music Score Library Project' ),	'P839',		imslpLink,						categoryExternalLink( 'IMSLP' ) },
	{ labelMusicBrainz,																	'P434',		musicBrainzArtistLink,			categoryExternalLink( 'MusicBrainz' ) },
	{ labelMusicBrainz,																	'P435',		musicBrainzWorkLink,			categoryExternalLink( 'MusicBrainz' ) },
	{ labelMusicBrainz,																	'P436',		musicBrainzReleazeGroupLink,	categoryExternalLink( 'MusicBrainz' ) },
	{ getLabelWithoutLink( 'Q22673', 'Project Gutenberg' ),								'P1938',	function(id)	return 'http://www.gutenberg.org/ebooks/author/' .. id end,	categoryExternalLink( 'Project Gutenberg' ) },
	-- literature
	{ labelISFDb,																		'P1233',	isfdbAuthorLink,				categoryExternalLink( 'ISFDb' ) },
	{ labelISFDb,																		'P1234',	isfdbPublicationLink,			categoryExternalLink( 'ISFDb' ) },
	{ labelISFDb,																		'P1235',	isfdbSeriesLink,				categoryExternalLink( 'ISFDb' ) },
	{ labelISFDb,																		'P1239',	isfdbPublisherLink,				categoryExternalLink( 'ISFDb' ) },
	{ labelISFDb,																		'P1274',	isfdbTitleLink,			    	categoryExternalLink( 'ISFDb' ) },
	{ getLabelWithoutLink( 'Q17299517', 'RKDartists' ),									'P650',		rkdArtistsLink,					categoryExternalLink( 'RKDartists' ) },
	{ getLabelWithoutLink( 'Q17299580', 'RKDimages' ),									'P350',		rkdImagesLink,					categoryExternalLink( 'RKDimages' ) },
	{ getLabelWithoutLink( 'Q2359213', 'Goodreads'),									'P2963',	function( id )	return 'https://www.goodreads.com/author/show/' .. id end,	categoryExternalLink( 'Goodreads' ) },
	{ getLabelWithoutLink( 'Q2359213', 'Goodreads'),									'P2969',	function( id )	return 'https://www.goodreads.com/book/show/' .. id end,	categoryExternalLink( 'Goodreads' ) },
	{ getLabelWithoutLink( 'Q2359213', 'Goodreads'),									'P6327',	function( id )	return 'https://www.goodreads.com/characters/' .. id end,	categoryExternalLink( 'Goodreads' ) },
	{ getLabelWithoutLink( 'Q2359213', 'Goodreads'),									'P6947',	function( id )	return 'https://www.goodreads.com/series/' .. id end,	categoryExternalLink( 'Goodreads' ) },
	-- common
	{ getLabelWithoutLink( 'Q649227', 'Родовід' ),										'P1185',	rodovidLink,					categoryExternalLink( 'Родовід' ) },
	{ getLabelWithoutLink( 'Q41226', 'Open Directory Project' ),						'P998',		function(id)	return 'https://www.curlie.org/' .. id	end,			categoryExternalLink( 'DMOZ' ) },
	{ getLabelWithoutLink( 'Q63056', 'Find a Grave' ),									'P535',		findagraveLink,					categoryExternalLink( 'Find a Grave' ) },
	{ getLabelWithoutLink( 'Q63056', 'Find a Grave' ),									'P2025',	function(id)	return 'http://www.findagrave.com/cgi-bin/fg.cgi?page=cr&CRid=' .. id end,			categoryExternalLink( 'Find a Grave' ) },
	{ getLabelWithoutLink( 'Q51711', 'Quora' ),									        'P3417',	function(id)	return 'https://www.quora.com/topic/' .. id end,		categoryExternalLink( 'Quora' ) },
	{ getLabelWithoutLink( 'Q213660', 'LinkedIn' ),								        'P4264',	function(id)	return 'https://www.linkedin.com/company/' .. id end,	categoryExternalLink( 'LinkedIn' ) },
}


local authorityControl = {
    { getLabelWithLink( 'Q213678', 'Bibliotheca Apostolica Vaticana', 'BAV'),				'P1017',	bavLink,	categoryAuthorityControl( 'BAV' ) },
    { getLabelWithLink( 'Q4584301', '', 'BIBSYS'),											'P1015', 	bibsysLink,	categoryAuthorityControl( 'BIBSYS' ) },
    { getLabelWithLink( 'Q1200925', 'Biblioteca de Catalunya', 'BNC'),						'P1273',	bncLink,	categoryAuthorityControl( 'BNC' ) },
    { getLabelWithLink( 'Q750403', 'Biblioteca Nacional de España', 'BNE'),					'P950', 	bneLink,	categoryAuthorityControl( 'BNE' ) },
    { getLabelWithLink( 'Q193563', 'Bibliothèque nationale de France', 'BNF'), 				'P268', 	bnfLink,	categoryAuthorityControl( 'BNF' ) },
    { getLabelWithLink( 'Q1868372', 'Biografisch Portaal', 'BPN'),							'P651',		bpnLink,	categoryAuthorityControl( 'BPN' ) },
    { getLabelWithLink( 'Q9384291', '中国高等教育文献保障系统', 'CALIS'),					'P270', 	calisLink,	categoryAuthorityControl( 'CALIS' ) },
    { getLabelWithLink( 'Q13407958', 'China Biographical Database Project', 'CBDB'),		'P497', 	cbdbLink,	categoryAuthorityControl( 'CBDB' ) },
    { getLabelWithLink( 'Q10726338', 'Citation Information by NII', 'CiNii'),				'P271', 	ciniiLink,	categoryAuthorityControl( 'CiNii' ) },
    { getLabelWithLink( 'Q16744133', 'CONOR', 'CONOR'), 									'P1280',	conorLink,	categoryAuthorityControl( 'CONOR' ) },
    { getLabelWithLink( 'Q20730803', 'Catalogus Professorum Academiae Groninganae ', 'CPAG'),'P2016',	function(id) return 'http://hoogleraren.ub.rug.nl/hoogleraren/' .. id end,	categoryAuthorityControl( 'CPAG' ) },
    { getLabelWithLink( 'Q5323129', 'Entertainment Identifier Registry', 'EIDR'),	  	    'P2704',	function(id) return 'https://ui.eidr.org/view/content?id=' .. id end,	categoryAuthorityControl( 'EIDR' ) },
    { getLabelWithLink( 'Q501851', 'مكتبة الإسكندرية الجديدة', 'EGAXA'),						   	'P1309', 	egaxaLink,	categoryAuthorityControl( 'EGAXA' ) },
    { getLabelWithLink( 'Q36578', 'Gemeinsame Normdatei', 'GND'),						   	'P227', 	gndLink,	categoryAuthorityControl( 'GND' ) },
    { getLabelWithLink( 'Q19832959', 'GNIS', 'GNIS'),							            'P590', 	function(id) return 'https://geonames.usgs.gov/apex/f?p=gnispq:3:::NO::P3_FID:' .. id end , categoryAuthorityControl( 'GNIS' ) },
    { getLabelWithLink( 'Q3803707', 'Istituto Centrale per il Catalogo Unico', 'ICCU'),		'P396', 	iccuLink,	categoryAuthorityControl( 'ICCU' ) },
    { getLabelWithLink( 'Q1654582', 'International Standard Audiovisual Number', 'ISAN'),	'P3212',	function(id) return 'http://www.isan.org/template/1.2/publicSearch.do?code=' .. id end,	categoryAuthorityControl( 'ISAN' ) }, 
    { getLabelWithLink( 'Q423048', 'International Standard Name Identifier', 'ISNI'),		'P213',		isniLink,	categoryAuthorityControl( 'ISNI' ) },
    { getLabelWithLink( 'Q620946', 'Library of Congress Control Number', 'LCCN'),			'P244',		lccnLink,	categoryAuthorityControl( 'LCCN' ) },
    { getLabelWithLink( 'Q1133733', 'Latvijas Nacionālā bibliotēka', 'LNB'),				'P1368',	lnbLink,	categoryAuthorityControl( 'LNB' ) },
    { getLabelWithLink( 'Q809830', 'Base Mérimée', 'Mérimée'),								'P380',		merimeeLink,categoryAuthorityControl( 'Mérimée' ) },
    { getLabelWithLink( 'Q618340', '國家圖書館 (中華民國)', 'NCL'),							'P1048', 	nclLink,	categoryAuthorityControl( 'NCL' ) },
    { getLabelWithLink( 'Q477675', '国立国会図書館', 'NDL'),								'P349',		ndlLink,	categoryAuthorityControl( 'NDL' ) },
    { getLabelWithLink( 'Q732353', '中国国家图书馆', 'NLC'),								'P1213', 	nlcLink,	categoryAuthorityControl( 'NLC' ) },
-- NLI numbers seems unstable
    { getLabelWithLink( 'Q1967876', 'Národní knihovna České republiky', 'NKC'),				'P691',		nkcLink,	categoryAuthorityControl( 'NKC' ) },
    { getLabelWithLink( 'Q623578', 'National Library of Australia', 'NLA'), 				'P1315',	function(id) return 'https://trove.nla.gov.au/people/' .. id end,	categoryAuthorityControl( 'LNA' ) },
    { getLabelWithLink( 'Q1467610', 'Αναγνωριστικό Καθιερωμένων από τον Κατάλογο Καθιερωμένων Όρων της Εθνικής Βιβλιοθήκης της Ελλάδος', 'NLG'), 'P3348', function(id) return 'https://catalogue.nlg.gr/Authority/Record?id=au.' .. id end, categoryAuthorityControl( 'NLG' ) },
    { getLabelWithLink( 'Q622012', 'Biblioteca Națională a României', 'NLR'), 				'P1003',	nlrLink,	categoryAuthorityControl( 'NLR' ) },
    { getLabelWithLink( 'Q631375', 'Nacionalna i sveučilišna knjižnica u Zagrebu', 'NSK'),	'P1375',	nskLink,	categoryAuthorityControl( 'NSK' ) },
    { getLabelWithLink( 'Q1526131', 'Koninklijke Bibliotheek', 'NTA'),						'P1006',	ntaLink,	categoryAuthorityControl( 'NTA' ) },
    { getLabelWithLink( 'Q1063819', 'Országos Széchényi Könyvtár', 'NSZL'),					'P951',		nszlLink,	categoryAuthorityControl( 'NSZL' ) },
    { getLabelWithLink( 'Q11789729', 'Narodowy Uniwersalny Katalog Centralny', 'NUKAT'),	'P1207',	nukatLink,	categoryAuthorityControl( 'NUKAT' ) },
    { getLabelWithLink( 'Q245966', 'Biblioteca Nacional de Portugal', 'PTBNP'),				'P1005',	ptbnpLink,	categoryAuthorityControl( 'PTBNP' ) },
    { getLabelWithLink( 'Q1048694', 'Російська державна бібліотека', 'РДБ'),		        'P947', 	rslLink,	categoryAuthorityControl( 'RSL' ) },
    { 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) then

		for qualifierIndex, qualifier in pairs( statement.qualifiers[qualifierName] ) do
			if (qualifier.datavalue ~= nil
					and qualifier.datavalue.type ~= nil
					and qualifier.datavalue.value ~= nil) then

				if ( qualifier.datavalue.type == "monolingualtext" ) then
					return qualifier.datavalue.value.text;
				end
				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
		end

	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

    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.datavalue) 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 .. '[[' .. link .. '|' .. 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 .. '[[' .. link .. '|' .. 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 collectDictionaryLinks()
    --Create rows
    local elements = {}

    local item = mw.wikibase.getEntity()
    if ( item == nil or item.claims == nil) then
    	return elements
    end

	local sourceToElementLinks = {};

	local claim = item.claims['P1343']
	if ( claim ) then
		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' );
	
					-- Wikisource link ?
					local entityId = getQualifierSingleValue( statement, 'P805' ) or getQualifierSingleValue( statement, 'P248' );
					if ( entityId ) then
						if (sourceToElementLinks[resourceId] == nil) then
							sourceToElementLinks[resourceId] = {};
						end
						table.insert( sourceToElementLinks[resourceId], { entityId = entityId, languages = languages, rank = rank} );
					end
	
					-- URL to encyclopedia
					local url = getQualifierSingleValue( statement, 'P854' );
					if (url ~= nil) then
						if (sourceToElementLinks[resourceId] == nil) then
							sourceToElementLinks[resourceId] = {};
						end
						table.insert( sourceToElementLinks[resourceId], { url = url, languages = languages, rank = rank} );
					end
				end
			end
		end
	end

    for _, description in pairs( dictionaries ) do
 		if ( description.linkF ) then
	   	    local claim = item.claims[ description.id ];
			if ( claim ) then
				for _, statement in pairs( claim ) do
					local rank = statement.rank or 'normal';
					if ( rank ~= 'deprecated' and statement.mainsnak.datavalue) then
						local value = statement.mainsnak.datavalue.value;
						local url = description.linkF( value );
						local languages = getQualifierValues( statement, 'P407' );
						if ( sourceToElementLinks[description.id] == nil) then
							sourceToElementLinks[description.id] = {};
						end
						table.insert( sourceToElementLinks[description.id], { url = url, languages = languages, rank = rank} );
					end
				end
			end
		end
    end

	local html = '';
	for _, description in pairs( dictionaries ) do
		local links = sourceToElementLinks[ description.id ];
		if ( links ) then
			for _, link in pairs( links ) do
				if ( link.url ) then
        			table.insert( elements, '[' .. link.url .. ' ' .. description.title .. ']' )
				end

				if ( link.entityId ) then
				    local entity = mw.wikibase.getEntity( link.entityId );
				    if ( entity and entity.sitelinks and entity.sitelinks[description.project] ) then
        				table.insert( elements, '[[' ..  description.projectCode .. entity.sitelinks[description.project].title .. '|' .. description.title .. ']]' )
				    end
				end
			end
		end
	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( frame )
	local colorArg = '#CCF';
	if ( frame ~= nil ) then
	    local parentArgs = frame: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( frame, colorArg );
	    	if ( byTemplate ) then
	    		colorArg = byTemplate;
	    	end
	    end
    end

	local navboxData = {
        name  = 'External links',
        navboxclass = 'navbox ukwikiArticleExternalLinksTable',
        bodyclass = 'hlist',
        groupstyle = 'background: ' .. colorArg .. ';',
    };
   	local rowIndex = 1

	local socialNetworksElements = collectLinks( socialNetworkProperties );
	if ( #socialNetworksElements > 0 ) then
		navboxData['group' .. rowIndex] = group1Label
		navboxData['list' .. rowIndex] = table.concat( socialNetworksElements , ' · ' )
		rowIndex = rowIndex + 1
	end

	local textsElements = collectLinks( textsProperties );
	if ( #textsElements > 0 ) then
		navboxData['group' .. rowIndex] = group2Label
		navboxData['list' .. rowIndex] = table.concat( textsElements , ' · ' )
		rowIndex = rowIndex + 1
	end

	local contentHostingElements = collectLinks( contentHostingProperties );
	if ( #contentHostingElements > 0 ) then
		navboxData['group' .. rowIndex] = group3Label
		navboxData['list' .. rowIndex] = table.concat( contentHostingElements , ' · ' )
		rowIndex = rowIndex + 1
	end

	local themeProfilesElements = collectLinks( themeProfilesProperties );
	if ( #themeProfilesElements > 0 ) then
		navboxData['group' .. rowIndex] = group4Label
		navboxData['list' .. rowIndex] = table.concat( themeProfilesElements , ' · ' )
		rowIndex = rowIndex + 1
	end

	local dictionaryElements = collectDictionaryLinks();
	if ( #dictionaryElements > 0 ) then
		navboxData['group' .. rowIndex] = group5Label
		navboxData['list' .. rowIndex] = table.concat( dictionaryElements , ' · ' )
		rowIndex = rowIndex + 1
	end

	local authorityControlElements = collectLinks( authorityControl );
	if ( #authorityControlElements > 0 ) then
		navboxData['group' .. rowIndex] = group6Label
		navboxData['list' .. rowIndex] = table.concat( authorityControlElements , ' · ' )
		rowIndex = rowIndex + 1
	end

	if ( rowIndex == 1 ) then
		if ( mw.title.getCurrentTitle().namespace == 0 ) then
			return '[[Category:' .. categoryTemplateEmpty .. ']]'
		end
	else
		navboxData['group1'] = '<div style="padding: 0px 18px 0px 0px; width: 100%;"><div style="float: left; padding-left: 4px;">[[File:Searchtool.svg|14px|' .. templateLink .. ']]</div>&nbsp;&nbsp;' .. navboxData['group1'] .. '</div>'
	end

    local navbox = moduleNavbox._navbox( navboxData )
    return navbox
end

function p.renderDocumentation( )
	local result = ''
	result = result .. '|-\n'
	result = result .. '! colspan=4 | ' .. group1Label .. '\n'
	result = result .. '|-\n'
	result = result .. renderDocumentationCategory( socialNetworkProperties );
	result = result .. '|-\n'
	result = result .. '! colspan=4 | ' .. group2Label .. '\n'
	result = result .. '|-\n'
	result = result .. renderDocumentationCategory( textsProperties );
	result = result .. '|-\n'
	result = result .. '! colspan=4 | ' .. group3Label .. '\n'
	result = result .. '|-\n'
	result = result .. renderDocumentationCategory( contentHostingProperties );
	result = result .. '|-\n'
	result = result .. '! colspan=4 | ' .. group4Label .. '\n'
	result = result .. '|-\n'
	result = result .. renderDocumentationCategory( themeProfilesProperties );
	result = result .. '|-\n'
	result = result .. '! colspan=4 | ' .. group5Label .. '\n'
	result = result .. '|-\n'
	result = result .. renderDocumentationCategory( dictionaryProperties );
	result = result .. '|-\n'
	result = result .. '! colspan=4 | ' .. group6Label .. '\n'
	result = result .. '|-\n'
	result = result .. renderDocumentationCategory( authorityControl );
	return result;
end

function renderDocumentationCategory( links )
	local result = ''
	
    for _, params in pairs( links ) do
    	local resourceLabel = params[1]
    	local resourceId = params[2]
    	local category = params[4]
    	local optional
    	if ( params[5] or false ) then
    		optional = 'TRUE'
    	else
    		optional = 'FALSE'
    	end
    	
    	result = result .. '| ' .. resourceLabel .. '\n'
   	    if string.match( resourceId, '^P' ) then
			result = result .. '| [[:d:Property:' .. resourceId .. '|' .. resourceId .. ']]\n'
		elseif string.match( resourceId, '^Q' ) then
			result = result .. '| [[:d:' .. resourceId .. '' .. '|' .. resourceId .. ']]\n'
		else 
			result = result .. '| &nbsp; \n'
		end

		if ( category ~= nil and category ~= false ) then
			result = result .. '| [[:Category:' .. category .. '|' .. category .. ']]\n'
		else
			result = result .. '| &nbsp; \n'
		end
		result = result .. '| ' .. optional .. '\n'
		result = result .. '|-\n'
    end

	return result;
end

return p