Module:User:JeffDoozan/taxlink

local export = {}

function format_text(text, rank, force_italics)

if force_italics then return "''" .. text .. "''"   end

if rank == "nothogenus" or rank == "subgenus" or rank == "subg." or rank == "genus" or rank == "subsection" or rank == "section" or rank == "subsect." or rank == "sect." or rank == "nothospecies" or rank == "infraspecies" or rank == "subspecies" or rank == "subsp." or rank == "species" or rank == "variety" or rank == "var." or rank == "forma" or rank == "form" or rank == "morph" or rank == "morpha" or rank == "species group" or rank == "cultivar" or rank == "cvar." or rank == "series" or rank == "ser." then text = require("Module:italics").i(text) end return text end

function format_result(target, rank, text, cats, warning) -- Don't create categories for entries on User: pages if cats ~= "" and mw.title.getCurrentTitle.nsText == "User" then cats = "" end

if warning ~= "" then warning = ' ' .. warning .. ' '   end

return ' ' ..  .. text ..  .. warning .. cats .. ' ' end

function export.taxlink(frame) local warn = "" local cats = ""

local params = { [1] = {required = true}, [2] = {required = true}, [3] = {},		["i"] = {type = "boolean"}, ["nocat"] = {type = "boolean"}, ["nomul"] = {}, ["wplink"] = {}, ["wslink"] = {}, }	local args, invalid_args = require("Module:parameters").process(frame:getParent.args, params, "return unknown")

if next(invalid_args) then --       cats = cats .. ""		-- Special:WhatLinksHere/Wiktionary:Tracking/bad_params/taxlink local track = require("Module:debug/track") track("bad_params/taxlink")

for k, v in pairs(invalid_args) do if warn ~= "" then warn = warn .. "; " end warn = warn .. "unexpected parameter: " .. k .. "=" .. v

-- Special:WhatLinksHere/Wiktionary:Tracking/bad_params/taxlink/PARAM track("bad_params/taxlink/" .. k)		end end

local taxon = args[1] or "" local rank = args[2] or "" local text = args[3] or taxon text = format_text(text, rank, args["i"])

local target -- if page exists and nomul= is not set, use a local link and add to cleanup category if (not args["nomul"]) and mw.title.new( taxon ):getContent ~= nil then cats = cats .. ""       target = taxon .. "#Translingual" if warn ~= "" then warn = warn .. "; " end warn = warn .. "(Please check if this is already defined at target. Replace  with a regular link if already defined. Add nomul=1 if not defined.)" else -- undocumented and unused in existing entries as of 2/24/2024, if rank is epithet use local link if rank == "epithet" then target = taxon .. "#Translingual"

else if args["wplink"] then if args["wplink"] == "0" then target = "w:" .. taxon elseif args["wplink"] == "1" then target = "w:" .. mw.title.getCurrentTitle.subpageText else target = "w:" .. args["wplink"] end else if args["wslink"] then target = "Wikispecies:" .. args["wslink"] else target = "Wikispecies:" .. taxon end end end end

if not args["nocat"] then label = rank and rank or "unknown" cats = cats .. ""   end

return format_result(target, rank, text, cats, warn) end

function export.taxfmt(frame) local warn = ""

local params = { [1] = {required = true}, [2] = {required = true}, [3] = {},		["i"] = {type = "boolean"},

-- unused parameters, allowed for easy renaming to 		["nocat"] = {type = "boolean"}, ["nomul"] = {}, ["wplink"] = {}, ["wslink"] = {}, }	local args = require("Module:parameters").process(frame:getParent.args, params)

local taxon = args[1] or "" local rank = args[2] or "" local text = args[3] or taxon text = format_text(text, rank, args["i"])

local target = taxon .. "#Translingual"

return format_result(target, rank, text, "", warn) end

return export