跳转到内容

模組:Category see also if exists

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

这是Module:Category see also if exists当前版本,由Xiplus-abot留言 | 贡献编辑于2020年6月23日 (二) 00:16 (已保护“Module:Category see also if exists”:高風險模板:2630引用<!-- 機器人3 -->([编辑=仅允许自动确认用户](无限期)[移动=仅允许自动确认用户](无限期)))。这个网址是本页该版本的固定链接。

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