Jump to content

Module:Sandbox/Grufo/PageProps

From Wikipedia, the free encyclopedia
require[[strict]]


local iface = {}


iface.page_properties_1 = function (frame)
	local pagename, titleobj
	local opts, retval = frame.args, ''
	if opts[2] ~= nil then pagename = opts[2]:match'^%s*(.*%S)' end
	if pagename == nil then titleobj = mw.title.getCurrentTitle()
	else
		titleobj = mw.title.new(pagename)
		if titleobj == nil then titleobj = mw.title.getCurrentTitle() end
	end
	local props = {}
	for key, val in pairs(titleobj) do
		if type(val) == 'string' then props[key] = val
		elseif type(val) == 'number' or type(val) == 'boolean' then
			props[key] = tostring(val)
		end
	end
	for key, val in pairs(props) do
		retval = retval .. key .. '→' .. val .. '<br />'
	end
	return retval
end


iface.page_properties_2 = function (frame)
	local pagename, titleobj
	local opts, retval = frame.args, ''
	if opts[2] ~= nil then pagename = opts[2]:match'^%s*(.*%S)' end
	if pagename == nil then titleobj = mw.title.getCurrentTitle()
	else
		titleobj = mw.title.new(pagename)
		if titleobj == nil then titleobj = mw.title.getCurrentTitle() end
	end
	local props = {
		isDisambiguationPage = tostring(titleobj.isDisambiguationPage)
	}
	for key, val in pairs(titleobj) do
		if type(val) == 'string' then props[key] = val
		elseif type(val) == 'number' or type(val) == 'boolean' then
			props[key] = tostring(val)
		end
	end
	for key, val in pairs(props) do
		retval = retval .. key .. '→' .. val .. '<br />'
	end
	return retval
end


return iface