Jump to content

Module:Authority control

विकिपीडिया से
SM7 (बातचीत | योगदान) (अनुवाद कइल वर्जन लगावत बाटे) के द्वारा 13:17, 21 जुलाई 2015 के बदलाव

require('Module:No globals')

local function getCatForId( id )

   local title = mw.title.getCurrentTitle()
   local namespace = title.namespace
   local bhid
   if id == "VIAF" then
       bhid="वी॰आइ॰एफ॰ए॰"
   elseif id == "LCCN" then
       bhid="एल॰सी॰सी॰एन॰"
   elseif id == "ISNI" then
       bhid="आइ॰एस॰एन॰आइ॰"
   elseif id == "GND" then
       bhid="जी॰एन॰डी॰"
   elseif id == "BNF" then
       bhid="बी॰एन॰एफ॰"
   elseif id == "ULAN" then
       bhid="यू॰एल॰ए॰एन॰"
   elseif id == "BIBSYS" then
       bhid= "बिबसिस"
   elseif id == "BNE" then
       bhid= "बी॰एन॰ई॰"
   elseif id == "BPN" then
       bhid= "बी॰पी॰एन॰"
   elseif id == "LNB" then
       bhid= "एल॰एन॰बी॰"
   elseif id == "MusicBrainz" then
       bhid= "म्यूजिक ब्रॉन्ज"
   elseif id == "NDL" then
       bhid= "एन॰डी॰एल॰"
   elseif id == "NLA" then
       bhid= "एन॰एल॰ए॰"
   elseif id == "NSK" then
       bhid= "एन॰एस॰के॰"
   elseif id == "ORCID" then
       bhid= "ओ॰आर॰सी॰आइ॰डी॰"
   elseif id == "RID" then
       bhid= "आर॰आइ॰डी॰"
   elseif id == "RKDartists" then
       bhid= "आर॰के॰डी॰ कलाकार"
   elseif id == "SELIBR" then
       bhid= "सेलिबर"
   else
       bhid= "अन्य संख्यात्मक मान"
   end
   if namespace == 0 then
       return 
   elseif namespace == 2 and not title.isSubpage then
       return 
   else
       return 
   end

end

local function viafLink( id )

   if not string.match( id, '^%d+$' ) then
       return false
   end
   return '.. id .. ' ' .. id .. '' .. getCatForId( 'VIAF' )

end

local function kulturnavLink( id )

   return '.. id .. ' id' 

end

local function sikartLink( id )

   return '.. id .. '&lng=en ' .. id .. '' 

end

local function tlsLink( id ) local id2 = mw.ustring.gsub(id, '%s', function(s) return mw.uri.encode(s, 'WIKI') end)

   return '.. id2 .. ' ' .. id .. '' 

end


local function ciniiLink( id )

   return '.. id .. '?l=en ' .. id .. '' 

end

local function bneLink( id )

   return '.. id .. ' ' .. id .. '' 

end


local function uscongressLink( id )

   return '.. id .. ' ' .. id .. '' 

end

local function narapersonLink( id )

   return '.. id .. ' ' .. id .. '' 

end

local function naraorganizationLink( id )

   return '.. id .. ' ' .. id .. '' 

end

local function botanistLink( id ) local id2 = mw.ustring.gsub(id, '%s', function(s) return mw.uri.encode(s, 'PATH') end)

   return '.. id2 .. ' ' .. id .. '' 

end

local function mgpLink( id )

   -- TODO Implement some sanity checking regex
   return '.. id .. ' ' .. id .. '' 

end

local function rslLink( id )

   -- TODO Implement some sanity checking regex
   return '.. id .. '&CON_LNG=ENG ' .. id .. ''

end

local function leonoreLink( id ) -- Identifiants allant de LH/1/1 à LH/2794/54 (légionnaires) -- Identifiants allant de C/0/1 à C/0/84 (84 légionnaires célèbres) -- Identifiants allant de 19800035/1/1 à 19800035/385/51670 (légionnaires décédés entre 1954 et 1977, et quelques dossiers de légionnaires décédés avant 1954)

   if not string.match( id, '^LH/%d%d?%d?%d?/%d%d?%d?$' ) and
      not string.match( id, '^C/0/%d%d?$' ) and

not string.match( id, '^19800035/%d%d?%d?%d?/%d%d?%d?%d?%d?$' ) then

       return false
   end
   return '.. id .. ' ' .. id .. '' 

end

local function sbnLink( id )

   if not string.match( id, '^IT\\ICCU\\%d%d%d%d%d%d%d%d%d%d$' ) and not string.match( id, '^IT\\ICCU\\%u%u[%d%u]%u\\%d%d%d%d%d%d$' ) then
       return false
   end
   return '.. id .. ' ' .. id .. ''

end

local function nkcLink( id ) return '.. id .. '&CON_LNG=ENG ' .. id .. '' end

local function nclLink( id )

   if not string.match( id, '^%d+$' ) then
       return false
   end
   return '.. id .. '&CON_LNG=ENG ' .. id .. '' 

end

local function ndlLink( id ) return '.. id .. ' ' .. id .. '' end

local function sudocLink( id )

   if not string.match( id, '^%d%d%d%d%d%d%d%d[%dxX]$' ) then
       return false
   end
   return '.. id .. ' ' .. id .. '' 

end

local function hlsLink( id )

   if not string.match( id, '^%d+$' ) then
       return false
   end
   return '.. id .. '.php ' .. id .. ''

end

local function lirLink( id )

   if not string.match( id, '^%d+$' ) then
       return false
   end
   return '.. id .. '.450.0.html ' .. id .. ''

end

local function splitLccn( id )

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

end

local function append(str, c, length)

   while str:len() < length do
       str = c .. str
   end
   return str

end

local function lccnLink( id )

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

end

local function mbLink( id )

   -- TODO Implement some sanity checking regex
   return '.. id .. ' ' .. id .. '' .. getCatForId( 'MusicBrainz' )

end

--Returns the ISNI check digit isni must be a string where the 15 first elements are digits local function getIsniCheckDigit( isni )

   local total = 0
   for i = 1, 15 do
       local digit = isni:byte( i ) - 48 --Get integer value
       total = (total + digit) * 2
   end
   local remainder = total % 11
   local result = (12 - remainder) % 11
   if result == 10 then
       return "X"
   end
   return tostring( result )

end

--Validate ISNI (and ORCID) and retuns it as a 16 characters string or returns false if it's invalid --See http://support.orcid.org/knowledgebase/articles/116780-structure-of-the-orcid-identifier local function validateIsni( id )

   id = id:gsub( '[ %-]',  ):upper()
   if not id:match( '^%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d[%dX]$' ) then
       return false
   end
   if getIsniCheckDigit( id ) ~= string.char( id:byte( 16 ) ) then
       return false
   end
   return id

end

local function isniLink( id )

   id = validateIsni( id )
   if not id then
       return false
   end
   return '.. id .. ' ' .. id:sub( 1, 4 ) .. ' ' .. id:sub( 5, 8 ) .. ' '  .. id:sub( 9, 12 ) .. ' '  .. id:sub( 13, 16 ) .. '' .. getCatForId( 'ISNI' )

end

local function orcidLink( id )

   id = validateIsni( id )
   if not id then
       return false
   end
   id = id:sub( 1, 4 ) .. '-' .. id:sub( 5, 8 ) .. '-'  .. id:sub( 9, 12 ) .. '-'  .. id:sub( 13, 16 )
   return '.. id .. ' ' .. id .. '' .. getCatForId( 'ORCID' )

end

local function gndLink( id )

   return '.. id .. ' ' .. id .. '' .. getCatForId( 'GND' )

end

local function selibrLink( id ) if not string.match( id, '^%d+$' ) then

       return false
   end
   return '.. id .. ' ' .. id .. '' .. getCatForId( 'SELIBR' )

end

local function bnfLink( id )

   --Add cb prefix if it has been removed
   if not string.match( id, '^cb.+$' ) then
       id = 'cb' .. id
   end
   return '.. id .. ' ' .. id .. ' .. id .. ' (data)' .. getCatForId( 'BNF' )

end

local function bpnLink( id )

   if not string.match( id, '^%d+$' ) then
       return false
   end
   return '.. id .. ' ' .. id .. '' .. getCatForId( 'BPN' )

end

local function ridLink( id )

   return '.. id .. ' ' .. id .. '' .. getCatForId( 'RID' )

end

local function bibsysLink( id )

   return '.. id .. '&feltselect=bs.autid ' .. id .. '' .. getCatForId( 'BIBSYS' )

end

local function ulanLink( id )

   return '.. id .. ' ' .. id .. '' .. getCatForId( 'ULAN' )

end

local function nlaLink( id ) return '.. id .. ' ' .. id .. '' .. getCatForId( 'NLA' ) end

local function rkdartistsLink( id ) return '.. id .. ' ' .. id .. '' .. getCatForId( 'RKDartists' ) end

local function getIdsFromWikidata( item, property )

   local ids = {}
   if not item.claims[property] then
       return ids
   end
   for _, statement in pairs( item.claims[property] ) do

if statement.mainsnak.datavalue then table.insert( ids, statement.mainsnak.datavalue.value ) end

   end
   return ids

end

local function matchesWikidataRequirements( item, reqs )

   for _, group in pairs( reqs ) do
       local property = 'p' .. group[1]
       local qid = group[2]
       if item.claims[property] ~= nil then
           for _, statement in pairs ( item.claims[property] ) do
           	if statement.mainsnak.datavalue ~= nil then

if statement.mainsnak.datavalue.value['numeric-id'] == qid then

   	                return true
       	        end
       	    end
           end
       end
   end
   return false

end

local function createRow( id, label, rawValue, link, withUid )

   if link then
       if withUid then
           return '* ' .. label .. ' ' .. link .. '\n'
       else
           return '* ' .. label .. ' ' .. link .. '\n'
       end
   else
       return '* The ' .. id .. ' id ' .. rawValue .. ' is not valid.\n'
   end

end

--In this order: name of the parameter, label, propertyId in Wikidata, formatting function local conf = {

   { 'VIAF', 'वी॰आइ॰ए॰एफ॰', 214, viafLink },
   { 'LCCN', 'एल॰सी॰सी॰एन॰', 244, lccnLink },
   { 'ISNI', 'आइ॰एस॰एन॰टी॰', 213, isniLink },
   { 'ORCID', 'ऑर्किड', 496, orcidLink },
   { 'GND', 'जी॰एन॰डी॰', 227, gndLink },
   { 'SELIBR', 'सेलिबर', 906, selibrLink },
   { 'SUDOC', 'एस॰यू॰डॉक', 269, sudocLink },    
   { 'BNF', 'बी॰एन॰एफ॰', 268, bnfLink },
   { 'BPN', 'बी॰पी॰एन॰', 651, bpnLink },
   { 'RID', 'रिसर्चरआइ॰डी॰', 1053, ridLink },
   { 'BIBSYS', 'बिबसिस', 1015, bibsysLink },
   { 'ULAN', 'यू॰एल॰ए॰एन॰', 245, ulanLink },
   { 'HDS', 'एच॰डी॰एस॰', 902, hlsLink },
   { 'LIR', 'एल॰आइ॰आर॰', 886, lirLink },
   { 'MBA', 'म्यूजिकब्रॉन्ज', 434, mbLink },
   { 'MGP', 'एम॰जी॰पी॰', 549, mgpLink },    
   { 'NLA', 'एन॰एल॰ए॰', 409, nlaLink },
   { 'NDL', 'एन॰डी॰एल॰', 349, ndlLink },
   { 'NCL', 'एन॰सी॰एल॰', 1048, nclLink },
   { 'NKC', 'एन॰के॰सी॰', 691, nkcLink },
   { 'Léonore', 'लियोनोरे', 640, leonoreLink }, 
   { 'SBN', 'आइ॰सी॰सीयू॰', 396, sbnLink },     
   { 'RLS', 'आर॰एल॰एस॰', 947, rslLink },
   { 'Botanist', 'बनस्पति_बिज्ञानी', 428, botanistLink },
   { 'NARA-person', 'एन॰ए॰आर॰ए॰', 1222, narapersonLink },
   { 'NARA-organization', 'एन॰ए॰आर॰ए॰', 1223, naraorganizationLink },
   { 'USCongress', 'यू॰एस॰ काँग्रेस', 1157, uscongressLink },
   { 'BNE', 'बी॰एन॰ई॰', 950, bneLink },
   { 'CINII', 'सीनी', 271, ciniiLink },
   { 'TLS', 'टी॰एल॰एस॰', 1362, tlsLink },
   { 'SIKART', 'सीकार्ट', 781, sikartLink },
   { 'KULTURNAV', 'कुलतुरनैव', 1248, kulturnavLink },
   { 'RKDartists', 'आर॰के॰डी॰', 650, rkdartistsLink },

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

local p = {}

function p.authorityControl( frame )

   local parentArgs = frame:getParent().args
   --Create rows
   local elements = {}
   --redirect PND to GND
   if (parentArgs.GND == nil or parentArgs.GND == ) and parentArgs.PND ~= nil and parentArgs.PND ~=  then
       parentArgs.GND = parentArgs.PND
   end
   --Wikidata fallback if requested
   local item = mw.wikibase.getEntityObject()
   if item ~= nil and item.claims ~= nil then
       for _, params in pairs( conf ) do
           if params[3] ~= 0 then
               local val = parentArgs[params[1]]
               if not val or val ==  then
               	local canUseWikidata = nil
                   if reqs[params[1]] ~= nil then
                       canUseWikidata = matchesWikidataRequirements( item, reqs[params[1]] )
                   else
                       canUseWikidata = true
                   end
                   if canUseWikidata then
                       local wikidataIds = getIdsFromWikidata( item, 'P' .. params[3] )
                       if wikidataIds[1] then
                           parentArgs[params[1]] = wikidataIds[1]
                       end
                   end
               end
           end
       end
   end
   --Worldcat
   if parentArgs['WORLDCATID'] and parentArgs['WORLDCATID'] ~=  then
       table.insert( elements, createRow( 'WORLDCATID', , parentArgs['WORLDCATID'], '.. parentArgs['WORLDCATID' .. ' WorldCat]', false ) ) --Validation?
   elseif parentArgs['LCCN'] and parentArgs['LCCN'] ~=  then
       local lccnParts = splitLccn( parentArgs['LCCN'] )
       if lccnParts and lccnParts[1] ~= 'sh' then
           table.insert( elements, createRow( 'LCCN', , parentArgs['LCCN'], '.. lccnParts[1 .. lccnParts[2] .. '-' .. lccnParts[3] .. ' वर्ल्डकैट]', false ) )
       end
   end
   --Configured rows
   local rct = 0
   for k, params in pairs( conf ) do
       local val = parentArgs[params[1]]
       if val and val ~=  then
           table.insert( elements, createRow( params[1], params[2] .. ':', val, params[4]( val ), true ) )
           rct = rct + 1
       end
   end
   local Navbox = require('Module:Navbox')
   local elementscats = 
   if rct > 13 then
   	elementscats  = 

end

if #elements ~= 0 then return Navbox._navbox( { name = 'ऑथारिटी कंट्रोल', bodyclass = 'hlist', group1 = 'ऑथारिटी कंट्रोल' .. elementscats, list1 = table.concat( elements ) } ) else return "" end end

return p