Module:Portal toolbox: Difference between revisions

Content deleted Content added
reduce amount of duplication needed
add "clear: right;" to the main CSS
 
(4 intermediate revisions by the same user not shown)
Line 3:
p = {}
 
local function toolbox_header_rowadd_header_row(frame, tbl, text)
local row = tbl:tag('tr')
row:tag('th')
Line 11:
 
local function edit(frame, pagename)
return frame:expandTemplate{ title='edit', args = { pagename } }
end
 
local function toolbox_rowadd_template_row(frame, tbl, pagename, text, right)
local row = tbl:tag('tr')
row:tag('td')
:wikitext(frame:expandTemplate{ title='tl', args={ pagename } })
row:tag('td')
right = :wikitext(edit(frame, 'Template:' .. pagename))
end
 
toolbox_rowlocal function add_wikilink_row(frame, tbl, pagename, text, right)
local row = tbl:tag('tr')
row:tag('td')
:wikitext('[[' .. pagename .. '|' .. (text or pagename) .. ']]')
row:tag('td')
:wikitext(right or edit(frame, pagename))
end
 
local function toolbox_sectionadd_section(frame, args, tbl, rootTitleadd_section_header, titlearg_prefix, prefixpage_prefix, page_prefixrow_function)
if textrow_function == nil then
toolbox_header_row(frame, tbl, title)
row_function = add_wikilink_row
end
local nums = {}
for k, _ in pairs(args) do
if type(k) == 'string' then
local num = k:match('^' .. prefixarg_prefix .. '(%d+)$')
if num then
table.insert(nums, tonumber(num))
end
end
end
if right#nums == nil0 then
return
end
table.sort(nums)
add_header_row(frame, tbl, add_section_header)
for _, num in ipairs(nums) do
local arg_name = prefixarg_prefix .. num
local aarg = args[arg_name]
local pagename = page_prefix .. aarg
local text = args[arg_name .. 'text']
local right = args[arg_name .. 'right']
row_function(frame, tbl, pagename, text or arg, 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
Line 53 ⟶ 61:
local args = getArgs(frame)
local tbl = mw.html.create('table')
:cssText('clear: right; float:right; border:1px navy solid;')
tbl:tag('caption')
:wikitext('Portal toolbox')
toolbox_header_rowadd_header_row(frame, tbl, 'Main portal page')
local rootTitle = mw.title.getCurrentTitle().rootPageTitle.subjectPageTitle
toolbox_rowadd_wikilink_row(frame, tbl, rootTitle.fullText, nil, edit(frame, rootTitle.fullText))
toolbox_sectionadd_section(frame, args, tbl, rootTitle, 'Static subpages', 'static', rootTitle.fullText .. '/')
toolbox_sectionadd_section(frame, args, tbl, rootTitle, 'Dynamic subpages', 'dynamic', rootTitle.fullText .. '/')
toolbox_sectionadd_section(frame, args, tbl, rootTitle, 'OtherTemplates', 'othertemplate', '', add_template_row)
add_section(frame, args, tbl, 'Other', 'other', '')
return tbl
end