跳转到内容

模組:Broader

维基百科,自由的百科全书

这是本页的一个历史版本,由Yinyue200留言 | 贡献2022年4月3日 (日) 13:25 建立内容为“--[[ -- This module produces a "For a broader coverage related to this topic" link. It implements -- the {{broader}} template. --]] local mHatlist = require('Module:Hatnote list') local mHatnote = require('Module:Hatnote') local mArguments -- lazily initialize local mTableTools --lazily initialize local p = {} local s = { --localizable strings broaderForm = '有关%s的更广泛信息, 请参见%s.', defaultTopic = '此主题' } function…”的新页面)编辑。这可能和当前版本存在着巨大的差异。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)

--[[
-- This module produces a "For a broader coverage related to this topic" link. It implements
-- the {{broader}} template.
--]]
 
local mHatlist = require('Module:Hatnote list')
local mHatnote = require('Module:Hatnote')
local mArguments -- lazily initialize
local mTableTools --lazily initialize

local p = {}

local s = { --localizable strings
	broaderForm = '有关%s的更广泛信息, 请参见%s.',
	defaultTopic = '此主题'
}

function p.broader(frame)
	mArguments = require('Module:Arguments')
	mTableTools = require('Module:TableTools')
	local originalArgs = mArguments.getArgs(frame, {parentOnly = true})
	local args = mTableTools.compressSparseArray(originalArgs)
	-- re-add non-numeric arguments omitted by compressSparseArray
	for _, name in pairs({'category', 'selfref', 'topic'}) do
		args[name] = originalArgs[name]
	end
	return p._broader(args)
end

function p._broader(args)
	if not args[1] then
		return mHatnote.makeWikitextError(
			'no page name specified',
			'Template:Broader#Errors',
			args.category
		)
	end
	local list = mHatlist.andList(args, true)
	local topic = args.topic or s.defaultTopic
	local text = string.format(s.broaderForm, topic, list)
	options = {selfref = args.selfref}
	return mHatnote._hatnote(text, options)
end

return p