Difference between revisions 21306672 and 21306673 on frwiktionary

local export = {}
local m_languages = require('Module:languages')

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	if mw.title.getCurrentTitle().nsText == "Template" then
		return "(This template should be used on pages in the Category: namespace.)"
(contracted; show full)		table.insert(categories, "[[Category:Empty categories]]")
	end
	
	if current:isHidden() then
		table.insert(categories, "__HIDDENCAT__")
	end
	

	table.insert(boxes, show_catfix(info))
	table.insert(boxes, show_editlink(current))
	table.insert(boxes, show_pagelist(info))
	
	-- Generate the displayed information
	table.insert(display, show_breadcrumbs(current))
	table.insert(display, show_description(current))
	table.insert(display, show_children(current))
	table.insert(display, show_TOC(info))
	
	show_categories(current, categories)
	
	return table.concat(categories, "") .. table.concat(boxes, "\n") .. "\n" .. table.concat(display, "\n\n")
end

function show_error(text)
	return  mw.getCurrentFrame():expandTemplate{title = "maintenance box", args = {
		"red",
		image = "[[File:Ambox warning pn.svg|50px]]",
		title = "The automatically-generated contents of this category has errors.",
		text = text,
		}}
end

-- Check the name of the current page, and return an error if it's not right.
function check_name(current, template, info)
	local errortext = nil
	local category = nil
	
	if not current then
		errortext =
			"The label \"" .. (info.label or "") .. "\" given to the " .. mw.getCurrentFrame():expandTemplate{title = "temp", args = {template}} .. " template is not valid. " ..
			"You may have mistyped it, or it simply has not been created yet. To add a new label, please consult the documentation of the template."
		category = "[[Category:Categories with invalid label]]"
	else
		
	end
	
	if errortext then
		return (category or "") .. show_error(errortext)
	else
		return nil
	end
end

function show_catfix(info)
	local code = info.code
	
	if not code then
		return nil
	end
	
	local lang = require("Module:languages").getByCode(code)
	
	if not lang  then
		return nil
	end
	
	return
		"<span id=\"catfix\" style=\"display:none;\" class=\"CATFIX-" .. mw.uri.anchorEncode(lang:getCanonicalName()) .. "\">" ..
		require("Module:script utilities").tag_text("&nbsp;", lang, (sc and require("Module:scripts").getByCode(info.sc) or nil), nil) ..
		"</span>"
end

-- Show the parent categories that the current category should be placed in.
function show_categories(current, categories)
	local parents = current:getParents()
	
	if not parents then
		return
	end
	
(contracted; show full)	end
	
	return table.concat(children_list, "\n")
end

-- Show a table of contents with links to each letter in the language's script.
function show_TOC(info)
	local code = info.code
 or "en"
	
	if not code or not require("Module:languages").getByCode(code) then
		return nil
	end
	
	local num_pages = 300 --mw.site.stats.pagesInCategory(mw.title.getCurrentTitle().text, "pages")
	
	-- No need for a TOC if all entry names can fit on one page.
	if num_pages > 200 then
		-- This category is very large, see if there is an "extended" version of the TOC.
		if num_pages > 2500 then
			local TOC_template_extended = mw.title.new("Template:" .. code .. "-categoryTOC/full")
			
			if TOC_template_extended.exists then
				return mw.getCurrentFrame():expandTemplate{title = TOC_template_extended.text, args = {}}
			end
		end
		
		local TOC_template = mw.title.new("Template:" .. code .. "-categoryTOC")
		
		if TOC_template.exists then
			return mw.getCurrentFrame():expandTemplate{title = TOC_template.text, args = {}}
		end
	end
	
	return nil
end

return export