Jump to content

Module:Taxonbar/confdoc

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jts1882 (talk | contribs) at 12:45, 14 November 2021 (explain handling url datatype). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

require('Module:No globals')

local conf = require( "Module:Taxonbar/conf" ) -- configuration module

local p = {}
	
function p.confdoc( frame )
	local wikitable = '{| class="wikitable sortable"\n' .. 
					  '|-\n' .. 
					  '! Parameter !! data-sort-type=number style="white-space: nowrap;"|Wikidata ID !! Authority !! Description'
	
	for _, db in pairs( conf.databases ) do
		local param = mw.ustring.lower(db[1])
		local prop = db[3]
		if type(prop) == 'number' and prop > 0 then
			local TaxonbarProperty = frame:expandTemplate{ title = 'Taxonbar/Property', args = { prop } }
			wikitable = wikitable .. '\n' .. 
					    '|-\n' .. 
					    '|' .. param .. '||' .. TaxonbarProperty
		end
	end
	
	return wikitable .. '\n|}'
end
--[[ p.wikidataInfo( frame )
    -function to show formatURL and id for taxonomic databases
]]

function p.wikidataInfo( frame )
	local wikitable = '{| class="wikitable sortable"\n' .. 
					  '|-\n' .. 
					  '! Parameter !! data-sort-type=number style="white-space: nowrap;"|Wikidata ID !! Database !! datatype !! formatterURL or alternative'
	
	for _, db in pairs( conf.databases ) do
		local param = mw.ustring.lower(db[1])
		local link = db[2]
		local prop = db[3]
		local id = 'id'
		local url = 'url'
		local datatype = ""
		
		if type(prop) == 'number' and prop > 0 then
			local item = mw.wikibase.getEntity('P'..prop)  --('P5354')
			
			if item and item ~= "" then
				datatype = item.datatype
				local statements = item:getBestStatements('P1630')[1] 
				if statements and statements.mainsnak and statements.mainsnak.datavalue and statements.mainsnak.datavalue.value then
					local formatterURL = statements.mainsnak.datavalue.value
					url = formatterURL
				else
					url = "No formatter URL (P1630)."
					if datatype == "url" then url = url .. " The id of the external database is the url." end
					local subjectItem = item:getBestStatements('P1629')[1]
					if subjectItem then
						local officialWebsite = mw.wikibase.getEntity(subjectItem.mainsnak.datavalue.value.id):getBestStatements('P856')[1]
						if officialWebsite then	
							url = url .. '<br/>website: ' ..  officialWebsite.mainsnak.datavalue.value
						end
					else
						url = url .. ' or official website (P856) of wikidata item of this property (P1629)'
						-- use third-party formatter URL. e.g for  Euring number (P3459) 
						local statements = item:getBestStatements('P3459')[1] 
						if statements and statements.mainsnak and statements.mainsnak.datavalue and statements.mainsnak.datavalue.value then
				   			local thirdPartyURL = statements.mainsnak.datavalue.value
							url = url ..'<br/>use third party url: ' .. thirdPartyURL
						else
							url = url .. ' or third party formatter url (P3459) '
						end
					end

				end
			end

		
			wikitable = wikitable .. '\n' .. '|-' 
					    .. '\n|' .. param 
					    .. '\n|' .. '[[:d:Property:P' .. prop .. '|P' .. prop .. ']]' 
					    .. '\n|' .. link
					    .. '\n|' .. datatype
					    .. '\n|' .. url
		end
	end
	
	return wikitable .. '\n|}'
end

return p