This module implements {{famcatboiler}}. The documentation here describes how the module works, and how to add, modify or remove information from the category tree. For information on how to use the template itself, see its documentation.

This module does not use labels. Effectively, there is only one label, whose data is hard-coded into the module.


local export = {}

-- Category object

local Category = {}
Category.__index = Category


local function infobox(fam)
	local ret = {}
	
	table.insert(ret, "<table class=\"wikitable\">\n")
	table.insert(ret, "<tr>\n<th colspan=\"2\" class=\"plainlinks\">[//en.wiktionary.org/w/index.php?title=Module:families/data&action=edit Edit family data]</th>\n</tr>\n")
	table.insert(ret, "<tr>\n<th>Canonical name</th><td>" .. fam:getCanonicalName() .. "</td>\n</tr>\n")
	
	if #fam:getOtherNames() > 0 then
		local names = {}
		
		for _, name in ipairs(fam:getOtherNames()) do
			table.insert(names, "<li>" .. name .. "</li>")
		end
		
		table.insert(ret, "<tr>\n<th>Other names</th><td>" .. table.concat(names, "\n") .. "</td>\n</tr>\n")
	end
	
	table.insert(ret, "<tr>\n<th>[[Wiktionary:Families|Family code]]</th><td><code>" .. fam:getCode() .. "</code></td>\n</tr>\n")
	table.insert(ret, "<tr>\n<th>[[w:Proto-language|Common ancestor]]</th><td>")
	
	local protoLanguage = fam:getProtoLanguage()
	
	if protoLanguage then
		table.insert(ret, "[[:Category:" .. mw.getContentLanguage():ucfirst(protoLanguage:getCategoryName()) .. "|" .. protoLanguage:getCanonicalName() .. "]]")
	else
		table.insert(ret, "none")
	end
	
	table.insert(ret, "</td>\n")
	table.insert(ret, "\n</tr>\n")
	
	local parent = fam:getFamily()
	
	if not parent then
		table.insert(ret, "<tr>\n<th>[[Wiktionary:Families|Parent family]]</th>\n<td>")
		table.insert(ret, "unclassified")
	elseif parent:getCode() == "qfa-not" then
		table.insert(ret, "<tr>\n<th>[[Wiktionary:Families|Parent family]]</th>\n<td>")
		table.insert(ret, "not a family")
	else
		local chain = {}
		while parent do
			table.insert(chain, "[[:Category:" .. mw.ustring.gsub(parent:getCategoryName(), "^.", mw.ustring.upper) .. "|" .. parent:getCanonicalName() .. "]]")
			parent = parent:getFamily()
		end
		
		table.insert(ret, "<tr>\n<th>[[Wiktionary:Families|Parent famil"
			.. (#chain == 1 and "y" or "ies") .. "]]</th>\n<td>")
		
		for i = #chain, 1, -1 do
			table.insert(ret, "<ul><li>" .. chain[i])
		end
		
		table.insert(ret, string.rep("</li></ul>", #chain))
	end
	
	table.insert(ret, "</td>\n</tr>\n")
	
	if fam:getWikidataItem() and mw.wikibase then
		local link = '[' .. mw.wikibase.getEntityUrl(fam:getWikidataItem()) .. ' ' .. fam:getWikidataItem() .. ']'
		table.insert(ret, "<tr><th>Wikidata</th><td>" .. link .. "</td></tr>")
	end
	
	table.insert(ret, "</table>")
	
	return table.concat(ret)
end


function Category.new(info)
	local self = setmetatable({}, Category)
	assert(type(info) == "table", "The \"info\" parameter must be a table.")
	self._info = {}
	
	for key, val in pairs(info) do
		if key == "code" then
			self._info.code = val
			self._fam = require("Module:families").getByCode(val) or error("The family code \"" .. val .. "\" is not valid.")
		else
			error("The parameter \"" .. key .. "\" was not recognized.")
		end
	end
	
	return self
end

export.new = Category.new


function Category:getInfo()
	return self._info
end


function Category:getBreadcrumbName()
	if not self._fam then
		return "languages by family"
	else
		return self._fam:getCanonicalName()
	end
end


function Category:getDataModule()
	return "Module:category tree/famcatboiler"
end


function Category:canBeEmpty()
	return true
end

function Category:isHidden()
	return false
end


function Category:getCategoryName()
	local ret = nil
	
	if not self._fam then
		ret = "languages by family"
	else
		ret = self._fam:getCategoryName()
	end
	
	return mw.getContentLanguage():ucfirst(ret)
end


function Category:getDescription()
	if not self._fam then
		return nil
	else
		local ret =
			mw.getCurrentFrame():expandTemplate{title = "sisterlinks", args = {self._fam:getCategoryName()}} ..
			mw.getCurrentFrame():expandTemplate{title = "wikipedia", args = {}} ..
			"This is the main category of the '''" .. self._fam:getCategoryName() .. "'''.\n\nInformation about " .. self._fam:getCanonicalName() .. ":\n\n" .. infobox(self._fam)
		
		return ret
	end
end


function Category:getParents()
	if not self._fam then
		return {
			{
				name = "Category:All languages",
				sort = " "
			},
			{
				name = "Category:All language families",
				sort = " "
			},
		}
	else
		local pinfo = mw.clone(self._info)
		local fam = self._fam:getFamily()
		
		if not fam or fam:getCode() == "qfa-iso" or fam:getCode() == "qfa-not" then
			pinfo.code = nil
		else
			pinfo.code = fam:getCode()
		end
		
		return {{name = Category.new(pinfo), sort = self._fam:getCanonicalName()}}
	end
end


function Category:getChildren()
	return nil
end


function Category:getUmbrella()
	return "Category:All language families"
end


return export