Modul:columns: Perbedaan antara revisi
Tampilan
Konten dihapus Konten ditambahkan
←Membuat halaman berisi 'local export = {} local html = mw.html.create local m_links = require("Module:links") local m_languages = require("Module:languages") local m_table = require("Module:table") local function format_list_items(list, args) local function term_already_linked(term) -- FIXME: "<span" is an ugly hack to prevent double-linking of terms already run through {{l|...}}: -- Thread:User talk:CodeCat/MewBot adding lang to column templates return term:find("<span")...' |
Swarabakti (bicara | kontrib) k coba mutakhirkan Tag: Dikembalikan |
||
Baris 1: | Baris 1: | ||
local |
local links_module = "Module:links" |
||
local parameter_utilities_module = "Module:parameter utilities" |
|||
local parameters_module = "Module:parameters" |
|||
local pron_qualifier_module = "Module:pron qualifier" |
|||
local string_utilities_module = "Module:string utilities" |
|||
local m_str_utils = require(string_utilities_module) |
|||
local concat = table.concat |
|||
local html = mw.html.create |
local html = mw.html.create |
||
local |
local is_substing = mw.isSubsting |
||
local find = string.find |
|||
local m_languages = require("Module:languages") |
|||
local |
local insert = table.insert |
||
local match = string.match |
|||
local remove = table.remove |
|||
local sub = string.sub |
|||
local trim = m_str_utils.trim |
|||
local u = m_str_utils.char |
|||
local export = {} |
|||
local function format_list_items(list, args) |
local function format_list_items(list, args) |
||
Baris 11: | Baris 24: | ||
-- FIXME: "<span" is an ugly hack to prevent double-linking of terms already run through {{l|...}}: |
-- FIXME: "<span" is an ugly hack to prevent double-linking of terms already run through {{l|...}}: |
||
-- [[Thread:User talk:CodeCat/MewBot adding lang to column templates]] |
-- [[Thread:User talk:CodeCat/MewBot adding lang to column templates]] |
||
return |
return find(term, "<span") |
||
end |
end |
||
for _, item in ipairs(args.content) do |
for _, item in ipairs(args.content) do |
||
Baris 17: | Baris 30: | ||
-- omitted item; do nothing |
-- omitted item; do nothing |
||
else |
else |
||
local text |
|||
if type(item) == "table" then |
if type(item) == "table" then |
||
text = item.term and term_already_linked(item.term) and item.term or |
|||
require(links_module).full_link(item) |
|||
if item.q then |
|||
-- We could use the "show qualifiers" flag to full_link() but not when term_already_linked(). |
|||
link = require("Module:qualifier").format_qualifier(item.q) .. " " .. link |
|||
if item.q and item.q[1] or item.qq and item.qq[1] or item.l and item.l[1] or item.ll and item.ll[1] or |
|||
item.refs and item.refs[1] then |
|||
text = require(pron_qualifier_module).format_qualifiers { |
|||
lang = item.lang or args.lang, |
|||
text = text, |
|||
q = item.q, |
|||
qq = item.qq, |
|||
l = item.l, |
|||
ll = item.ll, |
|||
refs = item.refs, |
|||
} |
|||
end |
end |
||
if item.qq then |
|||
link = link .. " " .. require("Module:qualifier").format_qualifier(item.qq) |
|||
end |
|||
item = link |
|||
elseif args.lang and not term_already_linked(item) then |
elseif args.lang and not term_already_linked(item) then |
||
text = require(links_module).full_link {lang = args.lang, term = item, sc = args.sc} |
|||
else |
|||
text = item |
|||
end |
end |
||
list = list:node(html("li") |
list = list:node(html("li") |
||
:wikitext( |
:wikitext(text) |
||
) |
) |
||
end |
end |
||
Baris 37: | Baris 60: | ||
return list |
return list |
||
end |
|||
local function make_sortbase(item) |
|||
if item == false then |
|||
return "*" -- doesn't matter, will be omitted in format_list_items() |
|||
elseif type(item) == "table" then |
|||
return item.alt or item.term |
|||
end |
|||
return item |
|||
end |
end |
||
Baris 60: | Baris 92: | ||
if args.alphabetize then |
if args.alphabetize then |
||
require("Module:collation").sort(args.content, args.lang, make_sortbase) |
|||
local function keyfunc(item) |
|||
if item == false then |
|||
item = "*" -- doesn't matter, will be omitted in format_list_items() |
|||
elseif type(item) == "table" then |
|||
item = item.term.term |
|||
end |
|||
return item |
|||
end |
|||
require("Module:collation").sort(args.content, args.lang, keyfunc) |
|||
end |
end |
||
Baris 83: | Baris 107: | ||
if args.collapse then |
if args.collapse then |
||
local nbsp = |
local nbsp = u(0xA0) |
||
output = html("div") |
output = html("div") |
||
:node(output) |
:node(output) |
||
Baris 116: | Baris 140: | ||
end |
end |
||
local param_mods = {"t", "alt", "tr", "ts", "pos", "lit", "id", "sc", "g", "q", "qq"} |
|||
local param_mod_set = m_table.listToSet(param_mods) |
|||
function export.display_from(frame_args, parent_args, frame) |
function export.display_from(frame_args, parent_args, frame) |
||
local boolean = {type = "boolean"} |
|||
local iparams = { |
local iparams = { |
||
["class"] = |
["class"] = true, |
||
-- Default for auto-collapse. Overridable by template |collapse= param. |
-- Default for auto-collapse. Overridable by template |collapse= param. |
||
["collapse"] = |
["collapse"] = boolean, |
||
-- If specified, this specifies the number of columns, and no columns |
-- If specified, this specifies the number of columns, and no columns |
||
-- parameter is available on the template. Otherwise, the columns |
-- parameter is available on the template. Otherwise, the columns |
||
Baris 133: | Baris 155: | ||
-- parameter is available on the template. Otherwise, the language-code |
-- parameter is available on the template. Otherwise, the language-code |
||
-- parameter can be specified as either |lang= or |1=. |
-- parameter can be specified as either |lang= or |1=. |
||
["lang"] = {}, |
["lang"] = {type = "language"}, |
||
-- Default for auto-sort. Overridable by template |sort= param. |
-- Default for auto-sort. Overridable by template |sort= param. |
||
["sort"] = |
["sort"] = boolean, |
||
-- The following is accepted but currently ignored, per an extended discussion in |
-- The following is accepted but currently ignored, per an extended discussion in |
||
-- [[Wiktionary:Beer parlour/2018/November#Titles of morphological relations templates]]. |
-- [[Wiktionary:Beer parlour/2018/November#Titles of morphological relations templates]]. |
||
["title"] = {default = ""}, |
["title"] = {default = ""}, |
||
["toggle_category"] = |
["toggle_category"] = true, |
||
} |
} |
||
local iargs = require( |
local iargs = require(parameters_module).process(frame_args, iparams) |
||
local compat = iargs |
local compat = iargs.lang or parent_args.lang |
||
local lang_param = compat and "lang" or 1 |
local lang_param = compat and "lang" or 1 |
||
local columns_param, first_content_param |
local columns_param, first_content_param |
||
Baris 151: | Baris 173: | ||
-- omitting it results in auto-determination. Old-style #columns specification is through the first numbered |
-- omitting it results in auto-determination. Old-style #columns specification is through the first numbered |
||
-- parameter after the lang parameter. |
-- parameter after the lang parameter. |
||
if parent_args |
if parent_args.n then |
||
columns_param = "n" |
columns_param = "n" |
||
first_content_param = compat and 1 or 2 |
first_content_param = compat and 1 or 2 |
||
else |
else |
||
columns_param = compat and 1 or 2 |
columns_param = compat and 1 or 2 |
||
first_content_param = columns_param + (iargs |
first_content_param = columns_param + (iargs.columns and 0 or 1) |
||
end |
end |
||
local deprecated |
local deprecated |
||
local params = { |
local params = { |
||
[lang_param] = |
[lang_param] = |
||
not iargs.lang and {required = true, type = "language", default = "und"} or nil, |
|||
[columns_param] = not iargs |
[columns_param] = not iargs.columns and {required = true, type = "number", default = 2} or nil, |
||
[first_content_param] = {list = true}, |
[first_content_param] = {list = true, allow_holes = true}, |
||
["title"] = {}, |
["title"] = {}, |
||
["collapse"] = |
["collapse"] = boolean, |
||
["sort"] = |
["sort"] = boolean, |
||
["sc"] = {}, |
["sc"] = {type = "script"}, |
||
["omit"] = {list = true}, -- used when calling from [[Module:saurus]] so the page displaying the synonyms/antonyms doesn't occur in the list |
["omit"] = {list = true}, -- used when calling from [[Module:saurus]] so the page displaying the synonyms/antonyms doesn't occur in the list |
||
} |
} |
||
Baris 176: | Baris 199: | ||
end |
end |
||
local m_param_utils = require(parameter_utilities_module) |
|||
local args = require("Module:parameters").process(parent_args, params, nil, "columns", "display_from") |
|||
local param_mods = m_param_utils.construct_param_mods { |
|||
local langcode = iargs["lang"] or args[lang_param] |
|||
{default = true, require_index = true}, |
|||
local lang = m_languages.getByCode(langcode, lang_param) |
|||
{group = "link"}, -- sc has separate_no_index = true; that's the only one |
|||
-- It makes no sense to have overall l=, ll=, q= or qq= params for columnar display. |
|||
{group = {"ref", "l", "q"}, require_index = true}, |
|||
} |
|||
local items, args = m_param_utils.process_list_arguments { |
|||
local sc = args["sc"] and require("Module:scripts").getByCode(sc, "sc") or nil |
|||
params = params, |
|||
param_mods = param_mods, |
|||
raw_args = parent_args, |
|||
termarg = first_content_param, |
|||
parse_lang_prefix = true, |
|||
allow_multiple_lang_prefixes = true, |
|||
disallow_custom_separators = true, |
|||
track_module = "columns", |
|||
lang = iargs.lang or lang_param, |
|||
sc = "sc.default", |
|||
} |
|||
local |
local lang = iargs.lang or args[lang_param] |
||
local langcode = lang:getCode() |
|||
if args["sort"] ~= nil then |
|||
local sc = args.sc.default |
|||
local sort = iargs.sort |
|||
if args.sort ~= nil then |
|||
sort = args.sort |
|||
end |
end |
||
local collapse = iargs |
local collapse = iargs.collapse |
||
if args |
if args.collapse ~= nil then |
||
collapse = args |
collapse = args.collapse |
||
end |
end |
||
for i, item in ipairs(items) do |
|||
local put |
|||
-- If a separate language code was given for the term, display the language name as a right qualifier. |
|||
for i, item in ipairs(args[first_content_param]) do |
|||
-- Otherwise it may not be obvious that the term is in a separate language (e.g. if the main language is 'zh' |
|||
-- Parse off an initial language code (e.g. 'la:minūtia' or 'grc:[[σκῶρ|σκατός]]'). Don't parse if there's a spac |
|||
-- and the term language is a Chinese lect such as Min Nan). But don't do this for Translingual terms, which |
|||
-- after the colon (happens e.g. if the user uses {{desc|...}} inside of {{col}}, grrr ...). |
|||
-- are often added to the list of English and other-language terms. |
|||
local termlangcode, actual_term = item:match("^([A-Za-z._-]+):([^ ].*)$") |
|||
if item.termlangs then |
|||
local termlang |
|||
local qqs = {} |
|||
-- Make sure that only real language codes are handled as language links, so as to not catch interwiki |
|||
for _, termlang in ipairs(item.termlangs) do |
|||
-- or namespaces links. |
|||
local termlangcode = termlang:getCode() |
|||
if termlangcode ~= langcode and termlangcode ~= "mul" then |
|||
mw.loadData("Module:languages/code to canonical name")[termlangcode] or |
|||
insert(qqs, termlang:getCanonicalName()) |
|||
mw.loadData("Module:etymology languages/code to canonical name")[termlangcode] |
|||
) then |
|||
-- -1 since i is one-based |
|||
termlang = m_languages.getByCode(termlangcode, first_content_param + i - 1, "allow etym") |
|||
item = actual_term |
|||
else |
|||
termlang = lang |
|||
termlangcode = nil |
|||
end |
|||
local termobj = {term = {lang = termlang, sc = sc}} |
|||
-- Check for inline modifier, e.g. מרים<tr:Miryem>. But exclude HTML entry with <span ...>, <i ...>, <br/> or |
|||
-- similar in it, caused by wrapping an argument in {{l|...}}, {{af|...}} or similar. Basically, all tags of |
|||
-- the sort we parse here should consist of a less-than sign, plus letters, plus a colon, e.g. <tr:...>, so if |
|||
-- we see a tag on the outer level that isn't in this format, we don't try to parse it. The restriction to the |
|||
-- outer level is to allow generated HTML inside of e.g. qualifier tags, such as foo<q:similar to {{m|fr|bar}}>. |
|||
if item:find("<") and not item:find("^[^<]*<[a-z]*[^a-z:]") then |
|||
if not put then |
|||
put = require("Module:parse utilities") |
|||
end |
|||
local run = put.parse_balanced_segment_run(item, "<", ">") |
|||
local orig_param = first_content_param + i - 1 |
|||
local function parse_err(msg) |
|||
error(msg .. ": " .. orig_param .. "= " .. table.concat(run)) |
|||
end |
|||
termobj.term.term = run[1] |
|||
for j = 2, #run - 1, 2 do |
|||
if run[j + 1] ~= "" then |
|||
parse_err("Extraneous text '" .. run[j + 1] .. "' after modifier") |
|||
end |
end |
||
if item.qq then |
|||
local modtext = run[j]:match("^<(.*)>$") |
|||
for _, qq in ipairs(item.qq) do |
|||
if not modtext then |
|||
insert(qqs, qq) |
|||
parse_err("Internal error: Modifier '" .. modtext .. "' isn't surrounded by angle brackets") |
|||
end |
|||
local prefix, arg = modtext:match("^([a-z]+):(.*)$") |
|||
if not prefix then |
|||
parse_err("Modifier " .. run[j] .. " lacks a prefix, should begin with one of '" .. |
|||
table.concat(param_mods, ":', '") .. ":'") |
|||
end |
|||
if param_mod_set[prefix] then |
|||
local obj_to_set |
|||
if prefix == "q" or prefix == "qq" then |
|||
obj_to_set = termobj |
|||
else |
|||
obj_to_set = termobj.term |
|||
end |
|||
if prefix == "t" then |
|||
prefix = "gloss" |
|||
elseif prefix == "g" then |
|||
prefix = "genders" |
|||
arg = mw.text.split(arg, ",") |
|||
elseif prefix == "sc" then |
|||
arg = require("Module:scripts").getByCode(arg, orig_param .. ":sc") |
|||
end |
|||
if obj_to_set[prefix] then |
|||
parse_err("Modifier '" .. prefix .. "' occurs twice, second occurrence " .. run[j]) |
|||
end |
end |
||
obj_to_set[prefix] = arg |
|||
else |
|||
parse_err("Unrecognized prefix '" .. prefix .. "' in modifier " .. run[j]) |
|||
end |
end |
||
end |
end |
||
item.qq = qqs |
|||
else |
|||
termobj.term.term = item |
|||
end |
end |
||
-- If a separate language code was given for the term, display the language name as a right qualifier. |
|||
-- Otherwise it may not be obvious that the term is in a separate language (e.g. if the main language is 'zh' |
|||
-- and the term language is a Chinese lect such as Min Nan). But don't do this for Translingual terms, which |
|||
-- are often added to the list of English and other-language terms. |
|||
if termlangcode and termlangcode ~= langcode and termlangcode ~= "mul" then |
|||
termobj.qq = {termlang:getCanonicalName(), termobj.qq} |
|||
end |
|||
local omitted = false |
local omitted = false |
||
for _, omitted_item in ipairs(args.omit) do |
for _, omitted_item in ipairs(args.omit) do |
||
if omitted_item == |
if omitted_item == item.term then |
||
omitted = true |
omitted = true |
||
break |
break |
||
Baris 285: | Baris 263: | ||
if omitted then |
if omitted then |
||
-- signal create_list() to omit this item |
-- signal create_list() to omit this item |
||
items[i] = false |
|||
else |
|||
args[first_content_param][i] = termobj |
|||
end |
end |
||
end |
end |
||
local ret = export.create_list { |
local ret = export.create_list { |
||
column_count = iargs.columns or args[columns_param], |
|||
content = |
content = items, |
||
alphabetize = sort, |
alphabetize = sort, |
||
header = args |
header = args.title, |
||
collapse = collapse, |
collapse = collapse, |
||
toggle_category = iargs |
toggle_category = iargs.toggle_category, |
||
-- columns-bg (in [[MediaWiki:Common.css]], [[MediaWiki:Mobile.css]]) provides the background color |
|||
class = iargs["class"], lang = lang, sc = sc, format_header = true } |
|||
class = (iargs.class and iargs.class .. " columns-bg" or "columns-bg"), |
|||
lang = lang, |
|||
sc = sc, |
|||
format_header = true |
|||
} |
|||
return deprecated and frame:expandTemplate{title = "check deprecated lang param usage", args = {ret, lang = args[lang_param]}} or ret |
return deprecated and frame:expandTemplate{title = "check deprecated lang param usage", args = {ret, lang = args[lang_param]}} or ret |
||
Baris 303: | Baris 285: | ||
function export.display(frame) |
function export.display(frame) |
||
if not is_substing() then |
|||
return export.display_from(frame.args, frame:getParent().args, frame) |
|||
return export.display_from(frame.args, frame:getParent().args, frame) |
|||
end |
|||
-- If substed, unsubst template with newlines between each term, redundant wikilinks removed, and remove duplicates + sort terms if sort is enabled. |
|||
local m_table = require("Module:table") |
|||
local m_template_parser = require("Module:template parser") |
|||
local parent = frame:getParent() |
|||
local elems = m_table.shallowCopy(parent.args) |
|||
local code = remove(elems, 1) |
|||
code = code and trim(code) |
|||
local lang = require("Module:languages").getByCode(code, 1) |
|||
local i = 1 |
|||
while true do |
|||
local elem = elems[i] |
|||
while elem do |
|||
elem = trim(elem, "%s") |
|||
if elem ~= "" then |
|||
break |
|||
end |
|||
remove(elems, i) |
|||
elem = elems[i] |
|||
end |
|||
if not elem then |
|||
break |
|||
elseif not ( -- Strip redundant wikilinks. |
|||
not match(elem, "^()%[%[") or |
|||
find(elem, "[[", 3, true) or |
|||
find(elem, "]]", 3, true) ~= #elem - 1 or |
|||
find(elem, "|", 3, true) |
|||
) then |
|||
elem = sub(elem, 3, -3) |
|||
elem = trim(elem, "%s") |
|||
end |
|||
elems[i] = elem .. "\n" |
|||
i = i + 1 |
|||
end |
|||
-- If sort is enabled, remove duplicates then sort elements. |
|||
if require("Module:yesno")(frame.args.sort) then |
|||
elems = m_table.removeDuplicates(elems) |
|||
require("Module:collation").sort(elems, lang) |
|||
end |
|||
-- Readd the langcode. |
|||
insert(elems, 1, code .. "\n") |
|||
-- TODO: Place non-numbered parameters after 1 and before 2. |
|||
local template = m_template_parser.getTemplateInvocationName(mw.title.new(parent:getTitle())) |
|||
return "{{" .. concat(m_template_parser.buildTemplate(template, elems), "|") .. "}}" |
|||
end |
end |
||
Revisi per 27 Desember 2024 04.19
Dokumentasi untuk modul ini dapat dibuat di Modul:columns/doc
local links_module = "Module:links"
local parameter_utilities_module = "Module:parameter utilities"
local parameters_module = "Module:parameters"
local pron_qualifier_module = "Module:pron qualifier"
local string_utilities_module = "Module:string utilities"
local m_str_utils = require(string_utilities_module)
local concat = table.concat
local html = mw.html.create
local is_substing = mw.isSubsting
local find = string.find
local insert = table.insert
local match = string.match
local remove = table.remove
local sub = string.sub
local trim = m_str_utils.trim
local u = m_str_utils.char
local export = {}
local function format_list_items(list, args)
local function term_already_linked(term)
-- FIXME: "<span" is an ugly hack to prevent double-linking of terms already run through {{l|...}}:
-- [[Thread:User talk:CodeCat/MewBot adding lang to column templates]]
return find(term, "<span")
end
for _, item in ipairs(args.content) do
if item == false then
-- omitted item; do nothing
else
local text
if type(item) == "table" then
text = item.term and term_already_linked(item.term) and item.term or
require(links_module).full_link(item)
-- We could use the "show qualifiers" flag to full_link() but not when term_already_linked().
if item.q and item.q[1] or item.qq and item.qq[1] or item.l and item.l[1] or item.ll and item.ll[1] or
item.refs and item.refs[1] then
text = require(pron_qualifier_module).format_qualifiers {
lang = item.lang or args.lang,
text = text,
q = item.q,
qq = item.qq,
l = item.l,
ll = item.ll,
refs = item.refs,
}
end
elseif args.lang and not term_already_linked(item) then
text = require(links_module).full_link {lang = args.lang, term = item, sc = args.sc}
else
text = item
end
list = list:node(html("li")
:wikitext(text)
)
end
end
return list
end
local function make_sortbase(item)
if item == false then
return "*" -- doesn't matter, will be omitted in format_list_items()
elseif type(item) == "table" then
return item.alt or item.term
end
return item
end
function export.create_list(args)
-- Fields in args that are used:
-- args.column_count, args.content, args.alphabetize, args.background_color,
-- args.collapse, args.toggle_category, args.class, args.lang
-- Check for required fields?
if type(args) ~= "table" then
error("expected table, got " .. type(args))
end
local class = args.class or "derivedterms"
local column_count = args.column_count or 1
local toggle_category = args.toggle_category or "derived terms"
local header = args.header
if header and args.format_header then
header = html("div")
:addClass("term-list-header")
:wikitext(header)
end
if args.alphabetize then
require("Module:collation").sort(args.content, args.lang, make_sortbase)
end
local list = html("ul")
list = format_list_items(list, args)
local output = html("div")
:addClass(class)
:addClass("term-list")
:addClass("ul-column-count")
:attr("data-column-count", column_count)
:css("background-color", args.background_color)
:node(list)
if args.collapse then
local nbsp = u(0xA0)
output = html("div")
:node(output)
:addClass("list-switcher")
:attr("data-toggle-category", toggle_category)
:node(html("div")
:addClass("list-switcher-element")
:attr("data-showtext", nbsp .. "show more ▼" .. nbsp)
:attr("data-hidetext", nbsp .. "show less ▲" .. nbsp)
:css("display", "none")
:wikitext(nbsp)
)
end
return tostring(header or "") .. tostring(output)
end
-- This function is for compatibility with earlier version of [[Module:columns]]
-- (now found in [[Module:columns/old]]).
function export.create_table(...)
-- Earlier arguments to create_table:
-- n_columns, content, alphabetize, bg, collapse, class, title, column_width, line_start, lang
local args = {}
args.column_count, args.content, args.alphabetize, args.background_color,
args.collapse, args.class, args.header, args.column_width,
args.line_start, args.lang = ...
args.format_header = true
return export.create_list(args)
end
function export.display_from(frame_args, parent_args, frame)
local boolean = {type = "boolean"}
local iparams = {
["class"] = true,
-- Default for auto-collapse. Overridable by template |collapse= param.
["collapse"] = boolean,
-- If specified, this specifies the number of columns, and no columns
-- parameter is available on the template. Otherwise, the columns
-- parameter is the first available numbered param after the language-code
-- parameter.
["columns"] = {type = "number"},
-- If specified, this specifies the language code, and no language-code
-- parameter is available on the template. Otherwise, the language-code
-- parameter can be specified as either |lang= or |1=.
["lang"] = {type = "language"},
-- Default for auto-sort. Overridable by template |sort= param.
["sort"] = boolean,
-- The following is accepted but currently ignored, per an extended discussion in
-- [[Wiktionary:Beer parlour/2018/November#Titles of morphological relations templates]].
["title"] = {default = ""},
["toggle_category"] = true,
}
local iargs = require(parameters_module).process(frame_args, iparams)
local compat = iargs.lang or parent_args.lang
local lang_param = compat and "lang" or 1
local columns_param, first_content_param
-- New-style #columns specification is through parameter n= so we can transition to the situation where
-- omitting it results in auto-determination. Old-style #columns specification is through the first numbered
-- parameter after the lang parameter.
if parent_args.n then
columns_param = "n"
first_content_param = compat and 1 or 2
else
columns_param = compat and 1 or 2
first_content_param = columns_param + (iargs.columns and 0 or 1)
end
local deprecated
local params = {
[lang_param] =
not iargs.lang and {required = true, type = "language", default = "und"} or nil,
[columns_param] = not iargs.columns and {required = true, type = "number", default = 2} or nil,
[first_content_param] = {list = true, allow_holes = true},
["title"] = {},
["collapse"] = boolean,
["sort"] = boolean,
["sc"] = {type = "script"},
["omit"] = {list = true}, -- used when calling from [[Module:saurus]] so the page displaying the synonyms/antonyms doesn't occur in the list
}
if lang_param == "lang" then
deprecated = true
end
local m_param_utils = require(parameter_utilities_module)
local param_mods = m_param_utils.construct_param_mods {
{default = true, require_index = true},
{group = "link"}, -- sc has separate_no_index = true; that's the only one
-- It makes no sense to have overall l=, ll=, q= or qq= params for columnar display.
{group = {"ref", "l", "q"}, require_index = true},
}
local items, args = m_param_utils.process_list_arguments {
params = params,
param_mods = param_mods,
raw_args = parent_args,
termarg = first_content_param,
parse_lang_prefix = true,
allow_multiple_lang_prefixes = true,
disallow_custom_separators = true,
track_module = "columns",
lang = iargs.lang or lang_param,
sc = "sc.default",
}
local lang = iargs.lang or args[lang_param]
local langcode = lang:getCode()
local sc = args.sc.default
local sort = iargs.sort
if args.sort ~= nil then
sort = args.sort
end
local collapse = iargs.collapse
if args.collapse ~= nil then
collapse = args.collapse
end
for i, item in ipairs(items) do
-- If a separate language code was given for the term, display the language name as a right qualifier.
-- Otherwise it may not be obvious that the term is in a separate language (e.g. if the main language is 'zh'
-- and the term language is a Chinese lect such as Min Nan). But don't do this for Translingual terms, which
-- are often added to the list of English and other-language terms.
if item.termlangs then
local qqs = {}
for _, termlang in ipairs(item.termlangs) do
local termlangcode = termlang:getCode()
if termlangcode ~= langcode and termlangcode ~= "mul" then
insert(qqs, termlang:getCanonicalName())
end
if item.qq then
for _, qq in ipairs(item.qq) do
insert(qqs, qq)
end
end
end
item.qq = qqs
end
local omitted = false
for _, omitted_item in ipairs(args.omit) do
if omitted_item == item.term then
omitted = true
break
end
end
if omitted then
-- signal create_list() to omit this item
items[i] = false
end
end
local ret = export.create_list {
column_count = iargs.columns or args[columns_param],
content = items,
alphabetize = sort,
header = args.title,
collapse = collapse,
toggle_category = iargs.toggle_category,
-- columns-bg (in [[MediaWiki:Common.css]], [[MediaWiki:Mobile.css]]) provides the background color
class = (iargs.class and iargs.class .. " columns-bg" or "columns-bg"),
lang = lang,
sc = sc,
format_header = true
}
return deprecated and frame:expandTemplate{title = "check deprecated lang param usage", args = {ret, lang = args[lang_param]}} or ret
end
function export.display(frame)
if not is_substing() then
return export.display_from(frame.args, frame:getParent().args, frame)
end
-- If substed, unsubst template with newlines between each term, redundant wikilinks removed, and remove duplicates + sort terms if sort is enabled.
local m_table = require("Module:table")
local m_template_parser = require("Module:template parser")
local parent = frame:getParent()
local elems = m_table.shallowCopy(parent.args)
local code = remove(elems, 1)
code = code and trim(code)
local lang = require("Module:languages").getByCode(code, 1)
local i = 1
while true do
local elem = elems[i]
while elem do
elem = trim(elem, "%s")
if elem ~= "" then
break
end
remove(elems, i)
elem = elems[i]
end
if not elem then
break
elseif not ( -- Strip redundant wikilinks.
not match(elem, "^()%[%[") or
find(elem, "[[", 3, true) or
find(elem, "]]", 3, true) ~= #elem - 1 or
find(elem, "|", 3, true)
) then
elem = sub(elem, 3, -3)
elem = trim(elem, "%s")
end
elems[i] = elem .. "\n"
i = i + 1
end
-- If sort is enabled, remove duplicates then sort elements.
if require("Module:yesno")(frame.args.sort) then
elems = m_table.removeDuplicates(elems)
require("Module:collation").sort(elems, lang)
end
-- Readd the langcode.
insert(elems, 1, code .. "\n")
-- TODO: Place non-numbered parameters after 1 and before 2.
local template = m_template_parser.getTemplateInvocationName(mw.title.new(parent:getTitle()))
return "{{" .. concat(m_template_parser.buildTemplate(template, elems), "|") .. "}}"
end
return export