Module:Minor planet list link: Difference between revisions
Appearance
Content deleted Content added
Tom.Reding (talk | contribs) m +preview warning recently added to Module:Minor planet meaning link by User:Hike395; -concat ws |
Tom.Reding (talk | contribs) Implement Category:Minor planet link error |
||
Line 13: | Line 13: | ||
local num = tonumber(args[1]) |
local num = tonumber(args[1]) |
||
if not num then |
if not num then |
||
local cat = '[[Category:Minor planet link error|List]]' |
|||
local warning = require('Module:If preview')._warning |
local warning = require('Module:If preview')._warning |
||
return warning({'Non-numeric or missing asteroid number'}) |
return warning({'Non-numeric or missing asteroid number'})..cat |
||
end |
end |
||
local subsec = string.sub(tostring(num + 1000), -3) |
local subsec = string.sub(tostring(num + 1000), -3) |
Latest revision as of 10:05, 29 January 2025
![]() | This Lua module is used on approximately 4,200 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
Implements {{Minor planet list link}}
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])
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)
if (num <= 1000) then
link = "List of minor planets: 1–1000#"..subsec
else
local pagefrom = math.floor((num - 1) / 1000)
local pageto = pagefrom + 1
link = "List of minor planets: "..pagefrom.."001–"..pageto.."000#"..subsec
end
if (args[2] == nil) then
result = "[["..link.."]]"
else
result = "[["..link.."|"..args[2].."]]"
end
return result
end
return p