Module:Variable arguments
Jump to navigation
Jump to search
This module is used to store functions for templates that take a variable number of arguments but do not use Module:Labelled list hatnote:
local p = {}
local mArguments = require("Module:Arguments")
local utils = require("Module:Utils")
local yesno = require("Module:Yesno")
function p.breadcrumb(frame)
local args = mArguments.getArgs(frame, {
parentOnly = true
})
local debugg = frame.args.debug_mode or args.debug_mode
local result = ""
local i = 0
local pname = ""
for k, v in pairs(args) do
pname = pname .. v
result = result .. (v == debugg and "" or string.format("[[%s|%s]] {{pipe}} ", pname, v))
i = i + 1
pname = pname .. "/"
end
result = result:sub(1, -11)
if result == nil or utils.trim(result) == "" then
result = "[[{{#titleparts: {{FULLPAGENAME}}|-1}}]]"
end
result = "<div class=\"mw-content-subtitle2\">\n"
.. "<div class=\"breadcrumb-article\">"
.. "<div class=\"subpages\">" .. string.format("< <bdi dir=\"ltr\">%s</bdi>", result) .. "</div>\n"
.. "</div></div>"
.. "{{#if: {{ARTICLESPACE}}||[[Category:Article subpages]]}}"
.. mw.getCurrentFrame():extensionTag("templatestyles", "", {
src = "Template:Breadcrumb/styles.css"
})
if yesno(debugg) == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return frame:preprocess(result)
end
function p.lua_banner(frame)
local args = mArguments.getArgs(frame, {
parentOnly = true
})
local debugg = frame.args.debug_mode or args.debug_mode
local fmt = "* [[Module: %s]]\n"
local namespace = string.lower(frame:preprocess("{{NAMESPACE}}"))
local result = ""
local i = 1
for k, v in pairs(args) do
result = result .. (v == debugg and "" or string.format(fmt, frame:preprocess(string.format("{{ucfirst:%s}}", v))))
i = i + 1
end
result = result:sub(1, -2)
if result == nil or utils.trim(result) == "" then
local rpn = frame:preprocess("{{ROOTPAGENAME}}")
result = string.format(fmt, rpn)
end
result = "{{sidebox\n| image = Lua-Logo.svg\n| image size = 30px\n| text = "
.. string.format("%s:\n%s\n",
(namespace == "module"
and "This module depends on the following other modules"
or "This template uses {{wlink|Lua|s=wp}}"),
result)
.. "}}"
if yesno(debugg) == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return frame:preprocess(result)
end
function p.nwr(frame)
local args = mArguments.getArgs(frame, {
parentOnly = true
})
local debugg = frame.args.debug_mode or args.debug_mode
local result = ""
local i = 0
for k, v in pairs(args) do
result = result .. (v == debugg and "" or
string.format("<span style=\"white-space: nowrap;\">%s</span>, ", utils.trim(v)))
i = i + 1
end
result = result:sub(1, -3)
if result == nil or utils.trim(result) == "" then
return ""
end
if yesno(debugg) == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return frame:preprocess(result)
end
function p.wikipedia(frame)
local args = mArguments.getArgs(frame, {
parentOnly = true
})
local debugg = frame.args.debug_mode or args.debug_mode
local fmt = "<div>'''{{wlink|%s}}'''</div>\n"
local result = ""
local i = 0
for k, v in pairs(args) do
v = string.gsub(v, "^%s*(.-)%s*$", "%1")
if string.lower(v) ~= "false" and string.lower(v) ~= "true" then
result = result .. (v == debugg and "" or string.format(fmt, v))
end
i = i + 1
end
if result == nil or utils.trim(result) == "" then
local arpn = frame:preprocess("{{ARTICLEROOTPAGENAME}}")
result = string.format(fmt, arpn)
end
result = "<div class=\"wikibanner\">\n"
.. "<div class=\"wikibanner-image\">[[File:Wikipedia-logo.png|44px|none|link=|alt=]]</div>\n"
.. "<div class=\"wikibanner-text\">"
.. string.format("English [[Wikipedia:Main Page|Wikipedia]] has %s on:\n%s</div>", (i > 1 and "articles" or "an article"), result)
.. "{{clear}}</div>"
.. mw.getCurrentFrame():extensionTag("templatestyles", "", {
src = "Template:Wikipedia/styles.css"
})
if yesno(debugg) == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return frame:preprocess(result)
end
return p