<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ATaxon_authority</id>
	<title>Module:Taxon authority - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ATaxon_authority"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Taxon_authority&amp;action=history"/>
	<updated>2026-05-27T11:25:32Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Taxon_authority&amp;diff=147161&amp;oldid=prev</id>
		<title>imported&gt;Erutuon: let linkBotanicalAuthorites be called from module</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Taxon_authority&amp;diff=147161&amp;oldid=prev"/>
		<updated>2019-07-05T17:50:43Z</updated>

		<summary type="html">&lt;p&gt;let linkBotanicalAuthorites be called from module&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local p = {}  -- exposed functions&lt;br /&gt;
local l = {}  -- local functions&lt;br /&gt;
&lt;br /&gt;
local botanicalAuthorites = require( &amp;quot;Module:Taxon_authority/data&amp;quot; ).botanicalAuthorites -- get list from submodule&lt;br /&gt;
local names = {&lt;br /&gt;
	[&amp;quot;L.&amp;quot;]      = &amp;quot;Carl Linnaeus&amp;quot;,&lt;br /&gt;
	[&amp;quot;Schldl.&amp;quot;] = &amp;quot;Diederich Franz Leonhard von Schlechtendal&amp;quot;,&lt;br /&gt;
    [&amp;quot;Cham.&amp;quot;]   = &amp;quot;Adelbert von Chamisso&amp;quot;,&lt;br /&gt;
}&lt;br /&gt;
--[[-------------------------------------------------------------------------------------&lt;br /&gt;
    main entry point&lt;br /&gt;
]]&lt;br /&gt;
p.main = function(frame)&lt;br /&gt;
	local option = mw.getCurrentFrame():getParent().args[&amp;#039;option&amp;#039;]&lt;br /&gt;
	if option == &amp;quot;wikidata&amp;quot; then&lt;br /&gt;
		return p.misc(frame)&lt;br /&gt;
	else&lt;br /&gt;
		return p.linkBotanicalAuthorites(frame:getParent().args[1])&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[ -------------------------------------------------------------------------------------&lt;br /&gt;
		function to adds wikilinks for valid botanical authorities&lt;br /&gt;
    	this version uses the keyed table at the top of this module&lt;br /&gt;
    	the name in the key needs to be escaped for the lua expression wildcard &amp;quot;.&amp;quot;&lt;br /&gt;
	]]  &lt;br /&gt;
p.linkBotanicalAuthorites = function(name)&lt;br /&gt;
	if names[name] then&lt;br /&gt;
		name = l.wikilinkName(names[name], name) -- if the passed authority matches a single authority name&lt;br /&gt;
	else&lt;br /&gt;
	    for k, v in pairs( names  ) do&lt;br /&gt;
	    	                                          -- if the passed authority contains the authority name&lt;br /&gt;
	    	if string.find( name, k, 1, false) then      -- plain=true as  don&amp;#039;t want to treat . as wildcard&lt;br /&gt;
&lt;br /&gt;
	    		name = string.gsub( name, l.escape(k), l.wikilinkName(v,k) )  -- is the wildcard . a potential problem?&lt;br /&gt;
		    end&lt;br /&gt;
	 	end&lt;br /&gt;
	 end&lt;br /&gt;
 	return &amp;#039;&amp;lt;small&amp;gt;&amp;#039; .. name .. &amp;#039;&amp;lt;/small&amp;gt;&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
--[[ ----------------------------------------------------------------------------------------------&lt;br /&gt;
		function to adds wikilinks for valid botanical authorities&lt;br /&gt;
    	- this version uses simple unkeyed table in the data submodule (Module:Taxon authority/data)&lt;br /&gt;
        - note: for some reason, the wild card &amp;quot;.&amp;quot; doesn&amp;#039;t need to be escaped&lt;br /&gt;
  ]]&lt;br /&gt;
p.linkBotanicalAuthorites2 = function(frame)&lt;br /&gt;
	local name = mw.getCurrentFrame():getParent().args[1]&lt;br /&gt;
    for k, v in pairs( botanicalAuthorites  ) do&lt;br /&gt;
    	&lt;br /&gt;
    	if name == v[1] then                     -- if the passed authority matches a single authority name&lt;br /&gt;
    		name = l.wikilinkName(v[2],v[1])&lt;br /&gt;
    	else                                     -- if the passed authority contains the authority name&lt;br /&gt;
	    	if string.find( name, v[1], 1, true) then   -- don&amp;#039;t want to treat . as wildcard&lt;br /&gt;
	    		name = string.gsub( name, v[1], l.wikilinkName(v[2],v[1]) ) &lt;br /&gt;
		    end&lt;br /&gt;
	    end&lt;br /&gt;
 	end	&lt;br /&gt;
 	return &amp;#039;&amp;lt;small&amp;gt;&amp;#039; .. name .. &amp;#039;&amp;lt;/small&amp;gt;&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
--[[------------------------------------------------------------------------------------&lt;br /&gt;
		function to add wikilink to formal authority names&lt;br /&gt;
]]&lt;br /&gt;
l.wikilinkName = function(targetPage, displayedName)&lt;br /&gt;
	return &amp;#039;[[&amp;#039; .. targetPage .. &amp;#039;|&amp;#039; .. displayedName .. &amp;#039;]]&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
--[[ ------------------------------------------------------------------------------------------&lt;br /&gt;
		function to escape the lua expression wildcardd &amp;quot;.&amp;quot; in the authority names (e.g. &amp;quot;L.&amp;quot;)&lt;br /&gt;
  ]]&lt;br /&gt;
l.escape = function(str)&lt;br /&gt;
	if string.find( str, &amp;quot;.&amp;quot;, 1, false) then -- need to esc the .&lt;br /&gt;
	   local s = mw.text.split( str, &amp;quot;%.&amp;quot;, plain ) &lt;br /&gt;
	   return  s[1] .. &amp;quot;%.&amp;quot; .. s[2]                -- escaped version of string&lt;br /&gt;
	end&lt;br /&gt;
	return str -- unaltered str&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[---------------------------------------------------------------------------------&lt;br /&gt;
           general purpose function to experiment with wikidata etc&lt;br /&gt;
  ]]&lt;br /&gt;
p.misc = function (frame)&lt;br /&gt;
	&lt;br /&gt;
	local output = &amp;quot;&amp;quot;&lt;br /&gt;
	--get  arguments from calling templates&lt;br /&gt;
    local parent = mw.getCurrentFrame():getParent() &lt;br /&gt;
	local name = parent.args[1]&lt;br /&gt;
	&lt;br /&gt;
	-- first check  the module list&lt;br /&gt;
	--p.linkBotanicalAuthorites2(frame)&lt;br /&gt;
&lt;br /&gt;
	-- if name not found so try wikidata&lt;br /&gt;
	if output == &amp;quot;&amp;quot; then&lt;br /&gt;
	&lt;br /&gt;
		local wdName, err = l.getBotanicalAuthorityFromWikiData(name)&lt;br /&gt;
	    if not err then  &lt;br /&gt;
	    	--output = wdName &lt;br /&gt;
	    	output = &amp;#039;[[&amp;#039; .. name .. &amp;#039;|&amp;#039; .. wdName .. &amp;#039;]]&amp;#039;&lt;br /&gt;
	    else&lt;br /&gt;
			output = l.errmsg(&amp;quot;wikidata item not found&amp;quot;)        -- return error message&lt;br /&gt;
			output = name                                       -- return unlinked name &lt;br /&gt;
		end	&lt;br /&gt;
	end	&lt;br /&gt;
	return &amp;#039;&amp;lt;small&amp;gt;&amp;#039; .. output .. &amp;#039;&amp;lt;/small&amp;gt;&amp;#039;  &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
l.errmsg = function(text)&lt;br /&gt;
	return &amp;#039;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;&amp;#039; .. text .. &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
l.getBotanicalAuthorityFromWikiData=function(name)&lt;br /&gt;
	if (2==1) then return &amp;quot;&amp;quot; end&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
	local WikidataId = mw.wikibase.getEntityIdForTitle(name)&lt;br /&gt;
&lt;br /&gt;
    if not (WikidataId and mw.wikibase.isValidEntityId( WikidataId )) then&lt;br /&gt;
    	local titleObj = mw.title.new( name ).redirectTarget&lt;br /&gt;
		if  titleObj and titleObj.text ~= nil then name = titleObj.text end&lt;br /&gt;
		WikidataId = mw.wikibase.getEntityIdForTitle(name)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
	if WikidataId and mw.wikibase.isValidEntityId( WikidataId ) then -- valid wikidata id&lt;br /&gt;
    	local value = &amp;quot;authority not found&amp;quot;&lt;br /&gt;
    	local item = mw.wikibase.getEntity(WikidataId)&lt;br /&gt;
    	local statements = item:getBestStatements(&amp;#039;P428&amp;#039;)[1] --botany authority&lt;br /&gt;
        if statements ~= nil then -- &lt;br /&gt;
	    	value = statements.mainsnak.datavalue.value&lt;br /&gt;
        end&lt;br /&gt;
    	return value&lt;br /&gt;
    end &lt;br /&gt;
    --return l.errmsg(&amp;quot;wikidata item not found for &amp;quot; .. name), true  -- return error message&lt;br /&gt;
    return  name, true                                        -- return unlinked name, true to indicate error&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;Erutuon</name></author>
	</entry>
</feed>