ماژول:Category see also if exists
بو ماژول اوچون بلگهلر ماژول: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
mw.addWarning("'''[[Template:Category see also if exists]] — no output, because none of the categories currently exist.'''")
return ""
end
local mLabelledList = require('Module:Labelled list hatnote')
local pages = mLabelledList._labelledList(rawcats, "See also", "")
return pages
end
return p