跳转到内容

模块:Category see also if exists

勤求古训,博采众方
WikiBot留言 | 贡献2026年8月1日 (六) 11:14的版本 (拉取适配 zhwiki hatnote 体系模块)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
--[[ v1.0
]]
local p = {}

function doesCatExist(catname)
	local catPage = mw.title.new( catname, "Category" )
	if catPage == nil then
		return false
	end
	if catPage.exists then
		return true
	end
	return false
end


function p.main(frame)
	local rawcats = {}
	local nvalid = 0
	for i, v in ipairs(mw.getCurrentFrame():getParent().args) do
		if (v ~= nil) then
			local thisArg = mw.text.trim(v)
			thisArg = mw.ustring.gsub(thisArg, "^[Cc]ategory:%s*", "", 1)
			if (thisArg ~= "") then
				if ( doesCatExist(thisArg)) then
					table.insert(rawcats, "Category:" .. thisArg)
					nvalid = nvalid + 1
				end
			end
		end
	end
	if (nvalid == 0) then
		return ""
	end
	local mLabelledList = require('Module:Labelled list hatnote')
	local pages = mLabelledList._labelledList(rawcats, "参见", "")
	return pages
end

return p