Diferencia entre revisiones de «Módulo:Control de autoridades»

De Wikipedia, la enciclopedia libre
Contenido eliminado Contenido añadido
Paso 10: configuraciones locales: filtro para BNC; doble enlace para BNF; enlace especial para INE; reemplazo para NARA; anulación de SELIBR, KVAB, ANMF, ISCO, CABA y SIPCA porque no funcionan; redirección para PND; y enlaces para WorldCat
m Arreglo error: inmediatamente antes de consultar el identificador "issn" se usa el identificador "worldcatid" [id entonces es 'issn', no 'worldcatid']
Línea 437: Línea 437:


--Worldcat
--Worldcat
if id == 'issn' and parentArgs[id..f] and parentArgs[id..f] ~= '' then -- 'issn' is the first element following the 'wikidata' item
if id == 'issn' and parentArgs['worldcatid'..f] and parentArgs['worldcatid'..f] ~= '' then -- 'issn' is the first element following the 'wikidata' item
table.insert( elements, createRow( id, '', parentArgs[id..f], '[//www.worldcat.org/identities/' .. parentArgs['worldcatid'..f] .. ' WorldCat]', false ) ) --Validation?
table.insert( elements, createRow( id, '', parentArgs['worldcatid'..f], '[//www.worldcat.org/identities/' .. parentArgs['worldcatid'..f] .. ' WorldCat]', false ) ) --Validation?
elseif id == 'viaf' and parentArgs[id..f] and string.match( parentArgs[id..f], '^%d+$' ) and not parentArgs['worldcatid'..f] then -- Hackishly copy the validation code; this should go away when we move to using P1793 and P1630
elseif id == 'viaf' and parentArgs[id..f] and string.match( parentArgs[id..f], '^%d+$' ) and not parentArgs['worldcatid'..f] then -- Hackishly copy the validation code; this should go away when we move to using P1793 and P1630
table.insert( elements, createRow( id, '', parentArgs[id..f], '[//www.worldcat.org/identities/containsVIAFID/' .. parentArgs[id..f] .. ' WorldCat]', false ) )
table.insert( elements, createRow( id, '', parentArgs[id..f], '[//www.worldcat.org/identities/containsVIAFID/' .. parentArgs[id..f] .. ' WorldCat]', false ) )

Revisión del 19:52 5 jul 2018

Icono de documentación de módulo Documentación del módulo[ver] [editar] [historial] [purgar]

A continuación se muestra la documentación transcluida desde la subpágina /doc. [salta a la caja de código]


Uso



Esta documentación está transcluida desde Módulo:Control de autoridades/doc.
Por favor, añade las categorías en la subpágina de documentación y los interwikis en Wikidata. Subpáginas de este módulo.

require('Módulo:No globals')

local function generic ( id, link, parameter )
	link = mw.ustring.gsub( link, '$1', id )
	return '[' .. link .. ' ' .. id .. ']'
end

local function bncLink ( id, link, parameter )
	-- filtro local del BNC, para evadir multitud de identificadores de Wikidata que no se enlazan adecuadamente
	-- véase https://www.wikidata.org/wiki/Wikidata:Database_reports/Constraint_violations/P1890#%22Format%22_violations
	if ( string.match( id, '^%d%d%d%d%d%d%d%d%d$' ) ) then
		return generic ( id, link, parameter )
	end
	return false
end

local function bnfLink ( id, link, parameter )
	-- representación local del BNF, con doble enlace
	return generic( id, link, parameter ) .. ' [http://data.bnf.fr/ark:/12148/cb' .. id .. ' (data)]'
end

local function ineLink ( id, link, parameter )
	-- representación especial del INE, enlace no estándar con cinco parámetros utilizados
	local ineMainRE, ineTailRE = '^(%d%d)(%d%d%d)', '(%d%d)(%d%d)(%d%d)'
	local codProv, codMuni, codEC, codES, codNUC = string.match( id, ineMainRE .. ineTailRE .. '$' )
	if not codEC or not codES or not codNUC then
		codProv, codMuni = string.match( id, ineMainRE .. '$' )
		if codProv and codMuni then
			codEC, codES, codNUC = '00', '00', '00'
		else
			codProv, codMuni = string.match( id, ineMainRE )
			codEC, codES, codNUC = '', '', ''
		end
	end
	if codProv and codMuni then
		link = 'http://www.ine.es/nomen2/inicio_a.do?accion=busquedaAvanzada&inicio=inicio_a&subaccion=&botonBusquedaAvanzada=Consultar+selecci%C3%B3n&numPag=0&ordenAnios=ASC&comunidad=00&entidad_amb=no&poblacion_amb=T&poblacion_op=%3D&poblacion_txt=&denominacion_op=like&denominacion_txt=&codProv=$1&codMuni=$2&codEC=$3&codES=$4&codNUC=$5'
		link = link:gsub('$1', codProv):gsub('$2', codMuni):gsub('$3', codEC):gsub('$4', codES):gsub('$5', codNUC)
		return generic( id, link, parameter )
	end
	return id
end

local conf = {}
--In this order: name of the parameter, label, propertyId in Wikidata, formatting function, category id
-- -- name of the parameter: unique name
-- -- label: internal link in wiki format
-- -- propertyId in Wikidata: number without 'P' suffix
-- -- formatting function: one of these four options
-- -- -- local function (like 'generic')
-- -- -- string 'y' (yes), to show a default identifier 'ID'
-- -- -- string 'n' (no), to show the real identifier
-- -- -- any other string, to show this string as identifier ('id', 'url', 'link', ...)
-- -- category id: one of these tree options
-- -- -- number 0, to not add category
-- -- -- number 1, to add a category based on the name of the parameter
-- -- -- any string, to add a category based on this string
conf.databases = {
	{ 'Wikidata', '[[Archivo:Wikidata-logo.svg|20px|link=https://www.wikidata.org/wiki/Wikidata:Main_Page|alt=Wd|Wikidata]]', 'Wikidata:$1', 'n', 0 },
	{ 'ISSN', '[[ISSN]]', 236, 'n', 1 },
	{ 'VIAF', '[[Virtual International Authority File|VIAF]]', 214, 'n', 1 },
	{ 'ISNI', '[[International Standard Name Identifier|ISNI]]', 213, 'n', 1 },

	{ 'BCN', '[[Biblioteca del Congreso de la Nación Argentina|BCN]]', 2879, 'n', 1 },
	{ 'BNA', '[[Biblioteca Nacional de la República Argentina|BNA]]', 3788, 'n', 1 },
	{ 'BNE', '[[Biblioteca Nacional de España|BNE]]', 950, 'n', 1 },
	{ 'BNF', '[[Bibliothèque nationale de France|BNF]]', 268, bnfLink, 1 },
	{ 'BNM', '[[Biblioteca Nacional de México|BNM]]', 4440, 'n', 1 },
	{ 'BNC', '[[Biblioteca Nacional de Chile|BNC]]', 1890, bncLink, 1 },
	{ 'CANTIC', '[[Biblioteca de Cataluña|CANTIC]]', 1273, 'n', 1 },
	{ 'GND', '[[Integrated Authority File|GND]]', 227, 'n', 1 },
	{ 'LCCN', '[[Library of Congress Control Number|LCCN]]', 244, 'n', 1 },
	{ 'NCL', '[[National Central Library|NCL]]', 1048, 'n', 0 },
	{ 'NDL', '[[National Diet Library|NDL]]', 349, 'n', 0 },
	{ 'NKC', '[[National Library of the Czech Republic|NKC]]', 691, 'n', 0 },
	{ 'NLA', '[[National Library of Australia|NLA]]', 409, 'n', 1 },
	{ 'RLS', '[[Biblioteca del Estado Ruso|BER]]', 947, 'n', 0 },

	{ 'CINII', '[[CiNii]]', 271, 'n', 0 },
	{ 'NARA', '[[National Archives and Records Administration|NARA]]', 1225, 'n', 0 },
	{ 'LCCNLCOC', '[[Library of Congress Control Number|LCCN]]', 1144, 'n', 0 },
	{ 'SNAC', '[[d:Q29861311|SNAC]]', 3430, 'n', 1 },

	{ 'SUDOC', '[[Système universitaire de documentation|SUDOC]]', 269, 'n', 0 },
	{ 'ULAN', '[[Union List of Artist Names|ULAN]]', 245, 'n', 1 },
	{ 'ORCID', '[[ORCID]]', 496, 'n', 1 },
	-- { 'SELIBR', '[[LIBRIS|SELIBR]]', 906, 'n', 1 },
	{ 'BIBSYS', '[[BIBSYS]]', 1015, 'n', 1 },
	{ 'UB', '[[Universidad de Barcelona|UB]]', 1580, 'n', 1 },
	{ 'IPNIaut', '[[Índice Internacional de Nombres de las Plantas|IPNI]]', 586, 'n', 'IPNI' },
	{ 'MGP', '[[Mathematics Genealogy Project|MGP]]', 549, 'n', 0 },
	{ 'autores.uy', '[[autores.uy]]', 2558, 'n', 1 },
	{ 'Slovenska biografija', '[[Slovenska biografija]]', 1254, 'n', 0 },
	{ 'SBN', '[[Istituto Centrale per il Catalogo Unico|ICCU]]', 396, 'n', 1 },

	{ 'CensoGuia', '[[Censo-Guía de Archivos de España e Iberoamérica]]', 3998, 'n', 'Censo-Guía' },
	{ 'Libraries.org', '[[Libraries.org]]', 4848, 'n', 1 },

	{ 'BOE', '[[Boletín Oficial del Estado|BOE]]', 4256, 'n', 1 },

	{ 'RoyalSociety', '[[Royal Society]]', 2070, 'url', 'Royal Society' },
	{ 'HAW', '[[Academia de Ciencias y Humanidades de Heidelberg|HAW]]', 2273, 'n', 1 },
	{ 'SAW', '[[Academia Sajona de Ciencias de Leipzig|SAW]]', 3411, 'n', 1 },
	{ 'KNAW', '[[Real Academia de Artes y Ciencias de los Países Bajos|KNAW]]', 2454, 'n', 1 },
	-- { 'KVAB', '[[Real Academia Flamenca de Ciencias y Artes de Bélgica|KVAB]]', 3887, 'n', 1 },
	{ 'Leopoldina', '[[Deutsche Akademie der Naturforscher Leopoldina|Leopoldina]]', 3413, 'n', 1 },
	{ 'CONICET', '[[CONICET]]', 3900, 'n', 1 },
	{ 'Grierson', '[[Directorio de científicos argentinos Dra. Grierson|Grierson]]', 3946, 'n', 1 },
	{ 'RANM', '[[Real Academia Nacional de Medicina|RANM]]', 3945, 'n', 1 },
	-- { 'ANMF', '[[Académie Nationale de Médecine|ANMF]]', 3956, 'n', 1 },

	{ 'Léonore', '[[Base Léonore|Léonore]]', 640, 'n', 0 },
	{ 'USCongress', '[[Biographical Directory of the United States Congress|US Congress]]', 1157, 'n', 0 },
	{ 'Auñamendi', '[[Enciclopedia Auñamendi|Auñamendi]]', 3218, 'n', 1 },
	{ 'GEA', '[[Gran Enciclopedia Aragonesa|GEA]]', 1807, 'n', 1 },
	{ 'DBSE', '[[Diccionario biográfico del socialismo español|DBSE]]', 2985, 'url', 1 },
	{ 'DBE', '[[Diccionario biográfico español|DBE]]', 4459, 'url', 1 },
	{ 'MNCARS', '[[Museo Nacional Centro de Arte Reina Sofía|MNCARS]]', 4439, 'url', 1 },
	{ 'MuseoDelPrado', '[[Museo del Prado]]', 5321, 'n', 'Museo del Prado' },

	{ 'BPN', '[[Biografisch Portaal|BPN]]', 651, 'n', 1 },
	{ 'HDS', '[[Historical Dictionary of Switzerland|HDS]]', 902, 'n', 0 },
	{ 'LIR', '[[Diccionario histórico de Suiza|LIR]]', 886, 'n', 0 },
	{ 'TLS', '[[Theaterlexikon der Schweiz|TLS]]', 1362, 'n', 0 },

	-- { 'ISCO', '[[d:Q1233766|ISCO]]', 952, 'n', 1 },
	{ 'AAT', '[[Art & Architecture Thesaurus|AAT]]', 1014, 'n', 1 },
	{ 'BDCYL', '[[Biblioteca Digital de Castilla y León|BDCYL]]', 3964, 'n', 1 },
	{ 'BVPB', '[[d:Q18596294|BVPB]]', 4802, 'n', 1 },
	{ 'BivaldiAutor', '[[Biblioteca Valenciana Digital|BiValDi]]', 3932, 'n', 'Bivaldi autor' },

	{ 'OpenLibrary', '[[Open Library]]', 648, 'n', 'Open Library' },
	{ 'GalicianaAutor', '[[Galiciana]]', 3307, 'n', 'Galiciana autor' },
	{ 'PARES', '[[PARES]]', 4813, 'n', 1 },
	{ 'BVMCpersona', '[[Biblioteca Virtual Miguel de Cervantes|BVMC]]', 2799, 'n', 'BVMC persona' },
	{ 'Persée', '[[Persée (portal)|Persée]]', 2732, 'n', 1 },
	{ 'Dialnet', '[[Dialnet]]', 1607, 'n', 1 },
	{ 'SSRN', '[[Social Science Research Network|SSRN]]', 3747, 'n', 'SSRN autor' },
	{ 'GutenbergAutor', '[[Proyecto Gutenberg]]', 1938, 'n', 'Proyecto Gutenberg autor' },
	{ 'UNZautor', '[[UNZ.org|UNZ]]', 2734, 'n', 'UNZ' },
	{ 'SIKART', '[[SIKART]]', 781, 'n', 0 },
	{ 'KULTURNAV', '[[KulturNav]]', 1248, 'id', 0 },
	{ 'RKDartists', '[[Rijksbureau voor Kunsthistorische Documentatie|RKD]]', 650, 'n', 1 },
	{ 'GoogleScholar', '[[Google Académico]]', 1960, 'n', 'Google Académico' },
	{ 'RID', '[[ResearcherID]]', 1053, 'n', 1 },

	{ 'BVMCobra', '[[Biblioteca Virtual Miguel de Cervantes|BVMC]]', 3976, 'n', 'BVMC obra' },
	{ 'NLM', '[[Biblioteca Nacional de Medicina de los Estados Unidos|NLM]]', 1055, 'n', 1 },
	{ 'Latindex', '[[Latindex]]', 3127, 'n', 1 },
	{ 'ERIH PLUS', '[[ERIH PLUS]]', 3434, 'n', 1 },
	{ 'IPNIpub', '[[Índice Internacional de Nombres de las Plantas|IPNI]]', 2008, 'n', 1 },
	{ 'SUDOCcat', '[[Système universitaire de documentation|SUDOC]]', 1025, 'n', 'SUDOC catálogo' },
	{ 'ZDB', '[[Zeitschriftendatenbank|ZDB]]', 1042, 'n', 1 },
	{ 'NorwegianRegister', '[[Norsk senter for forskningsdata|Norwegian Register]]', 1270, 'n', 'Norwegian Register' },
	{ 'PerséeRevista', '[[Persée (portal)|Persée]]', 2733, 'n', 'Persée revista' },
	{ 'DialnetRevista', '[[Dialnet]]', 1609, 'n', 'Dialnet revista' },
	{ 'Redalyc', '[[Redalyc]]', 3131, 'n', 1 },
	{ 'DOAJ', '[[Directory of Open Access Journals|DOAJ]]', 5115, 'n', 1 },
	{ 'UNZrevista', '[[UNZ.org|UNZ]]', 2735, 'n', 0 },
	{ 'JSTORrevista', '[[JSTOR]]', 1230, 'n', 'JSTOR revista' },
	{ 'HathiTrust', '[[HathiTrust]]', 1844, 'n', 1 },
	{ 'HemBNE', '[[Hemeroteca Digital de la Biblioteca Nacional de España|Hemeroteca BNE]]', 2768, 'n', 1 },
	{ 'BVPH', '[[Biblioteca Virtual de Prensa Histórica|BVPH]]', 2961, 'n', 1 },
	{ 'Galicianaobra', '[[Galiciana]]', 3004, 'n', 'Galiciana obra' },

	{ 'INE', '[[Instituto Nacional de Estadística (España)|INE]]', 772, ineLink, 1 },
	{ 'TGN', '[[Getty Thesaurus of Geographic Names|TGN]]', 1667, 'n', 1 },
	{ 'SNCZI-IPE-EMBALSE', '[[Sistema Nacional de Cartografía de Zonas Inundables|SNCZI]]-[[Inventario de Presas y Embalses de España|IPE]]', 4568, 'n', 'SNCZI-IPE embalse' },
	{ 'SNCZI-IPE-PRESA', '[[Sistema Nacional de Cartografía de Zonas Inundables|SNCZI]]-[[Inventario de Presas y Embalses de España|IPE]]', 4558, 'n', 'SNCZI-IPE presa' },
	{ 'NATURA2000', '[[Red Natura 2000|Natura 2000]]', 3425, 'n', 'Natura 2000' },
	{ 'WWF', '[[Fondo Mundial para la Naturaleza|WWF]]', 1294, 'n', 1 },

	{ 'HCDN', '[[Cámara de Diputados de la Nación Argentina|Estadísticas HCDN]]', 4693, 'n', 1 },
	{ 'HCDNbio', '[[Cámara de Diputados de la Nación Argentina|Biografía HCDN]]', 5225, 'n', 1 },
	-- { 'Legislatura CABA', '[[Legislatura de la Ciudad de Buenos Aires|Legislatura CABA]]', 4667, 'n', 1 },
	{ 'Asamblea de Madrid', '[[Asamblea de Madrid]]', 4797, 'n', 1 },

	{ 'World Heritage Site', '[[Patrimonio de la Humanidad]]', 757, 'n', 'Centro del Patrimonio Mundial' },
	{ 'CNMLBH', '[[Comisión Nacional de Monumentos, de Lugares y de Bienes Históricos|CNMLBH]]', 4587, 'n', 'cnmlbh' },
	{ 'IGESPAR', '[[Instituto de Gestão do Património Arquitectónico e Arqueológico|IGESPAR]]', 1702, 'n', 1 },
	{ 'SIPA', '[[Sistema de Informação para o Património Arquitectónico|SIPA]]', 1700, 'n', 1 },
	{ 'Infopatrimonio', '[[Infopatrimônio]]', 4372, 'n', 'Infopatrimônio' },
	{ 'AustriaObjektID', '[[Austria ObjektID]]', 2951,  'n', 'Austria ObjektID' },
	{ 'FBBID', '[[Fredede og Bevaringsværdige Bygninger|FBB]]', 2783,  'n', 'FBB' },
	{ 'Fornminnesregistret', '[[Fornminnesregistret|FMIS]]', 1260,  'n', 'FMIS' },
	{ 'BerlinerKulturdenkmal', 'Berliner Kulturdenkmal', 2424, 'n', 'Berliner Kulturdenkmal' },
	{ 'NHLE', '[[National Heritage List for England|NHLE]]', 1216, 'n', 1 },
	{ 'NRHP', '[[Registro Nacional de Lugares Históricos|NRHP]]', 649, 'n', 1 },
	{ 'KULTURMINNE', '[[Riksantikvaren|Kulturminne]]', 758, 'n', 'Kulturminne' },
	{ 'CRHP', '[[Canadian Register of Historic Places|CRHP]]', 477, 'n', 1 },
	{ 'MERIMEE', '[[Base Mérimée|Mérimée]]', 380, 'n', 'Mérimée' },
	{ 'CADW', '[[Cadw]]', 1459, 'n', 'Cadw' },
	{ 'Památkový Katalog', '[[Památkový katalog]]', 762, 'n', 'Památkový katalog' },
	{ 'PatrimonioIran', 'Patrimonio Nacional de Irán', 1369, 'n', 'Patrimonio Nacional de Irán' },
	{ 'BIC', '[[Bien de Interés Cultural (España)|BIC]]', 808, 'n', 1 },
	{ 'BCIN', '[[Bien Cultural de Interés Nacional|BCIN]]', 1586, 'n', 1 },
	{ 'IPAC', '[[Inventario del Patrimonio Arquitectónico de Cataluña|IPAC]]', 1600, 'n', 1 },
	{ 'IGPCV', '[[Inventario General del Patrimonio Cultural Valenciano|IGPCV]]', 2473, 'n', 1 },
	{ 'BDI-IAPH', '[[Instituto Andaluz del Patrimonio Histórico|IAPH]]', 3318, 'n', 1 },
	-- { 'SIPCA', '[[SIPCA]]', 3580, 'n', 1 },
	{ 'PWJCYL', '[[Junta de Castilla y León|Patrimonio Web JCyL]]', 3177, 'n', 'Patrimonio Web JCyL' },
	{ 'DocomomoIberico', '[[Fundación Docomomo Ibérico|Docomomo Ibérico]]', 3758, 'n', 'Docomomo Ibérico' },
	{ 'COAMinmueble', '[[Colegio Oficial de Arquitectos de Madrid|COAM]]', 2917, 'n', 'COAM inmueble' },
	{ 'HispaniaNostra', '[[Lista roja de patrimonio en peligro|Lista Roja Hispania Nostra]]', 4868, 'url', 'Lista Roja Hispania Nostra' },
	{ 'COAMpersona', '[[Colegio Oficial de Arquitectos de Madrid|COAM]]', 4488, 'n', 'COAM persona' },
	{ 'DOI', '[[Identificador de objeto digital|DOI]]', 356, 'n', 1 },
	{ 'Handle', '[[Sistema Handle|Handle]]', 1184, 'url', 1 },
	{ 'Europeana', '[[Europeana]]', 727, 'url', 1 },
}
--In this order: alternate name, name of parameter from databases table
conf.aliases = {
	{ 'Wd', 'Wikidata' },
	{ 'PND', 'GND' },
}

local function getCatForId( parameter, category )
	local title = mw.title.getCurrentTitle()
	local namespace = title.namespace
	if category == 0 then
		return ''
	elseif category == 1 then
		category = parameter
	end
	if namespace == 0 then
		return '[[Categoría:Wikipedia:Artículos con identificadores ' .. category .. ']]\n'
	elseif namespace == 2 and not title.isSubpage then
		return '[[Categoría:Wikipedia:Páginas de usuario con identificadores ' .. category .. ']]\n'
	else
		return '[[Categoría:Wikipedia:Páginas misceláneas con identificadores ' .. category .. ']]\n'
	end
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 getLink( property, val, mask )
	local link = ''
	if mw.ustring.find( val, '//' ) then
		link = val
	else
		if type(property) == 'number' then
			local entityObject = mw.wikibase.getEntityObject('P'..property)
			local dataType = entityObject.datatype
			if dataType == 'external-id' then
				local allStatements = entityObject:getAllStatements('P1630')
				if allStatements then
					for pos = 1, #allStatements, 1
					do
						local q = allStatements[pos].qualifiers
						if q and q.P407 and q.P407[1].datavalue.value.id == 'Q1321' then
							link = allStatements[pos].mainsnak.datavalue.value
						end
					end
				end
				if link == '' then
					local formatterURL = entityObject:getBestStatements('P1630')[1]
					if formatterURL then
						link = formatterURL.mainsnak.datavalue.value
					else
						local formatterURL = entityObject:getBestStatements('P3303')[1]
						if formatterURL then link = formatterURL.mainsnak.datavalue.value end
					end
				end
			elseif dataType == 'url' then
				local subjectItem = entityObject:getBestStatements('P1629')[1]
				if subjectItem then
					local officialWebsite = mw.wikibase.getEntityObject(subjectItem.mainsnak.datavalue.value.id):getBestStatements('P856')[1]
					if officialWebsite then
						link = officialWebsite.mainsnak.datavalue.value 
					end
				end
			elseif dataType == 'string' then
				local formatterURL = entityObject:getBestStatements('P1630')[1]
				if formatterURL then
					link = formatterURL.mainsnak.datavalue.value
				else
					local formatterURL = entityObject:getBestStatements('P3303')[1]
					if formatterURL then
						link = formatterURL.mainsnak.datavalue.value
					else
						local subjectItem = entityObject:getBestStatements('P1629')[1]
						if subjectItem then
							local officialWebsite = mw.wikibase.getEntityObject(subjectItem.mainsnak.datavalue.value.id):getBestStatements('P856')[1]
							if officialWebsite then
								link = officialWebsite.mainsnak.datavalue.value
							end
						end
					end
				end
			end
		elseif type(property) == 'string' then
			link = property
		end
	end
	link = mw.ustring.gsub(link, '^[Hh][Tt][Tt][Pp]([Ss]?)://', 'http%1://') -- fix wikidata URL
	if type(mask) == 'function' then
		return mask( val, link, property )
	end
	link = mw.ustring.gsub(link, '$1', mw.ustring.gsub( val, ' ', '%%%%20' ) or val )
	if mw.ustring.find( link, '//' ) then
		if type(mask) == 'string' then
			if mask == 'y' then
				return '['..link..' ID]'
			elseif mask == 'n' then
				return '['..link..' '..val..']'
			end
			return '['..link..' '..mask..']'
		end
	elseif link == '' then
		return val
	else
		return '[['..link..'|'..val..']]'
	end
end

local function createRow( id, label, rawValue, link, withUid )
	if link then
		if label and label ~= '' then label = label  .. ': ' end
		if withUid then
			return '* ' .. label .. '<span class="uid">' .. link .. '</span>\n'
		else
			return '* ' .. label .. link .. '\n'
		end
	else
		return '* <span class="error">El ' .. id .. ' id ' .. rawValue .. ' no es válido</span>[[Categoría:Wikipedia:Páginas con problemas en el control de autoridades]]\n'
	end
end

local function copyTable(inTable)
	if type(inTable) ~= 'table' then return inTable end
	local outTable = setmetatable({}, getmetatable(inTable))
	for key, value in pairs (inTable) do outTable[copyTable(key)] = copyTable(value) end
	return outTable
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 p = {}

function p.authorityControl( frame )
	local parentArgs = copyTable(frame:getParent().args)
	local stringArgs = false
	local fromForCount, firstRow, rowCount = 1, 0, 0
	--Cleanup args
	for k, v in pairs( frame:getParent().args ) do
		if type(k) == 'string' then
			--make args case insensitive
			local lowerk = mw.ustring.lower(k)
			if not parentArgs[lowerk] or parentArgs[lowerk] == '' then
				parentArgs[lowerk] = v
				parentArgs[k] = nil
			end
			--remap abc to abc1
			if not mw.ustring.find(lowerk, '%d$') then --if no number at end of param
				if not parentArgs[lowerk..'1'] or parentArgs[lowerk..'1'] == '' then
					parentArgs[lowerk..'1'] = v
					parentArgs[lowerk] = nil
				end
			end
			if v and v ~= '' then
				--find highest from param
				if mw.ustring.sub(lowerk,1,4) == 'from' then
					local fromNumber = tonumber(mw.ustring.sub(lowerk,5,-1))
					if fromNumber and fromNumber >= fromForCount then fromForCount = fromNumber end
				elseif mw.ustring.sub(lowerk,1,3) == 'for' then
					local forNumber = tonumber(mw.ustring.sub(lowerk,4,-1))
					if forNumber and forNumber >= fromForCount then fromForCount = forNumber end
				elseif mw.ustring.lower(v) ~= 'no' and lowerk ~= 'for' then
					stringArgs = true
				end
			end
		end
	end

	--Setup navbox
	local navboxParams = {
		name  = 'Control de autoridades',
		bodyclass = 'hlist',
		groupstyle = 'width: 12%; text-align:center;',
	}
	local itemCount = 0
	for f = 1,fromForCount,1
	do
		local elements, title = {}, {}
		--cleanup parameters
		if parentArgs['from'..f] == '' then parentArgs['from'..f] = nil end
		if parentArgs['for'..f] == '' then parentArgs['for'..f] = nil end
		--remap aliases
		for _, a in pairs( conf.aliases ) do
			local alias, name = mw.ustring.lower(a[1]), mw.ustring.lower(a[2])
			if parentArgs[alias..f] and not parentArgs[name..f] then
				parentArgs[name..f] = parentArgs[alias..f]
				parentArgs[alias..f] = nil
			end
		end

		--Fetch Wikidata item
		local item = mw.wikibase.getEntity(parentArgs['from'..f])
		local label = item and item:getLabel()
		if label and label ~= '' then
			title = mw.title.new(label)
			if not title then title = mw.title.getCurrentTitle() end
		else
			title = mw.title.getCurrentTitle()
		end

		if (not parentArgs['wikidata'..f] or parentArgs['wikidata'..f] == '') and (title.namespace == 0) then
			if parentArgs['from'..f] then parentArgs['wikidata'..f] = parentArgs['from'..f] elseif item then parentArgs['wikidata'..f] = item.id end
		end
		if title.namespace == 0 or stringArgs then --Only in the main namespace or if there are manual overrides
			for _, params in pairs( conf.databases ) do
				local id = mw.ustring.lower( params[1] )
				--Wikidata fallback if requested
				if (item ~= nil and item.claims ~= nil) and params[3] ~= 0 and (not parentArgs[id..f] or parentArgs[id..f] == '') then
					local wikidataIds = getIdsFromWikidata( item, 'P' .. params[3] )
					if wikidataIds[1] then
						parentArgs[id..f] = wikidataIds[1]
					end
				end

				--Worldcat
				if id == 'issn' and parentArgs['worldcatid'..f] and parentArgs['worldcatid'..f] ~= '' then -- 'issn' is the first element following the 'wikidata' item
					table.insert( elements, createRow( id, '', parentArgs['worldcatid'..f], '[//www.worldcat.org/identities/' .. parentArgs['worldcatid'..f] .. ' WorldCat]', false ) ) --Validation?
				elseif id == 'viaf' and parentArgs[id..f] and string.match( parentArgs[id..f], '^%d+$' ) and not parentArgs['worldcatid'..f] then -- Hackishly copy the validation code; this should go away when we move to using P1793 and P1630
					table.insert( elements, createRow( id, '', parentArgs[id..f], '[//www.worldcat.org/identities/containsVIAFID/' .. parentArgs[id..f] .. ' WorldCat]', false ) )
				elseif id == 'lccn' and parentArgs[id..f] and parentArgs[id..f] ~= '' and not parentArgs['viaf'..f] and not parentArgs['worldcatid'..f] then
					local lccnParts = splitLccn( parentArgs[id..f] )
					if lccnParts and lccnParts[1] ~= 'sh' then
						table.insert( elements, createRow( id, '', parentArgs[id..f], '[//www.worldcat.org/identities/lccn-' .. lccnParts[1] .. lccnParts[2] .. '-' .. lccnParts[3] .. ' WorldCat]', false ) )
					end
				end

				local val = parentArgs[id..f]
				if val and val ~= '' and mw.ustring.lower(val) ~= 'no' and params[3] ~= 0 then
					local link = getLink( params[3], val, params[4] )
					if link and link ~= '' then
						table.insert( elements, createRow( id, params[2], val, link, true ) .. getCatForId( params[1], params[5] or 0 ) )
						if id ~= 'wikidata' then
							itemCount = itemCount + 1
						end
					end
				end
			end

			--Generate navbox title

			if itemCount > 0 then
				rowCount = rowCount + 1
				if firstRow == 0 then firstRow = f end
				if parentArgs['for'..f] and parentArgs['for'..f] ~= '' then
					navboxParams['group'..f] = "''" .. parentArgs['for'..f] .. "''"
				else
					navboxParams['group'..f] = ''
				end
				navboxParams['list'..f] = table.concat( elements )
			end
		end
	end

	if rowCount > 0 then
		local Navbox = require('Módulo:Navbox')
		if rowCount > 1 then
			navboxParams['title'] = '[[Ayuda:Control de autoridades|Control de autoridades]]'
			--add missing names
			for f = 1,fromForCount,1
			do
				if navboxParams['group'..f] == '' then
					navboxParams['group'..f] = "''" .. mw.wikibase.getEntity(parentArgs['wikidata'..f]):getLabel().."''"
				end
			end
			if rowCount > 2 then
				navboxParams['navbar'] = 'plain'
			else
				navboxParams['state'] = 'off'
				navboxParams['navbar'] = 'off'
			end
		else
			navboxParams['group'..firstRow] = '[[Ayuda:Control de autoridades|Control de autoridades]]<br />' .. navboxParams['group'..firstRow]
		end
		if stringArgs then
			navboxParams['group1'] = navboxParams['group1'] .. '[[Categoría:Wikipedia:Páginas que utilizan control de autoridades con parámetros]]\n'
		end
		if itemCount > 13 then
			navboxParams['group1'] = navboxParams['group1'] .. '[[Categoría:Wikipedia:Control de autoridades con ' .. itemCount .. ' elementos]]\n'
		end
		return Navbox._navbox(navboxParams)
	else
		return ''
	end
end

return p