Jump to content

Module:See also if exists/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Pppery (talk | contribs) at 05:11, 20 February 2019. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
--[[ 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(mw.getCurrentFrame():getParent().args) do
		if (v ~= nil) then
			local thisArg = mw.text.trim(v)
			if (thisArg ~= "") then
				if ( doesPageExist(thisArg, namespace)) then
					if namespace then
						thisArg = namespace .. ":" .. thisArg
					end
					table.insert(rawpages, 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(rawpages, "See also", "")
	return pages
end

return p