Módulo:Taxonbar: diferenças entre revisões
Aspeto
Conteúdo apagado Conteúdo adicionado
criado de gl:Módulo:Taxonbar |
ajustes |
||
(Há 7 revisões intermédias de 2 utilizadores que não estão a ser apresentadas) | |||
Linha 1: | Linha 1: | ||
require(' |
require('strict') |
||
local conf = require( 'Module:Taxonbar/conf' ) -- configuration module |
|||
local function getCatForId( id ) |
|||
local title = mw.title.getCurrentTitle() |
|||
local function isNilOrEmpty( thing ) |
|||
local namespace = title.namespace |
|||
if |
if thing == nil or thing == '' then |
||
return true |
|||
return '[[!Artigos enciclopédicos com identificadores ' .. id .. ']]' |
|||
--elseif namespace == 2 and not title.isSubpage then |
|||
-- return '[[Categoria:!Páginas de usuário com identificadores ' .. id .. ']]' |
|||
--else |
|||
-- return '[[Categoria:!Páginas de teor misto com identificadores ' .. id .. ']]' |
|||
end |
end |
||
return nil |
|||
end |
end |
||
local function |
local function splitLccn( id ) |
||
if id:match( '^%l%l?%l?%d%d%d%d%d%d%d%d%d?%d?$' ) then |
|||
while str:len() < length do |
|||
id = id:gsub( '^(%l+)(%d+)(%d%d%d%d%d%d)$', '%1/%2/%3' ) |
|||
str = c .. str |
|||
end |
end |
||
if id:match( '^%l%l?%l?/%d%d%d?%d?/%d+$' ) then |
|||
return str |
|||
return mw.text.split( id, '/' ) |
|||
end |
|||
return false |
|||
end |
end |
||
local function getIdFromWikidata( item, property ) |
|||
--Links |
|||
local id = nil |
|||
if property == 'PWikispecies:$1' then |
|||
local function adwLink( id ) |
|||
local siteLinks = item.sitelinks |
|||
return '[http://animaldiversity.org/accounts/' .. id .. ' ' .. id .. ']' .. getCatForId( 'ADW' ) |
|||
if siteLinks then |
|||
local speciesWiki = item.sitelinks.specieswiki |
|||
if speciesWiki then |
|||
id = speciesWiki.title |
|||
end |
|||
end |
|||
return id |
|||
elseif item.claims[property] == nil then |
|||
return id |
|||
end |
|||
for _, statement in pairs( item.claims[property] ) do |
|||
if statement.mainsnak.datavalue then |
|||
id = statement.mainsnak.datavalue.value |
|||
break |
|||
end |
|||
end |
|||
return id |
|||
end |
end |
||
local function |
local function getLink( property, val, mask ) |
||
local link, returnVal = '', {} |
|||
return '[http://www.araneae.unibe.ch/data/' .. id .. ' ' .. id .. ']' .. getCatForId( 'Araneae' ) |
|||
returnVal.isError = false |
|||
if mw.ustring.find( val, '//' ) then |
|||
link = val |
|||
else |
|||
if type(property) == 'number' and property > 0 then |
|||
local entityObject = mw.wikibase.getEntity('P'..property) |
|||
local dataType |
|||
if entityObject then dataType = entityObject.datatype |
|||
else returnVal.isError = true end |
|||
if dataType == 'external-id' then |
|||
local formatterURL = nil |
|||
if property == 3746 then --Wildflowers of Israel ID's 2nd formatterURL is in English |
|||
formatterURL = entityObject:getBestStatements('P1630')[2] |
|||
end |
|||
if formatterURL == nil then formatterURL = entityObject:getBestStatements('P1630')[1] end |
|||
if formatterURL then |
|||
if formatterURL.mainsnak.datavalue and formatterURL.mainsnak.datavalue.value then --nil check for ABA |
|||
link = formatterURL.mainsnak.datavalue.value |
|||
end |
|||
end |
|||
elseif dataType == 'url' then |
|||
local subjectItem = entityObject:getBestStatements('P1629')[1] |
|||
if subjectItem then |
|||
local officialWebsite = mw.wikibase.getEntity(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 subjectItem = entityObject:getBestStatements('P1629')[1] |
|||
if subjectItem then |
|||
local officialWebsite = mw.wikibase.getEntity(subjectItem.mainsnak.datavalue.value.id):getBestStatements('P856')[1] |
|||
if officialWebsite then link = officialWebsite.mainsnak.datavalue.value end |
|||
end |
|||
end |
|||
else |
|||
returnVal.isError = true |
|||
end |
|||
elseif type(property) == 'string' then |
|||
link = property |
|||
end |
|||
local valurl = val |
|||
if mw.ustring.find( link, 'antweb.org' ) then valurl = mw.ustring.gsub(valurl, ' ', '%%20') end |
|||
if type(property) == 'number' then |
|||
--doublecheck language for Wildflowers of Israel ID |
|||
if property == 3746 then link = mw.ustring.gsub(link, '/hebrew/', '/english/') end |
|||
--format spaces in PfaF, e.g. for "Elaeagnus x ebbingei" |
|||
if property == 4301 then valurl = mw.ustring.gsub(valurl, ' ', '+') end |
|||
end |
|||
valurl = mw.ustring.gsub(valurl,'%%','%%%%') |
|||
link = mw.ustring.gsub(link, '$1', valurl) |
|||
end |
|||
link = mw.ustring.gsub(link, '^[Hh][Tt][Tt][Pp]([Ss]?)://', 'http%1://') -- fix wikidata URL |
|||
link = mw.ustring.gsub(link, ' ' , '') |
|||
val = mw.ustring.match(val, '([^=/]*)/?$') -- get display name from end of URL |
|||
if mw.ustring.find( link, '//' ) then |
|||
if mask == 'y' then |
|||
returnVal.text = '<span class="plainlinks">['..link..' ID]</span>' |
|||
else |
|||
returnVal.text = '<span class="plainlinks">['..link..' '..mw.text.encode(mw.uri.decode(val, 'PATH'),'%[%]')..']</span>' |
|||
end |
|||
elseif link == '' then |
|||
returnVal.text = val |
|||
else |
|||
returnVal.text = '[['..link..'|'..val..']]' |
|||
end |
|||
return returnVal |
|||
end |
end |
||
local function |
local function createRow( id, label, rawValue, link, withUid ) |
||
if link then |
|||
return '[http://www.rareplants.cnps.org/detail/' .. id .. '.html ' .. id .. ']' .. getCatForId( 'CNPS' ) |
|||
local outStr = '*<span style="white-space:nowrap;">' .. label .. ' <span' |
|||
if withUid then outStr = outStr..' class="uid"' end |
|||
return outStr..'>' .. link .. '</span></span>\n' |
|||
else |
|||
return '* ' .. mw.text.tag('span', {class='error'}, 'O identificador ' .. id .. ' ' .. rawValue .. ' é inválido.') .. '\n' |
|||
end |
|||
end |
end |
||
local function |
local function copyTable(inTable) |
||
if type(inTable) ~= 'table' then return inTable end |
|||
return '[http://www.theplantlist.org/tpl1.1/record/' .. id .. ' ' .. id .. ']' .. getCatForId( 'PlantList' ) |
|||
local outTable = setmetatable({}, getmetatable(inTable)) |
|||
for key, value in pairs (inTable) do outTable[copyTable(key)] = copyTable(value) end |
|||
return outTable |
|||
end |
end |
||
local |
local p = {} |
||
return '[https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id=' .. id .. ' ' .. id .. ']' .. getCatForId( 'NCBI' ) |
|||
end |
|||
function p.authorityControlTaxon( frame ) |
|||
local resolve = require( 'Module:ResolveEntityId' ) |
|||
return '[https://inpn.mnhn.fr/espece/cd_nom/' .. id .. ' ' .. id .. ']' .. getCatForId( 'TAXREF' ) |
|||
local parentArgs = copyTable(frame:getParent().args) |
|||
end |
|||
local currentTitle = mw.title.getCurrentTitle() |
|||
local currentEntityId = mw.wikibase.getEntityIdForCurrentPage() |
|||
local stringArgs = false |
|||
local fromTitleCount, firstRow, rowCount = 1, 0, 0 |
|||
local outString, errors = '', '' |
|||
local tFroms = {} --non-sequential table of unique froms |
|||
local iFroms = 0 --integer size of tFroms, b/c Lua |
|||
--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 isNilOrEmpty( parentArgs[lowerk] ) then |
|||
parentArgs[k] = nil |
|||
parentArgs[lowerk] = v |
|||
end |
|||
--remap abc to abc1 |
|||
if mw.ustring.find(lowerk,'%d$') == nil then --if no number at end of param |
|||
if isNilOrEmpty( parentArgs[lowerk..'1'] ) then |
|||
parentArgs[lowerk] = nil |
|||
lowerk = lowerk..'1' |
|||
parentArgs[lowerk] = v |
|||
end |
|||
end |
|||
if v and v ~= '' then |
|||
--remap 'for' to 'title' |
|||
if mw.ustring.sub(lowerk,1,3) == 'for' then |
|||
local forTitle = mw.ustring.gsub(lowerk,'^for','title',1) |
|||
if isNilOrEmpty( parentArgs[forTitle] ) then |
|||
parentArgs[lowerk] = nil |
|||
lowerk = forTitle |
|||
parentArgs[lowerk] = v |
|||
end |
|||
end |
|||
--find highest from or title param |
|||
if mw.ustring.sub(lowerk,1,4) == 'from' then |
|||
local fromNumber = tonumber(mw.ustring.sub(lowerk,5,-1)) |
|||
if fromNumber and fromNumber >= fromTitleCount then fromTitleCount = fromNumber end |
|||
--look for duplicate froms while we're here |
|||
if mw.ustring.find(v, '^Q%d') then |
|||
if tFroms[v] then |
|||
tFroms[v] = tFroms[v] + 1 |
|||
local function spratLink ( id ) |
|||
else |
|||
return '[http://www.environment.gov.au/cgi-bin/sprat/public/publicspecies.pl?taxon_id=' .. id .. ' ' .. id .. ']' .. getCatForId( 'SPRAT' ) |
|||
tFroms[v] = 1 |
|||
end |
|||
iFroms = iFroms + 1 |
|||
end |
|||
if iFroms == 2 then |
|||
end |
|||
local function zoobankLink ( id ) |
|||
end |
|||
return '[http://zoobank.org/NomenclaturalActs/' .. id .. ' ID]' .. getCatForId( 'ZooBank' ) |
|||
elseif mw.ustring.sub(lowerk,1,5) == 'title' then |
|||
end |
|||
local titleNumber = tonumber(mw.ustring.sub(lowerk,4,-1)) |
|||
if titleNumber and titleNumber >= fromTitleCount then fromTitleCount = titleNumber end |
|||
elseif mw.ustring.lower(v) ~= 'no' then |
|||
stringArgs = true |
|||
end |
|||
local function plaziLink ( id ) |
|||
end |
|||
return '[http://treatment.plazi.org/id/' .. id .. ' ID]' .. getCatForId( 'Plazi' ) |
|||
end |
end |
||
local function nbnLink ( id ) |
|||
return '[https://data.nbn.org.uk/Taxa/' .. id .. ' ' .. id .. ']' .. getCatForId( 'NBN' ) |
|||
end |
|||
local function dyntaxaLink ( id ) |
|||
return '[https://www.dyntaxa.se/taxon/info/' .. id .. ' ' .. id .. ']' .. getCatForId( 'Dyntaxa' ) |
|||
end |
|||
local function lepindexLink( id ) |
|||
return '[http://www.nhm.ac.uk/jdsml/research-curation/research/projects/lepindex/detail.dsml?TaxonNo=' .. id .. ' ' .. id .. ']' .. getCatForId( 'LepIndex' ) |
|||
end |
|||
local function butmothLink( id ) |
|||
return '[http://www.nhm.ac.uk/jdsml/research-curation/research/projects/butmoth/GenusDetails.dsml?NUMBER=' .. id .. ' ' .. id .. ']' .. getCatForId( 'ButMoth' ) |
|||
end |
|||
local function bacdiveLink( id ) |
|||
return '[http://bacdive.dsmz.de/index.php?rd=' .. id .. ' ' .. id .. ']' .. getCatForId( 'BacDive' ) |
|||
end |
|||
local function tropicosLink( id ) |
|||
return '[http://www.tropicos.org/Name/' .. id .. ' ' .. id .. ']' .. getCatForId( 'Tropicos' ) |
|||
end |
|||
local function eppoLink( id ) |
|||
return '[https://gd.eppo.int/taxon/' .. id .. ' ' .. id .. ']' .. getCatForId( 'EPPO' ) |
|||
end |
|||
local function eolLink ( id ) |
|||
return '[http://eol.org/pages/' .. id .. ' ' .. id .. ']' .. getCatForId( 'EOL' ) |
|||
end |
|||
local function biolibLink ( id ) |
|||
return '[http://www.biolib.cz/en/taxon/id' .. id .. ' ' .. id .. ']' .. getCatForId( 'BioLib' ) |
|||
end |
|||
local function ictvLink ( id ) |
|||
return '[http://ictvdb.bio-mirror.cn/ICTVdB/' .. id .. 'htm ' .. id .. ']' .. getCatForId( 'ICTV' ) |
|||
end |
|||
local function fwLink ( id ) |
|||
return '[http://fossilworks.org/bridge.pl?a=taxonInfo&taxon_no=' .. id .. ' ' .. id .. ']' ..getCatForId( 'FW' ) |
|||
end |
|||
local function mswLink ( id ) |
|||
return '[http://www.departments.bucknell.edu/biology/resources/msw3/browse.asp?s=y&id=' .. id .. ' ' .. id .. ']' ..getCatForId( 'MSW' ) |
|||
end |
|||
local function arkiveLink ( id ) |
|||
return '[http://www.arkive.org/' .. id .. ' ID]' ..getCatForId( 'ARKive' ) |
|||
end |
|||
local function ipniLink ( id ) |
|||
return '[http://www.ipni.org/ipni/idPlantNameSearch.do?id=' .. id .. ' ' .. id .. ']' .. getCatForId( 'IPNI' ) |
|||
end |
|||
local function speciesLink ( id ) |
|||
return '[http://speciesplus.net/#/taxon_concepts/' .. id .. '/legal ' .. id .. ']' .. getCatForId( 'Species+' ) |
|||
end |
|||
local function grassbaseLink ( id ) |
|||
return '[http://www.kew.org/data/grasses-db/www/' .. id .. '.htm ' .. id .. ']' .. getCatForId( 'GrassBase' ) |
|||
end |
|||
local function mycobankLink ( id ) |
|||
return '[http://www.mycobank.org/MycoTaxo.aspx?Link=T&Rec=' .. id .. ' ' .. id .. ']' .. getCatForId( 'MycoBank' ) |
|||
end |
|||
local function faunaEuropaeaLink ( id ) |
|||
return '[http://fauna.naturkundemuseum-berlin.de/full_results.php?id=' .. id .. ' ' .. id .. ']' .. getCatForId( 'FE' ) |
|||
end |
|||
local function wormsLink ( id ) |
|||
return '[http://www.marinespecies.org/aphia.php?p=taxdetails&id=' .. id .. ' ' .. id .. ']' .. getCatForId('WoRMS') |
|||
end |
|||
local function itisLink ( id ) |
|||
return '[http://www.itis.gov/servlet/SingleRpt/SingleRpt?search_topic=TSN&search_value=' .. id .. ' ' .. id .. ']' .. getCatForId('ITIS') |
|||
end |
|||
local function iucnLink ( id ) |
|||
return '[http://www.iucnredlist.org/details/' .. id .. '/0 ' .. id .. ']' .. getCatForId('IUCN') |
|||
end |
|||
local function fishbaseLink ( id ) |
|||
return '[http://www.fishbase.org/Summary/speciesSummary.php?id=' .. id .. ' ' .. id .. ']' .. getCatForId('FishBase') |
|||
end |
|||
local function fungorumLink ( id ) |
|||
return '[http://www.indexfungorum.org/names/NamesRecord.asp?RecordID=' .. id .. ' ' .. id .. ']' .. getCatForId('Fungorum') |
|||
end |
|||
local function gbifLink ( id ) |
|||
return '[http://www.gbif.org/species/' .. id .. ' ' .. id .. ']' .. getCatForId('GBIF') |
|||
end |
|||
local function avibaseLink ( id ) |
|||
return '[http://avibase.bsc-eoc.org/species.jsp?avibaseid=' .. id .. ' ' .. id .. ']' .. getCatForId( 'Avibase' ) |
|||
end |
|||
local function inaturalistLink ( id ) |
|||
return '[http://www.inaturalist.org/taxa/' .. id .. ' ' .. id .. ']' .. getCatForId( 'iNaturalist' ) |
|||
end |
|||
local function xenocantoLink ( id ) |
|||
return '[http://www.xeno-canto.org/species/' .. id .. ' ' .. id .. ']' .. getCatForId( 'Xenocanto') |
|||
end |
|||
local function fnaLink ( id ) |
|||
return '[http://www.efloras.org/florataxon.aspx?flora_id=1&taxon_id=' .. id .. ' ' .. id .. ']' .. getCatForId( 'FNA') |
|||
end |
|||
local function focLink ( id ) |
|||
return '[http://www.efloras.org/florataxon.aspx?flora_id=2&taxon_id=' .. id .. ' ' .. id .. ']' .. getCatForId( 'FoC') |
|||
end |
|||
local function vascanLink ( id ) |
|||
return '[http://data.canadensys.net/vascan/taxon/' .. id .. ' ' .. id .. ']' .. getCatForId( 'VASCAN') |
|||
end |
|||
local function vlindernetLink ( id ) |
|||
return '[http://www.vlindernet.nl/vlindersoort.php?vlinderid=' .. id .. ' ' .. id .. ']' .. getCatForId( 'Vlindernet') |
|||
end |
|||
local function usdaplantsLink ( id ) |
|||
return '[http://plants.usda.gov/core/profile?symbol=' .. id .. ' ' .. id .. ']' .. getCatForId( 'USDAPLANTS') |
|||
end |
|||
local function apdbLink ( id ) |
|||
return '[http://www.ville-ge.ch/musinfo/bd/cjb/africa/details.php?langue=an&id=' .. id .. ' ' .. id .. ']' .. getCatForId( 'APDB') |
|||
end |
|||
local function foaoLink ( id ) |
|||
return '[http://www.anbg.gov.au/abrs/online-resources/flora/stddisplay.xsql?pnid=' .. id .. ' ' .. id .. ']' .. getCatForId( 'FoAO') |
|||
end |
|||
local function florabaseLink ( id ) |
|||
return '[http://florabase.dec.wa.gov.au/browse/profile/' .. id .. ' ' .. id .. ']' .. getCatForId( 'FloraBase') |
|||
end |
|||
local function plantariumLink ( id ) |
|||
return '[http://www.plantarium.ru/page/view/item/' .. id .. '.html ' .. id .. ']' .. getCatForId( 'Plantarium') |
|||
end |
|||
local function soortenregisterLink ( id ) |
|||
return '[http://www.nederlandsesoorten.nl/linnaeus_ng/app/views/species/nsr_taxon.php?id=' .. id .. ' ' .. id .. ']' .. getCatForId( 'Soortenregister') |
|||
end |
|||
local function telabotanicaLink ( id ) |
|||
return '[http://www.tela-botanica.org/bdtfx-nn-' .. id .. ' ' .. id .. ']' .. getCatForId( 'TelaBotanica') |
|||
end |
|||
local function wcspfLink ( id ) |
|||
return '[http://apps.kew.org/wcsp/namedetail.do?name_id=' .. id .. ' ' .. id .. ']' .. getCatForId( 'WCSPF') |
|||
end |
|||
local function wscLink ( id ) |
|||
return '[http://www.wsc.nmbe.ch/lsid/' .. id .. ' ' .. id .. ']' .. getCatForId( 'WSC') |
|||
end |
|||
local function ibcLink ( id ) |
|||
return '[http://www.hbw.com/ibc/species/' .. id .. ' ID]' .. getCatForId( 'IBC') |
|||
end |
|||
local function bugguideLink ( id ) |
|||
return '[http://bugguide.net/node/view/' .. id .. ' ' .. id .. ']' .. getCatForId( 'BugGuide') |
|||
end |
|||
local function titanLink ( id ) |
|||
return '[http://titan.gbif.fr/sel_genann1.php?numero=' .. id .. ' ' .. id .. ']' .. getCatForId( 'Titan') |
|||
end |
|||
local function paldatLink ( id ) |
|||
return '[https://www.paldat.org/pub/' .. id .. ' ' .. id .. ']' .. getCatForId( 'PalDat') |
|||
end |
|||
------- |
|||
local function getIdsFromWikidata( item, property ) |
|||
local ids = {} |
|||
if not item.claims[property] then |
|||
return ids |
|||
end |
end |
||
for _, statement in pairs( item.claims[property] ) do |
|||
--Check for unknown parameters |
|||
if statement.mainsnak.datavalue then |
|||
--create knowns list |
|||
table.insert( ids, statement.mainsnak.datavalue.value ) |
|||
local acceptableArgs = { from = true, } --master list of l/c acceptable args |
|||
end |
|||
for _, d in pairs( conf.databases ) do |
|||
if d[1] ~= 'Wikidata' then --made obsolete by from |
|||
acceptableArgs[mw.ustring.lower(d[1])] = true |
|||
end |
|||
end |
|||
for _, a in pairs( conf.aliases ) do |
|||
acceptableArgs[mw.ustring.lower(a[1])] = true |
|||
end |
end |
||
--create trimmed parents list |
|||
return ids |
|||
local baseParentArgs = {} --condensed list of l/c parent args w/o trailing #s |
|||
end |
|||
for k, v in pairs( parentArgs ) do |
|||
if type(k) == 'string' then --ignore unnamed params, which have keys of type 'number' |
|||
local function matchesWikidataRequirements( item, reqs ) |
|||
local lowerk = mw.ustring.lower(k) |
|||
for _, group in pairs( reqs ) do |
|||
local |
local base = mw.ustring.gsub(lowerk, '[%d]*$', '') |
||
baseParentArgs[base] = true |
|||
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 |
||
end |
end |
||
--compare lists and spit out unknowns |
|||
return false |
|||
local unknownParams = {} |
|||
end |
|||
for k, v in pairs( baseParentArgs ) do |
|||
if acceptableArgs[k] == nil then |
|||
unknownParams[#unknownParams + 1] = k |
|||
local function createRow( id, label, rawValue, link, withUid ) |
|||
if link then |
|||
if withUid then |
|||
return '*<span style="white-space:nowrap;">' .. label .. ' <span class="uid">' .. link .. '</span></span>\n' |
|||
else |
|||
return '*<span style="white-space:nowrap;">' .. label .. ' ' .. link .. '</span>\n' |
|||
end |
end |
||
else |
|||
return '* <span class="error">O identificador ' .. id .. ' ' .. rawValue .. ' non é válido.</span>[[Categoria:!Artigos enciclopédicos com erros nos identificadores]]\n' |
|||
end |
end |
||
--warn if unknown(s) present |
|||
end |
|||
if #unknownParams > 0 then |
|||
if frame:preprocess( '{{REVISIONID}}' ) == '' then |
|||
errors = errors..'<div class="hatnote" style="color:red">'.. |
|||
'<strong>Atenção:</strong> parâmetros desconhecidos <strong>'..table.concat(unknownParams, ', ')..'</strong>.<br />'.. |
|||
'Corrige-os ou considere liga-los à Wikidata.<br />'.. |
|||
'Esta mensagem só se mostra na previsualização.</div>' |
|||
end |
|||
end |
|||
--Setup navbox |
|||
local navboxParams = { |
|||
name = 'Taxonbar', |
|||
bodyclass = 'hlist', |
|||
listclass = 'plainlinks', |
|||
groupstyle = 'width: 12%; text-align:center;', |
|||
} |
|||
for f = 1, fromTitleCount, 1 |
|||
do |
|||
local elements, title = {}, nil |
|||
--cleanup parameters |
|||
if parentArgs['from'..f] == '' then parentArgs['from'..f] = nil end |
|||
if parentArgs['title'..f] == '' then parentArgs['title'..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 parentArgs[name..f] == nil then |
|||
parentArgs[name..f] = parentArgs[alias..f] |
|||
parentArgs[alias..f] = nil |
|||
end |
|||
end |
|||
--Fetch Wikidata item |
|||
local from = resolve._entityid(frame, parentArgs['from'..f]) |
|||
local item = mw.wikibase.getEntity(from) |
|||
local label = nil |
|||
if type(item) == 'table' then |
|||
local statements = item:getBestStatements('P225')[1] --taxon name |
|||
if statements then |
|||
local datavalue = statements.mainsnak.datavalue |
|||
if datavalue then |
|||
label = datavalue.value |
|||
end |
|||
end |
|||
label = label or item:getLabel() |
|||
else |
|||
if parentArgs['from'..f] then |
|||
errors = errors .. mw.text.tag('strong', {class='error'}, 'Erro: "' .. |
|||
--Ordem: nome do parâmetro, etiqueta, ID da propriedade no Wikidata e nome da função de formato |
|||
parentArgs['from'..f] .. '" não é um ID de entidade Wikidata válido.<br />') |
|||
local conf = { |
|||
end |
|||
end |
|||
{ 'ADW', '[[Animal Diversity Web|ADW]]', 4024, adwLink}, |
|||
if label and label ~= '' then |
|||
{ 'APDB', 'APDB', 2036, apdbLink}, |
|||
title = mw.title.new(label) |
|||
{ 'Araneae', 'Araneae', 3594, araneaeLink}, |
|||
end |
|||
{ 'ARKive', '[[ARKive]]', 2833, arkiveLink}, |
|||
if title == nil and parentArgs['title'..f] then |
|||
{ 'Avibase', 'Avibase', 2026, avibaseLink}, |
|||
title = mw.title.new(parentArgs['title'..f]) |
|||
{ 'BacDive', '[[BacDive]]', 2946, bacdiveLink}, |
|||
end |
|||
{ 'BioLib', 'BioLib', 838, biolibLink}, |
|||
if title == nil and f == 1 then |
|||
{ 'BugGuide', '[[BugGuide]]', 2464, bugguideLink}, |
|||
title = currentTitle |
|||
{ 'ButMoth', '[[Natural History Museum#Butterflies and Moths of the World|ButMoth]]', 3060, butmothLink}, |
|||
end |
|||
{ 'Dyntaxa', 'Dyntaxa', 1939, dyntaxaLink}, |
|||
if title then |
|||
{ 'EOL', '[[Encyclopedia of Life|EOL]]', 830, eolLink}, |
|||
if isNilOrEmpty( parentArgs['wikidata'..f] ) and |
|||
{ 'EPPO', '[[Organización Europea e Mediterránea de Protección Vexetal|EPPO]]', 3031, eppoLink}, |
|||
(title.namespace == 0) then |
|||
{ 'FE', '[[Fauna Europaea|FE]]', 1895, faunaEuropaeaLink}, |
|||
if parentArgs['from'..f] then |
|||
{ 'FishBase', '[[FishBase]]', 938, fishbaseLink}, |
|||
parentArgs['wikidata'..f] = parentArgs['from'..f] |
|||
{ 'FloraBase', '[[FloraBase]]', 3101, florabaseLink}, |
|||
elseif item then |
|||
{ 'FNA', '[[Flora of North America|FNA]]', 1727, fnaLink}, |
|||
parentArgs['wikidata'..f] = item.id |
|||
{ 'FoAO', 'FoAO', 3100, foaoLink}, |
|||
end |
|||
{ 'FoC', '[[Flora of China|FoC]]', 1747, focLink}, |
|||
end |
|||
{ 'Fungorum', '[[Index Fungorum|Fungorum]]', 1391, fungorumLink}, |
|||
if title.namespace == 0 or stringArgs then --only in mainspace or if manual overrides exist |
|||
{ 'FW', '[[Fossilworks]]', 842, fwLink}, |
|||
local sourceCount = 0 |
|||
{ 'GBIF', '[[Global Biodiversity Information Facility|GBIF]]', 846, gbifLink}, |
|||
for _, params in pairs( conf.databases ) do |
|||
{ 'GrassBase', '[[Reais Xardíns Botánicos de Kew|GrassBase]]', 1832, grassbaseLink}, |
|||
params[1] = mw.ustring.lower(params[1]) |
|||
{ 'IBC', '[[Handbook of the Birds of the World|IBC]]', 3099, ibcLink}, |
|||
local propId = params[3] |
|||
{ 'ICTV', '[[Comité Internacional de Taxonomía dos Virus|ICTV]]', 1076, ictvLink}, |
|||
--Wikidata fallback if requested |
|||
{ 'iNaturalist', '[[iNaturalist]]', 3151, inaturalistLink}, |
|||
if (item and item.claims) and |
|||
{ 'IPNI', '[[International Plant Names Index|IPNI]]', 961, ipniLink}, |
|||
(type(propId) == 'string' or (type(propId) == 'number' and propId > 0)) then |
|||
{ 'ITIS', '[[Sistema Integrado de Información Taxonómica|ITIS]]', 815, itisLink}, |
|||
local wikidataId = getIdFromWikidata( item, 'P' .. propId ) |
|||
{ 'IUCN', '[[IUCN]]', 627, iucnLink}, |
|||
local v = parentArgs[params[1]..f] |
|||
{ 'LepIndex', '[[Natural History Museum#The Global Lepidoptera Names Index|LepIndex]]', 3064, lepindexLink}, |
|||
if wikidataId then |
|||
{ 'MSW', '[[Mammal Species of the World|MSW]]', 959, mswLink}, |
|||
if isNilOrEmpty(v) then |
|||
{ 'MycoBank', '[[MycoBank]]', 962, mycobankLink}, |
|||
parentArgs[params[1]..f] = wikidataId |
|||
{ 'NBN', '[[National Biodiversity Network|NBN]]', 3240, nbnLink}, |
|||
else |
|||
{ 'NCBI', '[[National Center for Biotechnology Information|NCBI]]', 685, ncbiLink}, |
|||
if v and v ~= 'no' and v ~= wikidataId then |
|||
{ 'PalDat', 'PalDat', 4122, paldatLink}, |
|||
{ 'Plantarium', 'Plantarium', 3102, plantariumLink}, |
|||
{ 'PlantList', '[[The Plant List|PlantList]]', 1070, plantlistLink}, |
|||
{ 'Plazi', '[[Plazi]]', 1992, plaziLink}, |
|||
{ 'Soortenregister', 'Soortenregister', 3405, soortenregisterLink}, |
|||
{ 'Species+', '[[CITES|Species+]]', 2040, speciesLink}, |
|||
{ 'SPRAT', '[[Species Profile and Threats Database|SPRAT]]', 2455, spratLink}, |
|||
{ 'TAXREF', 'TAXREF', 3186, taxrefLink}, |
|||
{ 'TelaBotanica', '[[Tela Botanica]]', 3105, telabotanicaLink}, |
|||
{ 'Titan', 'Titan', 4125, titanLink}, |
|||
{ 'Tropicos', '[[Tropicos]]', 960, tropicosLink}, |
|||
{ 'USDAPLANTS', '[[Departamento de Agricultura dos Estados Unidos|PLANTS]]', 1772, usdaplantsLink}, |
|||
{ 'VASCAN', 'VASCAN', 1745, vascanLink}, |
|||
{ 'Vlindernet', 'Vlindernet', 3322, vlindernetLink}, |
|||
{ 'WCSPF', '[[World Checklist of Selected Plant Families|WCSPF]]', 3591, wcspfLink}, |
|||
{ 'WoRMS', '[[World Register of Marine Species|WoRMS]]', 850, wormsLink}, |
|||
{ 'WSC', '[[World Spider Catalog|WSC]]', 3288, wscLink}, |
|||
{ 'Xenocanto', 'Xeno-canto', 2426, xenocantoLink}, |
|||
{ 'ZooBank', '[[ZooBank]]', 1746, zoobankLink} |
|||
} |
|||
elseif v and v == wikidataId then |
|||
-- Check that the Wikidata item has this property-->value before adding it |
|||
local reqs = {} |
|||
end |
|||
local p = {} |
|||
end |
|||
end |
|||
end |
|||
local val = parentArgs[params[1]..f] |
|||
if val and val ~= '' and mw.ustring.lower(val) ~= 'no' then |
|||
if params[1] == 'issn' and parentArgs['worldcatid'..f] and parentArgs['worldcatid'..f] ~= '' then -- 'issn' is the first element following the 'wikidata' item |
|||
table.insert( elements, createRow( params[1], '', parentArgs['worldcatid'..f], '[//www.worldcat.org/identities/' .. parentArgs['worldcatid'..f] .. ' WorldCat]', false ) ) --Validation? |
|||
elseif params[1] == 'viaf' and parentArgs[params[1]..f] and string.match( parentArgs[params[1]..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( params[1], '', parentArgs[params[1]], '[//www.worldcat.org/identities/containsVIAFID/' .. parentArgs[params[1]..f] .. ' WorldCat]', false ) ) |
|||
elseif params[1] == 'lccn' and parentArgs[params[1]..f] and parentArgs[params[1]..f] ~= '' and not parentArgs['viaf'..f] and not parentArgs['worldcatid'..f] then |
|||
local lccnParts = splitLccn( parentArgs[params[1]..f] ) |
|||
if lccnParts and lccnParts[1] ~= 'sh' then |
|||
table.insert( elements, createRow( params[1], '', parentArgs[params[1]..f], '[//www.worldcat.org/identities/lccn-' .. lccnParts[1] .. lccnParts[2] .. '-' .. lccnParts[3] .. ' WorldCat]', false ) ) |
|||
end |
|||
end |
|||
if type(propId) == 'number' then |
|||
if propId < 0 then propId = -propId end --allow link |
|||
if propId > 0 then --link |
|||
table.insert( elements, createRow( params[1], params[2]..':', val, getLink( propId, val, params[4] ).text, true ) ) |
|||
else --propId == 0; no link |
|||
table.insert( elements, createRow( params[1], params[2]..':', val, val, true ) ) |
|||
end |
|||
else |
|||
table.insert( elements, createRow( params[1], params[2]..':', val, getLink( propId, val, params[4] ).text, true ) ) |
|||
end |
|||
if params[1] ~= 'wikidata' and params[1] ~= 'wikispecies' then |
|||
sourceCount = sourceCount + 1 |
|||
end |
|||
end |
|||
end |
|||
function p.authorityControlTaxon( frame ) |
|||
--Generate navbox title |
|||
local parentArgs = frame:getParent().args |
|||
if sourceCount > 0 then --TODO: don't count Wikispecies towards 'taxon ID count' |
|||
--Create rows |
|||
rowCount = rowCount + 1 |
|||
local elements = {} |
|||
if firstRow == 0 then firstRow = f end |
|||
local title = mw.title.getCurrentTitle() |
|||
--set title from wikidata if it doesn't exist |
|||
local namespace = title.namespace |
|||
if isNilOrEmpty( parentArgs['title'..f] ) then |
|||
if namespace == 0 then --Só no espaço de nomes principal |
|||
parentArgs['noTitle'..f] = true |
|||
--redirect PND to GND |
|||
parentArgs['title'..f] = title.text |
|||
end |
|||
parentArgs.GND = parentArgs.PND |
|||
--if it exists now, set row heading to title |
|||
end |
|||
if not isNilOrEmpty( parentArgs['title'..f] ) then |
|||
else |
|||
--Wikidata fallback if requested |
|||
navboxParams['group'..f] = '' |
|||
local item = mw.wikibase.getEntityObject() |
|||
end |
|||
if item ~= nil and item.claims ~= nil then |
|||
navboxParams['list'..f] = table.concat( elements ) |
|||
for _, params in pairs( conf ) do |
|||
elseif currentEntityId then |
|||
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 |
|||
end |
|||
--Configured rows |
|||
local rct = 0 |
|||
end |
|||
for k, params in pairs( conf ) do |
|||
end |
|||
local val = parentArgs[params[1]] |
|||
end --for f = 1, fromTitleCount, 1 |
|||
if val and val ~= '' then |
|||
table.insert( elements, createRow( params[1], params[2] .. ':', val, params[4]( val ), true ) ) |
|||
if rowCount > 0 then |
|||
rct = rct + 1 |
|||
local Navbox = require('Module:Navbox') |
|||
end |
|||
if rowCount > 1 then |
|||
end |
|||
--remove duplicates and move page title to top |
|||
local Navbox = require('Módulo:Navbox') |
|||
local rowIDs = {} |
|||
for f = 1,fromTitleCount,1 |
|||
--if rct > 13 then |
|||
do |
|||
-- elementscats = '[[Categoria:!CA com ' .. rct .. ' elementos]]' |
|||
if not isNilOrEmpty( parentArgs['title'..f] ) then |
|||
--end |
|||
if rowIDs[parentArgs['wikidata'..f]] then --remove duplicate |
|||
navboxParams['group'..f] = nil |
|||
if #elements ~= 0 then |
|||
navboxParams['list'..f] = nil |
|||
return Navbox._navbox( { |
|||
else |
|||
name = 'Taxonbar', |
|||
rowIDs[parentArgs['wikidata'..f]] = true |
|||
bodyclass = 'hlist', |
|||
if f > firstRow and (parentArgs['title'..f] == currentTitle.text or |
|||
listclass = 'plainlinks', |
|||
parentArgs['wikidata'..f] == currentEntityId) then --move item linked to page to top |
|||
groupstyle = 'width: 15%; text-align:center;', |
|||
if navboxParams['group'..f] and |
|||
group1 = 'Identificadores Taxonómicos', --.. elementscats, |
|||
navboxParams['group'..f] ~= '' and |
|||
list1 = table.concat( elements ) |
|||
navboxParams['list'..f] and |
|||
} ) |
|||
navboxParams['list'..f] ~= '' then |
|||
else |
|||
local tempGroup, tempList = navboxParams['group'..f], navboxParams['list'..f] |
|||
return "" |
|||
navboxParams['group'..f], navboxParams['list'..f] = navboxParams['group'..firstRow], navboxParams['list'..firstRow] |
|||
end |
|||
navboxParams['group'..firstRow], navboxParams['list'..firstRow] = tempGroup, tempList |
|||
end |
|||
end |
|||
end |
|||
end |
|||
end |
|||
end |
|||
--adjust navbox for number of rows |
|||
navboxParams['title'] = '[[Taxonomia|Identificadores taxonómicos]]' |
|||
if rowCount > 2 then |
|||
navboxParams['navbar'] = 'plain' |
|||
else |
|||
navboxParams['state'] = 'off' |
|||
navboxParams['navbar'] = 'off' |
|||
end |
|||
elseif parentArgs['noTitle'..firstRow] then |
|||
navboxParams['group'..firstRow] = '[[Taxonomia|Identificadores taxonómicos]]' |
|||
else |
|||
navboxParams['group'..firstRow] = '[[Taxonomia|Identificadores taxonómicos]]<br />' .. navboxParams['group'..firstRow] |
|||
end |
|||
--return navbox |
|||
outString = Navbox._navbox(navboxParams) |
|||
end --if rowCount > 0 |
|||
--Add categories |
|||
if string.sub(currentTitle.subpageText,1,9) == 'testcases' then parentArgs['demo'] = true end |
|||
return outString .. errors |
|||
end |
end |
||
Edição atual tal como às 21h27min de 14 de agosto de 2023
![]() | Este módulo pode ter sua documentação deficiente. Por favor, documente-o ou melhore suas explicações caso o saiba usar ou tenha conhecimentos para tal. |
![]() | Este módulo está na categoria sujeitos a proteção de página. Ele é um módulo de alta visibilidade em uso por um grande número de páginas, ou é transcluído muito frequentemente. Por causa do vandalismo ou erros que podem afectar muitas páginas, e mesmo edições triviais podem causar cargas substanciais nos servidores, ele está protegido de editar. |
![]() | Este módulo é usado em mais de 65 000 páginas. (Ver Wikipedia:Predefinições em alto risco) Para evitar sobrecargas desnecessárias ao servidor e outros transtornos, quaisquer mudanças devem ser previamente testadas, seja na subpágina de testes deste módulo, na subpágina de testes de módulos (ou ainda em sua subpágina de testes). Por favor, sempre considere expor eventuais mudanças na página de discussão, antes de implementá-las. |
![]() | Este módulo toma dados de uma ou mais propriedades do Wikidata
|
Módulo que contém o código empregado pelo modelo {{Controle de autoridade}}
A documentação acima é transcluída de Módulo:Taxonbar/doc. (editar | histórico) Editores podem experimentar nas páginas de teste (criar | espelhar) e de exemplos para testes (criar) deste módulo. Subpáginas deste módulo. |
require('strict')
local conf = require( 'Module:Taxonbar/conf' ) -- configuration module
local function isNilOrEmpty( thing )
if thing == nil or thing == '' then
return true
end
return nil
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 getIdFromWikidata( item, property )
local id = nil
if property == 'PWikispecies:$1' then
local siteLinks = item.sitelinks
if siteLinks then
local speciesWiki = item.sitelinks.specieswiki
if speciesWiki then
id = speciesWiki.title
end
end
return id
elseif item.claims[property] == nil then
return id
end
for _, statement in pairs( item.claims[property] ) do
if statement.mainsnak.datavalue then
id = statement.mainsnak.datavalue.value
break
end
end
return id
end
local function getLink( property, val, mask )
local link, returnVal = '', {}
returnVal.isError = false
if mw.ustring.find( val, '//' ) then
link = val
else
if type(property) == 'number' and property > 0 then
local entityObject = mw.wikibase.getEntity('P'..property)
local dataType
if entityObject then dataType = entityObject.datatype
else returnVal.isError = true end
if dataType == 'external-id' then
local formatterURL = nil
if property == 3746 then --Wildflowers of Israel ID's 2nd formatterURL is in English
formatterURL = entityObject:getBestStatements('P1630')[2]
end
if formatterURL == nil then formatterURL = entityObject:getBestStatements('P1630')[1] end
if formatterURL then
if formatterURL.mainsnak.datavalue and formatterURL.mainsnak.datavalue.value then --nil check for ABA
link = formatterURL.mainsnak.datavalue.value
end
end
elseif dataType == 'url' then
local subjectItem = entityObject:getBestStatements('P1629')[1]
if subjectItem then
local officialWebsite = mw.wikibase.getEntity(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 subjectItem = entityObject:getBestStatements('P1629')[1]
if subjectItem then
local officialWebsite = mw.wikibase.getEntity(subjectItem.mainsnak.datavalue.value.id):getBestStatements('P856')[1]
if officialWebsite then link = officialWebsite.mainsnak.datavalue.value end
end
end
else
returnVal.isError = true
end
elseif type(property) == 'string' then
link = property
end
local valurl = val
if mw.ustring.find( link, 'antweb.org' ) then valurl = mw.ustring.gsub(valurl, ' ', '%%20') end
if type(property) == 'number' then
--doublecheck language for Wildflowers of Israel ID
if property == 3746 then link = mw.ustring.gsub(link, '/hebrew/', '/english/') end
--format spaces in PfaF, e.g. for "Elaeagnus x ebbingei"
if property == 4301 then valurl = mw.ustring.gsub(valurl, ' ', '+') end
end
valurl = mw.ustring.gsub(valurl,'%%','%%%%')
link = mw.ustring.gsub(link, '$1', valurl)
end
link = mw.ustring.gsub(link, '^[Hh][Tt][Tt][Pp]([Ss]?)://', 'http%1://') -- fix wikidata URL
link = mw.ustring.gsub(link, ' ' , '')
val = mw.ustring.match(val, '([^=/]*)/?$') -- get display name from end of URL
if mw.ustring.find( link, '//' ) then
if mask == 'y' then
returnVal.text = '<span class="plainlinks">['..link..' ID]</span>'
else
returnVal.text = '<span class="plainlinks">['..link..' '..mw.text.encode(mw.uri.decode(val, 'PATH'),'%[%]')..']</span>'
end
elseif link == '' then
returnVal.text = val
else
returnVal.text = '[['..link..'|'..val..']]'
end
return returnVal
end
local function createRow( id, label, rawValue, link, withUid )
if link then
local outStr = '*<span style="white-space:nowrap;">' .. label .. ' <span'
if withUid then outStr = outStr..' class="uid"' end
return outStr..'>' .. link .. '</span></span>\n'
else
return '* ' .. mw.text.tag('span', {class='error'}, 'O identificador ' .. id .. ' ' .. rawValue .. ' é inválido.') .. '\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 p = {}
function p.authorityControlTaxon( frame )
local resolve = require( 'Module:ResolveEntityId' )
local parentArgs = copyTable(frame:getParent().args)
local currentTitle = mw.title.getCurrentTitle()
local currentEntityId = mw.wikibase.getEntityIdForCurrentPage()
local stringArgs = false
local fromTitleCount, firstRow, rowCount = 1, 0, 0
local outString, errors = '', ''
local tFroms = {} --non-sequential table of unique froms
local iFroms = 0 --integer size of tFroms, b/c Lua
--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 isNilOrEmpty( parentArgs[lowerk] ) then
parentArgs[k] = nil
parentArgs[lowerk] = v
end
--remap abc to abc1
if mw.ustring.find(lowerk,'%d$') == nil then --if no number at end of param
if isNilOrEmpty( parentArgs[lowerk..'1'] ) then
parentArgs[lowerk] = nil
lowerk = lowerk..'1'
parentArgs[lowerk] = v
end
end
if v and v ~= '' then
--remap 'for' to 'title'
if mw.ustring.sub(lowerk,1,3) == 'for' then
local forTitle = mw.ustring.gsub(lowerk,'^for','title',1)
if isNilOrEmpty( parentArgs[forTitle] ) then
parentArgs[lowerk] = nil
lowerk = forTitle
parentArgs[lowerk] = v
end
end
--find highest from or title param
if mw.ustring.sub(lowerk,1,4) == 'from' then
local fromNumber = tonumber(mw.ustring.sub(lowerk,5,-1))
if fromNumber and fromNumber >= fromTitleCount then fromTitleCount = fromNumber end
--look for duplicate froms while we're here
if mw.ustring.find(v, '^Q%d') then
if tFroms[v] then
tFroms[v] = tFroms[v] + 1
else
tFroms[v] = 1
iFroms = iFroms + 1
end
if iFroms == 2 then
end
end
elseif mw.ustring.sub(lowerk,1,5) == 'title' then
local titleNumber = tonumber(mw.ustring.sub(lowerk,4,-1))
if titleNumber and titleNumber >= fromTitleCount then fromTitleCount = titleNumber end
elseif mw.ustring.lower(v) ~= 'no' then
stringArgs = true
end
end
end
end
--Check for unknown parameters
--create knowns list
local acceptableArgs = { from = true, } --master list of l/c acceptable args
for _, d in pairs( conf.databases ) do
if d[1] ~= 'Wikidata' then --made obsolete by from
acceptableArgs[mw.ustring.lower(d[1])] = true
end
end
for _, a in pairs( conf.aliases ) do
acceptableArgs[mw.ustring.lower(a[1])] = true
end
--create trimmed parents list
local baseParentArgs = {} --condensed list of l/c parent args w/o trailing #s
for k, v in pairs( parentArgs ) do
if type(k) == 'string' then --ignore unnamed params, which have keys of type 'number'
local lowerk = mw.ustring.lower(k)
local base = mw.ustring.gsub(lowerk, '[%d]*$', '')
baseParentArgs[base] = true
end
end
--compare lists and spit out unknowns
local unknownParams = {}
for k, v in pairs( baseParentArgs ) do
if acceptableArgs[k] == nil then
unknownParams[#unknownParams + 1] = k
end
end
--warn if unknown(s) present
if #unknownParams > 0 then
if frame:preprocess( '{{REVISIONID}}' ) == '' then
errors = errors..'<div class="hatnote" style="color:red">'..
'<strong>Atenção:</strong> parâmetros desconhecidos <strong>'..table.concat(unknownParams, ', ')..'</strong>.<br />'..
'Corrige-os ou considere liga-los à Wikidata.<br />'..
'Esta mensagem só se mostra na previsualização.</div>'
end
end
--Setup navbox
local navboxParams = {
name = 'Taxonbar',
bodyclass = 'hlist',
listclass = 'plainlinks',
groupstyle = 'width: 12%; text-align:center;',
}
for f = 1, fromTitleCount, 1
do
local elements, title = {}, nil
--cleanup parameters
if parentArgs['from'..f] == '' then parentArgs['from'..f] = nil end
if parentArgs['title'..f] == '' then parentArgs['title'..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 parentArgs[name..f] == nil then
parentArgs[name..f] = parentArgs[alias..f]
parentArgs[alias..f] = nil
end
end
--Fetch Wikidata item
local from = resolve._entityid(frame, parentArgs['from'..f])
local item = mw.wikibase.getEntity(from)
local label = nil
if type(item) == 'table' then
local statements = item:getBestStatements('P225')[1] --taxon name
if statements then
local datavalue = statements.mainsnak.datavalue
if datavalue then
label = datavalue.value
end
end
label = label or item:getLabel()
else
if parentArgs['from'..f] then
errors = errors .. mw.text.tag('strong', {class='error'}, 'Erro: "' ..
parentArgs['from'..f] .. '" não é um ID de entidade Wikidata válido.<br />')
end
end
if label and label ~= '' then
title = mw.title.new(label)
end
if title == nil and parentArgs['title'..f] then
title = mw.title.new(parentArgs['title'..f])
end
if title == nil and f == 1 then
title = currentTitle
end
if title then
if isNilOrEmpty( 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 mainspace or if manual overrides exist
local sourceCount = 0
for _, params in pairs( conf.databases ) do
params[1] = mw.ustring.lower(params[1])
local propId = params[3]
--Wikidata fallback if requested
if (item and item.claims) and
(type(propId) == 'string' or (type(propId) == 'number' and propId > 0)) then
local wikidataId = getIdFromWikidata( item, 'P' .. propId )
local v = parentArgs[params[1]..f]
if wikidataId then
if isNilOrEmpty(v) then
parentArgs[params[1]..f] = wikidataId
else
if v and v ~= 'no' and v ~= wikidataId then
elseif v and v == wikidataId then
end
end
end
end
local val = parentArgs[params[1]..f]
if val and val ~= '' and mw.ustring.lower(val) ~= 'no' then
if params[1] == 'issn' and parentArgs['worldcatid'..f] and parentArgs['worldcatid'..f] ~= '' then -- 'issn' is the first element following the 'wikidata' item
table.insert( elements, createRow( params[1], '', parentArgs['worldcatid'..f], '[//www.worldcat.org/identities/' .. parentArgs['worldcatid'..f] .. ' WorldCat]', false ) ) --Validation?
elseif params[1] == 'viaf' and parentArgs[params[1]..f] and string.match( parentArgs[params[1]..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( params[1], '', parentArgs[params[1]], '[//www.worldcat.org/identities/containsVIAFID/' .. parentArgs[params[1]..f] .. ' WorldCat]', false ) )
elseif params[1] == 'lccn' and parentArgs[params[1]..f] and parentArgs[params[1]..f] ~= '' and not parentArgs['viaf'..f] and not parentArgs['worldcatid'..f] then
local lccnParts = splitLccn( parentArgs[params[1]..f] )
if lccnParts and lccnParts[1] ~= 'sh' then
table.insert( elements, createRow( params[1], '', parentArgs[params[1]..f], '[//www.worldcat.org/identities/lccn-' .. lccnParts[1] .. lccnParts[2] .. '-' .. lccnParts[3] .. ' WorldCat]', false ) )
end
end
if type(propId) == 'number' then
if propId < 0 then propId = -propId end --allow link
if propId > 0 then --link
table.insert( elements, createRow( params[1], params[2]..':', val, getLink( propId, val, params[4] ).text, true ) )
else --propId == 0; no link
table.insert( elements, createRow( params[1], params[2]..':', val, val, true ) )
end
else
table.insert( elements, createRow( params[1], params[2]..':', val, getLink( propId, val, params[4] ).text, true ) )
end
if params[1] ~= 'wikidata' and params[1] ~= 'wikispecies' then
sourceCount = sourceCount + 1
end
end
end
--Generate navbox title
if sourceCount > 0 then --TODO: don't count Wikispecies towards 'taxon ID count'
rowCount = rowCount + 1
if firstRow == 0 then firstRow = f end
--set title from wikidata if it doesn't exist
if isNilOrEmpty( parentArgs['title'..f] ) then
parentArgs['noTitle'..f] = true
parentArgs['title'..f] = title.text
end
--if it exists now, set row heading to title
if not isNilOrEmpty( parentArgs['title'..f] ) then
else
navboxParams['group'..f] = ''
end
navboxParams['list'..f] = table.concat( elements )
elseif currentEntityId then
end
end
end
end --for f = 1, fromTitleCount, 1
if rowCount > 0 then
local Navbox = require('Module:Navbox')
if rowCount > 1 then
--remove duplicates and move page title to top
local rowIDs = {}
for f = 1,fromTitleCount,1
do
if not isNilOrEmpty( parentArgs['title'..f] ) then
if rowIDs[parentArgs['wikidata'..f]] then --remove duplicate
navboxParams['group'..f] = nil
navboxParams['list'..f] = nil
else
rowIDs[parentArgs['wikidata'..f]] = true
if f > firstRow and (parentArgs['title'..f] == currentTitle.text or
parentArgs['wikidata'..f] == currentEntityId) then --move item linked to page to top
if navboxParams['group'..f] and
navboxParams['group'..f] ~= '' and
navboxParams['list'..f] and
navboxParams['list'..f] ~= '' then
local tempGroup, tempList = navboxParams['group'..f], navboxParams['list'..f]
navboxParams['group'..f], navboxParams['list'..f] = navboxParams['group'..firstRow], navboxParams['list'..firstRow]
navboxParams['group'..firstRow], navboxParams['list'..firstRow] = tempGroup, tempList
end
end
end
end
end
--adjust navbox for number of rows
navboxParams['title'] = '[[Taxonomia|Identificadores taxonómicos]]'
if rowCount > 2 then
navboxParams['navbar'] = 'plain'
else
navboxParams['state'] = 'off'
navboxParams['navbar'] = 'off'
end
elseif parentArgs['noTitle'..firstRow] then
navboxParams['group'..firstRow] = '[[Taxonomia|Identificadores taxonómicos]]'
else
navboxParams['group'..firstRow] = '[[Taxonomia|Identificadores taxonómicos]]<br />' .. navboxParams['group'..firstRow]
end
--return navbox
outString = Navbox._navbox(navboxParams)
end --if rowCount > 0
--Add categories
if string.sub(currentTitle.subpageText,1,9) == 'testcases' then parentArgs['demo'] = true end
return outString .. errors
end
return p