Module:Util/pages/listSubpages: Difference between revisions
< Module:Util | pages
PhantomCaleb (talk | contribs) No edit summary |
PhantomCaleb (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
local dpl = require("Module:Util/pages/dpl") | local dpl = require("Module:Util/pages/dpl") | ||
local | local function filterPages(title, pages, options) | ||
function filterPages(title, pages, options) | |||
local filteredPages = {} | local filteredPages = {} | ||
local _, basePageDepth = string.gsub(title.prefixedText, "/", "") | local _, basePageDepth = string.gsub(title.prefixedText, "/", "") | ||
Line 30: | Line 16: | ||
end | end | ||
return filteredPages | return filteredPages | ||
end | |||
local function listSubpages(fullPageName, options) | |||
options = options or {} | |||
local title = fullPageName and mw.title.new(fullPageName) or mw.title.getCurrentTitle() | |||
local pages = dpl({ | |||
namespace= title.nsText, | |||
titlematch= '%' .. title.text .. '/%', | |||
}) | |||
if options.depth or options.noDocumentation then | |||
pages = filterPages(title, pages, options) | |||
end | |||
table.sort(pages) | |||
return pages | |||
end | end | ||
return listSubpages | return listSubpages |
Latest revision as of 17:05, 12 May 2024
listSubpages([fullPageName], [options])
Parameters
[fullPageName]
- A full page name with namespace prefix. If nil,
mw.title.getCurrentTitle()
is used.
Returns
- A list of subpages
Examples
# | Input | Output |
---|---|---|
1 | listSubpages(
"Module:Constants",
{
noDocumentation = true,
depth = 2,
}
)
| {
"Module:Constants/Data",
"Module:Constants/category/deprecatedParams",
"Module:Constants/category/invalidArgs",
"Module:Constants/category/templateErrors",
"Module:Constants/class/noexcerpt",
"Module:Constants/class/pixelArt",
"Module:Constants/class/tooltip",
"Module:Constants/number/maxImageArea",
"Module:Constants/number/maxNavboxPartitionSize",
"Module:Constants/url/discord",
}
|
2 | listSubpages("Module:Constants", { depth = 1 })
| {
"Module:Constants/Data",
"Module:Constants/Documentation",
}
|
3 | listSubpages("Module:Constants")
| {
"Module:Constants/Data",
"Module:Constants/Documentation",
"Module:Constants/category/deprecatedParams",
"Module:Constants/category/deprecatedParams/Documentation",
"Module:Constants/category/invalidArgs",
"Module:Constants/category/invalidArgs/Documentation",
"Module:Constants/category/templateErrors",
"Module:Constants/class/noexcerpt",
"Module:Constants/class/noexcerpt/Documentation",
"Module:Constants/class/pixelArt",
"Module:Constants/class/pixelArt/Documentation",
"Module:Constants/class/tooltip",
"Module:Constants/class/tooltip/Documentation",
"Module:Constants/number/maxImageArea",
"Module:Constants/number/maxImageArea/Documentation",
"Module:Constants/number/maxNavboxPartitionSize",
"Module:Constants/number/maxNavboxPartitionSize/Documentation",
"Module:Constants/url/discord",
"Module:Constants/url/discord/Documentation",
}
|
4 | listSubpages()
| {
"Module:Util/pages/listSubpages/Documentation",
"Module:Util/pages/listSubpages/Documentation/Spec",
}
|
local dpl = require("Module:Util/pages/dpl")
local function filterPages(title, pages, options)
local filteredPages = {}
local _, basePageDepth = string.gsub(title.prefixedText, "/", "")
for i, v in ipairs(pages) do
local isDocumentation = string.find(v, "/Documentation$") or string.find(v, "/Documentation/")
local _, pageDepth = string.gsub(v, "/", "")
if options.noDocumentation and isDocumentation then
-- no-op
elseif options.depth and options.depth > 0 and (pageDepth - basePageDepth) > options.depth then
-- no-op
else
table.insert(filteredPages, v)
end
end
return filteredPages
end
local function listSubpages(fullPageName, options)
options = options or {}
local title = fullPageName and mw.title.new(fullPageName) or mw.title.getCurrentTitle()
local pages = dpl({
namespace= title.nsText,
titlematch= '%' .. title.text .. '/%',
})
if options.depth or options.noDocumentation then
pages = filterPages(title, pages, options)
end
table.sort(pages)
return pages
end
return listSubpages