Module:Variable arguments: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
ArrowHead294 (talk | contribs)
mNo edit summary
ArrowHead294 (talk | contribs)
mNo edit summary
 
(145 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local p = {}
local mArguments = require("Module:Arguments")
local mArguments = require("Module:Arguments")
local p = {}
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\">"
.. "<div class=\"breadcrumb-article\">"
.. string.format("<div class=\"subpages\">&lt; <bdi dir=\"ltr\">%s</bdi></div>", result)
.. "</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.ulist(frame)
function p.lua_banner(frame)
    local args = mArguments.getArgs(frame, {
local args = mArguments.getArgs(frame, {
     parentOnly = true
     parentOnly = true
     })
     })
local out_str = "<ul>\n"
    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
for k, v in pairs(args) do
out_str = out_str .. "<li>" .. v .. "</li>\n"
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
end
out_str = out_str .. "</ul>"
return out_str
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
end


function p.olist(frame)
function p.nwr(frame)
    local args = mArguments.getArgs(frame, {
local args = mArguments.getArgs(frame, {
     parentOnly = true
     parentOnly = true
     })
     })
local out_str = "<ol>\n"
    local debugg = frame.args.debug_mode or args.debug_mode
local result = ""
local i = 0
for k, v in pairs(args) do
for k, v in pairs(args) do
out_str = out_str .. "<li>" .. v .. "</li>\n"
result = result .. (v == debugg and "" or
string.format("<span style=\"white-space: nowrap;\">%s</span>, ", utils.trim(v)))
i = i + 1
end
end
out_str = out_str .. "</ol>"
return out_str
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
end


function p.modlink(frame)
function p.wikipedia(frame)
    local args = mArguments.getArgs(frame, {
local args = mArguments.getArgs(frame, {
     parentOnly = true
     parentOnly = true
     })
     })
local out_str = ""
    local debugg = frame.args.debug_mode or args.debug_mode
    local fmt = "<div>'''{{wlink|%s}}'''</div>\n"
local result = ""
local i = 0
local i = 0
for k, v in pairs(args) do
for k, v in pairs(args) do
out_str = out_str .. "[[Module:" .. v .. "]]" .. ", "
v = string.gsub(v, "^%s*(.-)%s*$", "%1")
i = k
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
end
out_str = out_str:sub(1, -3)
.. " &ndash; The "
return frame:preprocess(result)
.. string.gsub("module that implement", "()", {[((i > 1) and {7} or {22})[1]] = "s"})
.. " the functionality."
return out_str
end
end


return p
return p

Latest revision as of 17:28, 25 November 2025

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 (4)
Line Function Params
7 breadcrumb (invokable) (frame)
46 lua_banner (invokable) (frame)
83 nwr (invokable) (frame)
110 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\">"
		.. "<div class=\"breadcrumb-article\">"
		.. string.format("<div class=\"subpages\">&lt; <bdi dir=\"ltr\">%s</bdi></div>", result)
		.. "</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