跳转到内容

模組:Main/2

维基百科,自由的百科全书
--[[
-- This module produces a link to a main article or articles. It implements the
-- template {{main}}.
-- 
-- If the module is used in category or category talk space, it produces "The
-- main article for this category is xxx". Otherwise, it produces
-- "Main article: xxx".
--]]

local mHatnote = require('Module:Hatnote')
local mTableTools -- lazily initialise
local mArguments -- lazily initialise
local mType

local p = {}

function p.main(frame)
	mTableTools = require('Module:TableTools')
	mArguments = require('Module:Arguments')
	local template_type=mArguments.getArgs(frame, {frameOnly = true})["type"]
	mType =require("Module:Main/"..template_type)
	
	local args = mArguments.getArgs(frame, {parentOnly = true})
	local pages = {}
	--模板版的限制
	local limit =mType.limit()
	local islimit=false
	local limittext =mType.limitWarnString(frame)
	--模板版的限制
	for k, v in pairs(args) do
		if type(k) == 'number' then
			if k > limit and limit~=-1 then 
				islimit=true 
				break 
			else	
				local display = args['l' .. tostring(k)]
				local page = {v, display}
				pages[k] = page
			end
		end
	end
	pages = mTableTools.compressSparseArray(pages)
	local options = {
		selfref = args.selfref
	}
	return p._main(frame,options, unpack(pages)) + ((islimit and limittext) or "")
end

function p._main(frame,options, ...)
	local text = mType.build(frame,...)

	-- Process the options and pass the text to the _rellink function in
	-- [[Module:Hatnote]].
	options = options or {}
	local hnOptions = {
		extraclasses = mType.extraclasses(), --追加noprint的css类
		selfref = options.selfref
	}
	return mHatnote._hatnote(text, hnOptions)
end

return p