Module:Authority control: திருத்தங்களுக்கு இடையிலான வேறுபாடு

தமிழர்விக்கியிலிருந்து
Jump to navigation Jump to search
உள்ளடக்கம் நீக்கப்பட்டது உள்ளடக்கம் சேர்க்கப்பட்டது
imported>Lingam
No edit summary
imported>Lingam
No edit summary
வரிசை 1: வரிசை 1:
--[[
require('Module:No globals')
__ __ _ _ _ _ _ _ _ _ _
| \/ | ___ __| |_ _| | ___ _ / \ _ _| |_| |__ ___ _ __(_) |_ _ _ ___ ___ _ __ | |_ _ __ ___ | |
| |\/| |/ _ \ / _` | | | | |/ _ (_) / _ \| | | | __| '_ \ / _ \| '__| | __| | | | / __/ _ \| '_ \| __| '__/ _ \| |
| | | | (_) | (_| | |_| | | __/_ / ___ \ |_| | |_| | | | (_) | | | | |_| |_| | | (_| (_) | | | | |_| | | (_) | |
|_| |_|\___/ \__,_|\__,_|_|\___(_)_/ \_\__,_|\__|_| |_|\___/|_| |_|\__|\__, | \___\___/|_| |_|\__|_| \___/|_|
|___/
This module is intended to be the engine behind "Template:Authority control".


Please do not modify this code without applying the changes first at "Module:Authority control/sandbox" and testing
local p = {}
at "Module:Authority control/testcases".


Authors and maintainers:
--[[==========================================================================]]
* User:Jarekt - original version
--[[ Category functions ]]
--[[==========================================================================]]


]]
function p.getCatForId( id )
local title = mw.title.getCurrentTitle()
local namespace = title.namespace
local catName = ''
if namespace == 0 then
catName = 'Wikipedia articles with ' .. id .. ' identifiers'
elseif namespace == 2 and not title.isSubpage then
catName = 'User pages with ' .. id .. ' identifiers'
else
catName = 'Miscellaneous pages with ' .. id .. ' identifiers'
end
return '[[Category:' .. catName .. ']]' .. p.redCatLink(catName)
end


local properties = require('Module:Authority control/conf')
function p.redCatLink( catName ) --catName == 'Blah', not 'Category:Blah', not '[[Category:Blah]]'
local core = require('Module:Core')
if catName and catName ~= '' and mw.title.new(catName, 14).exists == false then
return '[[Category:Pages with red-linked authority control categories]]'
end
return ''
end


--[[==========================================================================]]
-- ==================================================
-- === Internal functions ===========================
--[[ Property formatting functions ]]
--[[==========================================================================]]
-- ==================================================


function p.iaafLink( id )
local function getSitelink(item, lang)
-- get item's siteling in specific language
--P1146's format regex: [1-9][0-9]* (e.g. 123)
local langList = mw.language.getFallbacksFor(lang)
if not string.match( id, '^[1-9]%d*$' ) then
table.insert(langList, 1, lang)
return false
for _, language in ipairs(langList) do
local sitelink = mw.wikibase.sitelink( item, language .. 'wiki' )
if sitelink then
return 'w:'.. language ..':'.. sitelink
end
end
end
return nil
return '[https://www.iaaf.org/athletes/biographies/athcode='..id..' '..id..']'..p.getCatForId( 'IAAF' )
end
end


-- ==================================================
function p.viafLink( id )
local function getIdentifierNameLink( lang, item1, item2, label )
--P214's format regex: [1-9]\d(\d{0,7}|\d{17,20}) (e.g. 123456789, 1234567890123456789012)
-- Identifier names, like VIAF, LCCN, ISNI, need to be linked to the articles about them if possible
if not string.match( id, '^[1-9]%d%d?%d?%d?%d?%d?%d?%d?$' ) and
-- Alternativly they can be linked to the articles for institutions that issue them
not string.match( id, '^[1-9]%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d?%d?%d?$' ) then
local id_name_URL = nil
return false
-- 1) try wikipedia sitelink for the identifier in users language and in English
if item1 and item1 ~='' then
id_name_URL = getSitelink(item1, lang)
end
end
-- 2) try wikipedia sitelink for the issuedBy property in users language and in English
return '[https://viaf.org/viaf/'..id..' '..id..']'..p.getCatForId( 'VIAF' )
if id_name_URL==nil and item2 and item2 ~='' then -- if no link than
end
id_name_URL = getSitelink(item2, lang)

function p.kulturnavLink( id )
--P1248'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 string.match( id, '^%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
end
-- 3) if still no links than link to wikidata
return '[http://kulturnav.org/'..id..' '..id..']'..p.getCatForId( 'KULTURNAV' ) --no https yet (10/2018)
if id_name_URL then
end
return string.format("[[%s|%s]]", id_name_URL, label) -- link to wikipedia

else
function p.sikartLink( id )
return string.format("[[d:%s|%s]]", item1, label) -- link to wikidata
--P781's format regex: \d{7,9} (e.g. 123456789)
if not string.match( id, '^%d%d%d%d%d%d%d%d?%d?$' ) then
return false
end
end
return '[http://www.sikart.ch/KuenstlerInnen.aspx?id='..id..'&lng=en '..id..']'..p.getCatForId( 'SIKART' ) --no https yet (10/2018)
end
end


-- ==================================================
function p.tlsLink( id )
-- Create link to a single identifier
local id2 = id:gsub(' +', '_')
-- INPUTS:
--P1362's format regex: \p{Lu}[\p{L}\d_',\.\-\(\)\*/–]{3,59} (e.g. Abcd)
-- * val - value of the identifier
local class = "[%a%d_',%.%-%(%)%*/–]"
-- * P - property record, with URL_format and optional interwiki_format strings to create links
local regex = "^%u"..string.rep(class, 3)..string.rep(class.."?", 56).."$"
-- * params - additional parameters related to this type of identifiers. Single item from "conf"
if not mw.ustring.match( id2, regex ) then
-- * color - color of the link
return false
local function getIdentifierValLink(val, P, params, color)
if not val or val=='' then
return ''
end
end
-- check if identifier is in the right format
return '[http://tls.theaterwissenschaft.ch/wiki/'..id2..' '..id..']'..p.getCatForId( 'TLS' ) --no https yet (10/2018)
local mismatchStr = ''
end
local val_ = val:gsub( ' ', '' ) -- remove spaces

if (params.regexp and not val:match( params.regexp )) then
function p.ciniiLink( id )
mismatchStr = string.format("<span style=\"color:red\">[does not match %s pattern]</span>", params.regexp)
--P271's format regex: DA\d{7}[\dX] (e.g. DA12345678)
elseif (params.verify) then -- check if special "Verify" function is present
if not string.match( id, '^DA%d%d%d%d%d%d%d[%dX]$' ) then
mismatchStr = params.verify(val_) -- add error message if any
return false
end
end
-- identifier_value_URL
return '[https://ci.nii.ac.jp/author/'..id..'?l=en '..id..']'..p.getCatForId( 'CINII' )
if color~="blue" then
end
val = string.format('<span style=\"color:%s\">%s</span>', color, val)

function p.bneLink( id )
--P950's format regex: (XX|FF|a)\d{4,7}|(bima|bimo|bica|bis[eo]|bivi|Mise|Mimo|Mima)\d{10} (e.g. XX1234567)
if not string.match( id, '^[XF][XF]%d%d%d%d%d?%d?%d?$' ) and
not string.match( id, '^a%d%d%d%d%d?%d?%d?$' ) and
not string.match( id, '^bi[mcsv][aoei]%d%d%d%d%d%d%d%d%d%d$' ) and
not string.match( id, '^Mi[sm][eoa]%d%d%d%d%d%d%d%d%d%d$' ) then
return false
end
end
local val_link
return '[http://catalogo.bne.es/uhtbin/authoritybrowse.cgi?action=display&authority_id='..id..' '..id..']'..p.getCatForId( 'BNE' ) --no https yet (10/2018)
if P.interwiki_format and P.interwiki_format ~= '' then
end
val_link = string.format("[[%s:%s|%s]]", P.interwiki_format, val_, val)

else
function p.uscongressLink( id )
local val_URL = P.URL_format:gsub('$1', val_)-- URL part of the link for the identifier value
--P1157's format regex: [A-Z]00[01]\d{3} (e.g. A000123)
val_link = string.format("[%s %s]", val_URL, val)
if not string.match( id, '^[A-Z]00[01]%d%d%d$' ) then
return false
end
end
return string.format("<span class=\"plainlinks\">%s</span>%s", val_link, mismatchStr) -- link to the identifier's website
return '[http://bioguide.congress.gov/scripts/biodisplay.pl?index='..id..' '..id..']'..p.getCatForId( 'USCongress' ) --no https yet (10/2018)
end
end


-- ==================================================
function p.naraLink( id )
-- Convert between 2 formats of LCCN: "n/79/63767" -> "n79063767"
--P1225's format regex: ^([1-9]\d{0,7})$ (e.g. 12345678)
-- "n/79/63767" format was used as input by {{Authority Control}} templates
if not string.match( id, '^[1-9]%d?%d?%d?%d?%d?%d?%d?$' ) then
-- "n79063767" format is used by wikidata
return false
local function fixLCCN(id)
end
if id then
return '[https://catalog.archives.gov/id/'..id..' '..id..']'..p.getCatForId( 'NARA' )
local a, b, c = string.match(id, "([%a%d]*)/([%a%d]*)/([%a%d]*)")
end
if c then

local pad = 6 - string.len(c)
function p.botanistLink( id )
if pad > 0 then
--P428's format regex: ('t )?(d')?(de )?(la )?(van (der )?)?(Ma?c)?(De)?(Di)?\p{Lu}?C?['\p{Ll}]*([-'. ]*(van )?(y )?(d[ae][nr]?[- ])?(Ma?c)?[\p{Lu}bht]?C?['\p{Ll}]*)*\.? ?f?\.? (e.g. L.)
c = string.rep("0", pad)..c
--not easily/meaningfully implementable in Lua's regex since "(this)?" is not allowed...
end
if not mw.ustring.match( id, "^[%u%l%d%. '-]+$" ) then --better than nothing
id = a..b..c
return false
end
end
local id2 = id:gsub(' +', '%%20')
return '[https://www.ipni.org/ipni/advAuthorSearch.do?find_abbreviation='..id2..' '..id..']'..p.getCatForId( 'Botanist' )
end

function p.mgpLink( id )
--P549's format regex: \d{1,6} (e.g. 123456)
if not string.match( id, '^%d%d?%d?%d?%d?%d?$' ) then
return false
end
return '[http://www.genealogy.ams.org/id.php?id='..id..' '..id..']'..p.getCatForId( 'MGP' ) --no https yet (10/2018)
end

function p.rslLink( id )
--P947's format regex: \d{1,9} (e.g. 123456789)
if not string.match( id, '^%d%d?%d?%d?%d?%d?%d?%d?%d?$' ) then
return false
end
return '[http://aleph.rsl.ru/F?func=find-b&find_code=SYS&adjacent=Y&local_base=RSL11&request='..id..'&CON_LNG=ENG '..id..']'..p.getCatForId( 'RSL' ) --no https yet (10/2018)
end

function p.leonoreLink( id )
--P640's format regex: LH/\d{1,4}/\d{1,3}|19800035/\d{1,4}/\d{1,5}(Bis)?|C/0/\d{1,2} (e.g. LH/2064/18)
if not id:match( '^LH/%d%d?%d?%d?/%d%d?%d?$' ) and --IDs from LH/1/1 to LH/2794/54 (legionaries)
not id:match( '^19800035/%d%d?%d?%d?/%d%d?%d?%d?%d?$' ) and --IDs from 19800035/1/1 to 19800035/385/51670 (legionnaires who died 1954-1977 & some who died < 1954)
not id:match( '^C/0/%d%d?$' ) then --IDs from C/0/1 to C/0/84 (84 famous legionaries)
return false
end
return '[http://www.culture.gouv.fr/public/mistral/leonore_fr?ACTION=CHERCHER&FIELD_1=COTE&VALUE_1='..id..' '..id..']'..p.getCatForId( 'Léonore' ) --no https yet (10/2018)
end

function p.sbnLink( id )
--P396's format regex: IT\\ICCU\\(\d{10}|\D\D[\D\d]\D\\\d{6}) (e.g. IT\ICCU\CFIV\000163)
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[%u%d]%u\\%d%d%d%d%d%d$' ) then --legacy: %u used here instead of %D (but the faulty ID cat is empty, out of ~12k uses)
return false
end
return '[https://opac.sbn.it/opacsbn/opac/iccu/scheda_authority.jsp?bid='..id..' '..id..']'..p.getCatForId( 'SBN' )
end

function p.nkcLink( id )
--P691's format regex: [a-z]{2,4}[0-9]{2,14} (e.g. abcd12345678901234)
if not string.match( id, '^[a-z][a-z][a-z]?[a-z]?%d%d%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?$' ) then
return false
end
return '[https://aleph.nkp.cz/F/?func=find-c&local_base=aut&ccl_term=ica='..id..'&CON_LNG=ENG '..id..']'..p.getCatForId( 'NKC' )
end

function p.nclLink( id )
--P1048's format regex: \d+ (e.g. 1081436)
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..']'..p.getCatForId( 'NCL' ) --no https yet (10/2018)
end

function p.ndlLink( id )
--P349's format regex: 0?\d{8} (e.g. 012345678)
if not string.match( id, '^0?%d%d%d%d%d%d%d%d$' ) then
return false
end
return '[https://id.ndl.go.jp/auth/ndlna/'..id..' '..id..']'..p.getCatForId( 'NDL' )
end

function p.sudocLink( id )
--P269's format regex: (\d{8}[\dX]|) (e.g. 026927608)
if not string.match( id, '^%d%d%d%d%d%d%d%d[%dxX]$' ) then --legacy: allow lowercase 'x'
return false
end
return '[https://www.idref.fr/'..id..' '..id..']'..p.getCatForId( 'SUDOC' )
end

function p.hdsLink( id )
--P902's format regex: 50\d{3}|[1-4]\d{4}|[1-9]\d{0,3}| (e.g. 50123)
if not string.match( id, '^50%d%d%d$' ) and
not string.match( id, '^[1-4]%d%d%d%d$' ) and
not string.match( id, '^[1-9]%d?%d?%d?$' ) then
return false
end
return '[http://www.hls-dhs-dss.ch/textes/f/F'..id..'.php '..id..']'..p.getCatForId( 'HDS' ) --no https yet (10/2018)
end

function p.lirLink( id )
--P886's format regex: \d+ (e.g. 1)
if not string.match( id, '^%d+$' ) then
return false
end
return '[http://www.e-lir.ch/e-LIR___Lexicon.'..id..'.450.0.html '..id..']'..p.getCatForId( 'LIR' ) --no https yet (10/2018)
end

function p.splitLccn( id )
--P244's format regex: (n|nb|nr|no|ns|sh)([4-9][0-9]|00|20[0-1][0-9])[0-9]{6} (e.g. n78039510)
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

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

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

function p.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 string.match( id, '^%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..']'..p.getCatForId( 'MusicBrainz' )
end

function p.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 string.match( id, '^%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..']'..p.getCatForId( 'MusicBrainz area' )
end

function p.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 string.match( id, '^%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..']'..p.getCatForId( 'MusicBrainz instrument' )
end

function p.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 string.match( id, '^%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..']'..p.getCatForId( 'MusicBrainz label' )
end

function p.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 string.match( id, '^%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..']'..p.getCatForId( 'MusicBrainz place' )
end

function p.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 string.match( id, '^%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..']'..p.getCatForId( 'MusicBrainz release group' )
end

function p.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 string.match( id, '^%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..']'..p.getCatForId( 'MusicBrainz series' )
end

function p.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 string.match( id, '^%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..']'..p.getCatForId( 'MusicBrainz work' )
end

--Returns the ISNI check digit isni must be a string where the 15 first elements are digits, e.g. 0000000066534145
function p.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
function p.validateIsni( id )
--P213 (ISNI) format regex: [0-9]{4} [0-9]{4} [0-9]{4} [0-9]{3}[0-9X] (e.g. 0000-0000-6653-4145)
--P496 (ORCID) format regex: 0000-000(1-[5-9]|2-[0-9]|3-[0-4])\d{3}-\d{3}[\dX] (e.g. 0000-0002-7398-5483)
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 p.getIsniCheckDigit( id ) ~= string.char( id:byte( 16 ) ) then
return false
end
end
return id
return id
end
end -- fixLCCN


-- ==================================================
function p.isniLink( id )
-- Verify last "check" digit is correct. ISNI and several other
id = p.validateIsni( id ) --e.g. 0000-0000-6653-4145
-- identifiers use last digit as a verification digit
if not id then
local function verifyLastDigit( id )
return false
local total = 0
for i = 1, #id-1 do
local digit = id:byte( i ) - 48 --Get integer value
total = (total + digit) * 2
end
--local remainder = total % 11
local lastDigit = tostring((12 - total % 11) % 11)
if lastDigit == '10' then
lastDigit = "X"
end
if (lastDigit == string.sub( id, -1)) then
return ''
else
return "<span style=\"color:red\">[last digit should be " .. lastDigit .. "]</span>"
end
end
return '[http://isni.org/isni/'..id..' '..id:sub( 1, 4 )..' '..id:sub( 5, 8 )..' '..id:sub( 9, 12 )..' '..id:sub( 13, 16 )..']'..p.getCatForId( 'ISNI' ) --no https yet (10/2018)
end
end


-- ==================================================
function p.orcidLink( id )
-- === Settings =====================================
id = p.validateIsni( id ) --e.g. 0000-0002-7398-5483
-- ==================================================
if not id then
-- In order to add a new identifier associated with Wikidata property do the following
return false
-- 1) go to [[Template:Authority control/IdentifierList]] and verify that the property number is on the list, if not than edit the page to add it
end
-- 2) copy code generated at [[Template:Authority control/IdentifierList]] to protected [[Module:Authority control/conf]]
id = id:sub( 1, 4 )..'-'..id:sub( 5, 8 )..'-'..id:sub( 9, 12 )..'-'..id:sub( 13, 16 )
-- 3) add the property to the "conf" list below
return '[https://orcid.org/'..id..' '..id..']'..p.getCatForId( 'ORCID' )
end


-- load 'Module:Authority control/conf' which holds hardwired data derived from Wikidata's properties of
function p.gndLink( id )
-- properties
--P227's format regex: (1|1[01])\d{7}[0-9X]|[47]\d{6}-\d|[1-9]\d{0,7}-[0-9X]|3\d{7}[0-9X] (e.g. 4079154-3)
if not string.match( id, '^1[01]?%d%d%d%d%d%d%d[0-9X]$' ) and
not string.match( id, '^[47]%d%d%d%d%d%d%-%d$' ) and
not string.match( id, '^[1-9]%d?%d?%d?%d?%d?%d?%d?%-[0-9X]$' ) and
not string.match( id, '^3%d%d%d%d%d%d%d[0-9X]$' ) then
return false
end
return '[https://d-nb.info/gnd/'..id..' '..id..']'..p.getCatForId( 'GND' )
end


--conf holds list of identifiers to be displayed
function p.selibrLink( id )
local conf = {
--P906's format regex: [1-9]\d{4,5} (e.g. 123456)
-- people
if not string.match( id, '^[1-9]%d%d%d%d%d?$' ) then
{label='VIAF' , property='P214' , lang='' , regexp='^%d+$' },
return false
{label='ISNI' , property='P213' , lang='' , regexp='^%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d[%dX]$', verify=verifyLastDigit },
end
{label='ORCID' , property='P496' , lang='' , regexp='^0000%-000[1-3]%-%d%d%d%d%-%d%d%d[%dX]$' },
return '[https://libris.kb.se/auth/'..id..' '..id..']'..p.getCatForId( 'SELIBR' )
{label='ULAN' , property='P245' , lang='' , regexp='^500%d%d%d%d%d%d$' }, -- 'Union List of Artist Names' by Getty Research Institute
end
{label='ResearcherID', property='P1053', lang='' , regexp='^[A-Z]+%-%d%d%d%d%-[12][90]%d%d$' },
{label='LCCN' , property='P244' , lang='en', regexp='^[ns][broshj]?%d%d%d%d%d%d%d%d%d?%d?$' }, -- Library of Congress Authorities
{label='GND' , property='P227' , lang='de', regexp='^[%dX%-]+$'},
{label='SELIBR' , property='P906' , lang='se', regexp='^%d+$' }, -- National Library of Sweden
{label='SUDOC' , property='P269' , lang='fr', regexp='^%d%d%d%d%d%d%d%d[%dxX]$' },
{label='BNF' , property='P268' , lang='fr', regexp='^%d+%w?$' }, -- Bibliothèque nationale de France
{label='BPN' , property='P651' , lang='nl', regexp='^%d%d%d%d%d%d%d%d$' }, -- Biografisch Portaal number
{label='NAID' , property='P1225', lang='en', regexp='^%d+$' }, -- NARA ID (redirect for US National Archives Identifier (P1225))
{label='Museofile' , property='P539' , lang='fr', regexp='^M%d%d%d%d%-?%d?%d?$' }, --Ministry of Culture (France)
{label='NDL' , property='P349' , lang='ja', regexp='^0?%d%d%d%d%d%d%d%d$' }, -- National Diet Library (of Japan)
{label='NLA' , property='P409' , lang='en', regexp='^[1-9]%d*$' }, -- National Library of Australia
{label='BIBSYS' , property='P1015', lang='no', regexp='^%d+$' }, -- Norwegian information system BIBSYS
{label='HDS' , property='P902' , lang='de', regexp='^%d%d%d?%d?%d?%d?$' }, -- Historical Dictionary of Switzerland
{label='MusicBrainz' , property='P434' , lang='en', regexp='^[-%x]+$' },
{label='MGP' , property='P549' , lang='en', regexp='^%d%d?%d?%d?%d?%d?$' }, -- Mathematics Genealogy Project
{label='NCL' , property='P1048', lang='zh', regexp='^%d+$' }, --National Central Library (Taiwan)
{label='NKC' , property='P691' , lang='cs', regexp='^%l%l%l?%l?%d%d%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?$' }, --National Library of the Czech Republic
{label='Léonore' , property='P640' , lang='fr', regexp='^[LHC%/%d]+$' },
{label='SBN' , property='P396' , lang='it'}, -- Istituto Centrale per il Catalogo Unico / National Library Service (SBN) of Italy
{label='RSL' , property='P947' , lang='ru', regexp='^%d%d%d%d%d%d%d%d%d$' }, --Russian State Library
{label='Botanist' , property='P428' , lang='en' },
{label='US Congress' , property='P1157', lang='en', regexp='^%u00[01]%d%d%d' },
{label='BNE' , property='P950' , lang='es', regexp='' }, --Biblioteca Nacional de España
{label='CALIS' , property='P270' , lang='zh'}, --China Academic Library and Information
{label='CiNii' , property='P271' , lang='jp', regexp='^DA%d%d%d%d%d%d%d[%dX]$' },
{label='TLS' , property='P1362', lang='de', regexp='' }, -- Theaterlexikon der Schweiz
{label='SIKART' , property='P781' , lang='de', regexp='^%d%d%d%d%d%d%d%d?%d?%d?$' }, -- Swiss
{label='NLP' , property='P1695', lang='pl', regexp='' }, -- National Library of Poland
{label='WGA' , property='P1882', lang='en', regexp='' }, -- Web Gallery of Art
{label='KulturNav' , property='P1248', lang='no', regexp='' },
{label='RKD' , property='P650' , lang='nl', regexp='^[1-9]%d%d?%d?%d?%d?$' }, --Netherlands Institute for Art History#Online artist pages
{label='autores.uy' , property='P2558', lang='es', regexp='^[1-9]%d?%d?%d?%d?$' }, --autores.uy
{label='J9U' , property='P8189', lang='he', regexp='' }, --National Library of Israel J9U ID


{label='FIDE' , property='P1440', lang='en', regexp='' }, -- FIDE database for chess players
function p.bnfLink( id )
{label='Chess Games' , property='P1665', lang='en', regexp='' }, -- Chess Games
--P268's format regex: \d{8}[0-9bcdfghjkmnpqrstvwxz] (e.g. 123456789)
if not string.match( id, '^c?b?%d%d%d%d%d%d%d%d[0-9bcdfghjkmnpqrstvwxz]$' ) then
return false
end
--Add cb prefix if it has been removed
if not string.match( id, '^cb.+$' ) then
id = 'cb'..id
end
return '[https://catalogue.bnf.fr/ark:/12148/'..id..' '..id..'] [http://data.bnf.fr/ark:/12148/'..id..' (data)]'..p.getCatForId( 'BNF' )
end


{label='ISSN' , property='P236', lang='', regexp='' }, -- P1629: International Standard Serial Number
function p.bpnLink( id )
{label='OSM' , property='P402', lang='', regexp='' }, -- P1629: OpenStreetMap
--P651's format regex: \d{8} (e.g. 12345678)
{label='Joconde' , property='P347', lang='fr', regexp='' }, -- Joconde ID
if not string.match( id, '^%d%d%d%d%d%d%d%d$' ) then
{label='Rijksmonument',property='P359', lang='nl', regexp='' }, -- Rijksmonument ID
return false
{label='IMO' , property='P458', lang='', regexp='' }, --IMO ship number
end
{label='BNCF' , property='P508', lang='it', regexp='' }, -- BNCF Thesaurus ID
return '[http://www.biografischportaal.nl/en/persoon/'..id..' '..id..']'..p.getCatForId( 'BPN' ) --no https yet (10/2018)
{label='MMSI' , property='P587', lang='', regexp='' }, -- P1629: Maritime Mobile Service Identity
end
{label='Open Library', property='P648', lang='', regexp='' }, -- P1629: Open Library
{label='NRHP' , property='P649', lang='en', regexp='' }, -- NRHP reference number
{label='DBNL' , property='P723', lang='', regexp='' }, -- DBNL author ID
{label='UNESCO' , property='P757', lang='', regexp='' }, -- World Heritage Site ID
{label='BIC' , property='P808', lang='', regexp='' }, -- Bien de Interés Cultural (BIC) code
{label='LIR' , property='P886', lang='', regexp='' }, -- LIR
{label='BNR' , property='P1003', lang='ro', regexp='' }, -- NLR (Romania) ID
{label='Koninklijke' , property='P1006', lang='nl', regexp='' }, -- National Thesaurus for Author Names ID
{label='Louvre' , property='P9394', lang='', regexp='' }, -- Louvre ID
{label='OCLC' , property='P243', lang='', regexp='' }, -- OCLC
{label='ISBN-13' , property='P212', lang='', regexp='' }, -- ISBN-13
{label='ISBN-10' , property='P957', lang='', regexp='' }, -- ISBN-10
{label='Historic England', property='P1216', lang='en', regexp='' }, -- National Heritage List for England number


{label='Oxford Dict.', property='P1415', lang='en', regexp='' }, -- Oxford Dictionary of National Biography ID
function p.ridLink( id )
{label='kulturnoe-nasledie', property='P1483', lang='ru', regexp='' }, -- kulturnoe-nasledie.ru ID
--P1053's format regex: [A-Z]-\d{4}-(19|20)\d\d (e.g. A-1234-1934)
{label='Catalunya' , property='P1600', lang='ca', regexp='' }, -- Inventari del Patrimoni Arquitectònic de Catalunya code
if not string.match( id, '^[A-Z]%-%d%d%d%d%-19%d%d$' ) and
{label='COAM' , property='P2917', lang='es', regexp='' }, -- COAM structure ID
not string.match( id, '^[A-Z]%-%d%d%d%d%-20%d%d$' ) then
{label='SIMBAD' , property='P3083', lang='fr', regexp='' }, -- SIMBAD ID
return false
{label='JCyL' , property='P3177', lang='es', regexp='' }, -- Patrimonio Web JCyL ID
end
{label='Zaragoza' , property='P3178', lang='es', regexp='' }, -- Zaragoza monument ID
return '[https://www.researcherid.com/rid/'..id..' '..id..']'..p.getCatForId( 'RID' )
{label='BDI' , property='P3318', lang='es', regexp='' }, -- Patrimonio Inmueble de Andalucía ID
end
{label='SIPCA' , property='P3580', lang='es', regexp='' }, -- SIPCA code
{label='DOCOMOMO' , property='P3758', lang='', regexp='' }, -- DOCOMOMO Ibérico ID
{label='Czech Monument', property='P4075', lang='cz', regexp='' }, -- Czech Monument Catalogue Number
{label='MEG' , property='P4157', lang='ch', regexp='' }, -- P1629: Musée d'ethnographie de Genève
{label='Enciclopédia Itaú Cultural' , property='P4399', lang='pt_br', regexp='' }, -- Enciclopédia Itaú Cultural ID
{label='Monumentos de São Paulo' , property='P4360', lang='pt_br', regexp='' }, -- Monumentos de São Paulo ID
{label='Infopatrimônio' , property='P4372', lang='pt_br', regexp='' }, -- Infopatrimônio ID
{label="Musée d'Orsay" , property='P4659', lang='fr' , regexp='' }, -- Musée d'Orsay artwork ID
{label='MuBE' , property='P4721', lang='pt_br', regexp='' }, -- MuBE Virtual ID
{label='Hispania Nostra' , property='P4868', lang='es' , regexp='' }, -- Hispania Nostra Red List ID
{label='NLK' , property='P5034', lang='ko' , regexp='' }, -- National Library of Korea ID
}


-- ==================================================
function p.bibsysLink( id )
-- === External functions ===========================
--P1015's format regex: [1-9]\d* or [1-9](\d{0,8}|\d{12}) (e.g. 1234567890123)
-- ==================================================
--TODO: follow up @ [[d:Property talk:P1015#Discrepancy between the 2 regex constraints]] or escalate/investigate
local p = {}
if not string.match( id, '^[1-9]%d?%d?%d?%d?%d?%d?%d?%d?$' ) and
not string.match( id, '^[1-9]%d%d%d%d%d%d%d%d%d%d%d%d$' ) then
return false
end
return '[https://authority.bibsys.no/authority/rest/authorities/html/'..id..' '..id..']'..p.getCatForId( 'BIBSYS' )
end


function p.ulanLink( id )
function p.getAuthorityControlTag( lang )
-- get a localized interwiki link to article "Authority Control"
--P245's format regex: 500\d{6} (e.g. 500123456)
local field_name = "[[w:en:Help:Authority control|Authority control]]" -- hardwire the default
if not string.match( id, '^500%d%d%d%d%d%d$' ) then
if lang~='en' then
return false
field_name = core.getLabel("Q36524", lang)
end
end
return field_name
return '[https://www.getty.edu/vow/ULANFullDisplay?find=&role=&nation=&subjectid='..id..' '..id..']'..p.getCatForId( 'ULAN' )
end
end


-- ==================================================
function p.nlaLink( id )
function p._authorityControl(entity, args, lang, length)
--P409's format regex: [1-9][0-9]{0,11} (e.g. 123456789012)
-- INPUTS:
if not string.match( id, '^[1-9]%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?$' ) then
-- * entity - wikidata entity if already created or nil. If provided than you should still provide args.Wikidata
return false
-- * args - structure with identifier fields: args.VIAF, args.LCCN, args.Wikidata, etc.
end
-- * lang - language code
return '[https://nla.gov.au/anbd.aut-an'..id..' '..id..']'..p.getCatForId( 'NLA' )
-- * length - maximum length of the identifier array, or number of identifiers to display
end
-- OUTPUTS:
-- * results - wikicode string equivalent to {{Authority control|...|bare=1 }} call
-- * cats - wikicode with maintenance categories


-- count custom parameters (not pulled from Wikidata)
function p.rkdartistsLink( id )
local nCustomParam = 0
--P650's format regex: [1-9]\d{0,5} (e.g. 123456)
for _,params in ipairs( conf ) do
if not string.match( id, '^[1-9]%d?%d?%d?%d?%d?$' ) then
if (args[params.label]~=nil) then
return false
nCustomParam = nCustomParam + 1
end
end
end
return '[https://rkd.nl/en/explore/artists/'..id..' '..id..']'..p.getCatForId( 'RKDartists' )
-- Get entity - record of wikidata related to a single item
end
local q = args.wikidata

if not entity and q then
function p.snacLink( id )
entity = mw.wikibase.getEntity(q)
--P3430's format regex: \d*[A-Za-z][0-9A-Za-z]* (e.g. A)
if not string.match( id, '^%d*[A-Za-z][0-9A-Za-z]*$' ) then
return false
end
end
return '[http://socialarchive.iath.virginia.edu/ark:/99166/'..id..' '..id..']'..p.getCatForId( 'SNAC-ID' ) --no https yet (10/2018)
-- Check if this is category item
end
local cats = '' -- categories (mismatching and missing)

if entity and entity.claims and entity.claims.P31 then
function p.dblpLink( id )
for _, statement in pairs( entity.claims.P31) do
--P2456's format regex: \d{2,3} /\d+(-\d+)?|[a-z] /[a-zA-Z][0-9A-Za-z]*(-\d+)? (e.g. 123/123)
if (statement.mainsnak.snaktype == "value") and (statement.mainsnak.datavalue.value.id == 'Q4167836') then -- P31 == Wikimedia category
if not string.match( id, '^%d%d%d?/%d+$' ) and
cats = '[[Category:Wrong Wikidata ID in authority control data: category item]]'
not string.match( id, '^%d%d%d?/%d+%-%d+$' ) and
end
not string.match( id, '^[a-z]/[a-zA-Z][0-9A-Za-z]*$' ) and
if (statement.mainsnak.snaktype == "value") and (statement.mainsnak.datavalue.value.id == 'Q4167410') then -- P31 == Wikimedia disambiguation page
not string.match( id, '^[a-z]/[a-zA-Z][0-9A-Za-z]*%-%d+$' ) then
cats = '[[Category:Wrong Wikidata ID in authority control data: disambiguation item]]'
return false
end
end
end
end
return '[https://dblp.org/pid/'..id..' '..id..']'..p.getCatForId( 'DBLP' )
end


--compare provided arguments with Wikidata identifiers
function p.acmLink( id )
local data = {} -- structure similar to "args" but filled with wikidata data
--P864's format regex: \d{11} (e.g. 12345678901)
for _,params in ipairs( conf ) do
if not string.match( id, '^%d%d%d%d%d%d%d%d%d%d%d$' ) then
local label = string.lower(params.label)
return false
data[label] = nil
if entity and entity.claims and params.property and entity.claims[params.property] then -- if we have wikidata item and item has the property
-- capture all Wikidata values for the identifier
--for _, statement in pairs( entity.claims[params.property]) do
for _, statement in pairs( entity:getBestStatements( params.property )) do
if (statement.mainsnak.snaktype == "value") then -- or if statement.mainsnak.datavalue then
local v = statement.mainsnak.datavalue.value
if data[label]==nil then
data[label] = v -- save the first value
end
if args[label] == v then -- match between template and wikidata identifiers
data[label] = '' -- ignore identifier from wikidata
break
end
end
end
end
end
end
return '[https://dl.acm.org/author_page.cfm?id='..id..' '..id..']'..p.getCatForId( 'ACM-DL' )
end


--Create string with all the identifiers listed
function p.autoresuyLink( id )
local results1 = {} -- high priority list
--P2558's format regex: [1-9]\d{0,4} (e.g. 12345)
local results2 = {} -- low priority list
if not string.match( id, '^[1-9]%d?%d?%d?%d?$' ) then
properties.P214.item = 'Q54919'; -- hardwire link to VIAF
return false
local today = '+' .. os.date('!%F') .. 'T00:00:00Z/11'
end
local TransStr = 'https://quickstatements.toolforge.org/#/v1=%s|%s|%%22%s%%22|S143|Q565|S813|'.. today -- QuickStatementts URL
return '[https://autores.uy/autor/'..id..' '..id..']'..p.getCatForId( 'autores.uy' )
TransStr = '<span class=\"plainlinks\" title=\"Click (+) to copy to wikidata\">['.. TransStr .. ' (+)]</span>'
end
for _,params in ipairs( conf ) do
local label = string.lower(params.label)
local val1 = args[label] -- identifier value provided to the template
local val2 = data[label] -- identifier value pulled from wikidata
if val1 or val2 then
local P = properties[params.property] -- properties of wikidata identifier propertyc
-- name_link - link for the identifier name
local name_link = getIdentifierNameLink( lang, P.item, P.issuedBy, params.label )
-- val_link - identifier value or values
local transfer = ''
local val3 = string.gsub(val1 or '', ' ', '' ) -- remove spaces
local val_link
if not val1 then
val_link = getIdentifierValLink(val2, P, params, 'blue') -- wikidata only no local identifier
elseif val2=='' then
val_link = getIdentifierValLink(val1, P, params, 'magenta') -- match was found
elseif val2 then
val_link = getIdentifierValLink(val1, P, params, 'darkgreen') .. "/"..getIdentifierValLink(val2, P, params, 'blue')
cats = string.format("%s[[Category:Pages using authority control with identifiers mismatching Wikidata]]\n", cats)
transfer = string.format(TransStr, q, params.property, val3)
elseif not val2 and entity then
val_link = getIdentifierValLink(val1, P, params, 'darkgreen')
cats = string.format("%s[[Category:Pages using authority control with identifiers missing from Wikidata]]\n", cats)
transfer = string.format(TransStr, q, params.property, val3)
else
val_link = getIdentifierValLink(val1, P, params, 'blue') -- local identifier and no wikidata q-code
end


-- combine them all
function p.picLink( id )
local lineStr = string.format("\n*%s:&thinsp;<span class=\"uid\">%s</span>%s", name_link, val_link, transfer)
--P2750's format regex: [1-9]\d* (e.g. 1)
if (params.lang==lang) or (params.lang=='') then
if not string.match( id, '^[1-9]%d*$' ) then
table.insert(results1, lineStr) -- add to high priority list
return false
else
table.insert(results2, lineStr) -- add to low priority list
end
end
end -- for all sources
-- merge high and low priority lists, trim them if needed and convert to string
--table.insert(results1, "\n*End list 1") -- for debuging
--table.insert(results2, "\n*End list 2")
for _,v in pairs(results2) do table.insert(results1, v) end
local results = table.concat(results1, "", 1, math.min(#results1, length or #results1))
-- Add Link to wikidata
if q then
results = string.format("\n*[[File:Wikidata-logo.svg|20px|wikidata:%s|link=wikidata:%s]]: [[d:%s|%s]]%s",q,q,q,q,results)
end
end
return '[https://pic.nypl.org/constituents/'..id..' '..id..']'..p.getCatForId( 'PIC' )
-- Add link to Worldcat
end
if (args.worldcatid==nil and (args.lccn or data.lccn)) then

args.worldcatid = 'lccn-' .. (args.lccn or data.lccn)
function p.bildLink( id )
--P2092's format regex: \d+ (e.g. 1)
if not string.match( id, '^%d+$' ) then
return false
end
end
if args.worldcatid then
return '[https://www.bildindex.de/document/obj'..id..' '..id..']'..p.getCatForId( 'Bildindex' )
results = string.format("%s\n*<span class=\"uid\">[//www.worldcat.org/identities/%s WorldCat]</span>", results, args.worldcatid)
end

function p.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 string.match( id, regex ) then
return false
end
end
return '[http://www2.culture.gouv.fr/public/mistral/joconde_fr?ACTION=CHERCHER&FIELD_1=REF&VALUE_1='..id..' '..id..']'..p.getCatForId( 'Joconde' ) --no https yet (10/2018)
-- Add maintenance categories
end
if q == nil then

cats = string.format("%s[[Category:Pages using authority control without Wikidata link]]\n", cats)
function p.rkdidLink( id )
--P350's format regex: [1-9]\d{0,5} (e.g. 123456)
if not string.match( id, '^[1-9]%d?%d?%d?%d?%d?$' ) then
return false
end
end
if nCustomParam>0 then
return '[https://rkd.nl/nl/explore/images/'..id..' '..id..']'..p.getCatForId( 'RKDID' )
if cats=='' and entity ~= nil then
end
cats = string.format("%s[[Category:Pages using authority control with all identifiers matching Wikidata]]\n", cats)

end
function p.balatLink( id )
if string.find(results, "<span style=\"color:red\">") then
--P3293's format regex: \d+ (e.g. 1)
cats = string.format("%s[[Category:Pages using authority control with badly formated identifier]]\n", cats)
if not string.match( id, '^%d+$' ) then
end
return false
end
end
return '[http://balat.kikirpa.be/object/104257'..id..' '..id..']'..p.getCatForId( 'BALaT' ) --no https yet (10/2018)
end


-- return results
function p.lnbLink( id )
if results~='' then -- if there are any results than wrap them in <div> tag
--P1368's format regex: \d{9} (e.g. 123456789)
results = string.format('<div class="hlist">%s\n</div>', results)
if not string.match( id, '^%d%d%d%d%d%d%d%d%d$' ) then
return false
end
end
return results, cats
return '[https://kopkatalogs.lv/F?func=direct&local_base=lnc10&doc_number='..id..'&P_CON_LNG=ENG '..id..']'..p.getCatForId( 'LNB' )
end
end


function p.nskLink( id )
--P1375's format regex: \d{9} (e.g. 123456789)
if not string.match( id, '^%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..']'..p.getCatForId( 'NSK' ) --no https yet (10/2018)
end


-- ===========================================================================
function p.iciaLink( id )
-- === Version of the function to be called from template namespace
--P1736's format regex: \d+ (e.g. 1)
-- ===========================================================================
if not string.match( id, '^%d+$' ) then
function p.authorityControl(frame)
return false
-- prepare arguments
local args = core.getArgs(frame)
local bare = core.yesno(args.bare,false)
-- Convert template arguments to the same format as used on wikidata
if args.bnf then
args.bnf = string.sub(args.bnf, 3) -- trim first 2 characters
end
end
-- if args.isni then -- group in sets of 4
return '[https://www.imj.org.il/artcenter/newsite/en/?artist='..id..' '..id..']'..p.getCatForId( 'ICIA' )
-- args.isni = string.sub(args.isni, 1, 4).." "..string.sub(args.isni, 5, 8)
end
-- .." "..string.sub(args.isni, 9,12).." "..string.sub(args.isni,13,16)

-- end
function p.ta98Link( id )
if args.isbn then
--P1323's format regex: A\d{2}\.\d\.\d{2}\.\d{3}[FM]? (e.g. A12.3.45.678)
local isbn = isbn.gsub( ' ', '' )
if not string.match( id, '^A%d%d%.%d%.%d%d%.%d%d%d[FM]?$' ) then
if #isbn==10 then
return false
args['isbn-10'] = args.isbn
elseif #isbn==13 then
args['isbn-13'] = args.isbn
end
args.isbn = nil
end
end
args.gnd = args.gnd or args.pnd --redirect PND to GND
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..']'..p.getCatForId( 'TA98' )
args.lccn = fixLCCN(args.lccn)
end
args.wikidata = args.wikidata or args.q or nil

function p.teLink( id )
-- call the inner "core" function
--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 results, cats = p._authorityControl(nil, args, args.lang, args.length)
local e1, e2 = string.match( id, '^E([1-8])%.(%d%d?)%.%d%d?%.%d%d?%.%d%.%d%.%d%d?%d?$' )
local namespace = mw.title.getCurrentTitle().namespace
if not e1 then
local LUT = {[2]='user', [6]='file', [10]='template', [828]='module'}
return false
if (LUT[namespace] or math.fmod(namespace,2)==1) then
-- lets not add categories to some namespaces, or talk pages and concentrate
-- on templates and categories instead
cats = ''
end
end
local TEnum = 'TEe0'..e1 --no formatter URL in WD, probably due to this complexity
--package results as a infobox if not "bare"
if e1 == '5' or e1 == '7' then
if #e2 == 1 then e2 = '0'..e2 end
if not bare then
-- Get field name for authority control
TEnum = TEnum..e2
local field_name = p.getAuthorityControlTag(args.lang)
end
return '[http://www.unifr.ch/ifaa/Public/EntryPage/ViewTE/'..TEnum..'.html '..id..']'..p.getCatForId( 'TE' )
end


-- build table
function p.thLink( id )
results = string.format('<tr><td class="type fileinfo-paramfield">%s</td><td>\n%s\n</td></tr>', field_name, results)
--P1694's format regex: H\d\.\d{2}\.\d{2}\.\d\.\d{5} (e.g. H1.23.45.6.78901)
local dir = mw.language.new( args.lang ):getDir() -- get text direction
local h1, h2 = string.match( id, '^H(%d)%.(%d%d)%.%d%d%.%d%.%d%d%d%d%d$' )
local style = 'class="toccolours mw-content-%s layouttemplate commons-file-information-table" style="width: 100%%;" dir="%s" lang="%s"'
if not h1 then
style = string.format(style, dir, dir, args.lang)
return false
results = string.format('<table %s>\n%s\n</table>\n', style, results)
else
results = string.format('\n%s\n', results)
end
end
return results..cats
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..']'..p.getCatForId( 'TH' )
end
end



return p
return p

18:44, 27 மார்ச்சு 2024 இல் நிலவும் திருத்தம்

Documentation for this module may be created at Module:Authority control/doc

--[[  
  __  __           _       _           _         _   _                _ _                           _             _ 
 |  \/  | ___   __| |_   _| | ___ _   / \  _   _| |_| |__   ___  _ __(_) |_ _   _    ___ ___  _ __ | |_ _ __ ___ | |
 | |\/| |/ _ \ / _` | | | | |/ _ (_) / _ \| | | | __| '_ \ / _ \| '__| | __| | | |  / __/ _ \| '_ \| __| '__/ _ \| |
 | |  | | (_) | (_| | |_| | |  __/_ / ___ \ |_| | |_| | | | (_) | |  | | |_| |_| | | (_| (_) | | | | |_| | | (_) | |
 |_|  |_|\___/ \__,_|\__,_|_|\___(_)_/   \_\__,_|\__|_| |_|\___/|_|  |_|\__|\__, |  \___\___/|_| |_|\__|_|  \___/|_|
                                                                            |___/                                    
This module is intended to be the engine behind "Template:Authority control".

Please do not modify this code without applying the changes first at "Module:Authority control/sandbox" and testing 
at "Module:Authority control/testcases".

Authors and maintainers:
* User:Jarekt - original version 

]]

local properties = require('Module:Authority control/conf')
local core       = require('Module:Core')

-- ==================================================
-- === Internal functions ===========================
-- ==================================================

local function getSitelink(item, lang)
    -- get item's siteling in specific language
	local langList = mw.language.getFallbacksFor(lang)
	table.insert(langList, 1, lang)
	for _, language in ipairs(langList) do 
		local sitelink = mw.wikibase.sitelink( item, language .. 'wiki' )
		if sitelink then 
			return 'w:'.. language ..':'.. sitelink
		end
	end
	return nil
end

-- ==================================================
local function getIdentifierNameLink( lang, item1, item2, label )
-- Identifier names, like VIAF, LCCN, ISNI, need to be linked to the articles about them if possible
-- Alternativly they can be linked to the articles for institutions that issue them
	local id_name_URL = nil
	-- 1) try wikipedia sitelink for the identifier in users language and in English
	if item1 and item1 ~='' then
		id_name_URL = getSitelink(item1, lang)
	end
	-- 2) try wikipedia sitelink for the issuedBy property in users language and in English
	if id_name_URL==nil and item2 and item2 ~='' then -- if no link than
		id_name_URL = getSitelink(item2, lang)
	end
	-- 3) if still no links than link to wikidata
	if id_name_URL then	
		return string.format("[[%s|%s]]", id_name_URL, label) -- link to wikipedia
	else    
		return string.format("[[d:%s|%s]]", item1, label) -- link to wikidata
	end
end

-- ==================================================
-- Create link to a single identifier
-- INPUTS:
--  * val - value of the identifier
--  * P - property record, with URL_format and optional interwiki_format strings to create links
--  * params - additional parameters related to this type of identifiers. Single item from "conf"
--  * color - color of the link
local function getIdentifierValLink(val, P, params, color)
	if not val or val=='' then
		return ''
	end
	-- check if identifier is in the right format
	local mismatchStr = ''
	local val_ = val:gsub( ' ', '' ) -- remove spaces
	if (params.regexp and not val:match( params.regexp )) then
		mismatchStr  = string.format("<span style=\"color:red\">[does not match %s pattern]</span>", params.regexp)
	elseif (params.verify) then -- check if special "Verify" function is present
		mismatchStr = params.verify(val_) -- add error message if any
	end
	-- identifier_value_URL
	if color~="blue" then
		val = string.format('<span style=\"color:%s\">%s</span>', color, val)
	end
	local val_link
	if P.interwiki_format and P.interwiki_format ~= '' then
		val_link = string.format("[[%s:%s|%s]]", P.interwiki_format, val_, val)
	else
		local val_URL = P.URL_format:gsub('$1', val_)-- URL part of the link for the identifier value
		val_link = string.format("[%s %s]", val_URL, val)
	end
	return string.format("<span class=\"plainlinks\">%s</span>%s", val_link, mismatchStr) -- link to the identifier's website
end 

-- ==================================================
-- Convert between 2 formats of LCCN: "n/79/63767" -> "n79063767"
-- "n/79/63767" format was used as input by {{Authority Control}} templates
-- "n79063767" format is used by wikidata
local function fixLCCN(id)
  if id then
		local a, b, c = string.match(id, "([%a%d]*)/([%a%d]*)/([%a%d]*)")
		if c then
			local pad = 6 - string.len(c)
			if pad > 0 then
				c = string.rep("0", pad)..c
			end
			id = a..b..c
		end
	end
	return id
end -- fixLCCN

-- ==================================================
-- Verify last "check" digit is correct. ISNI and several other 
-- identifiers use last digit as a verification digit
local function verifyLastDigit( id )
    local total = 0
    for i = 1, #id-1 do
        local digit = id:byte( i ) - 48 --Get integer value
        total = (total + digit) * 2
    end
	
    --local remainder = total % 11
    local lastDigit = tostring((12 - total % 11) % 11)
    if lastDigit == '10' then
        lastDigit = "X"
    end
	
    if (lastDigit == string.sub( id, -1)) then
		return ''
	else
		return "<span style=\"color:red\">[last digit should be " .. lastDigit .. "]</span>"
	end
end

-- ==================================================
-- === Settings =====================================
-- ==================================================
-- In order to add a new identifier associated with Wikidata property do the following 
-- 1) go to [[Template:Authority control/IdentifierList]] and verify that the property number is on the list, if not than edit the page to add it
-- 2) copy code generated at [[Template:Authority control/IdentifierList]] to protected [[Module:Authority control/conf]]
-- 3) add the property to the "conf" list below

-- load 'Module:Authority control/conf' which holds hardwired data derived from Wikidata's properties of 
-- properties

--conf  holds list of identifiers to be displayed
local conf = {
    -- people 
	{label='VIAF'        , property='P214' , lang=''  , regexp='^%d+$' },
	{label='ISNI'        , property='P213' , lang=''  , regexp='^%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d[%dX]$', verify=verifyLastDigit }, 
	{label='ORCID'       , property='P496' , lang=''  , regexp='^0000%-000[1-3]%-%d%d%d%d%-%d%d%d[%dX]$' },
	{label='ULAN'        , property='P245' , lang=''  , regexp='^500%d%d%d%d%d%d$' }, -- 'Union List of Artist Names' by Getty Research Institute
	{label='ResearcherID', property='P1053', lang=''  , regexp='^[A-Z]+%-%d%d%d%d%-[12][90]%d%d$' }, 
	{label='LCCN'        , property='P244' , lang='en', regexp='^[ns][broshj]?%d%d%d%d%d%d%d%d%d?%d?$' }, -- Library of Congress Authorities
	{label='GND'         , property='P227' , lang='de', regexp='^[%dX%-]+$'},
	{label='SELIBR'      , property='P906' , lang='se', regexp='^%d+$' }, -- National Library of Sweden
	{label='SUDOC'       , property='P269' , lang='fr', regexp='^%d%d%d%d%d%d%d%d[%dxX]$' },    
	{label='BNF'         , property='P268' , lang='fr', regexp='^%d+%w?$' }, -- Bibliothèque nationale de France
	{label='BPN'         , property='P651' , lang='nl', regexp='^%d%d%d%d%d%d%d%d$' }, -- Biografisch Portaal number
	{label='NAID'        , property='P1225', lang='en', regexp='^%d+$' }, -- NARA ID (redirect for US National Archives Identifier (P1225))
	{label='Museofile'   , property='P539' , lang='fr', regexp='^M%d%d%d%d%-?%d?%d?$' }, --Ministry of Culture (France)
	{label='NDL'         , property='P349' , lang='ja', regexp='^0?%d%d%d%d%d%d%d%d$' }, -- National Diet Library (of Japan)
	{label='NLA'         , property='P409' , lang='en', regexp='^[1-9]%d*$' }, -- National Library of Australia
	{label='BIBSYS'      , property='P1015', lang='no', regexp='^%d+$' }, -- Norwegian information system BIBSYS
	{label='HDS'         , property='P902' , lang='de', regexp='^%d%d%d?%d?%d?%d?$' },  -- Historical Dictionary of Switzerland
	{label='MusicBrainz' , property='P434' , lang='en', regexp='^[-%x]+$' }, 
	{label='MGP'         , property='P549' , lang='en', regexp='^%d%d?%d?%d?%d?%d?$' },  -- Mathematics Genealogy Project
	{label='NCL'         , property='P1048', lang='zh', regexp='^%d+$' },  --National Central Library (Taiwan)
	{label='NKC'         , property='P691' , lang='cs', regexp='^%l%l%l?%l?%d%d%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?%d?$' },  --National Library of the Czech Republic
	{label='Léonore'     , property='P640' , lang='fr', regexp='^[LHC%/%d]+$' }, 
	{label='SBN'         , property='P396' , lang='it'},  -- Istituto Centrale per il Catalogo Unico /  National Library Service (SBN) of Italy
	{label='RSL'         , property='P947' , lang='ru', regexp='^%d%d%d%d%d%d%d%d%d$' },  --Russian State Library
	{label='Botanist'    , property='P428' , lang='en' }, 
	{label='US Congress' , property='P1157', lang='en', regexp='^%u00[01]%d%d%d' }, 
	{label='BNE'         , property='P950' , lang='es', regexp='' }, --Biblioteca Nacional de España
	{label='CALIS'       , property='P270' , lang='zh'}, --China Academic Library and Information 
	{label='CiNii'       , property='P271' , lang='jp', regexp='^DA%d%d%d%d%d%d%d[%dX]$' }, 
	{label='TLS'         , property='P1362', lang='de', regexp='' }, -- Theaterlexikon der Schweiz
	{label='SIKART'      , property='P781' , lang='de', regexp='^%d%d%d%d%d%d%d%d?%d?%d?$' }, -- Swiss
	{label='NLP'         , property='P1695', lang='pl', regexp='' }, -- National Library of Poland
	{label='WGA'         , property='P1882', lang='en', regexp='' }, -- Web Gallery of Art
	{label='KulturNav'   , property='P1248', lang='no', regexp='' }, 
	{label='RKD'         , property='P650' , lang='nl', regexp='^[1-9]%d%d?%d?%d?%d?$' }, --Netherlands Institute for Art History#Online artist pages
	{label='autores.uy'  , property='P2558', lang='es', regexp='^[1-9]%d?%d?%d?%d?$' },   --autores.uy
	{label='J9U'         , property='P8189', lang='he', regexp='' },  --National Library of Israel J9U ID

	{label='FIDE'        , property='P1440', lang='en', regexp='' }, -- FIDE database for chess players
	{label='Chess Games' , property='P1665', lang='en', regexp='' }, -- Chess Games

	{label='ISSN'        , property='P236',  lang='', regexp='' }, -- P1629: International Standard Serial Number
	{label='OSM'         , property='P402',  lang='', regexp='' },  -- P1629: OpenStreetMap
	{label='Joconde'     , property='P347',  lang='fr', regexp='' }, -- Joconde ID
	{label='Rijksmonument',property='P359',  lang='nl', regexp='' }, -- Rijksmonument ID
	{label='IMO'         , property='P458',  lang='', regexp='' }, --IMO ship number
	{label='BNCF'        , property='P508',  lang='it', regexp='' }, -- BNCF Thesaurus ID
	{label='MMSI'        , property='P587',  lang='', regexp='' }, -- P1629: Maritime Mobile Service Identity
	{label='Open Library', property='P648',  lang='', regexp='' }, -- P1629: Open Library
	{label='NRHP'        , property='P649',  lang='en', regexp='' }, -- NRHP reference number
	{label='DBNL'        , property='P723',  lang='', regexp='' }, -- DBNL author ID
	{label='UNESCO'      , property='P757',  lang='', regexp='' }, -- World Heritage Site ID
	{label='BIC'         , property='P808',  lang='', regexp='' }, -- Bien de Interés Cultural (BIC) code
	{label='LIR'         , property='P886',  lang='', regexp='' }, -- LIR
	{label='BNR'         , property='P1003', lang='ro', regexp='' }, -- NLR (Romania) ID
	{label='Koninklijke' , property='P1006', lang='nl', regexp='' }, -- National Thesaurus for Author Names ID
	{label='Louvre'      , property='P9394', lang='', regexp='' }, -- Louvre ID
	
	{label='OCLC'        , property='P243',  lang='', regexp='' }, -- OCLC
	{label='ISBN-13'     , property='P212',  lang='', regexp='' }, -- ISBN-13
	{label='ISBN-10'     , property='P957',  lang='', regexp='' }, -- ISBN-10
	{label='Historic England', property='P1216', lang='en', regexp='' }, -- National Heritage List for England number

	{label='Oxford Dict.', property='P1415', lang='en', regexp='' }, -- Oxford Dictionary of National Biography ID
	{label='kulturnoe-nasledie', property='P1483', lang='ru', regexp='' },  -- kulturnoe-nasledie.ru ID
	{label='Catalunya'   , property='P1600', lang='ca', regexp='' }, -- Inventari del Patrimoni Arquitectònic de Catalunya code
	{label='COAM'        , property='P2917', lang='es', regexp='' }, -- COAM structure ID
	{label='SIMBAD'      , property='P3083', lang='fr', regexp='' }, -- SIMBAD ID
	{label='JCyL'        , property='P3177', lang='es', regexp='' }, -- Patrimonio Web JCyL ID
	{label='Zaragoza'    , property='P3178', lang='es', regexp='' },  -- Zaragoza monument ID
	{label='BDI'         , property='P3318', lang='es', regexp='' }, -- Patrimonio Inmueble de Andalucía ID
	{label='SIPCA'       , property='P3580', lang='es', regexp='' }, -- SIPCA code
	{label='DOCOMOMO'    , property='P3758', lang='', regexp='' }, -- DOCOMOMO Ibérico ID
	{label='Czech Monument', property='P4075', lang='cz', regexp='' }, -- Czech Monument Catalogue Number
	{label='MEG'         , property='P4157', lang='ch', regexp='' }, -- P1629: Musée d'ethnographie de Genève
	{label='Enciclopédia Itaú Cultural' , property='P4399', lang='pt_br', regexp='' }, -- Enciclopédia Itaú Cultural ID
	{label='Monumentos de São Paulo'    , property='P4360', lang='pt_br', regexp='' }, -- Monumentos de São Paulo ID
	{label='Infopatrimônio'             , property='P4372', lang='pt_br', regexp='' }, -- Infopatrimônio ID
	{label="Musée d'Orsay"              , property='P4659', lang='fr'   , regexp='' }, -- Musée d'Orsay artwork ID
	{label='MuBE'                       , property='P4721', lang='pt_br', regexp='' }, -- MuBE Virtual ID
	{label='Hispania Nostra'            , property='P4868', lang='es'   , regexp='' }, -- Hispania Nostra Red List ID
	{label='NLK'            , property='P5034', lang='ko'   , regexp='' }, -- National Library of Korea ID
	}

-- ==================================================
-- === External functions ===========================
-- ==================================================
local p = {}

function p.getAuthorityControlTag( lang )
-- get a localized interwiki link to article "Authority Control"
	local field_name = "[[w:en:Help:Authority control|Authority control]]" -- hardwire the default
	if lang~='en' then
		field_name = core.getLabel("Q36524", lang)
	end
	return field_name
end

-- ==================================================
function p._authorityControl(entity, args, lang, length)
-- INPUTS:
--  * entity - wikidata entity if already created or nil. If provided than you should still provide args.Wikidata
--  * args   - structure with identifier fields: args.VIAF, args.LCCN, args.Wikidata, etc.
--  * lang   - language code
--  * length - maximum length of the identifier array, or number of identifiers to display
-- OUTPUTS:
--  * results - wikicode string equivalent to {{Authority control|...|bare=1 }} call
--  * cats    - wikicode with maintenance categories

  -- count custom parameters (not pulled from Wikidata)
	local nCustomParam = 0 
	for _,params in ipairs( conf ) do
		if (args[params.label]~=nil) then
			nCustomParam = nCustomParam + 1
		end
	end
	
	-- Get entity - record of wikidata related to a single item
	local q = args.wikidata
	if not entity and q then
		entity = mw.wikibase.getEntity(q)
	end
	
	-- Check if this is category item
	local cats = '' -- categories (mismatching and missing)
	if entity and entity.claims and entity.claims.P31 then 
		for _, statement in pairs( entity.claims.P31) do
			if (statement.mainsnak.snaktype == "value") and (statement.mainsnak.datavalue.value.id == 'Q4167836')  then -- P31 == Wikimedia category 
				cats = '[[Category:Wrong Wikidata ID in authority control data: category item]]'
			end
			if (statement.mainsnak.snaktype == "value") and (statement.mainsnak.datavalue.value.id == 'Q4167410')  then -- P31 == Wikimedia disambiguation page 
				cats = '[[Category:Wrong Wikidata ID in authority control data: disambiguation item]]'
			end
		end
	end

	--compare provided arguments with Wikidata identifiers
	local data = {} -- structure similar to "args" but filled with wikidata data
	for _,params in ipairs( conf ) do
		local label = string.lower(params.label)
		data[label] = nil
		if entity and entity.claims and params.property and entity.claims[params.property] then -- if we have wikidata item and item has the property
			-- capture all Wikidata values for the identifier
			--for _, statement in pairs( entity.claims[params.property]) do
			for _, statement in pairs( entity:getBestStatements( params.property )) do
				if (statement.mainsnak.snaktype == "value") then -- or if statement.mainsnak.datavalue then 
					local v = statement.mainsnak.datavalue.value
					if data[label]==nil then
						data[label] = v       -- save the first value
					end
					if args[label] == v then  -- match between template and wikidata identifiers
						data[label] = ''      -- ignore identifier from wikidata
						break  
					end
				end
			end
		end
	end

	--Create string with all the identifiers listed
	local results1 = {} -- high priority list
	local results2 = {} -- low  priority list
	properties.P214.item = 'Q54919';   -- hardwire link to VIAF
	local today = '+' .. os.date('!%F') .. 'T00:00:00Z/11'
	local TransStr = 'https://quickstatements.toolforge.org/#/v1=%s|%s|%%22%s%%22|S143|Q565|S813|'.. today -- QuickStatementts URL
	TransStr = '<span class=\"plainlinks\" title=\"Click (+) to copy to wikidata\">['.. TransStr .. ' (+)]</span>'
	for _,params in ipairs( conf ) do
		local label = string.lower(params.label)
		local val1 = args[label] -- identifier value provided to the template
		local val2 = data[label] -- identifier value pulled from wikidata
		if val1 or val2 then
			local P = properties[params.property] -- properties of wikidata identifier propertyc
			-- name_link - link for the identifier name
			local name_link = getIdentifierNameLink( lang, P.item, P.issuedBy, params.label )
			
			-- val_link - identifier value or values
			local transfer = ''
			local val3 = string.gsub(val1 or '', ' ', '' ) -- remove spaces
			local val_link
			if not val1 then
				val_link = getIdentifierValLink(val2, P, params, 'blue') -- wikidata only no local identifier
			elseif val2=='' then
				val_link = getIdentifierValLink(val1, P, params, 'magenta') -- match was found
			elseif val2 then
				val_link = getIdentifierValLink(val1, P, params, 'darkgreen') .. "/"..getIdentifierValLink(val2, P, params, 'blue')
				cats  = string.format("%s[[Category:Pages using authority control with identifiers mismatching Wikidata]]\n", cats)
				transfer  = string.format(TransStr, q, params.property, val3)
			elseif not val2 and entity then
				val_link = getIdentifierValLink(val1, P, params, 'darkgreen')
				cats  = string.format("%s[[Category:Pages using authority control with identifiers missing from Wikidata]]\n", cats)
				transfer  = string.format(TransStr, q, params.property, val3)
			else
				val_link = getIdentifierValLink(val1, P, params, 'blue') -- local identifier and no wikidata q-code
			end

			-- combine them all
			local lineStr = string.format("\n*%s:&thinsp;<span class=\"uid\">%s</span>%s", name_link, val_link, transfer)
			if (params.lang==lang) or (params.lang=='') then
				table.insert(results1, lineStr) -- add to high priority list
			else
				table.insert(results2, lineStr) -- add to low priority list
			end
		end
	end -- for all sources
	
	-- merge high and low priority lists, trim them if needed and convert to string 
	--table.insert(results1, "\n*End list 1") -- for debuging
	--table.insert(results2, "\n*End list 2")
	for _,v in pairs(results2) do table.insert(results1, v) end
	local results = table.concat(results1, "", 1, math.min(#results1, length or #results1)) 
	
	-- Add Link to wikidata 
	if q then
		results = string.format("\n*[[File:Wikidata-logo.svg|20px|wikidata:%s|link=wikidata:%s]]: [[d:%s|%s]]%s",q,q,q,q,results)
	end
	
	-- Add link to Worldcat
	if (args.worldcatid==nil and (args.lccn or data.lccn))  then
		args.worldcatid = 'lccn-' .. (args.lccn or data.lccn)
	end
	if args.worldcatid  then
		results = string.format("%s\n*<span class=\"uid\">[//www.worldcat.org/identities/%s WorldCat]</span>", results, args.worldcatid)
	end
	
	-- Add maintenance categories
	if q == nil then
		cats = string.format("%s[[Category:Pages using authority control without Wikidata link]]\n", cats)
	end
	if nCustomParam>0 then
		if cats=='' and entity ~= nil then
			cats = string.format("%s[[Category:Pages using authority control with all identifiers matching Wikidata]]\n", cats)
		end
		if string.find(results, "<span style=\"color:red\">") then 
			cats = string.format("%s[[Category:Pages using authority control with badly formated identifier]]\n", cats)
		end
	end

	-- return results
	if results~='' then -- if there are any results than wrap them in <div> tag
		results  = string.format('<div class="hlist">%s\n</div>', results)
	end
	return results, cats
end


-- ===========================================================================
-- === Version of the function to be called from template namespace
-- ===========================================================================
function p.authorityControl(frame)
	-- prepare arguments
	local args = core.getArgs(frame)
	local bare = core.yesno(args.bare,false)         
	
	-- Convert template arguments to the same format as used on wikidata
	if args.bnf then
		args.bnf = string.sub(args.bnf, 3) -- trim first 2 characters
	end
--	if args.isni then -- group in sets of 4
--		args.isni = string.sub(args.isni, 1, 4).." "..string.sub(args.isni, 5, 8)
--		     .." "..string.sub(args.isni, 9,12).." "..string.sub(args.isni,13,16)
--	end
	if args.isbn then
		local isbn = isbn.gsub( ' ', '' )
		if #isbn==10 then
			args['isbn-10'] = args.isbn
		elseif #isbn==13 then
			args['isbn-13'] = args.isbn
		end
		args.isbn = nil
	end
	args.gnd  = args.gnd or args.pnd --redirect PND to GND
	args.lccn = fixLCCN(args.lccn)
	args.wikidata = args.wikidata or args.q or nil
	
	-- call the inner "core" function
	local results, cats = p._authorityControl(nil, args, args.lang, args.length)
	local namespace = mw.title.getCurrentTitle().namespace
	local LUT = {[2]='user', [6]='file', [10]='template', [828]='module'}
	if (LUT[namespace] or math.fmod(namespace,2)==1) then
		-- lets not add categories to some namespaces, or talk pages and concentrate
		-- on templates and categories instead
		cats = '' 
	end
	
	--package results as a infobox if not "bare"
	if not bare then
		-- Get field name for authority control
		local field_name = p.getAuthorityControlTag(args.lang)

		-- build table
		results = string.format('<tr><td class="type fileinfo-paramfield">%s</td><td>\n%s\n</td></tr>', field_name, results)
		local dir   = mw.language.new( args.lang ):getDir()    -- get text direction
		local style = 'class="toccolours mw-content-%s layouttemplate commons-file-information-table" style="width: 100%%;" dir="%s" lang="%s"' 
		style = string.format(style, dir, dir, args.lang)
		results = string.format('<table %s>\n%s\n</table>\n', style, results)
	else
		results = string.format('\n%s\n', results)
	end
	return results..cats
end

return p
"https://tamilar.wiki/w/index.php?title=Module:Authority_control&oldid=82248" இலிருந்து மீள்விக்கப்பட்டது