Module:usex/templates: Difference between revisions
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
local export = {} | local export = {} | ||
local | local table_module = "Module:table" | ||
local usex_module = "Module:usex" | |||
local yesno_module = "Module:yesno" | |||
local insert = table.insert | |||
local rfind = mw.ustring.find | |||
local rsplit = mw.text.split | local rsplit = mw.text.split | ||
function export.usex_t(frame) | function export.usex_t(frame) | ||
local | local boolean = {type = "boolean"} | ||
[1] = {required = true}, | local list = {list = true} | ||
[2] = {}, | local language = {type = "language"} | ||
[ | local script = {type = "script"} | ||
-- Invocation arguments (passed in the template #invoke call). | |||
local iargs = require("Module:parameters").process(frame.args, { | |||
["quote"] = true, | |||
["inline"] = true, | |||
["nocat"] = boolean, | |||
["class"] = true, | |||
}) | |||
local parent_args = frame:getParent().args | |||
-- Template (parent) arguments. | |||
local args = require("Module:parameters").process(parent_args, { | |||
-- Usex/quotation text parameters | |||
[1] = {required = true, type = "language"}, | |||
[2] = true, | |||
["termlang"] = language, | |||
["tr"] = true, | |||
["transliteration"] = {alias_of = "tr", deprecated = true}, | |||
["ts"] = true, | |||
["transcription"] = {alias_of = "ts", deprecated = true}, | |||
["sc"] = script, | |||
["norm"] = true, | |||
["normalization"] = {alias_of = "norm", deprecated = true}, | |||
["normsc"] = script, | |||
["subst"] = true, | |||
["q"] = list, | |||
["qualifier"] = {alias_of = "q", list = false, deprecated = true}, | |||
["qq"] = list, | |||
["ref"] = true, | |||
-- Usex/quotation audio parameters, | |||
[" | ["audio"] = true, | ||
-- Translation of usex text | |||
[ | [3] = true, | ||
["t"] = {alias_of = 3}, | ["t"] = {alias_of = 3}, | ||
["translation"] = {alias_of = 3}, | ["translation"] = {alias_of = 3, deprecated = true}, | ||
[" | ["lit"] = true, | ||
[" | |||
[" | -- Original text, if the usex/quotation is a translation | ||
[" | ["orig"] = true, | ||
[" | ["origlang"] = language, | ||
[" | ["origtr"] = true, | ||
[" | ["origts"] = true, | ||
["origsc"] = script, | |||
["orignorm"] = true, | |||
["orignormsc"] = script, | |||
["origsubst"] = true, | |||
["origq"] = list, | |||
["origqq"] = list, | |||
["origref"] = true, | |||
-- Citation-related parameters; for anything more complex, usex {{quote-*}} | |||
["source"] = true, | |||
["footer"] = true, | |||
-- Formatting parameters | |||
["inline"] = true, | |||
["brackets"] = boolean, | |||
-- Categorization parameters | |||
["nocat"] = boolean, | |||
["sort"] = true, | |||
}) | |||
local lang = args[1] | |||
local sc = args.sc | |||
local normsc = args.normsc | |||
if normsc and not args.norm then | |||
error("Cannot specify normsc= without norm=") | |||
end | end | ||
local termlang = args.termlang | |||
if termlang then | |||
local | insert(args.qq, 1, "in " .. lang:getCanonicalName()) | ||
end | end | ||
if | |||
local origlang, origsc, orignormsc | |||
if args.orig then | |||
origlang = args.origlang | |||
insert(args.origqq, 1, "in " .. origlang:getCanonicalName()) | |||
origsc = args.origsc | |||
orignormsc = args.orignormsc | |||
if orignormsc and not args.orignorm then | |||
error("Cannot specify orignormsc= without orignorm=") | |||
end | |||
else | else | ||
for _, noparam in ipairs { "origlang", "origtr", "origts", "origsc", "orignorm", "orignormsc", "origsubst", | |||
for | "origref" } do | ||
if args[noparam] then | |||
error(("Cannot specify %s= without orig="):format(noparam)) | |||
end | end | ||
end | end | ||
if #args.origq > 0 then | |||
error("Cannot specify origq= without orig=") | |||
end | |||
if #args.origqq > 0 then | |||
error("Cannot specify origqq= without orig=") | |||
end | |||
end | |||
local inline = args.inline or iargs.inline | |||
if inline ~= "auto" then | |||
inline = require(yesno_module)(inline) | |||
end | end | ||
-- | local data = { | ||
lang = lang, | |||
termlang = termlang, | |||
return | sc = sc, | ||
normsc = normsc, | |||
usex = args[2], | |||
translation = args[3], | |||
transliteration = args.tr, | |||
transcription = args.ts, | |||
normalization = args.norm, | |||
inline = inline, | |||
ref = args.ref, | |||
quote = iargs.quote, | |||
lit = args.lit, | |||
subst = args.subst, | |||
-- FIXME, change to left and right qualifiers | |||
qq = #args.qq > 0 and args.qq or args.q, | |||
audio = args.audio, | |||
source = args.source, | |||
footer = args.footer, | |||
nocat = args.nocat or iargs.nocat, | |||
brackets = args.brackets, | |||
sortkey = args.sort, | |||
class = iargs.class, | |||
-- Original text, if the usex/quotation is a translation | |||
orig = args.orig, | |||
origlang = origlang, | |||
origtr = args.origtr, | |||
origts = args.origts, | |||
origsc = origsc, | |||
orignorm = args.orignorm, | |||
orignormsc = orignormsc, | |||
origsubst = args.origsubst, | |||
origq = args.origq, | |||
origqq = args.origqq, | |||
origref = args.origref, | |||
} | |||
return require(usex_module).format_usex(data) | |||
end | end | ||
Latest revision as of 12:49, 24 September 2025
Documentation for this module may be created at Module:usex/templates/doc
local export = {}
local table_module = "Module:table"
local usex_module = "Module:usex"
local yesno_module = "Module:yesno"
local insert = table.insert
local rfind = mw.ustring.find
local rsplit = mw.text.split
function export.usex_t(frame)
local boolean = {type = "boolean"}
local list = {list = true}
local language = {type = "language"}
local script = {type = "script"}
-- Invocation arguments (passed in the template #invoke call).
local iargs = require("Module:parameters").process(frame.args, {
["quote"] = true,
["inline"] = true,
["nocat"] = boolean,
["class"] = true,
})
local parent_args = frame:getParent().args
-- Template (parent) arguments.
local args = require("Module:parameters").process(parent_args, {
-- Usex/quotation text parameters
[1] = {required = true, type = "language"},
[2] = true,
["termlang"] = language,
["tr"] = true,
["transliteration"] = {alias_of = "tr", deprecated = true},
["ts"] = true,
["transcription"] = {alias_of = "ts", deprecated = true},
["sc"] = script,
["norm"] = true,
["normalization"] = {alias_of = "norm", deprecated = true},
["normsc"] = script,
["subst"] = true,
["q"] = list,
["qualifier"] = {alias_of = "q", list = false, deprecated = true},
["qq"] = list,
["ref"] = true,
-- Usex/quotation audio parameters,
["audio"] = true,
-- Translation of usex text
[3] = true,
["t"] = {alias_of = 3},
["translation"] = {alias_of = 3, deprecated = true},
["lit"] = true,
-- Original text, if the usex/quotation is a translation
["orig"] = true,
["origlang"] = language,
["origtr"] = true,
["origts"] = true,
["origsc"] = script,
["orignorm"] = true,
["orignormsc"] = script,
["origsubst"] = true,
["origq"] = list,
["origqq"] = list,
["origref"] = true,
-- Citation-related parameters; for anything more complex, usex {{quote-*}}
["source"] = true,
["footer"] = true,
-- Formatting parameters
["inline"] = true,
["brackets"] = boolean,
-- Categorization parameters
["nocat"] = boolean,
["sort"] = true,
})
local lang = args[1]
local sc = args.sc
local normsc = args.normsc
if normsc and not args.norm then
error("Cannot specify normsc= without norm=")
end
local termlang = args.termlang
if termlang then
insert(args.qq, 1, "in " .. lang:getCanonicalName())
end
local origlang, origsc, orignormsc
if args.orig then
origlang = args.origlang
insert(args.origqq, 1, "in " .. origlang:getCanonicalName())
origsc = args.origsc
orignormsc = args.orignormsc
if orignormsc and not args.orignorm then
error("Cannot specify orignormsc= without orignorm=")
end
else
for _, noparam in ipairs { "origlang", "origtr", "origts", "origsc", "orignorm", "orignormsc", "origsubst",
"origref" } do
if args[noparam] then
error(("Cannot specify %s= without orig="):format(noparam))
end
end
if #args.origq > 0 then
error("Cannot specify origq= without orig=")
end
if #args.origqq > 0 then
error("Cannot specify origqq= without orig=")
end
end
local inline = args.inline or iargs.inline
if inline ~= "auto" then
inline = require(yesno_module)(inline)
end
local data = {
lang = lang,
termlang = termlang,
sc = sc,
normsc = normsc,
usex = args[2],
translation = args[3],
transliteration = args.tr,
transcription = args.ts,
normalization = args.norm,
inline = inline,
ref = args.ref,
quote = iargs.quote,
lit = args.lit,
subst = args.subst,
-- FIXME, change to left and right qualifiers
qq = #args.qq > 0 and args.qq or args.q,
audio = args.audio,
source = args.source,
footer = args.footer,
nocat = args.nocat or iargs.nocat,
brackets = args.brackets,
sortkey = args.sort,
class = iargs.class,
-- Original text, if the usex/quotation is a translation
orig = args.orig,
origlang = origlang,
origtr = args.origtr,
origts = args.origts,
origsc = origsc,
orignorm = args.orignorm,
orignormsc = orignormsc,
origsubst = args.origsubst,
origq = args.origq,
origqq = args.origqq,
origref = args.origref,
}
return require(usex_module).format_usex(data)
end
local ignore_prefixes = {"User:", "Talk:",
"Wiktionary:Beer parlour", "Wiktionary:Translation requests",
"Wiktionary:Grease pit", "Wiktionary:Etymology scriptorium",
"Wiktionary:Information desk", "Wiktionary:Tea room",
"Wiktionary:Requests for", "Wiktionary:Votes"
}
function export.page_should_be_ignored(page)
-- Ignore user pages, talk pages and certain Wiktionary pages
for _, ip in ipairs(ignore_prefixes) do
if rfind(page, "^" .. ip) then
return true
end
end
if rfind(page, " talk:") then
return true
end
return false
end
function export.page_should_be_ignored_t(frame)
return export.page_should_be_ignored(frame.args[1]) and "true" or ""
end
return export