跳转到内容

模組:Category see also if exists

被永久保护的模块
维基百科,自由的百科全书

这是本页的一个历史版本,由Yangfl留言 | 贡献2018年10月11日 (四) 13:20 建立内容为“--v1.0 local p = {} function doesCatExist(catname) local catPage = mw.title.new( catname, "Category" ) if catPage == nil then return fals…”的新页面)编辑。这可能和当前版本存在着巨大的差异。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)
--[[ 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