Module:TOC001/sandbox explained
local p =
function p.TOC001(frame) local title = mw.title.getCurrentTitle local pn = title.text local pagebase = mw.ustring.match(pn, '^(List of minor planets:)%d') or mw.ustring.match(pn, '^(Meanings of minor[-]planet names:)%d') or 'testcase' local parent_from = mw.ustring.match(pn, '(%d+)–') or 0 --en dash; 1, 1001, 2001, ... local prefix = (parent_from - 1)/1000 --0, 1, 2, ... local left = parent_from - 5000 --left-most navigational 'from'; floor = 1 local hlist, anchor local nav_upper, nav_lower = , --testcase prep if pagebase
'testcase' then --obsolete parameters allowed only on non-LoMP|MoMP pages local args = frame:getParent.args if mw.ustring.match(pn, '(TOC001)') or mw.ustring.match(pn, '(MinorPlanetListFooter)') then args.prefix = 1 end if args.prefix then prefix = args.prefix if prefix
0 then parent_from = 1 else parent_from = prefix..'001' end left = parent_from - 5000 if args.meanings then pagebase = 'Meanings of minor planet names: ' else pagebase = 'List of minor planets: ' end else return ' requires a |prefix=
outside of LoMP/MoMP-space.' end end --hlist if pagebase
'List of minor planets: ' then hlist = frame:expandTemplate else --MoMP hlist = frame:expandTemplate end --TOC top local TOC_top = frame:expandTemplate --nav_upper if left < 1 then left = 1 end local i = 0 while i <= 10 do local from = left + 1000*i local to = left-1 + 1000*(i+1) local sep = ' ' if from < 1500 then sep = '-' end --TODO: RFM to the correct form pagebase = string.gsub(pagebase, '(minor)[-](planet names)', '%1'..sep..'%2') nav_upper = nav_upper..'\n* '.. mw.getContentLanguage:formatNum(from - 1)..'s' i = i + 1 end --nav_lower i = 0 while i <= 9 do anchor = i..'01' --001, 002, ... nav_lower = nav_lower..'\n* '.. mw.getContentLanguage:formatNum(tonumber(prefix..anchor))..'…' i = i + 1 end --cleanup nav_ for lowest numbered pages (do this once after the whiles, instead of conditionals inside) nav_upper = string.gsub(nav_upper, '|0s]]', '|1–1000]]') nav_lower = string.gsub(nav_lower, '|001…]]', '|1–100]]') --TOC bottom local TOC_bottom = frame:expandTemplate --concat all return TOC_top..nav_upper..'\n
\n
'..nav_lower..'\n
'..TOC_bottomend
return p