Jump to content

Module:Minor planet list link and Module:Minor planet list link/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
 
m Pppery moved page Module:LoMP/sandbox to Module:Minor planet list link/sandbox without leaving a redirect: Module renamed
 
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])
if not num then
local cat = '[[Category:Minor planet link error|List]]'
local warning = require('Module:If preview')._warning
return warning({'Non-numeric or missing asteroid number'})..cat
end
local subsec = string.sub(tostring(num + 1000), -3)
local subsec = string.sub(tostring(num + 1000), -3)
if (num <= 1000) then
if (num <= 1000) then
link = "List of minor planets: 1–1000#"..subsec
link = "List of minor planets: 1–1000#" .. subsec
else
else
local pagefrom = math.floor((num - 1) / 1000)
local pagefrom = math.floor((num - 1) / 1000)
local pageto = pagefrom + 1
local pageto = pagefrom + 1
link = "List of minor planets: "..pagefrom.."001–"..pageto.."000#"..subsec
link = "List of minor planets: " .. pagefrom .. "001–" .. pageto .. "000#" .. subsec
end
end
if (args[2] == nil) then
if (args[2] == nil) then
result = "[["..link.."]]"
result = "[[" .. link .. "]]"
else
else
result = "[["..link.."|"..args[2].."]]"
result = "[[" .. link .. "|" .. args[2] .. "]]"
end
end
return result
return result