Jump to content

Module:Minor planet list link: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
debug stuff
try and get it using 2nd param
Line 12: Line 12:
-- For calling from other Lua modules.
-- For calling from other Lua modules.
local num = tonumber(args[1])
local num = tonumber(args[1])
local text = args[2]
local subsec = string.sub(tostring(num + 1000), 3, -1)
local subsec = string.sub(tostring(num + 1000), 3, -1)
if (num < 1000) then
if (num < 1000) then
Line 21: Line 20:
link = "List of minor planets: " .. pagefrom .. "001–" .. pageto .. "000#" .. subsec
link = "List of minor planets: " .. pagefrom .. "001–" .. pageto .. "000#" .. subsec
end
end
if (text ~= '') then
if (args[2] == nil) then
result = "[[" .. link .. "|" .. link .. "]]"
result = "[[" .. link .. "|" .. link .. "]]"
else
else
result = "[[" .. link .. "|" .. text .. "]]"
result = "[[" .. link .. "|" .. args[2] .. "]]"
end
end
result = result .. "('''" .. args[1] .. "''', ''" .. args[2] .. "'')"
return result
return result
end
end

Revision as of 23:57, 24 September 2016

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, result
	-- For calling from other Lua modules.
	local num = tonumber(args[1])
	local subsec = string.sub(tostring(num + 1000), 3, -1)
	if (num < 1000) then
		link = "List of minor planets: 1–1000#" .. subsec
	else
		local pagefrom = math.floor(num / 1000)
		local pageto = pagefrom + 1
		link = "List of minor planets: " .. pagefrom .. "001–" .. pageto .. "000#" .. subsec
	end
	if (args[2] == nil) then
		result = "[[" .. link .. "|" .. link .. "]]"
	else
		result = "[[" .. link .. "|" .. args[2] .. "]]"
	end
	return result
end

return p