Modul:category tree

Vikilug‘atdan olingan

Ushbu modul turkumda stereotiplarni andozalari ishlab chiqarish uchun ishlatiladi. Bu toʻgʻri foydalanish uchun moʻljallangan emas. Aksincha, har bir Andoza deb andozalarini oʻziga qoʻllari oʻz submodule ega boʻladi. Ushbu hujjatlar faqat turkumda daraxt tizimini Generics oʻz ichiga oladi. Agar maʼlum bir andozani yoki qoʻshish yoki turkumda ma'lumotlarni oʻzgartirish uchun qanday hujjatlar uchun izlayotgan boʻlsangiz, bu andozalarini hujjatiga qarang.

Parametrlar[tahrirlash]

Turkum daraxt moduli sifatida taklif etiladi:

{{#invoke:category tree|show|template=name of the template|...other parameters...}}

Every template that uses this module should have a submodule of this module with the name given in the template= parameter. This submodule should export a function named new which takes a single parameter: a table named info that contains the various parameters that were passed to the template initially. This function should return a new Category object representing those parameters, or nil if the combination of parameters was not valid (i.e. no such category exists).

Most templates accept and pass this common set of parameters. The parameters passed to the module by a template are defined by that template individually, so not every template will necessarily use all of these. {{famcatboiler}} for example only passes the code= parameter to the module.

code=
The code that specifies what 'owns' the category's contents. This is usually a language code such as en, but it can also be a script code like Latn or the code of a language family, depending on how the specific template treats it.
label=
A name for the thing that is being categorised. The submodule determines how the label is interpreted, so it depends on the template being used. Many templates use it to look up data in a table, while others may interpret it as a language code of some kind.
sc=
The script code of the items to be categorised. This is usually empty, but many categories such as those used by Mandarin Chinese can split into subcategories based on script.

General workings[tahrirlash]

The module is based on the principle of two main kinds of category:

Basic categories are those for which the code= parameter is not empty. These therefore belong to a specific language (or similar) and are the "regular" categories. Examples are: Category:English nouns, Category:French templates, Category:nl:Linguistics, Category:English terms derived from Japanese, Category:Latin script characters.

Umbrella categories do not have a code, but contain all basic categories of their label, one for each code. These are the "by language" type categories. Examples are: Category:Nouns by language, Category:Templates by language, Category:Linguistics, Category:Terms derived from Japanese, Category:Characters by script.

Some templates also distinguish a third type of category, the fundamental category. This category is used as the parent category for umbrella categories.

Turkum obʼektlari[tahrirlash]

Andoza:documentation outdated Turkum obʼektlar har bir submoduli yangi funktsiyasi tomonidan qaytarilur. Ular daraxtda bir kategoriya vakili. A turkum obʼekt turkumidagi haqida maʼlumot soʻrash uchun u chaqirdi mumkin, turli usullarini bor.

getBreadcrumbName[tahrirlash]

getBreadcrumbName()

Turkum sahifaning tepasida "ket haqli sinib" kategoriyadagi uchun ishlatiladi nomini qaytaradi.

getDataModule[tahrirlash]

getDataModule()

Ushbu turkumda uchun maʼlumotlarni oʻz ichiga olgan modul nomini qaytaradi. Bu foydalanuvchilar topish va yanada oson maʼlumotlarni tahrir qilish imkonini beradi toifali kuni, "tartibga solish" bogʻ yaratish uchun ishlatiladi.

getCategoryName[tahrirlash]

getCategoryName()

Ushbu turkumda obʼekt ifodalaydi toifali nomini qaytaradi.

getDescription[tahrirlash]

getDescription()

Turkum sahifaning yuqorisida koʻrsatilgan bayoni matnni qaytaradi. Turkum yoʻq tavsifi ega boʻlsa, bu nol qaytaradi.

getParents[tahrirlash]

getParents()

Ushbu turkumda ota toifalarida bir jadval qaytaradi. Jadvalda har bir element ikki elementlar bilan bir stol oʻzi emas:

.nom
Ota-kategoriya vakili An turkumda obʼekt, yoki toʻg'ridan-toʻgʻri, ota-toifali nomini bildiradi, bir string: ikki imkoniyatlari biri.
.sort
Ota-ona joriy kategoriya ishlatilishi kerak saralash tugmasini bosing.

Turkum yoʻq ota-onasiga bor boʻlsa, bu nol qaytaradi.

getChildren[tahrirlash]

getChildren()

Ushbu toifadagi bolalar toifalari jadvali qaytaradi. Jadvalda har bir element bola kategoriya vakili boʻlgan turkumda obʼekt hisoblanadi. Turkum farzandi yoʻq, bu qaytadi ega boʻlsa nil.

getUmbrella[tahrirlash]

getUmbrella()

Hozirgi kategoriyalari ning mos soyabon turkumidagi uchun bir kategoriya obyekti qaytaradi. Joriy Turkum soyabon turkumda allaqachon boʻlsa, bu nol qaytaradi. Bundan tashqari, kategoriya yoʻq soyabon kategoriya ega boʻlsa nol qaytaradi.


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

-- Asosiy kirish nuqtasi.
-- Bu shablonni huquqdan mumkin faqat funktsiya hisoblanadi.
function export.show(frame)
	if mw.title.getCurrentTitle().nsText == "Andoza" then
		return "(Ushbu shablonini Turkum sahifalarda foydalanilishi lozim: ism.)"
	elseif mw.title.getCurrentTitle().nsText ~= "Turkum" then
		error("Ushbu shablonini / moduli faqat Turkum sahifalarda foydalanish mumkin: ism.")
	end
	
	local args = frame.args
	
	-- Barcha parametrlarni va yorliq maʼlumotlarini qiling
	local info = {}
	
	for key, val in pairs(args) do
		info[key] = val; if info[key] == "" then info[key] = nil end
	end
	
	-- mavzu mushuk uchun auto plomba parametrlari
	if info.template == "topic cat" and not info.code and not info.label then
		pagename = mw.title.getCurrentTitle().text
		pagename = mw.text.split(pagename,':')
		if #pagename == 1 then
			info.label = pagename[1]
		elseif #pagename == 2 then
			info.code = pagename[1]
			info.label = pagename[2]
		end
	end
		
	if not info.template then
		error("Bu \"Andoza \" parametr belgilangan edi.")
	end
	
	local template = info.template
	info.template = nil
	local current = require("Module:category tree/" .. template).new(info, true)
	local display = {}
	local categories = {}
	
	-- Turkum boʻsh boʻlsa tekshiring
	local isEmpty = mw.site.stats.pagesInCategory(mw.title.getCurrentTitle().text, "all") == 0
	
	-- Parametrlar amal qiladi?
	if not current then
		table.insert(categories, "[[Turkum:Asossiz yorligʻi bilan kategoriyalar]]")
		table.insert(categories, isEmpty and "[[Turkum:Boʻsh toifalar]]" or nil)
		table.insert(display, show_error(
			"Belgi \"" .. (info.label or "") .. "\" berilgan " ..
			mw.getCurrentFrame():expandTemplate{title = "temp", args = {template}} ..
			" andoza tegishli emas. Siz uni yozgan boʻlishingiz mumkin, yoki u shunchaki hali yaratilmagan emas. " ..
			" Yangi teg kiritish uchun, andozalarini hujjatiga murojaat qiling."))
		
		-- Bu yerda kattaroq barcha kodi hozirgi emas, balki shaxs Nil tayanadi, bu erda chiqish
		return table.concat(categories, "") .. table.concat(display, "\n\n") .. "<br clear=\"all\"/>"
	end
	
	-- Turkum toʻgʻri ismi bormi?
	if mw.title.getCurrentTitle().text ~= current:getCategoryName() then
		table.insert(categories, "[[Turkum:Xato nomi bilan Kategoriyalar]]")
		table.insert(display, show_error(
			" Berilgan parametrlar asosida " ..
			mw.getCurrentFrame():expandTemplate{title = "temp", args = {template}} ..
			" Andoza, bu kategoriya deb nomlangan lozim '''[[:Turkum:" .. current:getCategoryName() .. "]]'''."))
	end
	
	-- Boʻsh toifalari uchun tozalash kategoriyasi qoʻshish
	if isEmpty and not current:canBeEmpty() then
		table.insert(categories, "[[Turkum:Boʻsh toifalar]]")
	end
	
	-- Koʻrsatilgan maʻlumotlarni yaratish
	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(display, "\n\n") .. "<br clear=\"all\"/>"
end

function show_error(text)
	return  mw.getCurrentFrame():expandTemplate{title = "Xizmat qutisi", args = {
		"red",
		image = "[[Fayl:Ambox warning pn.svg|50px]]",
		title = "Ushbu toifadagi avtomatik ravishda hosil tarkibi xatolar bor.",
		text = text,
		}}
end

-- Hozirgi sahifa nomini tekshiring, va u oʻng emas, agar xato qaytaradi.
function check_name(current, template, info)
	local errortext = nil
	local category = nil
	
	if not current then
		errortext =
			"Belgi \"" .. (info.label or "") .. "\" berilgan " .. mw.getCurrentFrame():expandTemplate{title = "temp", args = {template}} .. " andoza tegishli emas. " ..
			"Siz uni yozgan boʻlishingiz mumkin, yoki u shunchaki hali yaratilmagan emas. Yangi teg kiritish uchun, andozalarini hujjatiga murojaat qiling."
		category = "[[Turkum:Asossiz yorligʻi bilan Kategoriyalar]]"
	else
		
	end
	
	if errortext then
		return (category or "") .. show_error(errortext)
	else
		return nil
	end
end

-- Joriy Turkum joylashtirilgan boʻlishi kerak, ota-ona kategoriyalari koʻrsatish.
function show_categories(current, categories)
	local parents = current:getParents()
	
	if not parents then
		return
	end
	
	for _, parent in ipairs(parents) do
		if type(parent.name) == "string" then
			table.insert(categories, "[[" .. parent.name .. "|" .. parent.sort .. "]]")
		else
			local parent_name = parent.name:getCategoryName()
			table.insert(categories, "[[Turkum:" .. parent_name .. "|" .. parent.sort .. "]]")
		end
	end
	
	-- Bundan tashqari, uning mos "Umbrella" yoki "til" turkumidagi kategoriya qoʻydi.
	local umbrella = current:getUmbrella()
	
	if umbrella then
		if type(umbrella) == "string" then
			table.insert(categories, "[[" .. umbrella .. "|" .. current:getCategoryName() .. "]]")
		else
			table.insert(categories, "[[Turkum:" .. umbrella:getCategoryName() .. "|" .. current:getCategoryName() .. "]]")
		end
	end
end

-- Sahifaning yuqorisida navigatsiya "tapas" koʻrsatadi.
function show_breadcrumbs(current)
	local steps = {}
	
	-- Joriy teg boshlang va biz keyingi borish mumkin emas qadar, ota-ona uchun farzand dan "zanjiri» Bizning yoʻlimizga up harakat.
	while current do
		local category = nil
		local display_name = nil
		
		if type(current) == "string" then
			category = current
			display_name = current:gsub("^Turkum:", "")
		else
			category = "Turkum:" .. current:getCategoryName()
			display_name = current:getBreadcrumbName()
		end
		
		display_name = mw.getContentLanguage():ucfirst(display_name)
		table.insert(steps, 1, "» [[:" .. category .. "|" .. display_name .. "]]")
		
		-- Bir darajada tomonidan "zanjir" tashkil suring.
		if type(current) == "string" then
			current = nil
		else
			current = current:getParents()
			
			if current then
				current = current[1].name
			end
		end
	end
	
	return "<small>" .. table.concat(steps, " ") .. "</small>"
end

-- Kategoriya uchun qisqa bayoni matnni koʻrsatish.
function show_description(current)
	return (current:getDescription() or "") .. mw.getCurrentFrame():expandTemplate{title = "edit", args = {current:getDataModule(), type = "sup"}}
end

-- Bolalar toifalari roʻyxatini koʻrsatish.
function show_children(current)
	local children = current:getChildren()
	
	if not children then
		return nil
	end
	
	table.sort(children, function(first, second) return first.sort < second.sort end)
	
	local children_list = {}
	
	for _, child in ipairs(children) do
		local child_basic = child.name:getCategoryName()
		local child_page = mw.title.new("Turkum:" .. child_basic)
		
		if child_page.exists then
			local child_description = child.name:getDescription()
			table.insert(children_list, "* [[:Turkum:" .. child_basic .. "]]: " .. child_description)
		end
	end
	
	return table.concat(children_list, "\n")
end

-- Til Skript har bir harf uchun ulanish bilan mazmunan bir jadval koʻrsatish.
function show_TOC(info)
	local code = info.code or "en"
	local num_pages = 300 --mw.site.stats.pagesInCategory(mw.title.getCurrentTitle().text, "pages")
	
	-- A TOC uchun hojat yoʻq, barcha kirish nomlari bir sahifada mos mumkin.
	if num_pages > 200 then
		-- TOC bir "kengaytirilgan" versiyasi mavjud boʻlsa Ushbu turkumda juda katta, qarang.
		if num_pages > 2500 then
			local TOC_template_extended = mw.title.new("Andoza:" .. 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("Andoza:" .. code .. "-categoryTOC")
		
		if TOC_template.exists then
			return mw.getCurrentFrame():expandTemplate{title = TOC_template.text, args = {}}
		end
	end
	
	return nil
end

return export