Module:Category tree/requests
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Category tree/requests/documentation
local m_languages = require("Module:languages")
local export = {}
local function show_pagelist()
local recent = mw.getCurrentFrame():callParserFunction{
name = "#tag",
args = {
"DynamicPageList",
"category=" .. mw.title.getCurrentTitle().text .. "\n" ..
"count=10\n" ..
"mode=ordered\n" ..
"ordermethod=categoryadd\n" ..
"order=descending"
}
}
local oldest = mw.getCurrentFrame():callParserFunction{
name = "#tag",
args = {
"DynamicPageList",
"category=" .. mw.title.getCurrentTitle().text .. "\n" ..
"count=10\n" ..
"mode=ordered\n" ..
"ordermethod=lastedit\n" ..
"order=ascending"
}
}
return [=[
{| id="newest-and-oldest-pages" class="wikitable" style="float: right; clear: both; margin: 0 0 .5em 1em;"
! Recent additions to the category
|-
| id="recent-additions" style="font-size:0.9em;" | ]=] .. recent .. [=[
|-
! Oldest pages ordered by last edit
|-
| id="oldest-pages" style="font-size:0.9em;" | ]=] .. oldest .. [=[
|}]=]
end
local function replace_template_refs(result, items, frame)
--[[ Replaces pseudo-template code {{{ }}} with the corresponding member
of the "items" table. Has to be done at least twice,
since some of the items are nested:
{{{template_syntax_with_language_code}}}
⇓
{{{{{template_name}}}|{{{language_code}}}}}
⇓
{{attention|en}} ]]
while result:find("{{{") do
result = mw.ustring.gsub(
result,
"{{{([^%}%{]+)}}}",
function(item)
if items[item] then
if type(items[item]) == "string" or type(items[item]) == "number" then
return items[item]
else
error('The item "{{{' .. item .. '}}}" is a ' .. type(item) .. ' and can\'t be concatenated. (Pagename: ' .. items.pagename .. '.)')
end
else
error('The item "' .. item .. '" was not found in the "items" table. (Pagename: ' .. items.pagename .. '.)')
end
end
)
end
-- Preprocess template code surrounded by << >>. In some cases we have a
-- << >> template call nested inside of another one (this happens e.g. with
-- "Requests for SCRIPT script for LANGUAGE terms"), so process them
-- repeatedly from inside out.
while result:find("<<") do
result = mw.ustring.gsub(
result,
"<<([^><]+)>>",
function (template_code)
return frame:preprocess(template_code)
end
)
end
return result
end
function export.contents(frame)
local items = {}
local no_catfix = false
local valid_category = false
if type(frame) == "table" then
items.pagename = mw.title.getCurrentTitle().text
elseif type(frame) == "string" then
items.pagename = frame
frame = mw.getCurrentFrame()
end
local en = m_languages.getByCode("en")
-- This array consists of category match specs. Each spec contains
-- one or more properties, whose values are strings that may contain
-- references to other properties using the {{{PROPERTY}}} syntax.
-- Each such spec should have a least a `regex` property that matches the
-- name of the category. Capturing groups in this regex can be referenced
-- in other properties using {{{1}}} for the first group, {{{2}}} for the
-- second group, etc. Property expansion happens recursively if needed
-- (i.e. a property can reference another property, which in turn
-- references a third property).
--
-- If there is a `language_name` propery, it specifies the language name
-- (and will typically be a reference to a capturing group from the `regex`
-- property); if not specified, it defaults to "{{{1}}}" unless the `nolang`
-- property is set, in which case there is no language name derivable from
-- the category name. The language name must be the canonical name of a
-- recognized language, or an error is thrown. Based on the language name,
-- the `language_code` and `language_object` properties are automatically
-- filled in.
--
-- If the `regex` values of multiple category specs match, the first one
-- takes precedence.
--
-- Recognized or predefined properties:
--
-- `pagename`: Current pagename.
-- `regex`: See above.
-- `1`, `2`, `3`, ...: See above.
-- `language_name`, `language_code`, `language_object`: See above.
-- `nolang`: See above.
-- `template_name`: Name of template which generates this category.
-- `template_syntax`: Syntax for calling the template. Defaults to
-- "{{{template_name}}}|{{{language_code}}}". Used to display
-- an example template call and the output of this call.
-- `template_syntax_nocat`: Syntax for calling the template. Takes
-- precedence over `template_syntax` when generating example template
-- output (but not when displaying an example template call) and is
-- intended for a template call that uses the |nocat=1 parameter.
-- `template_example_output`: Override the text that displays example
-- template output (see `template_syntax`).
-- `additional_template_description`: Extra text to be displayed after
-- the example template output.
-- `this_request_in_all_languages`: Parent all-language category.
-- Sort key is based on the language name.
-- `one_level_above_in_the_same_language`: Parent category in the same
-- language, if any. Sort key is based on `request_sortkey`.
-- `request_sortkey`: Sort key for this category in the same-language
-- category specified by `one_level_above_in_the_same_language`.
-- `not_hidden_category`: Don't hide the category.
-- `catfix_lang`: Language object to use for generating a "catfix" on
-- the page to ensure that entries on the page are appropriately styled;
-- see [[Module:utilities]] for more information. Defaults to
-- `language_object`.
-- `no_catfix`: Disable generation of a "catfix" on the page (see
-- `catfix_lang`).
--
-- An actual template call can be inserted into a string using the syntax
-- <<{{TEMPLATE|ARG1|ARG2|...}}>>. Currently this is used internally
-- to display the example template output (see `template_syntax` above).
local categories = {
{
regex = "^Requests concerning (.+)$",
request_sortkey = "requests",
this_request_in_all_languages = "Requests by language",
not_hidden_category = true
},
{
regex = "^Requests for etymologies in (.+) entries$",
request_sortkey = "etymologies",
template_name = "rfe",
this_request_in_all_languages = "Requests for etymologies by language",
},
{
regex = "^Requests for expansion of etymologies in (.+) entries$",
request_sortkey = "expansion of etymologyies",
template_name = "etystub",
this_request_in_all_languages = "Requests for expansion of etymologies by language",
},
{
regex = "^Requests for pronunciation in (.+) entries$",
request_sortkey = "pronunciation",
template_name = "rfp",
this_request_in_all_languages = "Requests for pronunciation by language",
},
{
regex = "^Requests for audio pronunciation in (.+) entries$",
request_sortkey = "audio pronunciation",
template_name = "rfap",
this_request_in_all_languages = "Requests for audio pronunciation by language",
},
{
regex = "^Requests for definitions in (.+) entries$",
request_sortkey = "definitions",
template_name = "rfdef",
this_request_in_all_languages = "Requests for definitions by language",
},
{
regex = "^Requests for clarification of definitions in (.+) entries$",
request_sortkey = "clarification of definitions",
template_name = "rfclarify",
this_request_in_all_languages = "Requests for clarification of definitions by language",
},
{
-- This is for part-of-speech-specific categories such as
-- "Requests for inflections in Northern Ndebele noun entries" or
-- "Requests for accents in Ukrainian proper noun entries".
-- Here and below, we assume that the part of speech is begins with
-- a lowercase letter, while the preceding language name ends in a
-- capitalized word. Note that this entry comes before the
-- following one and takes precedence over it.
regex = "^Requests for inflections in (.-) ([a-z]+[a-z ]*) entries$",
request_sortkey = "{{{2}}}",
template_name = "rfinfl",
template_syntax = "{{rfinfl|{{{language_code}}}|{{{2}}}}}",
one_level_above_in_the_same_language = "Requests for inflections in {{{language_name}}} entries",
this_request_in_all_languages = "Requests for inflections of {{{2}}}s by language",
},
{
regex = "^Requests for inflections in (.+) entries$",
request_sortkey = "inflections",
template_name = "rfinfl",
this_request_in_all_languages = "Requests for inflections by language",
},
{
regex = "^Requests for inflections of (.+) by language$",
nolang = true,
request_sortkey = "inflections of {{{1}}}",
},
{
regex = "^Requests for tone in (.-) ([a-z]+[a-z ]*) entries$",
request_sortkey = "{{{2}}}",
template_name = "rftone",
template_syntax = "{{rftone|{{{language_code}}}|{{{2}}}}}",
one_level_above_in_the_same_language = "Requests for tone in {{{language_name}}} entries",
this_request_in_all_languages = "Requests for tone of {{{2}}}s by language",
},
{
regex = "^Requests for tone in (.+) entries$",
request_sortkey = "tone",
template_name = "rftone",
this_request_in_all_languages = "Requests for tone by language",
},
{
regex = "^Requests for tone of (.+) by language$",
nolang = true,
request_sortkey = "tone of {{{1}}}",
},
{
regex = "^Requests for accents in (.-) ([a-z]+[a-z ]*) entries$",
request_sortkey = "{{{2}}}",
template_name = "rfaccents",
template_syntax = "{{rfaccents|{{{language_code}}}|{{{2}}}}}",
one_level_above_in_the_same_language = "Requests for accents in {{{language_name}}} entries",
this_request_in_all_languages = "Requests for accents of {{{2}}}s by language",
},
{
regex = "^Requests for accents in (.+) entries$",
request_sortkey = "accents",
template_name = "rfaccents",
this_request_in_all_languages = "Requests for accents by language",
},
{
regex = "^Requests for accents of (.+) by language$",
nolang = true,
request_sortkey = "accents of {{{1}}}",
},
{
regex = "^Requests for aspect in (.-) ([a-z]+[a-z ]*) entries$",
request_sortkey = "{{{2}}}",
template_name = "rfaspect",
template_syntax = "{{rfaspect|{{{language_code}}}|{{{2}}}}}",
one_level_above_in_the_same_language = "Requests for aspect in {{{language_name}}} entries",
this_request_in_all_languages = "Requests for aspect of {{{2}}}s by language",
},
{
regex = "^Requests for aspect in (.+) entries$",
request_sortkey = "aspect",
template_name = "rfaspect",
this_request_in_all_languages = "Requests for aspect by language",
},
{
regex = "^Requests for aspect of (.+) by language$",
nolang = true,
request_sortkey = "aspect of {{{1}}}",
},
{
regex = "^Requests for gender in (.-) ([a-z]+[a-z ]*) entries$",
request_sortkey = "{{{2}}}",
template_name = "rfgender",
template_syntax = "{{rfgender|{{{language_code}}}|{{{2}}}}}",
one_level_above_in_the_same_language = "Requests for gender in {{{language_name}}} entries",
this_request_in_all_languages = "Requests for gender of {{{2}}}s by language",
},
{
regex = "^Requests for gender in (.+) entries$",
request_sortkey = "gender",
template_name = "rfgender",
this_request_in_all_languages = "Requests for gender by language",
},
{
regex = "^Requests for gender of (.+) by language$",
nolang = true,
request_sortkey = "gender of {{{1}}}",
},
{
regex = "^Requests for example sentences in (.+)$",
request_sortkey = "example sentences",
template_name = "rfex",
this_request_in_all_languages = "Requests for example sentences by language",
},
{
regex = "^Requests for quotations in (.+)$",
request_sortkey = "quotations",
template_name = "rfquote",
this_request_in_all_languages = "Requests for quotations by language",
},
{
regex = "^Requests for translations into (.+)$",
request_sortkey = "translations",
template_name = "t-needed",
this_request_in_all_languages = "Requests for translations by language",
catfix_lang = en,
},
{
regex = "^Requests for translations of (.+) usage examples$",
request_sortkey = "translations of usage examples",
template_name = "t-needed",
template_syntax = "{{t-needed|{{{language_code}}}|usex=1}}",
template_syntax_nocat = "{{t-needed|{{{language_code}}}|usex=1|nocat=1}}",
this_request_in_all_languages = "Requests for translations of usage examples by language",
additional_template_description = "\n\nThe <<{{temp|ux}}>>, <<{{temp|uxi}}>>, <<{{temp|quote}}>>, <<{{temp|Q}}>>, <<{{temp|ja-usex}}>> and <<{{temp|zh-x}}>> template automatically add the page to this category if the example is in a foreign language and the translation is missing."
},
{
regex = "^Requests for review of (.+) translations$",
request_sortkey = "review of translations",
template_name = "t-check",
template_syntax = "{{t-check|{{{language_code}}}|example}}",
template_example_output = "",
this_request_in_all_languages = "Requests for review of translations by language",
catfix_lang = en,
},
{
regex = "^Requests for transliteration of (.+) terms$",
request_sortkey = "transliteration",
template_name = "rftranslit",
this_request_in_all_languages = "Requests for transliteration by language",
},
{
regex = "^Requests for native script for (.+) terms$",
request_sortkey = "native script",
template_name = "rfscript",
template_syntax_nocat = "{{rfscript|{{{language_code}}}|nocat=1}}",
this_request_in_all_languages = "Requests for native script by language",
no_catfix = true,
additional_template_description = "\n\nMany templates such as <<{{temp|l}}>>, <<{{temp|m}}>> and <<{{temp|t}}>> automatically place the page in this category when they are missing the term but have been provided with a transliteration."
},
{
regex = "^Requests for native script in (.+) usage examples$",
request_sortkey = "native script in usage examples",
template_name = "rfscript",
template_syntax = "{{rfscript|{{{language_code}}}|usex=1}}",
template_syntax_nocat = "{{rfscript|{{{language_code}}}|usex=1|nocat=1}}",
this_request_in_all_languages = "Requests for native script in usage examples by language",
no_catfix = true,
additional_template_description = "\n\nThe <<{{temp|ux}}>> and <<{{temp|uxi}}>> templates automatically add the page to this category if the example itself is missing but the translation is supplied."
},
{
regex = "^Requests for (.+) script for (.+) terms$",
language_name = "{{{2}}}",
request_sortkey = "{{{1}}} script",
template_name = "rfscript",
script_code = "<<{{#invoke:scripts/templates|getByCanonicalName|{{{1}}}}}>>",
template_syntax = "{{rfscript|{{{language_code}}}|sc={{{script_code}}}}}",
template_syntax_nocat = "{{rfscript|{{{language_code}}}|sc={{{script_code}}}|nocat=1}}",
one_level_above_in_the_same_language = "Requests for native script for {{{language_name}}} terms",
this_request_in_all_languages = "Requests for {{{1}}} script by language",
no_catfix = true,
additional_template_description = "\n\nMany templates such as <<{{temp|l}}>>, <<{{temp|m}}>> and <<{{temp|t}}>> automatically place the page in this category when they are missing the term but have been provided with a transliteration."
},
{
regex = "^Requests for (.+) script by language$",
nolang = true,
request_sortkey = "{{{1}}} script",
},
{
regex = "^Requests for images in (.+) entries$",
request_sortkey = "images",
template_name = "rfi",
this_request_in_all_languages = "Requests for images by language",
},
{
regex = "^Requests for references for (.+) terms$",
request_sortkey = "references",
template_name = "rfref",
this_request_in_all_languages = "Requests for references by language",
},
{
regex = "^Requests for references for etymologies in (.+) entries$",
request_sortkey = "references for etymologies",
template_name = "rfv-etym",
one_level_above_in_the_same_language = "Requests for references for {{{language_name}}} terms",
this_request_in_all_languages = "Requests for references for etymologies by language",
},
{
regex = "^Requests for references for pronunciations in (.+) entries$",
request_sortkey = "references for pronunciations",
template_name = "rfv-pron",
one_level_above_in_the_same_language = "Requests for references for {{{language_name}}} terms",
this_request_in_all_languages = "Requests for references for pronunciations by language",
},
{
regex = "^Requests for attention concerning (.+)$",
request_sortkey = "attention",
template_name = "attention",
template_example_output = "This template does not generate any text in entries.",
this_request_in_all_languages = "Requests for attention by language",
no_catfix = true,
},
{
regex = "^Requests for cleanup in (.+) entries$",
request_sortkey = "cleanup",
template_name = "rfc",
template_syntax_nocat = "{{rfc|{{{language_code}}}|nocat=1}}",
this_request_in_all_languages = "Requests for cleanup by language",
},
{
regex = "^Requests for cleanup of Pronunciation N headers in (.+) entries$",
request_sortkey = "cleanup of Pronunciation N headers",
template_name = "rfc-pron-n",
template_syntax_nocat = "{{rfc-pron-n|{{{language_code}}}|nocat=1}}",
template_example_output = "This template does not generate any text in entries.",
this_request_in_all_languages = "Requests for cleanup of Pronunciation N headers by language",
additional_template_description = [=[
The purpose of this category is to tag entries that use headers with "Pronunciation" and a number.
While these headers and structure are sometimes used, they are not specifically prescribed by [[WT:ELE]]. No complete proposal has yet been made on how they should work, what the semantics are, or how they interact with multiple etymologies. As a result they should generally be avoided. Instead, merge the entries (possibly under multiple Etymology sections, if appropriate), and list all pronunciations, appropriately tagged, under a Pronunciation header.
[[User:KassadBot|KassadBot]] tags these entries (or used to tag these entries, when the bot was operational). At some point if a proposal is made and adopted as policy, these entries should be reviewed.
This category is hidden.]=],
},
{
regex = "^Requests for deletion in (.+) entries$",
request_sortkey = "deletion",
template_name = "rfd",
template_syntax_nocat = "{{rfd|{{{language_code}}}|nocat=1}}",
this_request_in_all_languages = "Requests for deletion by language",
},
{
regex = "^Requests for verification in (.+) entries$",
request_sortkey = "verification",
template_name = "rfv",
this_request_in_all_languages = "Requests for verification by language",
},
{
regex = "^Requests for attention in etymologies in (.+) entries$",
request_sortkey = "attention in etymologies",
this_request_in_all_languages = "Requests for attention in etymologies by language",
},
{
regex = "^Requests for quotation/(.+)$",
request_sortkey = "{{{1}}}",
nolang = true,
template_name = "rfquotek",
template_syntax = "{{rfquotek|LANGCODE|{{{1}}}}}",
template_example_output = "\n(where LANGCODE is the language code of the entry)\n\nIt results in the message below:\n\n<<{{rfquotek|und|{{{1}}}}}>>",
one_level_above_in_the_same_language = "Requests for quotation by source",
},
{
regex = "^Requests for date/(.+)$",
request_sortkey = "{{{1}}}",
nolang = true,
template_name = "rfdatek",
template_syntax = "{{rfdatek|LANGCODE|{{{1}}}}}",
template_example_output = "\n(where LANGCODE is the language code of the entry)\n\nIt results in the message below:\n\n<<{{rfdatek|und|{{{1}}}}}>>",
one_level_above_in_the_same_language = "Requests for date by source",
},
}
for i, category in ipairs(categories) do
local matchvals = {mw.ustring.match(items.pagename, category.regex)}
if #matchvals > 0 then
valid_category = true
for key, value in pairs(category) do
items[key] = value
end
for key, value in ipairs(matchvals) do
items["" .. key] = value
end
if not category.not_hidden_category then
items.hidden_category = "__HIDDENCAT__"
end
break
end
end
if not valid_category and mw.ustring.find(items.pagename, "^Requests .* by language$") then
for i, category in ipairs(categories) do
if items.pagename == category.this_request_in_all_languages then
valid_category = true
items.request_sortkey = category.request_sortkey
end
end
end
if not valid_category then
error("Category name is not recognized.")
end
if items.regex and not items.nolang then
items.language_name = items.language_name or "{{{1}}}"
items.language_name = replace_template_refs(items.language_name, items, frame)
items.language_object = m_languages.getByCanonicalName(items.language_name) or error ('The category title contains an invalid language name, "' .. items.language_name .. '". Choose a canonical name from the data modules of Module:languages.')
items.language_code = items.language_object:getCode()
end
items.edit_link = "{| class='wikitable noprint plainlinks' style='float: right'\n| '''[https://en.wiktionary.org/w/index.php?title=Module:category_tree/requests&action=edit Edit category data]'''\n|}"
items.description = ("\nThis category contains '''{{{pagename}}}'''.")
if items.template_name then
if items.template_syntax then
items.template_syntax_with_language_code = items.template_syntax
else
items.template_syntax_with_language_code = ("{{{{{template_name}}}|{{{language_code}}}}}")
end
items.full_text_about_the_template = "\n" .. ("To make this request, in this specific language, use this code in the entry (see also the documentation at [[Template:{{{template_name}}}]]):\n\n<pre>{{{template_syntax_with_language_code}}}</pre>")
if items.template_example_output then
items.full_text_about_the_template = items.full_text_about_the_template .. " " .. items.template_example_output
else
if items.template_syntax_nocat then
items.full_text_about_the_template = items.full_text_about_the_template .. "\nIt results in the message below:\n\n<<{{{template_syntax_nocat}}}>>"
else
items.full_text_about_the_template = items.full_text_about_the_template .. "\nIt results in the message below:\n\n<<{{{template_syntax_with_language_code}}}>>"
end
end
if items.additional_template_description then
items.full_text_about_the_template = items.full_text_about_the_template .. items.additional_template_description
end
end
if not items.one_level_above_in_the_same_language then
if mw.ustring.find(items.pagename, "^Requests .* by language$") then
items.one_level_above_in_the_same_language = "Request subcategories by language"
elseif mw.ustring.find(items.pagename, "^Requests concerning .*") then
items.one_level_above_in_the_same_language = "{{{language_name}}} entry maintenance"
else
items.one_level_above_in_the_same_language = "Requests concerning {{{language_name}}}"
end
end
if items.one_level_above_in_the_same_language then
items.one_level_above_in_the_same_language_text = "[[Category:{{{one_level_above_in_the_same_language}}}|{{{request_sortkey}}}]]"
end
if items.regex and not items.nolang then
items.this_request_in_all_languages_text = ("[[Category:{{{this_request_in_all_languages}}}|{{{language_name}}}]]")
end
if items.catfix_lang or ( not items.no_catfix and items.language_object ) then
items.catfix = require("Module:utilities").catfix(items.catfix_lang or items.language_object)
end
items.pagename = mw.ustring.gsub(items.pagename, "Requests", "requests")
result = require("Module:table").compressSparseArray{ items.hidden_category, items.catfix, items.edit_link, show_pagelist(), items.description, items.full_text_about_the_template, items.one_level_above_in_the_same_language_text, items.this_request_in_all_languages_text }
table.insert(result, "__EXPECTUNUSEDCATEGORY__")
result = table.concat(result, "\n")
result = replace_template_refs(result, items, frame)
return result
end
function export.test(frame)
if type(frame) ~= "table" then
error('The function "' .. test '" requires a frame object as argument.')
end
local pagenames = {}
local results = {}
for i, item in pairs(frame.args) do
mw.text.trim(item)
table.insert(pagenames, item)
item = export.contents(item)
item = frame:extensionTag{ name = "syntaxhighlight", content = item, args = { lang = "html" } }
table.insert(results, item)
end
local output = {}
table.insert(output, '{| class="wikitable"')
for i, result in pairs(results) do
table.insert(output, '\n|-\n| [[:Category:' .. pagenames[i] .. '|' .. pagenames[i] .. ']] || ' .. result)
end
table.insert(output, '\n|}')
return table.concat(output)
end
return export
-- For Vim, so we get 4-space tabs
-- vim: set ts=4 sw=4 noet: