模組:interproject
Guā-māu
可在模組:interproject/doc建立此模組的說明文件
local export = {}
local m_params = require("Module:parameters")
local function track(page)
require("Module:debug/track")("interproject/" .. page)
return true
end
local function process_links(linkdata, prefix, name, wmlang, sc)
prefix = prefix .. ":" .. (wmlang:getCode() == "nan" and "" or wmlang:getCode() .. ":")
local links = {}
local iplinks = {}
local m_links = require("Module:links")
local lang = wmlang:getWiktionaryLanguage()
local ipalt = name .. " " .. (wmlang:getCode() == "nan" and "" or "<sup>" .. wmlang:getCode() .. "</sup>")
for i, link in ipairs(linkdata) do
link.lang = lang
link.sc = sc
link.term = prefix .. link.term
link.tr = "-"
table.insert(iplinks, "<span class=\"interProject\">[[" .. link.term .. "|" .. ipalt .. "]]</span>")
table.insert(links, m_links.full_link(link, "bold"))
end
return links, iplinks
end
function export.wikipedia_box(frame)
local plain_param = {}
local params = {
[1] = plain_param,
[2] = plain_param,
["cat"] = plain_param,
["category"] = {alias_of = "cat"},
["i"] = {type = "boolean"},
["lang"] = {default = "nan"},
["mul"] = plain_param,
["mullabel"] = plain_param,
["mulcat"] = plain_param,
["mulcatlabel"] = plain_param,
["portal"] = plain_param,
["sc"] = plain_param,
}
local args = m_params.process(frame:getParent().args, params)
if args.mul or args.mullabel or args.mulcat or args.mulcatlabel then
track("wikipedia-box-mul")
end
local wmlang = require("Module:wikimedia languages").getByCodeWithFallback(args["lang"]) or error("Wikimedia language code \"" .. args["lang"] .. "\" bô-hāu.")
local sc = args["sc"] and require("Module:scripts").getByCode(args["sc"], "sc") or nil
local linkdata = {}
if args["cat"] then
table.insert(linkdata, {term = "Category:" .. args["cat"], alt = args[1] or args["cat"]})
elseif args["portal"] then
table.insert(linkdata, {term = "Portal:" .. args["portal"], alt = args[1] or args["portal"]})
else
local term = args[1] or mw.title.getCurrentTitle().text
table.insert(linkdata, {term = term, alt = args[2] or term})
end
if args["mul"] or args["mulcat"] then
if args["mulcat"] then
table.insert(linkdata, {term = "Category:" .. args["mulcat"], alt = args["mulcatlabel"] or args["mulcat"]})
else
table.insert(linkdata, {term = args["mul"], alt = args["mullabel"] or args["mul"]})
end
end
local links, iplinks = process_links(linkdata, "w", "Wikipedia", wmlang, sc)
if frame.args["slim"] then
return
"<div class=\"sister-wikipedia sister-project noprint floatright\" style=\"border: solid #aaa 1px; font-size: 90%; background: #f9f9f9; width: 250px; padding: 4px; text-align: left;\">" ..
"<div style=\"float: left;\">[[File:Wikipedia-logo.png|14px|none| ]]</div>" ..
"<div style=\"margin-left: 15px;\">" ..
"" ..
table.concat(links, " kah ") ..
"tī " ..
(wmlang:getCode() == "nan" and "" or wmlang:getCanonicalName()) ..
" Wikipeida téng-koân ê chu-liāu" ..
"</div>" ..
"</div>"
else
local linktype
if args["cat"] then
linktype = " chi̍t ê hun-lūi "
elseif args["mul"] then
linktype = " bûn-chiong "
elseif args["mulcat"] then
linktype = " hun-lūi "
elseif args["portal"] then
linktype = " chi̍t ê chú-tê "
else
linktype = " chi̍t phiⁿ bûn-chiong "
end
return
"<div class=\"sister-wikipedia sister-project noprint floatright\" style=\"border: 1px solid #aaa; font-size: 90%; background: #f9f9f9; width: 250px; padding: 4px; text-align: left;\">" ..
"<div style=\"float: left;\">[[File:Wikipedia-logo-v2.svg|44px|none|link=|alt=]]</div>" ..
"<div style=\"margin-left: 60px;\">" ..
wmlang:getCanonicalName() .. " [[Wikipedia]] ū" .. linktype .. "sī leh kóng:" ..
"<div style=\"margin-left: 10px;\">" .. table.concat(links, " kah ") .. "</div>" ..
"</div>" ..
--table.concat(iplinks) .. ((args[1] == mw.title.getCurrentTitle().text and not args[2]) and "[[Category:wikipedia with redundant first parameter]]" or "") ..
"</div>"
end
end
function export.projectlink(frame, compat)
local plain_param = {}
local required = {required = true}
local boolean = {type = "boolean"}
local iparams = {
["prefix"] = required,
["name"] = required,
["image"] = required,
["requirelang"] = boolean,
["compat"] = boolean,
}
local iargs = m_params.process(frame.args, iparams)
compat = compat or iargs.compat
local lang_required = iargs.requirelang or false
local lang_param = compat and "lang" or 1
local term_param = compat and 1 or 2
local alt_param = compat and 2 or 3
local params = {
[lang_param] = {required = lang_required},
[term_param] = plain_param,
[alt_param] = plain_param,
["i"] = boolean,
["nodot"] = plain_param,
["sc"] = plain_param,
}
local args = m_params.process(frame:getParent().args, params)
local wmlang = args[lang_param] or "nan"
wmlang = require("Module:wikimedia languages").getByCodeWithFallback(wmlang) or error("Wikimedia language code \"" .. wmlang .. "\" bô-hāu.")
local sc = args["sc"] and require("Module:scripts").getByCode(args["sc"], "sc") or nil
local term = args[term_param] or mw.title.getCurrentTitle().text
local linkdata = {term = term, alt = args[alt_param] or term}
if args["i"] then
linkdata.alt = "''" .. linkdata.alt .. "''"
end
local links, iplinks = process_links({linkdata}, iargs["prefix"], iargs["name"], wmlang, sc)
return
"[[Image:" .. iargs["image"] .. "|15px|link=" .. linkdata.term .. "]] " ..
table.concat(links, " kah ") ..
"Tī" ..
(wmlang:getCode() == "nan" and "" or "" .. wmlang:getCanonicalName() .. "") ..
"" .. iargs["name"] .. " téng-koân ê chu-liāu" .. (args["nodot"] and "" or ".") ..
table.concat(iplinks)
end
return export