Module:See also if exists/sandbox

From blackwiki
< Module:See also if exists
Revision as of 14:28, 20 February 2019 by blackwiki>Pppery
Jump to navigation Jump to search

Documentation for this module may be created at Module:See also if exists/sandbox/doc

--[[ v1.0
]]
local p = {}

function doesPageExist(thisPage, ns)
	local thisPage = mw.title.new( thisPage ,ns)
	if thisPage == nil then
		return false
	end
	if thisPage.exists then
		return true
	end
	return false
end


function p.main(frame)
	local rawpages = {}
	local nvalid = 0
	local namespace = frame.args.ns
	for i, v in ipairs(frame:getParent().args) do
		if (v ~= nil) then
			local thisArg = mw.text.trim(v)
			if (thisArg ~= "") then
				local title = mw.title.new(thisArg, namespace)
				if title ~= nil and title.exists then
					table.insert(rawpages, title.fullText)
					nvalid = nvalid + 1
				end
			end
		end
	end
	if (nvalid == 0) then
		return ""
	end
	local mLabelledList = require('Module:Labelled list hatnote')
	local pages = mLabelledList._labelledList(rawpages, "See also", "")
	return pages
end

return p