Module:Variable arguments

Revision as of 11:54, 25 May 2025 by ArrowHead294 (talk | contribs)
Module documentation[view] [edit] [history] [purge]
This module should not be invoked directly; use its corresponding templates instead.

This module is used to store functions for templates that take a variable number of arguments but do not use Module:Labelled list hatnote:

Introspection summary for Module:Variable arguments 
Functions provided (5)
Line Function Params
7 breadcrumb (invokable) (frame)
38 lua_banner (invokable) (frame)
77 nwr (invokable) (frame)
100 ts_banner (invokable) (frame)
136 wikipedia (invokable) (frame)
Lua modules required (3)
Variable Module Functions used
mArguments Module:Arguments getArgs
utils Module:Utils trim
yesno Module:Yesno yesno

No function descriptions were provided. The Lua code may have further information.


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("&lt; <bdi dir=\"ltr\">%s</bdi>", result) .. "</div>\n"
		.. "</div></div>"
		.. "{{#if: {{ARTICLESPACE}}||[[Category:Article subpages]]}}"
	return frame:preprocess(yesno(debugg) == true and "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>" or 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 = 0
	
	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 = "<div class=\"mbox-lua\" "
		.. string.format("style=\"width: %ipx;\">\n", (namespace == "module" and 272 or 238))
		.. "{|\n"
		.. "|-\n"
		.. "| <span style=\"line-height: 110%; display: inline-block; "
		.. "margin: 0.125em 0em 0.125em 0.792em;\">[[File:Lua-Logo.svg|30px]]</span>"
		.. " || <span style=\"display: inline-block; font-size: 0.88em; "
		.. "line-height: 110%; padding: 0.22em 0.22em 0.22em 0.792em;\">"
		.. string.format("%s:\n%s</span>\n",
			(namespace == "module"
				and "This module depends on the following other modules"
				or "This template uses [[wikipedia:wp:Lua|Lua]]"),
			result)
		.. "|}\n</div>"
	return frame:preprocess(yesno(debugg) == true and "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>" or 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
		result = ""
	end
	
	return frame:preprocess(yesno(debugg) == true and "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>" or result)
end

function p.ts_banner(frame)
	local args = mArguments.getArgs(frame, {
    	parentOnly = true
    })
    local debugg = frame.args.debug_mode or args.debug_mode
    local fmt = "* [[%s]]\n"
    local namespace = string.lower(frame:preprocess("{{NAMESPACE}}"))
	local result = ""
	local i = 0
	
	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 arpn_s = frame:preprocess("{{ARTICLEROOTPAGENAME}}/styles.css")
		result = string.format(fmt, arpn_s)
	end
	
	result = "<div class=\"mbox-lua\" "
		.. string.format("style=\"width: %ipx;\">\n", (namespace == "module" and 272 or 238))
		.. "{|\n"
		.. "|-\n"
		.. "| <span style=\"line-height: 110%; display: inline-block; "
		.. "margin: 0.125em 0em 0.125em 0.792em;\">[[File:Farm-Fresh_css_add.svg|32px]]</span>"
		.. " || <span style=\"display: inline-block; font-size: 0.88em; "
		.. "line-height: 110%; padding: 0.22em 0.22em 0.22em 0.792em;\">"
		.. string.format("This %s uses [[mw:extension:TemplateStyles|TemplateStyles]]:\n%s</span>\n",
			namespace, result)
		.. "|}\n</div>"
	return frame:preprocess(yesno(debugg) == true and "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>" or 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 style=\"background: #f9f9f9; border: 1px solid #aaa; clear: right; float: right; "
		.. "font-size: 90%; width: 300px; margin: 0 0 4px 4px; padding: 4px 4px 4px 4px; text-align: left;\">\n"
	    .. "<div style=\"float: left;\">[[File:Wikipedia-logo.png|44px|none|link=|alt=]]</div>\n"
	    .. "<div style=\"margin-left: 60px;\">"
	    .. string.format("English [[Wikipedia:Main Page|Wikipedia]] has %s on:\n%s</div>", (i > 1 and "articles" or "an article"), result)
	    .. "{{clear}}</div>"
	return frame:preprocess(yesno(debugg) == true and "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>" or result)
end

return p