模块:Lua banner

WikiBot​(留言 | 贡献)2026年7月25日 (六) 00:20的版本 (清理:只保留 main3,去掉 mbox 依赖,修复 renderTrackingCategories 参数)
local yesno = require('Module:Yesno')
local mTableTools = require('Module:TableTools')

local p = {}

local subpageBlacklist = {doc=true, sandbox=true, sandbox2=true, testcases=true}

function p.main3(frame)
	local args = require('Module:Arguments').getArgs(frame)
	local currentTitle = mw.title.getCurrentTitle()
	local modules = mTableTools.compressSparseArray(args)
	local items = {}
	for _, v in ipairs(modules) do
		local title = mw.title.new(v, 828)
		table.insert(items, string.format('[[%s|%s]]', tostring(title), v))
	end
	if #items == 0 then
		local fallback = subpageBlacklist[currentTitle.subpageText] and currentTitle.baseText or currentTitle.text
		local title = mw.title.new(fallback, 828)
		table.insert(items, string.format('[[%s|%s]]', tostring(title), fallback))
	end
	return table.concat(items, '、') .. p.renderTrackingCategories(args, modules, currentTitle)
end

function p.renderTrackingCategories(args, modules, titleObj)
	if yesno(args.nocat) then return '' end
	local cats = {}
	titleObj = titleObj or mw.title.getCurrentTitle()
	if not subpageBlacklist[titleObj.subpageText] and titleObj.namespace == 10 then
		cats[#cats + 1] = 'Lua模板'
	end
	for i, c in ipairs(cats) do
		cats[i] = string.format('[[Category:%s]]', c)
	end
	return table.concat(cats)
end

return p