Module:Newarticletext: Difference between revisions
Appearance
ReisuDesign (talk | contribs) Created page with "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 Each Section for i,section_data in ipairs(sections) do if section_data['header'] and section_data['sections'] then local evenTest local section = page_layo..." |
ReisuDesign (talk | contribs) No edit summary |
||
| (9 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function p.main(frame) | function p.main(frame) | ||
local td_attr = { | local td_attr = { | ||
valign='top' | valign = 'top' | ||
} | } | ||
local td_css = { | local td_css = { | ||
width='50%' | width = '50%' | ||
} | } | ||
local title = mw.title.getCurrentTitle().text | local title = mw.title.getCurrentTitle().text | ||
local sections = mw.loadData('Module:Newarticletext/data') | local sections = mw.loadData('Module:Newarticletext/data') | ||
local output = {} | local output = {} | ||
-- For Each Section | -- For Each Section | ||
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 | ||
local evenTest | local evenTest | ||
| Line 19: | Line 22: | ||
local row | local row | ||
local column | local column | ||
-- For Each Link Area | -- For Each Link Area | ||
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 | ||
if evenTest==1 then | |||
if evenTest == 1 then | |||
row = section:tag('tr') | row = section:tag('tr') | ||
end | end | ||
column = row:tag('td') | column = row:tag('td') | ||
:attr(td_attr):css(td_css) | :attr(td_attr) | ||
if | :css(td_css) | ||
local ul = column:wikitext(link_data['text'] .. '<br/>'):tag('ul') | |||
if type(link_data['link']) == 'table' then | |||
local ul = column | |||
:wikitext(link_data['text'] .. '<br/>') | |||
:tag('ul') | |||
:addClass('pipe_delimit') | :addClass('pipe_delimit') | ||
:css('font-size',link_data['link']['size']) | :css('font-size', link_data['link']['size']) | ||
for k,sub_link in ipairs(link_data['link']) do | |||
for k, sub_link in ipairs(link_data['link']) do | |||
ul:tag('li') | ul:tag('li') | ||
: | :node( | ||
preload_link( | |||
title, | |||
sub_link['link'], | |||
sub_link['text'] | |||
) | |||
) | |||
end | end | ||
else | else | ||
column: | column:node( | ||
preload_link( | |||
title, | |||
link_data['link'], | |||
tostring(link_data['text']) | |||
) | |||
) | |||
end | end | ||
end | end | ||
if evenTest==1 then | |||
column:attr('colspan',2) | if evenTest == 1 then | ||
column:attr('colspan', 2) | |||
end | end | ||
table.insert(output, tostring(section)) | table.insert(output, tostring(section)) | ||
end | end | ||
| Line 48: | Line 73: | ||
return table.concat(output) | return table.concat(output) | ||
end | end | ||
function preload_link(page,preload,display) | |||
return | function preload_link(page, preload, display) | ||
return mw.html.create('span') | |||
:attr('class', 'preload-plus-link') | |||
:attr('data-preload', tostring(preload)) | |||
:attr('data-page', tostring(page)) | |||
:wikitext(display) | |||
end | end | ||
function page_layout(section_title) | function page_layout(section_title) | ||
local table_attr = { | local table_attr = { | ||
class | class = 'wikitable mw-collapsible plainlinks', | ||
['data-expandtext'] | ['data-expandtext'] = '+', | ||
['data-collapsetext'] = '-' | ['data-collapsetext'] = '-' | ||
} | } | ||
local table_css = { | local table_css = { | ||
width | width = '100%', | ||
['text-align'] = 'center' | ['text-align'] = 'center' | ||
} | } | ||
| Line 70: | Line 97: | ||
:attr(table_attr) | :attr(table_attr) | ||
:css(table_css) | :css(table_css) | ||
:tag('tr'):tag('th') | :tag('tr') | ||
:tag('th') | |||
:attr('colspan', 2) | |||
:wikitext(section_title) | |||
:allDone() | |||
end | end | ||
return p | return p | ||
Latest revision as of 13:37, 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 Each Section
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 Each Link Area
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')
:node(
preload_link(
title,
sub_link['link'],
sub_link['text']
)
)
end
else
column:node(
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 mw.html.create('span')
:attr('class', 'preload-plus-link')
:attr('data-preload', tostring(preload))
:attr('data-page', tostring(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