Ir al contenido

Módulo:Namespace other

De Wikisource, la biblioteca libre.
Documentación del módulo


Uso

Módulo para {{main other}} y potencialmente otras plantillas similares.
Esta documentación está transcluida desde Módulo:Namespace other/doc.
Los editores pueden experimentar en la zona de pruebas
Por favor, añade las categorías a la subpágina de documentación.
(subpáginas - enlaces)

require('strict')

local p = {}

local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')

function p._namespace_other(args)
	local namespace = string.lower(args.demospace or mw.title.getCurrentTitle().nsText)
	local target = string.lower(args.target or 'main')
	
	if yesno(args['include-talk']) then
		namespace = string.gsub(namespace, '[%s_]*talk', '')
	end
	
	local special_targets = {
		['talk'] = function (ns)
			return mw.title.new(mw.title.getCurrentTitle().rootText, namespace).isTalkPage
		end,
		['main'] = function (ns)
			return ns == '' or ns == 'main'
		end
	}
	
	if namespace == target or (special_targets[target] and special_targets[target](namespace)) then
		return args[1]
	else
		return args[2]
	end
end

function p.namespace_other(frame)
	return p._namespace_other(getArgs(frame))
end

return p