Módulo:Subpáginas numeradas

Revisão em 01h27min de 14 de maio de 2024 por Jaewoo (discussão | contribs) (Criou a página com "-- Este módulo implementa {{Subpáginas numeradas}}. local getArgs = require('Module:Arguments').getArgs p = {} local function ifexist(page) if not page then return false end if mw.title.new(page).exists then return true end return false end function p.main(frame) local args = getArgs(frame) local maxk = tonumber(args.max or '50') or 50 local mink = tonumber(args.min or '1') or 1 local root = '' local missing = args.missing or (args.max and 'transclud...")
(dif) ← Revisão anterior | Revisão atual (dif) | Revisão seguinte → (dif)

A documentação para este módulo pode ser criada na página Módulo:Subpáginas numeradas/doc

-- Este módulo implementa {{Subpáginas numeradas}}.
local getArgs = require('Module:Arguments').getArgs
p = {}
local function ifexist(page)
				if not page then return false end
				if mw.title.new(page).exists then return true end
				return false
end
function p.main(frame)
	local args = getArgs(frame)
	local maxk = tonumber(args.max or '50') or 50
	local mink = tonumber(args.min or '1') or 1
	local root = ''
	local missing = args.missing or (args.max and 'transclude' or 'skip')
	local res = ''
	
	if missing ~= 'transclude' then
		root = frame:preprocess('{{FULLPAGENAME}}')
	end
	maxk = (maxk > (mink + 250)) and (mink + 250) or maxk
	for i=mink,maxk do
		if missing == 'transclude' then
			res = res .. frame:expandTemplate{title = 'subpágina', args = { i } }
		else
			if ifexist(root .. '/' .. i) then
				res = res .. frame:expandTemplate{title = 'subpágina', args = { i } }
			else
				if missing == 'link' then
					res = res .. '[[' .. root .. '/' .. i .. ']] '
				elseif missing == 'stop' then
					i = maxk + 1
				end
			end
		end
	end
	
	return res
end
return p