Module:Newarticletext: Difference between revisions
Appearance
ReisuDesign (talk | contribs) No edit summary |
ReisuDesign (talk | contribs) No edit summary |
||
| Line 15: | Line 15: | ||
local output = {} | local output = {} | ||
for i, section_data in ipairs(sections) do | for i, section_data in ipairs(sections) do | ||
if section_data['header'] and section_data['sections'] then | if section_data['header'] and section_data['sections'] then | ||
| Line 23: | Line 22: | ||
local column | local column | ||
for j, link_data in ipairs(section_data['sections']) do | for j, link_data in ipairs(section_data['sections']) do | ||
evenTest = j % 2 | evenTest = j % 2 | ||
| Line 75: | Line 73: | ||
function preload_link(page, preload, display) | function preload_link(page, preload, display) | ||
return | return tostring( | ||
mw. | mw.html.create('a') | ||
:attr('href', mw.util.getUrl(page)) | |||
:attr('class', 'preload-plus-link') | |||
:attr('data-preload', preload) | |||
:attr('data-page', page) | |||
) | :wikitext(display) | ||
) | |||
end | end | ||
Revision as of 13:25, 17 September 2026
| Main | Documentation | Usage |
This module is used in MediaWiki:Newarticletext. Used through {{Newarticletext}}
local p = {}
function p.main(frame)
local td_attr = {
valign = 'top'
}
local td_css = {
width = '50%'
}
local title = mw.title.getCurrentTitle().text
local sections = mw.loadData('Module:Newarticletext/data')
local output = {}
for i, section_data in ipairs(sections) do
if section_data['header'] and section_data['sections'] then
local evenTest
local section = page_layout(section_data['header'])
local row
local column
for j, link_data in ipairs(section_data['sections']) do
evenTest = j % 2
if evenTest == 1 then
row = section:tag('tr')
end
column = row:tag('td')
:attr(td_attr)
:css(td_css)
if type(link_data['link']) == 'table' then
local ul = column
:wikitext(link_data['text'] .. '<br/>')
:tag('ul')
:addClass('pipe_delimit')
:css('font-size', link_data['link']['size'])
for k, sub_link in ipairs(link_data['link']) do
ul:tag('li')
:wikitext(
preload_link(
title,
sub_link['link'],
sub_link['text']
)
)
end
else
column:wikitext(
preload_link(
title,
link_data['link'],
tostring(link_data['text'])
)
)
end
end
if evenTest == 1 then
column:attr('colspan', 2)
end
table.insert(output, tostring(section))
end
end
return table.concat(output)
end
function preload_link(page, preload, display)
return tostring(
mw.html.create('a')
:attr('href', mw.util.getUrl(page))
:attr('class', 'preload-plus-link')
:attr('data-preload', preload)
:attr('data-page', page)
:wikitext(display)
)
end
function page_layout(section_title)
local table_attr = {
class = 'wikitable mw-collapsible plainlinks',
['data-expandtext'] = '+',
['data-collapsetext'] = '-'
}
local table_css = {
width = '100%',
['text-align'] = 'center'
}
return mw.html.create('table')
:attr(table_attr)
:css(table_css)
:tag('tr')
:tag('th')
:attr('colspan', 2)
:wikitext(section_title)
:allDone()
end
return p