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
Line 33: Line 33:
.. "</div></div>"
.. "</div></div>"
.. "{{#if: {{ARTICLESPACE}}||[[Category:Article subpages]]}}"
.. "{{#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=\"sidebox\" "
.. string.format("style=\"width: %ipx;\">\n", (namespace == "module" and 272 or 238))
.. "{|\n"
.. "|-\n"
.. "| <span class=\"sidebox-image\">[[File:Lua-Logo.svg|30px]]</span>"
.. " || <span class=\"sidebox-text\">"
.. 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>"
.. mw.getCurrentFrame():extensionTag("templatestyles", "", {
src = "Module:Variable arguments/styles.css"
})
return frame:preprocess(yesno(debugg) == true and "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>" or result)
return frame:preprocess(yesno(debugg) == true and "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>" or result)
end
end
Line 99: Line 59:
end
end


function p.ts_banner(frame)
function p.side_banner(frame)
local args = mArguments.getArgs(frame, {
local args = mArguments.getArgs(frame, {
     parentOnly = true
     parentOnly = true
     })
     })
     local debugg = frame.args.debug_mode or args.debug_mode
     local debugg = frame.args.debug_mode or args.debug_mode
     local fmt = "* [[%s]]\n"
    local header = frame.args.header or args.header
    local imgname = frame.args.image or args.image
    local imgsize = frame.args.image_size or args.image_size
    local ns_local = frame.args.ns or args.ns
     local fmt = "* [[%s%s]]\n"
     local namespace = string.lower(frame:preprocess("{{NAMESPACE}}"))
     local namespace = string.lower(frame:preprocess("{{NAMESPACE}}"))
local result = ""
local result = ""
Line 110: Line 74:
for k, v in pairs(args) do
for k, v in pairs(args) do
result = result .. (v == debugg and "" or string.format(fmt, frame:preprocess(string.format("{{ucfirst:%s}}", v))))
result = result .. (v == debugg and "" or
string.format(fmt, ns_local, frame:preprocess(string.format("{{ucfirst:%s}}", v))))
i = i + 1
i = i + 1
end
end
Line 117: Line 82:
if result == nil or utils.trim(result) == "" then
if result == nil or utils.trim(result) == "" then
local arpn_s = frame:preprocess("{{ARTICLEROOTPAGENAME}}/styles.css")
local arpn_s = frame:preprocess("{{ARTICLEROOTPAGENAME}}")
result = string.format(fmt, arpn_s)
result = string.format(fmt, ns_local, arpn_s)
end
end
result = "<div class=\"sidebox\" "
result = "<div class=\"sidebox\" "
.. string.format("style=\"width: %ipx;\">\n", (namespace == "module" and 272 or 238))
.. string.format("style=\"width: %ipx;\">\n", (namespace == "Module" and 272 or 238))
.. "{|\n"
.. "{|\n"
.. "|-\n"
.. "|-\n"
.. "| <span class=\"sidebox-image\">[[File:Farm-Fresh_css_add.svg|32px]]</span>"
.. string.format("| <span class=\"sidebox-image\">[[File:%s|%s]]</span>", imgname, imgsize)
.. " || <span class=\"sidebox-text\">"
.. " || <span class=\"sidebox-text\">"
.. string.format("This %s uses [[mw:extension:TemplateStyles|TemplateStyles]]:\n%s</span>\n",
.. string.format("%s:\n%s</span>\n",
namespace, result)
header, result)
.. "|}\n</div>"
.. "|}\n</div>"
.. mw.getCurrentFrame():extensionTag("templatestyles", "", {
.. mw.getCurrentFrame():extensionTag("templatestyles", "", {

Revision as of 12:14, 25 May 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)
38 nwr (invokable) (frame)
61 side_banner (invokable) (frame)
103 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.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.side_banner(frame)
	local args = mArguments.getArgs(frame, {
    	parentOnly = true
    })
    local debugg = frame.args.debug_mode or args.debug_mode
    local header = frame.args.header or args.header
    local imgname = frame.args.image or args.image
    local imgsize = frame.args.image_size or args.image_size
    local ns_local = frame.args.ns or args.ns
    local fmt = "* [[%s%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, ns_local, 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}}")
		result = string.format(fmt, ns_local, arpn_s)
	end
	
	result = "<div class=\"sidebox\" "
		.. string.format("style=\"width: %ipx;\">\n", (namespace == "Module" and 272 or 238))
		.. "{|\n"
		.. "|-\n"
		.. string.format("| <span class=\"sidebox-image\">[[File:%s|%s]]</span>", imgname, imgsize)
		.. " || <span class=\"sidebox-text\">"
		.. string.format("%s:\n%s</span>\n",
			header, result)
		.. "|}\n</div>"
		.. mw.getCurrentFrame():extensionTag("templatestyles", "", {
			src = "Module:Variable arguments/styles.css"
		})
	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