Module:ListSubpages: Difference between revisions
Appearance
imported>Xena Module for listing subpages |
imported>Ochiverde m Protected "Module:ListSubpages": Excessive vandalism ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)) |
||
| (4 intermediate revisions by one other user not shown) | |||
| Line 5: | Line 5: | ||
function p.list( frame ) | function p.list( frame ) | ||
local page = frame.args[1] or frame.args['page'] or | local page = frame.args[1] or frame.args['page'] or tostring(mw.title.getCurrentTitle()) | ||
-- empty parameter check | |||
if page == '' then page = tostring(mw.title.getCurrentTitle()) end | |||
-- get parent page name | |||
page = frame:callParserFunction('TOPLEVELPAGE', {page}) | page = frame:callParserFunction('TOPLEVELPAGE', {page}) | ||
local allSubpages = frame:callParserFunction('SUBPAGES', { page, sep = " | -- get subpages | ||
allSubpages = mw.text.split(allSubpages, " | local allSubpages = frame:callParserFunction('SUBPAGES', { page, sep = ",,,,,,,,,," }) | ||
result = {} | allSubpages = mw.text.split(allSubpages, ",,,,,,,,,,", true) | ||
local result = {} | |||
-- add main page | -- add main page | ||
| Line 16: | Line 20: | ||
result[#result+1] = [==[|<span style="color:white;">Main</span>]]</div>]==] | result[#result+1] = [==[|<span style="color:white;">Main</span>]]</div>]==] | ||
-- add subpages | |||
if #allSubpages[1] > 0 then for i = 1, #allSubpages do | if #allSubpages[1] > 0 then for i = 1, #allSubpages do | ||
result[#result+1] = [==[<div style="display:inline-block; position: relative; background-color: #d97308; width: 80px; color:white; text-align: center; padding:5px; border-radius: 5px; margin-right: 5px; ">[[]==] | result[#result+1] = [==[<div style="display:inline-block; position: relative; background-color: #d97308; width: 80px; color:white; text-align: center; padding:5px; border-radius: 5px; margin-right: 5px; ">[[]==] | ||
result[#result+1] = allSubpages[i] | result[#result+1] = allSubpages[i] | ||
result[#result+1] = [==[|<span style="color:white;">]==] | result[#result+1] = [==[|<span style="color:white;">]==] | ||
result[#result+1] = | result[#result+1] = frame:callParserFunction('SUBPAGENAME', {allSubpages[i]}) | ||
result[#result+1] = '</span>]]</div>' | result[#result+1] = '</span>]]</div>' | ||
end end | end end | ||
return table.concat(result) | |||
end | end | ||
Latest revision as of 13:44, 18 April 2024
Documentation for this module may be created at Module:ListSubpages/doc
local p = {} --p stands for package
function p.list( frame )
local page = frame.args[1] or frame.args['page'] or tostring(mw.title.getCurrentTitle())
-- empty parameter check
if page == '' then page = tostring(mw.title.getCurrentTitle()) end
-- get parent page name
page = frame:callParserFunction('TOPLEVELPAGE', {page})
-- get subpages
local allSubpages = frame:callParserFunction('SUBPAGES', { page, sep = ",,,,,,,,,," })
allSubpages = mw.text.split(allSubpages, ",,,,,,,,,,", true)
local result = {}
-- add main page
result[#result+1] = [==[<div style="display:inline-block; position: relative; background-color: #d97308; width: 80px; color:white; text-align: center; padding:5px; border-radius: 5px; margin-right: 5px; ">[[]==]
result[#result+1] = page
result[#result+1] = [==[|<span style="color:white;">Main</span>]]</div>]==]
-- add subpages
if #allSubpages[1] > 0 then for i = 1, #allSubpages do
result[#result+1] = [==[<div style="display:inline-block; position: relative; background-color: #d97308; width: 80px; color:white; text-align: center; padding:5px; border-radius: 5px; margin-right: 5px; ">[[]==]
result[#result+1] = allSubpages[i]
result[#result+1] = [==[|<span style="color:white;">]==]
result[#result+1] = frame:callParserFunction('SUBPAGENAME', {allSubpages[i]})
result[#result+1] = '</span>]]</div>'
end end
return table.concat(result)
end
return p