Jump to content

Module:Numbered subpages

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Frietjes (talk | contribs) at 15:18, 27 October 2016. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

-- This module implements {{numbered subpages}}.

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

p = {}

-- Gets a mw.title object, using pcall to avoid generating script errors if we
-- are over the expensive function count limit (among other possible causes).
-- (Function imported from [[Module:Redirect]])
local function getTitle(...)
	local success, titleObj = pcall(mw.title.new, ...)
	if success then
		return titleObj
	else
		return nil
	end
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 = frame:preprocess('{{FULLPAGENAME}}')
	local res = ''
	
	for i=mink,maxk do
		local sname = getTitle(root .. '/' .. i)
		if sname then
			res = res .. frame:expandTemplate{title = 'subpage', args = { i } }
		end
	end
end

return p