Module:See also if exists

From blackwiki
Revision as of 21:11, 30 October 2018 by blackwiki>BrownHairedGirl (convert)
Jump to navigation Jump to search

{{Module rating }}

Usage

Used by Template:see also if exists and Template:Category see also if exists.

{{#invoke:See also if exists| main}}


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

function doesPageExist(thisPage)
	local thisPage = mw.title.new( thisPage )
	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
	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)) then
					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