Module:Numbered subpages: Difference between revisions
Appearance
Content deleted Content added
pass parameter "preload" to Template:Subpage |
parameter "preload" only makes sense for non-existent pages |
||
Line 29: | Line 29: | ||
if missing == 'transclude' then |
if missing == 'transclude' then |
||
if headertemplate == '' then |
if headertemplate == '' then |
||
res = res .. frame:expandTemplate{title = 'subpage', args = { i, SPAN=SPAN |
res = res .. frame:expandTemplate{title = 'subpage', args = { i, SPAN=SPAN } } |
||
else |
else |
||
res = res .. frame:expandTemplate{title = 'subpage', args = { i, headertemplate=headertemplate, SPAN=SPAN |
res = res .. frame:expandTemplate{title = 'subpage', args = { i, headertemplate=headertemplate, SPAN=SPAN } } |
||
end |
end |
||
else |
else |
||
subpagename = root .. '/' .. i |
|||
if ifexist(subpagename) then |
|||
if headertemplate == '' then |
if headertemplate == '' then |
||
res = res .. frame:expandTemplate{title = 'subpage', args = { i, SPAN=SPAN |
res = res .. frame:expandTemplate{title = 'subpage', args = { i, SPAN=SPAN } } |
||
else |
else |
||
res = res .. frame:expandTemplate{title = 'subpage', args = { i, headertemplate=headertemplate, SPAN=SPAN |
res = res .. frame:expandTemplate{title = 'subpage', args = { i, headertemplate=headertemplate, SPAN=SPAN } } |
||
end |
end |
||
else |
else |
||
if missing == 'link' then |
if missing == 'link' then |
||
if preload then |
|||
⚫ | |||
res = res .. frame:expandTemplate{title = 'edit', args = { subpagename, preload=preload } } |
|||
else |
|||
⚫ | |||
end |
|||
elseif missing == 'stop' then |
elseif missing == 'stop' then |
||
i = maxk + 1 |
i = maxk + 1 |
Revision as of 21:59, 7 June 2020
Implements {{Numbered subpages}}
-- This module implements {{numbered subpages}}.
local getArgs = require('Module:Arguments').getArgs
p = {}
local function ifexist(page)
if not page then return false end
if mw.title.new(page).exists then return true end
return false
end
function p.main(frame)
local args = getArgs(frame)
local maxk = tonumber(args.max or '50') or 50
local mink = tonumber(args.min or '1') or 1
local root = ''
local missing = args.missing or (args.max and 'transclude' or 'skip')
local res = ''
local headertemplate = args.headertemplate or ''
if missing ~= 'transclude' then
root = frame:preprocess('{{FULLPAGENAME}}')
end
maxk = (maxk > (mink + 250)) and (mink + 250) or maxk
local SPAN = args.SPAN or ''
local preload = args.preload or ''
for i=mink,maxk do
if missing == 'transclude' then
if headertemplate == '' then
res = res .. frame:expandTemplate{title = 'subpage', args = { i, SPAN=SPAN } }
else
res = res .. frame:expandTemplate{title = 'subpage', args = { i, headertemplate=headertemplate, SPAN=SPAN } }
end
else
subpagename = root .. '/' .. i
if ifexist(subpagename) then
if headertemplate == '' then
res = res .. frame:expandTemplate{title = 'subpage', args = { i, SPAN=SPAN } }
else
res = res .. frame:expandTemplate{title = 'subpage', args = { i, headertemplate=headertemplate, SPAN=SPAN } }
end
else
if missing == 'link' then
if preload then
res = res .. frame:expandTemplate{title = 'edit', args = { subpagename, preload=preload } }
else
res = res .. '[[' .. subpagename .. ']] '
end
elseif missing == 'stop' then
i = maxk + 1
end
end
end
end
return res
end
return p