Difference between revisions of "Module:Portal toolbox"
Jump to navigation
Jump to search
test>Andrybak m (prefer user supplied text to 'subpageText') |
test>Andrybak (reduce amount of duplication needed) |
||
| Line 22: | Line 22: | ||
end | end | ||
| − | local function toolbox_section(frame, args, tbl, rootTitle, title, prefix) | + | local function toolbox_section(frame, args, tbl, rootTitle, title, prefix, page_prefix) |
toolbox_header_row(frame, tbl, title) | toolbox_header_row(frame, tbl, title) | ||
local nums = {} | local nums = {} | ||
| Line 37: | Line 37: | ||
local arg_name = prefix .. num | local arg_name = prefix .. num | ||
local a = args[arg_name] | local a = args[arg_name] | ||
| − | local | + | local pagename = page_prefix .. a |
local text = args[arg_name .. 'text'] | local text = args[arg_name .. 'text'] | ||
local right = args[arg_name .. 'right'] | local right = args[arg_name .. 'right'] | ||
| − | if | + | if text == nil then |
| − | text = | + | text = a |
end | end | ||
if right == nil then | if right == nil then | ||
| − | right = edit(frame, | + | right = edit(frame, pagename) |
end | end | ||
| − | toolbox_row(frame, tbl, | + | toolbox_row(frame, tbl, pagename, text, right) |
end | end | ||
end | end | ||
| Line 60: | Line 60: | ||
toolbox_row(frame, tbl, rootTitle.fullText, nil, edit(frame, rootTitle.fullText)) | toolbox_row(frame, tbl, rootTitle.fullText, nil, edit(frame, rootTitle.fullText)) | ||
| − | toolbox_section(frame, args, tbl, rootTitle, 'Static subpages', 'static') | + | toolbox_section(frame, args, tbl, rootTitle, 'Static subpages', 'static', rootTitle.fullText .. '/') |
| − | toolbox_section(frame, args, tbl, rootTitle, 'Dynamic subpages', 'dynamic') | + | toolbox_section(frame, args, tbl, rootTitle, 'Dynamic subpages', 'dynamic', rootTitle.fullText .. '/') |
| − | toolbox_section(frame, args, tbl, rootTitle, 'Other', 'other') | + | toolbox_section(frame, args, tbl, rootTitle, 'Other', 'other', '') |
return tbl | return tbl | ||
end | end | ||
Revision as of 15:33, 13 June 2020
| This module is rated as pre-alpha. It is unfinished, and may or may not be in active development. It should not be used from article namespace pages. Modules remain pre-alpha until the original editor (or someone who takes one over if it is abandoned for some time) is satisfied with the basic structure. |
This module implements {{Portal toolbox}}. Please see the template page for documentation.
local getArgs = require('Module:Arguments').getArgs
p = {}
local function toolbox_header_row(frame, tbl, text)
local row = tbl:tag('tr')
row:tag('th')
:attr('colspan', '2')
:wikitext(text)
end
local function edit(frame, pagename)
return frame:expandTemplate{ title='edit', args = { pagename } }
end
local function toolbox_row(frame, tbl, pagename, text, right)
local row = tbl:tag('tr')
row:tag('td')
:wikitext('[[' .. pagename .. '|' .. (text or pagename) .. ']]')
row:tag('td')
:wikitext(right)
end
local function toolbox_section(frame, args, tbl, rootTitle, title, prefix, page_prefix)
toolbox_header_row(frame, tbl, title)
local nums = {}
for k, _ in pairs(args) do
if type(k) == 'string' then
local num = k:match('^' .. prefix .. '(%d+)$')
if num then
table.insert(nums, tonumber(num))
end
end
end
table.sort(nums)
for _, num in ipairs(nums) do
local arg_name = prefix .. num
local a = args[arg_name]
local pagename = page_prefix .. a
local text = args[arg_name .. 'text']
local right = args[arg_name .. 'right']
if text == nil then
text = a
end
if right == nil then
right = edit(frame, pagename)
end
toolbox_row(frame, tbl, pagename, text, right)
end
end
local function main(frame)
local args = getArgs(frame)
local tbl = mw.html.create('table')
:cssText('float:right; border:1px navy solid;')
tbl:tag('caption')
:wikitext('Portal toolbox')
toolbox_header_row(frame, tbl, 'Main portal page')
local rootTitle = mw.title.getCurrentTitle().rootPageTitle.subjectPageTitle
toolbox_row(frame, tbl, rootTitle.fullText, nil, edit(frame, rootTitle.fullText))
toolbox_section(frame, args, tbl, rootTitle, 'Static subpages', 'static', rootTitle.fullText .. '/')
toolbox_section(frame, args, tbl, rootTitle, 'Dynamic subpages', 'dynamic', rootTitle.fullText .. '/')
toolbox_section(frame, args, tbl, rootTitle, 'Other', 'other', '')
return tbl
end
p.main = main
return p