跳转到内容

模組:Category see also if exists

被永久保护的模块
维基百科,自由的百科全书
--[[ 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