模組:Category tree/poscatboiler/data/wiktionary


此數據子模塊定義了維基詞典分類結構的一部分。

關於poscatboiler系統的介紹以及如何添加或更改分類,請參見Module:category tree/poscatboiler/data/documentation


local raw_categories = {}
local raw_handlers = {}

local ceil = math.ceil
local concat = table.concat
local insert = table.insert
local log10 = math.log10

-----------------------------------------------------------------------------
--                                                                         --
--                              RAW CATEGORIES                             --
--                                                                         --
-----------------------------------------------------------------------------


raw_categories["維基詞典"] = {
	description = "有關維基詞典及其運作的材料的高級分類。",
	parents = "分類",
}

raw_categories["維基詞典統計"] = {
	description = "Categories and pages containing statistics about how Wiktionary is used.",
	parents = {"維基詞典", sort = "統計"},
}

raw_categories["維基詞典使用者"] = {
	description = "根據使用者權限列出維基詞典使用者的頁面,以及根據使用者的語言和程式設計能力列出維基詞典使用者的分類。",
	breadcrumb = "使用者",
	additional = "關於自動產生的所有使用者的列表,請參閱[[Special:ListUsers]]。",
	parents = {"維基詞典", sort = "使用者"},
}

raw_categories["被WMF封禁的維基媒體人"] = {
	description = "Users who have received a [[m:Global bans|global ban]] imposed by the [[m:Wikimedia Foundation|Wikimedia Foundation]], in accordance with the [[m:WMF Global Ban Policy|WMF Global Ban Policy]].",
	breadcrumb = "被WMF封禁",
	parents = "維基詞典使用者",
}

raw_categories["使用者語文"] = {
	description = "根據維基詞典使用者的語言能力所列出的分類。",
	parents = {
		"維基詞典使用者",
		-- "Category:Wiktionary multilingual issues",
	},
}

raw_categories["有無效代碼的使用者語言"] = {
	description = "根據語言能力列出維基人的分類,其中語言代碼對在基詞典中無效。",
	additional = "這些代碼大多數都是有效的 ISO 639-3 代碼,但由於各種原因在維基詞典中無法使用," ..
	"通常是由於在切分和合併語言方面做出了不同的選擇。",
	parents = {name = "使用者語文", sort = " "},
}

raw_categories["User scripts"] = {
	description = "Categories listing Wiktionarians according to their abilities to read a given script.",
	parents = {
		"Wiktionary users",
		"Category:Wiktionary multilingual issues",
	},
}

raw_categories["User coders"] = {
	description = "Categories listing Wiktionarians according to their coding abilities.",
	parents = "維基詞典使用者",
}


raw_categories["有詞條的頁面"] = {
	description = "包含語言詞條的頁面。",
	additional = "此分類中的子分類被用於確定中文維基詞典上的條目總數。",
	parents = "維基詞典",
	can_be_empty = true,
	hidden = true,
}

raw_categories["Redirects connected to a Wikidata item"] = {
	description = "Redirect pages which are connected to a [[d:|Wikidata]] item.",
	additional = "These are rarely needed, but are occasionally useful following a page merger, where other wikis may still separate the two.",
	parents = "Wiktionary statistics",
	can_be_empty = true,
	hidden = true,
}

raw_categories["不支援的頁面名稱"] = {
	description = "標題不受 MediaWiki -{zh-hans:软件; zh-hant:軟體}-支援的頁面。",
	additional = "有關某些標題不受支援的原因的解釋,請參閱 [[Appendix:不支援的頁面名稱]]。",
	parents = {"維基詞典"},
	can_be_empty = true,
	hidden = true,
}

-- Tracked according to [[phab:T347324]].
for ext, data in pairs {
	["DynamicPageList"] = {"DynamicPageList (Wikimedia)", "T287380"},
	["EasyTimeline"] = {"EasyTimeline", "T137291"},
	["Graph"] = {"Graph", "T334940"},
	["Kartographer"] = {"Kartographer"},
	["Phonos"] = {"Phonos"},
	["Score"] = {"Score"},
	["WikiHiero"] = {"WikiHiero", "T344534"},
} do
	local link, phab = unpack(data)
	raw_categories["Pages using the " .. ext .. " extension"] = {
		description = ("Pages which make use of the [[mw:Extension:%s|%s]] extension."):format(link, ext),
		additional = phab and ("See [[phab:%s|%s]] on the Phabricator for background information on why this extension is tracked."):format(phab, phab) or nil,
		breadcrumb = ("Using the %s extension"):format(ext),
		parents = "Wiktionary statistics",
		can_be_empty = true,
		hidden = true,
	}
end

-----------------------------------------------------------------------------
--                                                                         --
--                                RAW HANDLERS                             --
--                                                                         --
-----------------------------------------------------------------------------


local function get_level_params(data)
	local speak_verb = "speak"
	if data.typ == "lang" then
		local is_sign_language = data.obj and data.obj:getFamilyCode():find("^sgn") or data.name:find("Sign Language$")
		speak_verb = data.args.verb or is_sign_language and "communicate in" or "speak"
	end
	return {
		["-"] = {
			leftcolor = "#99B3FF",
			rightcolor = "#E0E8FF",
			lang = "These users " .. speak_verb .. " NAME.",
			script = "These users read NAME.",
			coder = "These users know how to code in NAME.",
		},
		["0"] = {
			leftcolor = "#FFB3B3",
			rightcolor = "#FFE0E8",
			lang = "These users do not understand NAME (or understand it with considerable difficulty).",
			script = "These users '''cannot''' read NAME.",
			coder = "These users know '''little''' about NAME and just mimic existing usage.",
		},
		["1"] = {
			leftcolor = "#C0C8FF",
			rightcolor = "#F0F8FF",
			lang = "These users " .. speak_verb .. " NAME at a '''basic''' level.",
			script = "These users can read NAME at a '''basic''' level.",
			coder = "These users know the '''basics''' of how to write NAME code and make minor tweaks.",
		},
		["2"] = {
			leftcolor = "#77E0E8",
			rightcolor = "#D0F8FF",
			lang = "These users " .. speak_verb .. " NAME at an '''intermediate''' level.",
			script = "These users can read NAME at an '''intermediate''' level.",
			coder = "These users have a '''fair command''' of NAME, and can understand some scripts written by others.",
		},
		["3"] = {
			leftcolor = "#99B3FF",
			rightcolor = "#E0E8FF",
			lang = "These users " .. speak_verb .. " NAME at an '''advanced''' level.",
			script = "These users can read NAME at an '''advanced''' level.",
			coder = "These users can write '''more complex''' NAME code, and can understand and modify most scripts written by others.",
		},
		["4"] = {
			leftcolor = "#CCCC00",
			rightcolor = "#FFFF99",
			lang = "These users " .. speak_verb .. " NAME at a '''near-native''' level.",
			script = "These users can read NAME at a '''near native''' level.",
			coder = "These users can write and understand '''very complex''' NAME code.",
		},
		["5"] = {
			leftcolor = "#FF5E5E",
			rightcolor = "#FF8080",
			lang = "These users " .. speak_verb .. " NAME at a '''professional''' level.",
			script = "These users can read NAME at a '''professional''' level.",
			coder = "These users can write and understand NAME code at a '''professional''' level.",
		},
		["N"] = {
			leftcolor = "#6EF7A7",
			rightcolor = "#C5FCDC",
			lang = "These users are '''native''' speakers of NAME.",
			script = "These users' '''native''' script is NAME.",
		},
	}
end


local coder_links = {
	Bash = "w:Bash",
	C = "w:C语言",
	["C++"] = "w:C++",
	["C Sharp"] = {link = "w:C♯", name = "C#"},
	CSS = "w:CSS",
	Go = "w:Go",
	HTML = "w:HTML",
	Java = "w:Java",
	JavaScript = "w:JavaScript",
	Julia = "w:Julia语言",
	Lisp = "w:Lisp",
	Lua = "Wiktionary:Scribunto",
	Perl = "w:Perl",
	Python = "w:Python",
	Ruby = "w:Ruby",
	Scala = "w:Scala",
	Scheme = "w:Scheme",
	template = {link = "Wiktionary:模板", name = "維基模板"},
	VBScript = "w:VBScript",
}


-- Generic implementation of competency handler for (natural) languages, scripts, and "coders" (= programming languages).
local function competency_handler(data)
	local langtext = data.langtext
	local typ = data.typ
	local args = data.args
	local code = data.code
	local name = data.name
	local namecat = data.namecat
	local level = data.level
	local parents = data.parents
	local topright = data.topright
	local data_addl = data.additional

	local parts = {}
	local function ins(txt)
		insert(parts, txt)
	end
	local level_params = get_level_params(data)

	local params = level_params[level or "-"]
	if not params then
		error(("Internal error: No params for for code '%s', level %s"):format(code, level or "-"))
	end
	local function insert_text()
		if langtext then
			ins(langtext)
			ins("<hr />")
		end
		if not params[typ] then
			error(("No English text for code '%s', type '%s', level %s"):format(code, typ, level or "-"))
		end
		ins(params[typ]:gsub("NAME", ("'''" .. namecat .. "'''"):format(name)))
	end

	local additional
	if level then
		additional = ("To be included on this list, add {{tl|Babel|%s}} to your user page. Complete instructions are " ..
			"available at [[Wiktionary:Babel]]."):format(level == "N" and code or ("%s-%s"):format(code, level)) ..
			(data_addl and "\n\n" .. data_addl or "")
	else
		additional = ("To be included on this list, use {{tl|Babel}} on your user page. Complete instructions are " ..
			"available at [[Wiktionary:Babel]].") ..
			(data_addl and "\n\n" .. data_addl or "")
	end

	if level then
		ins(('<div style="float:left;border:solid %s 1px;margin:1px">'):format(params.leftcolor))
		ins(('<table cellspacing="0" style="width:238px;background:%s"><tr>'):format(params.rightcolor))
		ins(('<td style="width:45px;height:45px;background:%s;text-align:center;font-size:14pt">'):format(params.leftcolor))
		ins(("'''%s-%s'''</td>"):format(code, level))
		ins('<td style="font-size:8pt;padding:4pt;line-height:1.25em">')
		insert_text()
		ins('</td></tr></table></div><br clear="left">')

		return {
			description = concat(parts),
			additional = additional,
			breadcrumb = "Level " .. level,
			parents = parents,
		}, not not args
	else
		ins(('<div style="float:left;border:solid %s 1px;margin:1px;">\n'):format(params.leftcolor))
		ins(('{| cellspacing="0" style="width:260px;background:%s;"\n'):format(params.rightcolor))
		ins(('| style="width:45px;height:45px;background:%s;text-align:center;font-size:14pt;" | '):format(params.leftcolor))
		ins(("'''%s'''\n"):format(code))
		ins('| style="font-size:8pt;padding:4pt;line-height:1.25em;text-align:center;" | ')
		insert_text()
		ins('\n|}</div><br clear="left">')

		return {
			topright = topright,
			description = concat(parts),
			additional = additional,
			breadcrumb = name,
			parents = parents,
		}, not not args
	end
end


insert(raw_handlers, function(data)
	local code, level = data.category:match("^User ([a-z][a-z][a-z]?)%-([0-5N])$")
	if not code then
		code, level = data.category:match("^User ([a-z][a-z][a-z]?%-[a-zA-Z-]+)%-([0-5N])$")
	end
	if not code then
		code, level = data.category:match("^User ([a-z][a-z][a-z]?%-[a-zA-Z-]+)%-([0-5N])$")
	end
	if not code then
		code = data.category:match("^User ([a-z][a-z][a-z]?)$")
	end
	if not code then
		code = data.category:match("^User ([a-z][a-z][a-z]?%-[a-zA-Z-]+)$")
	end
	if not code then
		return
	end

	local args = require("Module:parameters").process(data.args, {
		text = true,
		verb = true,
		langname = true,
		commonscat = true,
	})
	
	local lang = require("Module:languages").getByCode(code, nil, "allow etym")
	local langname = args.langname
	
	if not lang then
		-- If unrecognized language and called from inside, we're handling the parents and breadcrumb for a
		-- higher-level category, so at least return something.
		if not level and data.called_from_inside then
			return {
				breadcrumb = {name = code, nocap = true}, -- FIXME, scrape langname= category?
				parents = {"User languages with invalid code", sort = code}
			}, true
		end
		
		if not langname then
			-- Check if the code matches a Wikimedia language (e.g. "ku" for Kurdish). If it does, treat
			-- its canonical name as though it had been given as langname=.
			local wm_lang = require("Module:wikimedia languages").getByCode(code)
			if not wm_lang then
				return
			end
			langname = wm_lang:getCanonicalName()
		end
	elseif not langname then
		langname = lang:getCanonicalName()
	end

	-- Insert text, appropriately script-tagged, unless already script-tagged (we check for '<span'), in which case we
	-- insert it directly. Also handle <<...>> in text and convert to bolded link to parent category.
	local function wrap(txt)
		if not txt then
			return
		end
		-- Substitute <<...>> (where ... is supposed to be the native rendering of the language) with a link to the
		-- top-level 'User CODE' category (e.g. [[:Category:User fr]] or [[:Category:User fr-CA]]) if we're in a
		-- sublevel category, or to the top-level language category (e.g. [[:Category:French language]] or
		-- [[:Category:Canadian English]]) if we're in a top-level 'User CODE' category.
		txt = txt:gsub("<<(.-)>>", function(inside)
			if level then
				return ("'''[[:Category:User %s|%s]]'''"):format(code, inside)
			elseif lang then
				return ("'''[[:Category:%s|%s]]'''"):format(lang:getCategoryName(), inside)
			else
				return ("'''%s'''"):format(inside)
			end
		end)
		if txt:find("<span") or not lang then
			return txt
		else
			return require("Module:script utilities").tag_text(txt, lang)
		end
	end

	local function insert_request_cats(parents)
		if args.text or code == "en" or code:find("^en%-") then
			return
		end
		local num_pages = mw.site.stats.pagesInCategory(data.category, "pages")
		local count_cat, count_sort
		if num_pages == 0 then
			count_cat = "Requests for translations in user-competency categories with 0 users"
			count_sort = "*" .. code
		elseif num_pages == 1 then
			count_cat = "Requests for translations in user-competency categories with 1 user"
			count_sort = "*" .. code
		else
			local lowernum, uppernum
			lowernum = 2
			while true do
				uppernum = lowernum * 2 - 1
				if num_pages <= uppernum then
					break
				end
				lowernum = lowernum * 2
			end
			count_cat = ("Requests for translations in user-competency categories with %s-%s users"):format(
				lowernum, uppernum)
			count_sort = "*" .. ("%0" .. #(tostring(uppernum)) .. "d"):format(num_pages)
		end

		insert(parents, {
			name = "Requests for translations in user-competency categories by language",
			sort = code,
		})
		insert(parents, {
			name = count_cat,
			sort = count_sort,
		})
	end

	local invalid_lang_warning
	if not lang then
		invalid_lang_warning = "'''WARNING''': The specified language code is invalid on Wiktionary. Please migrate all " ..
			"competency ratings to the closest valid code."
	end

	local parents
	if level then
		parents = {"User languages with invalid code", sort = code}
	elseif lang then
		parents = {
			{name = "User languages", sort = code},
			{name = lang:getCategoryName(), sort = "user"},
		}
		if lang:hasType("etymology-only") then
			insert(parents, {name = lang:getFull():getCategoryName(), sort = " " .. code})
		end
	else
		parents = {
			{name = "User languages with invalid code", sort = code},
		}
	end
	insert_request_cats(parents)

	local topright
	if args.commonscat then
		local commonscat = require("Module:yesno")(args.commonscat, "+")
		if commonscat == "+" or commonscat == true then
			commonscat = data.category
		end
		if commonscat then
			topright = ("{{commonscat|%s}}"):format(commonscat)
		end
	end

	local namecat
	if level then
		namecat = ("[[:Category:User %s|%%s]]"):format(code)
	elseif lang then
		namecat = ("[[:Category:%s|%%s]]"):format(lang:getCategoryName())
	else
		namecat = "[[%s]]"
	end

	local additional
	if level then
		additional = ("To be included on this list, add {{tl|Babel|%s}} to your user page. Complete instructions are " ..
			"available at [[Wiktionary:Babel]]."):format(level == "N" and code or ("%s-%s"):format(code, level)) ..
			(invalid_lang_warning and "\n\n" .. invalid_lang_warning or "")
	else
		additional = ("To be included on this list, use {{tl|Babel}} on your user page. Complete instructions are " ..
			"available at [[Wiktionary:Babel]].") ..
			(invalid_lang_warning and "\n\n" .. invalid_lang_warning or "")
	end
	return competency_handler {
		category = data.category,
		langtext = wrap(args.text),
		typ = "lang",
		args = args,
		obj = lang,
		code = code,
		name = langname,
		namecat = namecat,
		level = level,
		parents = parents,
		topright = topright,
		additional = invalid_lang_warning,
	}
end)

	
insert(raw_handlers, function(data)
	local code, level = data.category:match("^User ([A-Z][a-z][a-z][a-z][a-z]?)%-([0-5N])$")
	if not code then
		code = data.category:match("^User ([A-Z][a-z][a-z][a-z][a-z]?)$")
	end
	if not code then
		code, level = data.category:match("^User ([a-z][a-z][a-z]?%-[A-Z][a-z][a-z][a-z][a-z]?)%-([0-5N])$")
	end
	if not code then
		code = data.category:match("^User ([a-z][a-z][a-z]?%-[A-Z][a-z][a-z][a-z][a-z]?)$")
	end
	if not code then
		return
	end
	local sc = require("Module:scripts").getByCode(code)
	if not sc then
		return
	end

	local parents
	if level then
		parents = {("User %s"):format(code), sort = level}
	else
		parents = {
			{name = "User scripts", sort = code},
			{name = sc:getCategoryName(), sort = "user"},
		}
	end

	local namecat
	-- Better to display 'Foo script' than just 'Foo', as so many scripts are the same as language names.
	if level then
		namecat = ("[[:Category:User %s|%s]]"):format(code, sc:getCategoryName())
	else
		namecat = ("[[:Category:%s|%s]]"):format(sc:getCategoryName(), sc:getCategoryName())
	end

	return competency_handler {
		category = data.category,
		typ = "script",
		obj = sc,
		code = code,
		name = sc:getCanonicalName(),
		namecat = namecat,
		level = level,
		parents = parents,
	}
end)


insert(raw_handlers, function(data)
	local code, level
	if not code then
		code, level = data.category:match("^User ([A-Za-z+-]+) coder%-([0-5N])$")
	end
	if not code then
		code = data.category:match("^User ([A-Za-z+-]+) coder$")
	end
	if not code or not coder_links[code] then
		return
	end

	local parents
	if level then
		parents = {("User %s coder"):format(code), sort = level}
	else
		parents = {"User coders", sort = code}
	end

	local langdata = coder_links[code]
	if type(langdata) == "string" then
		langdata = {link = langdata}
	end

	local namecat = ("[[%s|%%s]]"):format(langdata.link)

	return competency_handler {
		category = data.category,
		typ = "coder",
		code = code,
		name = langdata.name or code,
		namecat = namecat,
		level = level,
		parents = parents,
	}
end)

insert(raw_handlers, function(data)
	local n = data.category:match("^有(%d+)個詞條的頁面$")
	
	-- Only match if there are no leading zeroes and the suffix is correct.
	if not (n and not n:match("^0%d")) then
		return
	end
	return {
		breadcrumb = ("%d個詞條"):format(n),
		description = ("包含%s個語言詞條的頁面。"):format(n, suffix),
		additional = "此分類和其他類似分類用於確定中文維基詞典上的詞條總數。",
		hidden = true,
		can_be_empty = true,
		parents = {
			{name = "有詞條的頁面", sort = ("#%0" .. ceil(log10(require("Module:list of languages").count())) .. "d"):format(n)},
			n == "0" and "維基詞典維護" or nil, -- "Pages with 0 entries" only contains pages with something wrong.
		},
	}
end)


return {RAW_CATEGORIES = raw_categories, RAW_HANDLERS = raw_handlers}