Jump to content

Module:Pagetype

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 01:33, 24 October 2013 (start a pagetype module alternative). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local dts = require('Module:User:Anomie/deepToString').deepToString -- for debugging

local yesno = require('Module:Yesno')

local p = {}

local pagetypes = {
	main                  = 'article',
	mediawiki             = 'interface page',
	help                  = 'help page',
	project               = 'project page',
	book                  = 'book',
	file                  = 'file',
	template              = 'template',
	category              = 'category',
	module                = 'module',
	portal                = 'portal',
	timedtext             = 'Timed Text page',
	['education program'] = 'education program page',
	talk                  = 'talk page'
}

local function getNamespacePagetype(k, v)
	local ret = yesno(v, v) -- Returns true/false for "yes", "no", etc., and returns v for other input.
	if ret and type(ret) ~= 'string' then
		ret = pagetypes[k]
	end
	if not ret then
		ret = 'page'
	end
	return ret
end

function p._main(args)
	return getNamespacePagetype('module', false)
end

function p.main(frame)
	-- If called via #invoke, use the args passed into the invoking template, or the args passed to #invoke if any exist.
	-- Otherwise assume args are being passed directly in from the debug console or from another Lua module.
	local origArgs
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
		for k, v in pairs(frame.args) do
			origArgs = frame.args
			break
		end
	else
		origArgs = frame
	end
	-- Trim whitespace and remove blank arguments.
	local args = {}
	for k, v in pairs(origArgs) do
		if type(v) == 'string' then
			v = mw.text.trim(v)
		end
		if v ~= '' then
			args[k] = v
		end
	end
	return p._main(args)
end

return p