Jump to content

Module:Minor planet list link

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by JohnBlackburne (talk | contribs) at 23:39, 24 September 2016 (Lua version of Template:LoMP, first draft). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local p = {}

function p.LoMP(frame)
	-- For calling from #invoke.
	local pframe = frame:getParent()
	local args = pframe.args
	return p._LoMP(args)
end

function p._LoMP(args)
	local link, page
	-- For calling from other Lua modules.
	local num = args[1]
	local text = args[2]
	local subsec = string.sub(tostring(num + 1000), 3, -1)
	if (num < 1000) then
		link = "List of minor planets: 1–1000#" .. subsec
	else
		local pagefrom = num / 1000
		local pageto = pagefrom + 1
		link = "List of minor planets: " .. pagefrom .. "001-" .. pageto .. "000#" .. subsec
	end
	if (text ~= '') then
		return "[[" .. link .. "|" .. link .. "]]"
	else
		return "[[" .. link .. "|" .. text .. "]]"
	end
end

return p