وحدة:ضبط استنادي

من كوبتيكبيديا
اذهب إلى التنقل اذهب إلى البحث

تحتوي هذه الوحدة على كود قالب {{ضبط استنادي}}. طالع توثيقه.

استخدام

{{ضبط استنادي|id=Q76}}
خطأ لوا في السطر 904: attempt to index field 'wikibase' (a nil value).

تصانيف التتبع

جديد

قديم جديد
تصنيف:مقالات فيها معرفات VIAF (٠ صفحة) تصنيف:صفحات تستخدم خاصية P214 (٠ صفحة)
تصنيف:مقالات فيها معرفات EGAXA (٠ صفحة) تصنيف:صفحات تستخدم خاصية P1309 (٠ صفحة)
تصنيف:مقالات فيها معرفات LCCN (٠ صفحة) تصنيف:صفحات تستخدم خاصية P244 (٠ صفحة)
تصنيف:مقالات فيها معرفات ISNI (٠ صفحة) تصنيف:صفحات تستخدم خاصية P213 (٠ صفحة)
تصنيف:مقالات فيها معرفات ORCID (٠ صفحة) تصنيف:صفحات تستخدم خاصية P496 (٠ صفحة)
تصنيف:مقالات فيها معرفات GND (٠ صفحة) تصنيف:صفحات تستخدم خاصية P227 (٠ صفحة)
تصنيف:مقالات فيها معرفات SELIBR (٠ صفحة) تصنيف:صفحات تستخدم خاصية P906 (٠ صفحة)
تصنيف:مقالات فيها معرفات SUDOC (٠ صفحة) تصنيف:صفحات تستخدم خاصية P269 (٠ صفحة)
تصنيف:مقالات فيها معرفات BNF (٠ صفحة) تصنيف:صفحات تستخدم خاصية P268 (٠ صفحة)
تصنيف:مقالات فيها معرفات BPN (٠ صفحة) تصنيف:صفحات تستخدم خاصية P651 (٠ صفحة)
تصنيف:مقالات فيها معرفات RID (٠ صفحة) تصنيف:صفحات تستخدم خاصية P1053 (٠ صفحة)
تصنيف:مقالات فيها معرفات BIBSYS (٠ صفحة) تصنيف:صفحات تستخدم خاصية P1015 (٠ صفحة)
تصنيف:مقالات فيها معرفات ULAN (٠ صفحة) تصنيف:صفحات تستخدم خاصية P245 (٠ صفحة)
تصنيف:مقالات فيها معرفات HDS (٠ صفحة) تصنيف:صفحات تستخدم خاصية P902 (٠ صفحة)
تصنيف:مقالات فيها معرفات LIR (٠ صفحة) تصنيف:صفحات تستخدم خاصية P886 (٠ صفحة)
تصنيف:مقالات فيها معرفات MBA (٠ صفحة) تصنيف:صفحات تستخدم خاصية P434 (٠ صفحة)
تصنيف:مقالات فيها معرفات MGP (٠ صفحة) تصنيف:صفحات تستخدم خاصية P549 (٠ صفحة)
تصنيف:مقالات فيها معرفات NLA (٠ صفحة) تصنيف:صفحات تستخدم خاصية P409 (٠ صفحة)
تصنيف:مقالات فيها معرفات NDL (٠ صفحة) تصنيف:صفحات تستخدم خاصية P349 (٠ صفحة)
تصنيف:مقالات فيها معرفات NCL (٠ صفحة) تصنيف:صفحات تستخدم خاصية P1048 (٠ صفحة)
تصنيف:مقالات فيها معرفات NKC (٠ صفحة) تصنيف:صفحات تستخدم خاصية P691 (٠ صفحة)
تصنيف:مقالات فيها معرفات Léonore (٠ صفحة) تصنيف:صفحات تستخدم خاصية P640 (٠ صفحة)
تصنيف:مقالات فيها معرفات SBN (٠ صفحة) تصنيف:صفحات تستخدم خاصية P396 (٠ صفحة)
تصنيف:مقالات فيها معرفات RLS (٠ صفحة) تصنيف:صفحات تستخدم خاصية P947 (٠ صفحة)
تصنيف:مقالات فيها معرفات Botanist (٠ صفحة) تصنيف:صفحات تستخدم خاصية P428 (٠ صفحة)
تصنيف:مقالات فيها معرفات NARA-person (٠ صفحة) تصنيف:صفحات تستخدم خاصية P1222 (٠ صفحة)
تصنيف:مقالات فيها معرفات NARA-organization (٠ صفحة) تصنيف:صفحات تستخدم خاصية P1225 (٠ صفحة)
تصنيف:مقالات فيها معرفات USCongress (٠ صفحة) تصنيف:صفحات تستخدم خاصية P1157 (٠ صفحة)
تصنيف:مقالات فيها معرفات BNE (٠ صفحة) تصنيف:صفحات تستخدم خاصية P950 (٠ صفحة)
تصنيف:مقالات فيها معرفات CINII (٠ صفحة) تصنيف:صفحات تستخدم خاصية P271 (٠ صفحة)
تصنيف:مقالات فيها معرفات TLS (٠ صفحة) تصنيف:صفحات تستخدم خاصية P1362 (٠ صفحة)
تصنيف:مقالات فيها معرفات SIKART (٠ صفحة) تصنيف:صفحات تستخدم خاصية P781 (٠ صفحة)
تصنيف:مقالات فيها معرفات UNDocument (٠ صفحة) تصنيف:صفحات تستخدم خاصية P3069 (٠ صفحة)
تصنيف:مقالات فيها معرفات KULTURNAV (٠ صفحة) تصنيف:صفحات تستخدم خاصية P1248 (٠ صفحة)
تصنيف:مقالات فيها معرفات RKDartists (٠ صفحة) تصنيف:صفحات تستخدم خاصية P650 (٠ صفحة)
تصنيف:مقالات فيها معرفات J9U (٠ صفحة) تصنيف:صفحات تستخدم خاصية P8189 (٠ صفحة)

require('Module:No globals')
local p = {}
local properties_id = {}
local function getCatForId( id, cate )
    local title = mw.title.getCurrentTitle()
    local namespace = title.namespace
	local namespace1 = '[[تصنيف:مقالات فيها معرفات ' .. id .. ']]'
	--local namespace1 = '[[تصنيف:صفحات تستخدم خاصية ' .. id .. ']]'
	if cate and cate ~='' 
		then namespace1 = '[[category:' .. cate .. ']]'
	else 
		if properties_id[id] then
			namespace1 =   '[[تصنيف:صفحات تستخدم خاصية ' .. properties_id[id] .. ']]'
		end
	end
    local namespace2= '[[تصنيف:صفحات مستخدمين فيها معرفات ' .. id .. ']]'
    local namespace3= '[[تصنيف:صفحات متفرقة فيها معرفات ' .. id .. ']]'
    if namespace == 0 then
        return namespace1
    elseif namespace == 2 and not title.isSubpage then
        return namespace2
    else
        return namespace3
    end
end

local function ntaLink( id )
	--P1006's format regex: \d{8}[\dX] (e.g. 12345678X)
	if not id:match( '^%d%d%d%d%d%d%d%d[%dX]$' ) then
		return false
	end
	return '[http://data.bibliotheken.nl/id/thes/p'..id..' '..id..']'.. getCatForId( 'NTA' )
end

local function viafLink( id )
    if not string.match( id, '^%d+$' ) then
        return false
    end
    return '[https://viaf.org/viaf/' .. id .. ' ' .. id .. ']' .. getCatForId( 'VIAF' )
end

local function kulturnavLink( id )
    return '[http://kulturnav.org/language/en/' .. id .. ' id]' 
end
local function UNdocumentsymbol( id )
    return '[https://undocs.org/' .. id .. ' ' .. id .. ']' .. getCatForId( 'UNDocument' )
end
local function sikartLink( id )
    return '[http://www.sikart.ch/KuenstlerInnen.aspx?id=' .. id .. '&lng=en ' .. id .. ']' 
end

local function egaxaLink( id )
    return  '[http://viaf.org/processed/EGAXA%7Cvtls' .. id .. ' ' .. id .. ']' .. getCatForId( 'EGAXA' )
end

local function tlsLink( id )
	local id2 = mw.ustring.gsub(id, '%s', function(s) return mw.uri.encode(s, 'WIKI') end)
    return '[http://tls.theaterwissenschaft.ch/wiki/' .. id2 .. ' ' .. id .. ']' 
end


local function ciniiLink( id )
    return '[http://ci.nii.ac.jp/author/' .. id .. '?l=en ' .. id .. ']' 
end

local function bneLink( id )
    return '[http://catalogo.bne.es/uhtbin/authoritybrowse.cgi?action=display&authority_id=' .. id .. ' ' .. id .. ']' 
end


local function uscongressLink( id )
    return '[http://bioguide.congress.gov/scripts/biodisplay.pl?index=' .. id .. ' ' .. id .. ']' 
end

local function narapersonLink( id )
    return '[https://research.archives.gov/person/' .. id .. ' ' .. id .. ']' 
end

local function naraorganizationLink( id )
    return '[https://research.archives.gov/organization/' .. id .. ' ' .. id .. ']' 
end

local function botanistLink( id )
	local id2 = mw.ustring.gsub(id, '%s', function(s) return mw.uri.encode(s, 'PATH') end)
    return '[http://www.ipni.org/ipni/advAuthorSearch.do?find_abbreviation=' .. id2 .. ' ' .. id .. ']' 
end
local function IPNILink( id )
    return '[http://www.ipni.org/ipni/idAuthorSearch.do?id=' .. id .. ' ' .. id .. ']' 
end

local function mgpLink( id )
    -- TODO Implement some sanity checking regex
    return '[http://www.genealogy.ams.org/id.php?id=' .. id .. ' ' .. id .. ']' 
end

local function rslLink( id )
    -- TODO Implement some sanity checking regex
    return '[http://aleph.rsl.ru/F?func=find-b&find_code=SYS&adjacent=Y&local_base=RSL11&request=' .. id .. '&CON_LNG=ENG ' .. id .. ']'
end

local function leonoreLink( id )
-- Identifiants allant de LH/1/1 à LH/2794/54 (légionnaires)
-- Identifiants allant de C/0/1 à C/0/84 (84 légionnaires célèbres)
-- Identifiants allant de 19800035/1/1 à 19800035/385/51670 (légionnaires décédés entre 1954 et 1977, et quelques dossiers de légionnaires décédés avant 1954)
    if not string.match( id, '^LH/%d%d?%d?%d?/%d%d?%d?$' ) and
       not string.match( id, '^C/0/%d%d?$' ) and
	   not string.match( id, '^19800035/%d%d?%d?%d?/%d%d?%d?%d?%d?$' ) then
        return false
    end
    return '[//www.culture.gouv.fr/public/mistral/leonore_fr?ACTION=CHERCHER&FIELD_1=COTE&VALUE_1=' .. id .. ' ' .. id .. ']' 
end

local function sbnLink( id )
    if not string.match( id, '^IT\\ICCU\\%d%d%d%d%d%d%d%d%d%d$' ) and not string.match( id, '^IT\\ICCU\\%u%u[%d%u]%u\\%d%d%d%d%d%d$' ) then
        return false
    end
    return '[http://opac.sbn.it/opacsbn/opac/iccu/scheda_authority.jsp?bid=' .. id .. ' ' .. id .. ']' .. getCatForId( 'SBN' )
end

local function nkcLink( id )
	return '[http://aleph.nkp.cz/F/?func=find-c&local_base=aut&ccl_term=ica=' .. id .. '&CON_LNG=ENG ' .. id .. ']' ..getCatForId( '', 'صفحات تستخدم خاصية P691' )
end

local function nclLink( id )
    if not string.match( id, '^%d+$' ) then
        return false
    end
    return '[http://aleweb.ncl.edu.tw/F/?func=accref&acc_sequence=' .. id .. '&CON_LNG=ENG ' .. id .. ']' 
end

local function ndlLink( id )
	return '[http://id.ndl.go.jp/auth/ndlna/' .. id .. ' ' .. id .. ']' ..getCatForId( '', 'صفحات تستخدم خاصية P349' )
end

local function sudocLink( id )
    if not string.match( id, '^%d%d%d%d%d%d%d%d[%dxX]$' ) then
        return false
    end
    return '[http://www.idref.fr/' .. id .. ' ' .. id .. ']' 
end

local function hlsLink( id )
    if not string.match( id, '^%d+$' ) then
        return false
    end
    return '[http://www.hls-dhs-dss.ch/textes/f/F' .. id .. '.php ' .. id .. ']'
end

local function lirLink( id )
    if not string.match( id, '^%d+$' ) then
        return false
    end
    return '[http://www.e-lir.ch/e-LIR___Lexicon.' .. id .. '.450.0.html ' .. id .. ']'
end

local function splitLccn( id )
    if id:match( '^%l%l?%l?%d%d%d%d%d%d%d%d%d?%d?$' ) then
        id = id:gsub( '^(%l+)(%d+)(%d%d%d%d%d%d)$', '%1/%2/%3' )
    end
    if id:match( '^%l%l?%l?/%d%d%d?%d?/%d+$' ) then
         return mw.text.split( id, '/' )
    end
    return false
end

local function LNLLink( id )
	return '[http://viaf.org/processed/LNL%7C'..id..' '..id..']'..getCatForId( 'LNL' )
end
local function aagLink( id )
	--P3372's format regex: \d+ (e.g. 1)
	if not id:match( '^%d+$' ) then
		return false
	end
	return '[https://www.aucklandartgallery.com/explore-art-and-ideas/artist/'..id..'/ '..id..']'..getCatForId( 'AAG' )
end

local function acmLink( id )
	--P864's format regex: \d{11} (e.g. 12345678901)
	if not id:match( '^%d%d%d%d%d%d%d%d%d%d%d$' ) then
		return false
	end
	return '[https://dl.acm.org/profile/'..id..' '..id..']'..getCatForId( 'ACM-DL' )
end

local function adbLink( id )
	--P1907's format regex: [a-z][-a-z]+-([1-2]\d|[1-9])\d{0,3} (e.g. barton-sir-edmund-toby-71)
	if not id:match( '^[a-z][-a-z]+-[1-2]%d%d?%d?%d?$' ) and
	   not id:match( '^[a-z][-a-z]+-[1-9]%d?%d?%d?$' ) then
		return false
	end
	return '[http://adb.anu.edu.au/biography/'..id..' '..id..']'..getCatForId( 'ADB' )
end

local function agsaLink( id )
	--P6804's format regex: [1-9]\d* (e.g. 3625)
	if not id:match( '^[1-9]%d*$' ) then
		return false
	end
	return '[https://www.agsa.sa.gov.au/collection-publications/collection/creators/_/'..id..'/ '..id..']'..getCatForId( 'AGSA' )
end

local function autoresuyLink( id )
	--P2558's format regex: [1-9]\d{0,4} (e.g. 12345)
	if not id:match( '^[1-9]%d?%d?%d?%d?$' ) then
		return false
	end
	return '[https://autores.uy/autor/'..id..' '..id..']'..getCatForId( 'autores.uy' )
end

local function awrLink( id )
	--P4186's format regex: (([A-Z]{3}\d{4})|([A-Z]{2}\d{5}))[a-z] (e.g. PR00768b)
	if not id:match( '^[A-Z][A-Z][A-Z]%d%d%d%d[a-z]$' ) and
	   not id:match( '^[A-Z][A-Z]%d%d%d%d%d[a-z]$' ) then
		return false
	end
	return '[http://www.womenaustralia.info/biogs/'..id..'.htm '..id..']'..getCatForId( 'AWR' )
end

local function balatLink( id )
	--P3293's format regex: \d+ (e.g. 1)
	if not id:match( '^%d+$' ) then
		return false
	end
	return '[http://balat.kikirpa.be/object/104257'..id..' '..id..']'..getCatForId( 'BALaT' ) --no https as of 9/2019
end



local function bildLink( id )
	--P2092's format regex: \d+ (e.g. 1)
	if not id:match( '^%d+$' ) then
		return false
	end
	return '[https://www.bildindex.de/document/obj'..id..' '..id..']'..getCatForId( 'Bildindex' )
end

local function bncLink( id )
	--P1890's format regex: \d{9} (e.g. 123456789)
	if not id:match( '^%d%d%d%d%d%d%d%d%d$' ) then
		return false
	end
	return '[http://www.bncatalogo.cl/F?func=direct&local_base=red10&doc_number='..id..' '..id..']'..getCatForId( 'BNC' )
end

local function canticLink( id )
	--P1273's format regex: a\d{7}[0-9x] (e.g. a10640745)
	if not id:match( '^a%d%d%d%d%d%d%d[%dx]$' ) then
		return false
	end
	return '[http://cantic.bnc.cat/registres/CUCId/'..id..' '..id..']'..getCatForId( 'CANTIC' ) --no https as of 10/2019
end

local function daaoLink( id )
	--P1707's format regex: [a-z\-]+\d* (e.g. rolf-harris)
	if not id:match( '^[a-z%-]+%d*$' ) then
		return false
	end
	return '[https://www.daao.org.au/bio/'..id..' '..id..']'..getCatForId( 'DAAO' )
end

local function dblpLink( id )
	--P2456's format regex: \d{2,3} /\d+(-\d+)?|[a-z] /[a-zA-Z][0-9A-Za-z]*(-\d+)? (e.g. 123/123)
	if not id:match( '^%d%d%d?/%d+$' ) and
	   not id:match( '^%d%d%d?/%d+%-%d+$' ) and
	   not id:match( '^[a-z]/[a-zA-Z][0-9A-Za-z]*$' ) and
	   not id:match( '^[a-z]/[a-zA-Z][0-9A-Za-z]*%-%d+$' ) then
		return false
	end
	return '[https://dblp.org/pid/'..id..' '..id..']'..getCatForId( 'DBLP' )
end

local function dsiLink( id )
	--P2349's format regex: [1-9]\d* (e.g. 1538)
	if not id:match( '^[1-9]%d*$' ) then
		return false
	end
	return '[http://www.uni-stuttgart.de/hi/gnt/dsi2/index.php?table_name=dsi&function=details&where_field=id&where_value='..id..' '..id..']'..getCatForId( 'DSI' )
end

local function fnzaLink( id )
	--P6792's format regex: [1-9]\d* (e.g. 9785)
	if not id:match( '^[1-9]%d*$' ) then
		return false
	end
	return '[https://findnzartists.org.nz/artist/'..id..'/ '..id..']'..getCatForId( 'FNZA' )
end


local function hdsLink( id )
	--P902's format regex: \d{6} (e.g. 050123)
	if not id:match( '^%d%d%d%d%d%d$' ) then
		return false
	end
	return '[https://hls-dhs-dss.ch/fr/articles/'..id..' '..id..']'..getCatForId( 'HDS' )
end

local function iaafLink( id )
	--P1146's format regex: [0-9][0-9]* (e.g. 012)
	if not id:match( '^%d+$' ) then
		return false
	end
	return '[https://www.iaaf.org/athletes/_/'..id..' '..id..']'..getCatForId( 'IAAF' )
end

local function iciaLink( id )
	--P1736's format regex: \d+ (e.g. 1)
	if not id:match( '^%d+$' ) then
		return false
	end
	return '[https://www.imj.org.il/artcenter/newsite/en/?artist='..id..' '..id..']'..getCatForId( 'ICIA' )
end


local function jocondeLink( id )
	--P347's format regex: [\-0-9A-Za-z]{11} (e.g. 12345678901)
	local regex = '^'..string.rep('[%-0-9A-Za-z]', 11)..'$'
	if not id:match( regex ) then
		return false
	end
	return '[https://www.pop.culture.gouv.fr/notice/joconde/'..id..' '..id..']'..getCatForId( 'Joconde' )
end



local function lnbLink( id )
	--P1368's format regex: \d{9} (e.g. 123456789)
	if not id:match( '^%d%d%d%d%d%d%d%d%d$' ) then
		return false
	end
	return '[https://kopkatalogs.lv/F?func=direct&local_base=lnc10&doc_number='..id..'&P_CON_LNG=ENG '..id..']'..getCatForId( 'LNB' )
end
local function AUBID_link( id )
	return '[https://libcat.aub.edu.lb/record='..id..'/ '..id..']'.. getCatForId( '' , 'صفحات تستخدم خاصية P9409' )
end
local function BAUID_link( id )
	return '[http://librarycatalog.bau.edu.lb/cgi-bin/koha/opac-detail.pl?biblionumber='..id..'/ '..id..']'.. getCatForId( '' , 'صفحات تستخدم خاصية P9504' )
end
local function aagLink( id )
	--P3372's format regex: \d+ (e.g. 1)
	if not id:match( '^%d+$' ) then
		return false
	end
	return '[https://www.aucklandartgallery.com/explore-art-and-ideas/artist/'..id..'/ '..id..']'.. getCatForId( 'AAG' )
end

local function mbaLink( id )
	--P434's format regex: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} (e.g. 12345678-1234-1234-1234-1234567890AB)
	if not id:match( '^%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x$' ) then
		return false
	end
	return '[https://musicbrainz.org/artist/'..id..' '..id..']'..getCatForId( '', 'صفحات تستخدم خاصية P434' )
end

local function mbareaLink( id )
	--P982's format regex: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} (e.g. 12345678-1234-1234-1234-1234567890AB)
	if not id:match( '^%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x$' ) then
		return false
	end
	return '[https://musicbrainz.org/area/'..id..' '..id..']'..getCatForId( '', 'صفحات تستخدم خاصية P982' )
end

local function mbiLink( id )
	--P1330's format regex: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} (e.g. 12345678-1234-1234-1234-1234567890AB)
	if not id:match( '^%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x$' ) then
		return false
	end
	return '[https://musicbrainz.org/instrument/'..id..' '..id..']'..getCatForId( '', 'صفحات تستخدم خاصية P1330' )
end

local function mblLink( id )
	--P966's format regex: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} (e.g. 12345678-1234-1234-1234-1234567890AB)
	if not id:match( '^%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x$' ) then
		return false
	end
	return '[https://musicbrainz.org/label/'..id..' '..id..']'..getCatForId( '', 'صفحات تستخدم خاصية P966' )
end

local function mbpLink( id )
	--P1004's format regex: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} (e.g. 12345678-1234-1234-1234-1234567890AB)
	if not id:match( '^%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x$' ) then
		return false
	end
	return '[https://musicbrainz.org/place/'..id..' '..id..']'..getCatForId( '', 'صفحات تستخدم خاصية P1004' )
end

local function mbrgLink( id )
	--P436's format regex: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} (e.g. 12345678-1234-1234-1234-1234567890AB)
	if not id:match( '^%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x$' ) then
		return false
	end
	return '[https://musicbrainz.org/release-group/'..id..' '..id..']'..getCatForId( '', 'صفحات تستخدم خاصية P436' )
end

local function mbsLink( id )
	--P1407's format regex: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} (e.g. 12345678-1234-1234-1234-1234567890AB)
	if not id:match( '^%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x$' ) then
		return false
	end
	return '[https://musicbrainz.org/series/'..id..' '..id..']'..getCatForId( '', 'صفحات تستخدم خاصية P1407' )
end

local function mbwLink( id )
	--P435's format regex: [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} (e.g. 12345678-1234-1234-1234-1234567890AB)
	if not id:match( '^%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x$' ) then
		return false
	end
	return '[https://musicbrainz.org/work/'..id..' '..id..']'..getCatForId( '', 'صفحات تستخدم خاصية P435' )
end


local function naraLink( id )
	--P1225's format regex: ^([1-9]\d{0,8})$ (e.g. 123456789)
	if not id:match( '^[1-9]%d?%d?%d?%d?%d?%d?%d?%d?$' ) then
		return false
	end
	return '[https://catalog.archives.gov/id/'..id..' '..id..']'..getCatForId( 'NARA' )
end

local function ngvLink( id )
	--P2041's format regex: \d+ (e.g. 12354)
	if not id:match( '^%d+$' ) then
		return false
	end
	return '[https://www.ngv.vic.gov.au/explore/collection/artist/'..id..'/ '..id..']'..getCatForId( 'NGV' )
end

local function nlgLink( id )
	--P3348's format regex: [1-9]\d* (e.g. 1)
	if not id:match( '^[1-9]%d*$' ) then
		return false
	end
	return '[https://data.nlg.gr/resource/authority/record'..id..' '..id..']'..getCatForId( 'NLG' )
end

local function nliLink( id )
	--P949's format regex: \d{9} (e.g. 123456789)
	if not id:match( '^%d%d%d%d%d%d%d%d%d$' ) then
		return false
	end
	return '[http://uli.nli.org.il/F/?func=direct&doc_number='..id..'&local_base=nlx10'..' '..id..']'..getCatForId( 'NLI' )
end

local function nlkLink( id )
	--P5034's format regex: KA.(19|20).{7} (e.g. KAC201501465)
	if not id:match( '^KA.19.......$' ) and
	   not id:match( '^KA.20.......$' ) then
		return false
	end
	return '[https://nl.go.kr/authorities/resource/'..id..' '..id..']'..getCatForId( 'NLK' )
end

local function nlpLink( id )
	--P1695's format regex: 9810[0-9]\d* or A[0-9]{7}[0-9X] (e.g. 9810123456789012345 or A10414836)
	if not id:match( '^9810%d+$' ) and
	   not id:match( '^A%d%d%d%d%d%d%d[%dX]$' ) then
		return false
	end
	return '[https://tools.wmflabs.org/wikidata-externalid-url?p=1695&id='..id..' '..id..']'..getCatForId( 'NLP' )
end

local function nlrLink( id )
	--P1003's format regex: \d{9} (e.g. 123456789)
	if not id:match( '^%d%d%d%d%d%d%d%d%d$' ) then
		return false
	end
	return '[http://alephnew.bibnat.ro:8991/F?func=find-b&request='..id..'&find_code=SYS&adjacent=Y&local_base=NLR10 '..id..']'..getCatForId( 'NLR' )
end

local function nskLink( id )
	--P1375's format regex: \d{9} (e.g. 123456789)
	if not id:match( '^%d%d%d%d%d%d%d%d%d$' ) then
		return false
	end
	return '[http://katalog.nsk.hr/F/?func=direct&doc_number='..id..'&local_base=nsk10 '..id..']'..getCatForId( 'NSK' ) --no https as of 9/2019
end

local function ntaLink( id )
	--P1006's format regex: \d{8}[\dX] (e.g. 12345678X)
	if not id:match( '^%d%d%d%d%d%d%d%d[%dX]$' ) then
		return false
	end
	return '[http://data.bibliotheken.nl/id/thes/p'..id..' '..id..']'..getCatForId( 'NTA' )
end

local function picLink( id )
	--P2750's format regex: [1-9]\d* (e.g. 1)
	if not id:match( '^[1-9]%d*$' ) then
		return false
	end
	return '[https://pic.nypl.org/constituents/'..id..' '..id..']'..getCatForId( 'PIC' )
end

local function rkdidLink( id )
	--P350's format regex: [1-9]\d{0,5} (e.g. 123456)
	if not id:match( '^[1-9]%d?%d?%d?%d?%d?$' ) then
		return false
	end
	return '[https://rkd.nl/nl/explore/images/'..id..' '..id..']'..getCatForId( 'RKDID' )
end

local function snacLink( id )
	--P3430's format regex: \d*[A-Za-z][0-9A-Za-z]* (e.g. A)
	if not id:match( '^%d*[A-Za-z][0-9A-Za-z]*$' ) then
		return false
	end
	return '[https://snaccooperative.org/ark:/99166/'..id..' '..id..']'..getCatForId( 'SNAC-ID' )
end

local function reroLink( id )
	--P3065's format regex: 0[1-2]-[A-Z0-9]{1,10} (e.g. 02-A012345678)
	if not id:match( '^0[1-2]%-[A-Z%d][A-Z%d]?[A-Z%d]?[A-Z%d]?[A-Z%d]?[A-Z%d]?[A-Z%d]?[A-Z%d]?[A-Z%d]?[A-Z%d]?$' ) then
		return false
	end
	return '[http://data.rero.ch/'..id..' '..id..']'.. getCatForId( 'RERO' )
end

local function s2authoridLink( id )
	--P4012's format regex: [1-9]\d* (e.g. 1796130)
	if not id:match( '^[1-9]%d*$' ) then
		return false
	end
	return '[https://www.semanticscholar.org/author/'..id..' '..id..']'..getCatForId( 'Semantic Scholar author' ) --special category name
end

local function ta98Link( id )
	--P1323's format regex: A\d{2}\.\d\.\d{2}\.\d{3}[FM]? (e.g. A12.3.45.678)
	if not id:match( '^A%d%d%.%d%.%d%d%.%d%d%d[FM]?$' ) then
		return false
	end
	return '[http://tools.wmflabs.org/wikidata-externalid-url/?p=1323&url_prefix=https:%2F%2Fwww.unifr.ch%2Fifaa%2FPublic%2FEntryPage%2FTA98%20Tree%2FEntity%20TA98%20EN%2F&url_suffix=%20Entity%20TA98%20EN.htm&id='..id..' '..id..']'..getCatForId( 'TA98' )
end

local function tdviaLink( id )
	--P7314's format regex: [a-z/-]+] (e.g. barkan-omer-lutfi)
	if not id:match( '^[a-z/-]+$' ) then
		return false
	end
	return '[https://islamansiklopedisi.org.tr/'..id..' '..id..']'..getCatForId( 'TDVİA' )
end

local function teLink( id )
	--P1693's format regex: E[1-8]\.\d{1,2}\.\d{1,2}\.\d{1,2}\.\d{1}\.\d{1}\.\d{1,3} (e.g. E1.23.45.67.8.9.0)
	local e1, e2 = id:match( '^E([1-8])%.(%d%d?)%.%d%d?%.%d%d?%.%d%.%d%.%d%d?%d?$' )
	if not e1 then
		return false
	end
	local TEnum = 'TEe0'..e1 --no formatter URL in WD, probably due to this complexity
	if e1 == '5' or e1 == '7' then
		if #e2 == 1 then e2 = '0'..e2 end
		TEnum = TEnum..e2
	end
	return '[http://www.unifr.ch/ifaa/Public/EntryPage/ViewTE/'..TEnum..'.html '..id..']'..getCatForId( 'TE' )
end

local function tepapaLink( id )
	--P3544's format regex: \d+ (e.g. 1)
	if not id:match( '^%d+$' ) then
		return false
	end
	return '[https://collections.tepapa.govt.nz/agent/'..id..' '..id..']'..getCatForId( 'TePapa' )
end

local function thLink( id )
	--P1694's format regex: H\d\.\d{2}\.\d{2}\.\d\.\d{5} (e.g. H1.23.45.6.78901)
	local h1, h2 = id:match( '^H(%d)%.(%d%d)%.%d%d%.%d%.%d%d%d%d%d$' )
	if not h1 then
		return false
	end
	local THnum = 'THh'..h1..h2 --no formatter URL in WD, probably due to this complexity
	return '[http://www.unifr.ch/ifaa/Public/EntryPage/ViewTH/'..THnum..'.html '..id..']'..getCatForId( 'TH' )
end


local function troveLink( id )
	--P1315's format regex: [1-9]\d{5,7} (e.g. 12345678)
	if not id:match( '^[1-9]%d%d%d%d%d%d?%d?$' ) then
		return false
	end
	return '[https://trove.nla.gov.au/people/'..id..' '..id..']'..getCatForId( 'Trove' )
end

local function append(str, c, length)
    while str:len() < length do
        str = c .. str
    end
    return str
end

local function lccnLink( id )
    local parts = splitLccn( id )
    if not parts then
        return false
    end
    local lccnType = parts[1] ~= 'sh' and 'names' or 'subjects'
    id = parts[1] .. parts[2] .. append( parts[3], '0', 6 )
    return '[http://id.loc.gov/authorities/' .. lccnType .. '/' .. id .. ' ' .. id .. ']' .. getCatForId( 'LCCN' )
end

local function mbLink( id )
    -- TODO Implement some sanity checking regex
    return '[//musicbrainz.org/artist/' .. id .. ' ' .. id .. ']' .. getCatForId( '', 'صفحات تستخدم خاصية P434' )
end

--Returns the ISNI check digit isni must be a string where the 15 first elements are digits
local function getIsniCheckDigit( isni )
    local total = 0
    for i = 1, 15 do
        local digit = isni:byte( i ) - 48 --Get integer value
        total = (total + digit) * 2
    end
    local remainder = total % 11
    local result = (12 - remainder) % 11
    if result == 10 then
        return "X"
    end
    return tostring( result )
end

--Validate ISNI (and ORCID) and retuns it as a 16 characters string or returns false if it's invalid
--See http://support.orcid.org/knowledgebase/articles/116780-structure-of-the-orcid-identifier
local function validateIsni( id )
    id = id:gsub( '[ %-]', '' ):upper()
    if not id:match( '^%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d[%dX]$' ) then
        return false
    end
    if getIsniCheckDigit( id ) ~= string.char( id:byte( 16 ) ) then
        return false
    end
    return id
end

local function isniLink( id )
    id = validateIsni( id )
    if not id then
        return false
    end
    return '[http://isni.org/isni/' .. id .. ' ' .. id:sub( 1, 4 ) .. ' ' .. id:sub( 5, 8 ) .. ' '  .. id:sub( 9, 12 ) .. ' '  .. id:sub( 13, 16 ) .. ']' .. getCatForId( 'ISNI' )
end

local function orcidLink( id )
    id = validateIsni( id )
    if not id then
        return false
    end
    id = id:sub( 1, 4 ) .. '-' .. id:sub( 5, 8 ) .. '-'  .. id:sub( 9, 12 ) .. '-'  .. id:sub( 13, 16 )
    return '[http://orcid.org/' .. id .. ' ' .. id .. ']' .. getCatForId( 'ORCID' )
end

local function gndLink( id )
    return '[http://d-nb.info/gnd/' .. id .. ' ' .. id .. ']' .. getCatForId( 'GND' )
end

local function selibrLink( id )
	if not string.match( id, '^%d+$' ) then
        return false
    end
    return '[//libris.kb.se/auth/' .. id .. ' ' .. id .. ']' .. getCatForId( 'SELIBR' )
end

local function bnfLink( id )
    --Add cb prefix if it has been removed
    if not string.match( id, '^cb.+$' ) then
        id = 'cb' .. id
    end

    return '[http://catalogue.bnf.fr/ark:/12148/' .. id .. ' ' .. id .. '] [http://data.bnf.fr/ark:/12148/' .. id .. ' (data)]' .. getCatForId( 'BNF' )
end

local function bpnLink( id )
    if not string.match( id, '^%d+$' ) then
        return false
    end
    return '[http://www.biografischportaal.nl/en/persoon/' .. id .. ' ' .. id .. ']' .. getCatForId( 'BPN' )
end

local function ridLink( id )
    return '[http://www.researcherid.com/rid/' .. id .. ' ' .. id .. ']' .. getCatForId( 'RID' )
end

local function bibsysLink( id )
    return '[http://ask.bibsys.no/ask/action/result?cmd=&kilde=biblio&cql=bs.autid+%3D+' .. id .. '&feltselect=bs.autid ' .. id .. ']' .. getCatForId( 'BIBSYS' )
end

local function ulanLink( id )
    return '[//www.getty.edu/vow/ULANFullDisplay?find=&role=&nation=&subjectid=' .. id .. ' ' .. id .. ']' .. getCatForId( 'ULAN' )
end

local function nlaLink( id )
	return '[//nla.gov.au/anbd.aut-an' .. id .. ' ' .. id .. ']' .. getCatForId( 'NLA' )
end
local function Ar_Ontology_Link( id )
	return '[///ontology.birzeit.edu/concept/' .. id .. ' ' .. id .. ']' .. getCatForId( 'Arabic Ontology ID' )
end

local function rkdartistsLink( id )
	return '[https://rkd.nl/en/explore/artists/' .. id .. ' ' .. id .. ']' .. getCatForId( 'RKDartists' )
end

local function getIdsFromWikidata( item, property )
    local ids = {}
    if not item.claims[property] then
        return ids
    end
    for _, statement in pairs( item:getBestStatements( property )) do
		if statement.mainsnak.datavalue then
			table.insert( ids, statement.mainsnak.datavalue.value )
		end
    end
    return ids
end

local function matchesWikidataRequirements( item, reqs )
    for _, group in pairs( reqs ) do
        local property = 'p' .. group[1]
        local qid = group[2]
        if item.claims[property] ~= nil then
            for _, statement in pairs ( item.claims[property] ) do
            	if statement.mainsnak.datavalue ~= nil then
	                if statement.mainsnak.datavalue.value['numeric-id'] == qid then
    	                return true
        	        end
        	    end
            end
        end
    end
    return false
end

local function createRow( id, label, rawValue, link, withUid )
    if link then
        if withUid then
            return '* ' .. label .. ' <span class="uid">' .. link .. '</span>\n'
        else
            return '* ' .. label .. ' ' .. link .. '\n'
        end
    else
        return '* <span class="error">The ' .. id .. ' id ' .. rawValue .. ' is not valid.</span>[[Category:Wikipedia articles with faulty authority control identifiers (' .. id .. ')]]\n'
    end
end

local function link_8189( id )
    return '[http://uli.nli.org.il/F/?func=find-b&local_base=NLX10&find_code=UID&request=' .. id ..' ' .. id .. ']' .. getCatForId( 'J9U' )
end

--In this order: name of the parameter, label, propertyId in Wikidata, formatting function
local conf = {
	{ 'BAUID', '[[جامعة بيروت العربية|BAUID]]', 9504, BAUID_link },
	{ 'AUBID', '[[الجامعة الأميركية في بيروت|AUBID]]', 9409, AUBID_link },
	{ 'AAG', '[[:en:Auckland Art Gallery Toi o Tāmaki|AAG]]', 3372, aagLink },
    { 'LNL', '[[المكتبة الوطنية اللبنانية|LNL]]', 7026, LNLLink },
	{ 'ACM-DL', '[[:en:ACM Digital Library|ACM DL]]', 864, acmLink },
	{ 'ADB', '[[:en:Australian Dictionary of Biography|ADB]]', 1907, adbLink },
	{ 'AGSA', '[[:en:Art Gallery of South Australia|AGSA]]', 6804, agsaLink },
	{ 'Arabic Ontology ID', '[[الأنطولوجيا العربية|Arabic Ontology ID]]' , 6771, Ar_Ontology_Link },    
	{ 'autores.uy', '[[:en:autores.uy]]', 2558, autoresuyLink },
	{ 'AWR', '[[:en:Australian Women\'s Register|AWR]]', 4186, awrLink },
	{ 'BALaT', '[[:en:Royal Institute for Cultural Heritage#Online artworks pages|BALaT]]', 3293, balatLink },
	{ 'BIBSYS', '[[:en:Bibsys|BIBSYS]]', 1015, bibsysLink },
	{ 'Bildindex', '[[:en:Marburg Picture Index|Bildindex]]', 2092, bildLink },
	{ 'BNC', '[[:en:Biblioteca Nacional de Chile|BNC]]', 1890, bncLink },
	{ 'BNE', '[[المكتبة الوطنية الإسبانية|BNE]]', 950, bneLink },
	{ 'BNF', '[[المكتبة الوطنية الفرنسية|BNF]]', 268, bnfLink },
	{ 'Botanist', '[[:en:Author citation (botany)|Botanist]]', 428, botanistLink },
	{ 'BPN', '[[:en:Biografisch Portaal|BPN]]', 651, bpnLink },
	{ 'CANTIC', '[[:en:Name and Title Authority File of Catalonia|CANTIC]]', 1273, canticLink },
	{ 'CINII', '[[سايني|CiNii]]', 271, ciniiLink },
	{ 'DAAO', '[[:en:Dictionary of Australian Artists|DAAO]]', 1707, daaoLink },
	{ 'DBLP', '[[:en:DBLP|DBLP]]', 2456, dblpLink },
	{ 'DSI', '[[:en:Stuttgart Database of Scientific Illustrators 1450–1950|DSI]]', 2349, dsiLink },
	{ 'EGAXA', '[[مكتبة الإسكندرية الجديدة|EGAXA]]', 1309, egaxaLink },
	{ 'FNZA', '[[:d:Property:P6792|FNZA]]', 6792, fnzaLink },
	{ 'GND', '[[ملف الضبط الاستنادي المتكامل|GND]]', 227, gndLink },
	{ 'HDS', '[[قاموس سويسرا التاريخي|HDS]]', 902, hlsLink },
	{ 'IAAF', '[[:en:World Athletics|World Athletics]]', 1146, iaafLink },
	{ 'ICIA', '[[:en:Information Center for Israeli Art|ICIA]]', 1736, iciaLink },
	{ 'ISNI', '[[معرف الاسم المعياري الدولي|ISNI]]', 213, isniLink },
	{ 'IPNI', 'IPNI', 586, IPNILink } ,
	{ 'Joconde', '[[:en:Joconde|Joconde]]' , 347, jocondeLink },
	{ 'KULTURNAV', '[[:en:KulturNav|KulturNav]]', 1248, kulturnavLink },
	{ 'LCCN', '[[رقم الضبط في مكتبة الكونغرس|LCCN]]', 244, lccnLink },
	{ 'LIR', '[[:en:Historical Dictionary of Switzerland#Lexicon_Istoric_Retic|LIR]]', 886, lirLink },
	{ 'LNB', '[[:en:National Library of Latvia|LNB]]', 1368, lnbLink },
	{ 'Léonore', '[[:en:Base Léonore|Léonore]]', 640, leonoreLink },
	{ 'MBA', '[[ميوزك برينز|MusicBrainz]]', 434, mbLink },
	{ 'MBAREA', '[[ميوزك برينز|MusicBrainz]]', 982, mbareaLink }, 
	{ 'MBI', '[[ميوزك برينز|MusicBrainz]]', 1330, mbiLink }, 
	{ 'MBL', '[[ميوزك برينز|MusicBrainz]]', 966, mblLink }, 
	{ 'MBP', '[[ميوزك برينز|MusicBrainz]]', 1004, mbpLink }, 
	{ 'MBRG', '[[ميوزك برينز|MusicBrainz]] release group', 436, mbrgLink }, 
	{ 'MBS', '[[ميوزك برينز|MusicBrainz]]', 1407, mbsLink }, 
	{ 'MBW', '[[ميوزك برينز|MusicBrainz]] work', 435, mbwLink}, 
	{ 'MGP', '[[مشروع إحصاء علماء الرياضيات|MGP]]', 549, mgpLink },    
	{ 'NARA', '[[إدارة الأرشيف والوثائق الوطنية|NARA]]', 1225, naraLink },
	--{ 'NARA-person', '[[إدارة الأرشيف والوثائق الوطنية|NARA]]', 1222, narapersonLink },
	{ 'NARA-organization', '[[إدارة الأرشيف والوثائق الوطنية|NARA]]', 1225, naraorganizationLink },
	{ 'NCL', '[[:en:National Central Library|NCL]]', 1048, nclLink },
	{ 'NDL', '[[مكتبة البرلمان الوطني|NDL]]', 349, ndlLink },
	{ 'NGV', '[[:en:National Gallery of Victoria|NGV]]', 2041, ngvLink },
	{ 'NKC', '[[المكتبة الوطنية لجمهورية التشيك|NKC]]', 691, nkcLink },
	{ 'NLA', '[[المكتبة الوطنية الأسترالية|NLA]]', 409, nlaLink },
	{ 'NLG', '[[:en:National Library of Greece|NLG]]', 3348, nlgLink },
	{ 'NLI', '[[:en:National Library of Israel|NLI]]', 949, nliLink },
	{ 'NLK', '[[:en:National Library of Korea|NLK]]', 5034, nlkLink },
	{ 'NLP', '[[المكتبة الوطنية البولندية|NLP]]', 1695, nlpLink },
	{ 'NLR', '[[:en:National Library of Romania|NLR]]', 1003, nlrLink },
	{ 'NSK', '[[:en:National and University Library in Zagreb|NSK]]', 1375, nskLink },
	{ 'NTA', '[[المكتبة الوطنية في هولندا|NTA]]', 1006, ntaLink },
	{ 'ORCID', '[[المعرف المفتوح للباحثين والمساهمين|ORCID]]', 496, orcidLink },
	{ 'PIC', '[[:d:Q23892012|PIC]]', 2750, picLink },
	{ 'RID', '[[معرف الباحث|ResearcherID]]', 1053, ridLink },
	{ 'RERO', '[[:en:RERO (Library Network of Western Switzerland)|RERO]]', 3065, reroLink },
	{ 'RKDartists', '[[:en:Netherlands Institute for Art History#Online artist pages|RKD]]', 650, rkdartistsLink },
	{ 'RKDID', '[[:d:Q17299580|RKDimages ID]]', 350, rkdidLink },
	{ 'RLS', '[[المكتبة الوطنية الروسية|RLS]]', 947, rslLink },
	{ 'RSL', '[[مكتبة دولة روسيا|RSL]]', 947, rslLink },
	{ 'SBN', '[[:en:ICCU (identifier)|ICCU]]', 396, sbnLink },
	{ 'SELIBR', '[[ليبريس|SELIBR]]', 906, selibrLink },
	{ 'SIKART', '[[:en:SIKART|SIKART]]', 781, sikartLink },
	{ 'SNAC-ID', '[[:en:SNAC|SNAC]]', 3430, snacLink },
	{ 'SUDOC', '[[:en:SUDOC (identifier)|SUDOC]]', 269, sudocLink },
	{ 'S2AuthorId', '[[:en:Semantic Scholar|S2AuthorId]]', 4012, s2authoridLink}, 
	{ 'TA98', '[[:en:Terminologia Anatomica|TA98]]', 1323, ta98Link },
	{ 'TDVİA', '[[:d:Q21527102|TDVİA]]', 7314, tdviaLink },
	{ 'TE', '[[:en:Terminologia Embryologica|TE]]', 1693, teLink },
	{ 'TePapa', '[[:en:Museum of New Zealand Te Papa Tongarewa|TePapa]]', 3544, tepapaLink },
	{ 'TH', '[[:en:Terminologia Histologica|TH]]', 1694, thLink },
	{ 'TLS', '[[:en:Theaterlexikon der Schweiz|TLS]]', 1362, tlsLink },
	{ 'Trove', '[[:en:Trove|Trove]]', 1315, troveLink },
	{ 'ULAN', '[[قائمة الاتحاد لأسماء الفنانين|ULAN]]', 245, ulanLink },
	{ 'USCongress', '[[:en:Biographical Directory of the United States Congress|US Congress]]', 1157, uscongressLink },
	{ 'UNDocument', 'UN Document', 3069, UNdocumentsymbol},
	{ 'VIAF', '[[ملف الضبط الاستنادي الدولي الافتراضي|VIAF]]', 214, viafLink },
	{ 'WORLDCATID', '[[:en:WorldCat Identities|WorldCat Identities]]', 7859, nil },
	{ 'J9U', 'J9U' ,  8189, link_8189 },
}

-- Legitimate aliases to p.conf, for convenience
-- Format: { 'alias', 'parameter name in p.conf' }
p.aliases = {
	{ 'RLS', 'RSL' },
	{ 'MusicBrainz', 'MBA' },
	{ 'MusicBrainz artist', 'MBA' },
	{ 'MusicBrainz label', 'MBL' },
	{ 'MusicBrainz release group', 'MBRG' },
	{ 'MusicBrainz work', 'MBW' },
	{ 'Leonore', 'Léonore' },
	{ 'TDVIA', 'TDVİA' },
}

-- Deprecated aliases to p.conf; tracked in [[Category:Wikipedia articles with deprecated authority control identifiers]]
-- Format: { 'deprecated parameter name', 'replacement parameter name in p.conf' }
p.deprecated = {
	{ 'GKD', 'GND' },
	{ 'PND', 'GND' },
	{ 'SWD', 'GND' },
	{ 'NARA-organization', 'NARA' },
	{ 'NARA-person', 'NARA' },
}

for _, params in pairs( conf ) do
    if params[3] ~= 0 then
        properties_id[params[1]] = "P" .. params[3]
    end
end

-- Check that the Wikidata item has this property-->value before adding it
local reqs = {}

function p.authorityControl( frame )
    local parentArgs = frame:getParent().args
    local qid = frame:getParent().args.id or frame.args.id or nil
    --Create rows
    local elements = {}
	local worldcatCat = ''
	local suppressedIdCat = ''
	local deprecatedIdCat = ''

	--Redirect aliases to proper parameter names
	for _, a in pairs( p.aliases ) do
		local alias, param = a[1], a[2]
		
		if (parentArgs[param] == nil or parentArgs[param] == '') and parentArgs[alias] ~= nil and parentArgs[alias] ~= '' then
			parentArgs[param] = parentArgs[alias]
		end
	end
	
	--Redirect deprecated parameters to proper parameter names, and assign tracking cat
	for _, d in pairs( p.deprecated ) do
		local dep, param = d[1], d[2]
		if (parentArgs[param] == nil or parentArgs[param] == '') and parentArgs[dep] ~= nil and parentArgs[dep] ~= '' then
			parentArgs[param] = parentArgs[dep]
			if namespace == 0 then
				deprecatedIdCat = '[[Category:Wikipedia articles with deprecated authority control identifiers|'..dep..']]'
			end
		end
	end

    --redirect PND to GND
    if (parentArgs.GND == nil or parentArgs.GND == '') and parentArgs.PND ~= nil and parentArgs.PND ~= '' then
        parentArgs.GND = parentArgs.PND
    end

    --Wikidata fallback if requested
    local item = mw.wikibase.getEntityObject( qid )
    if item ~= nil and item.claims ~= nil then
        for _, params in pairs( conf ) do
            if params[3] ~= 0 then
                local val = parentArgs[params[1]]
                if not val or val == '' then
                	local canUseWikidata = nil
                    if reqs[params[1]] ~= nil then
                        canUseWikidata = matchesWikidataRequirements( item, reqs[params[1]] )
                    else
                        canUseWikidata = true
                    end
                    if canUseWikidata then
                        local wikidataIds = getIdsFromWikidata( item, 'P' .. params[3] )
                        if wikidataIds[1] then
                            parentArgs[params[1]] = wikidataIds[1]
                        end
                    end
                end
            end
        end
    end

    --Worldcat
    if parentArgs['WORLDCATID'] and parentArgs['WORLDCATID'] ~= '' then
        table.insert( elements, createRow( 'WORLDCATID', '', parentArgs['WORLDCATID'], '[//www.worldcat.org/identities/' .. parentArgs['WORLDCATID'] .. ' WorldCat]', false ) ) --Validation?
    elseif parentArgs['LCCN'] and parentArgs['LCCN'] ~= '' then
        local lccnParts = splitLccn( parentArgs['LCCN'] )
        if lccnParts and lccnParts[1] ~= 'sh' then
            table.insert( elements, createRow( 'LCCN', '', parentArgs['LCCN'], '[//www.worldcat.org/identities/lccn-' .. lccnParts[1] .. lccnParts[2] .. '-' .. lccnParts[3] .. ' WorldCat]', false ) )
        end
    end

	--Configured rows
	local rct = 0
	for _, params in pairs( conf ) do
		local val = parentArgs[params[1]]
		if val and val ~= '' and type(params[4]) == 'function' then
			table.insert( elements, createRow( params[1], params[2]..':', val, params[4]( val ), true, params.category ) )
			rct = rct + 1
		end
	end

    local Navbox = require('Module:Navbox')
    local elementscats = ''
    if rct > 13 then
    	----elementscats  = '[[Category:AC with ' .. rct .. ' elements]]'
	end
	
	if #elements ~= 0 then
		return Navbox._navbox( {
			name  = 'Authority control',
			navboxclass = 'authority-control',
			bodyclass = 'hlist',
			group1 = '[[ضبط استنادي]]' .. elementscats,
			list1style  = 'text-align:left;', 
			list1 = table.concat( elements )
			} )
	else
		return "[[تصنيف:قالب ضبط استنادي دون معرفات]]"
	end
end

return p