Jump to content

Module:Category more if exists

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by BrownHairedGirl (talk | contribs) at 14:43, 3 October 2020 (test). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

--[[ v1.0
]]
local p = {}
local yesno = require("Module:yesno")

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
		if yesno(frame.args.warning) then
			if namespace:sub(-1) == "y" then
				namespace = namespace:sub(0, -2) .. "ie"
			elseif namespace == nil then
				namespace = "page"
			end
			mw.addWarning(string.format("'''[[%s]] — no output, because none of the %ss currently exist.'''",
				frame:getParent():getTitle(),namespace))
		end
		return ""
	end
	local mLabelledList = require('Module:Labelled list hatnote')
	local pages = mLabelledList._labelledList(rawpages, {"For more information, see ", "For more information, see "}	)
	return pages
end

return p