440
edits
(make rowclass apply to headers as well as data cells, per protected edit request) |
m (61 revisions imported from templatewiki:Module:Infobox) |
||
(32 intermediate revisions by 16 users not shown) | |||
Line 2:
-- This module implements {{Infobox}}
--
local p = {}
local
local args = {}
local origArgs
local root
local function notempty( s ) return s and s:match( '%S' ) end
function union(t1, t2)▼
local function fixChildBoxes(sval, tt)
if notempty(sval) then
local marker = '<span class=special_infobox_marker>'
local s = sval
s = mw.ustring.gsub(s, '(<%s*[Tt][Rr])', marker .. '%1')
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>)', '%1' .. marker)
if s:match(marker) then
s = mw.ustring.gsub(s, marker .. '%s*' .. marker, '')
s = mw.ustring.gsub(s, '([\r\n]|-[^\r\n]*[\r\n])%s*' .. marker, '%1')
s = mw.ustring.gsub(s, marker .. '%s*([\r\n]|-)', '%1')
s = mw.ustring.gsub(s, '(</[Cc][Aa][Pp][Tt][Ii][Oo][Nn]%s*>%s*)' .. marker, '%1')
s = mw.ustring.gsub(s, '(<%s*[Tt][Aa][Bb][Ll][Ee][^<>]*>%s*)' .. marker, '%1')
s = mw.ustring.gsub(s, '^(%{|[^\r\n]*[\r\n]%s*)' .. marker, '%1')
s = mw.ustring.gsub(s, '([\r\n]%{|[^\r\n]*[\r\n]%s*)' .. marker, '%1')
s = mw.ustring.gsub(s, marker .. '(%s*</[Tt][Aa][Bb][Ll][Ee]%s*>)', '%1')
s = mw.ustring.gsub(s, marker .. '(%s*\n|%})', '%1')
end
if s:match(marker) then
local subcells = mw.text.split(s, marker)
s = ''
for k = 1, #subcells do
if k == 1 then
s = s .. subcells[k] .. '</' .. tt .. '></tr>'
elseif k == #subcells then
local rowstyle = ' style="display:none"'
if notempty(subcells[k]) then rowstyle = '' end
s = s .. '<tr' .. rowstyle ..'><' .. tt .. ' colspan=2>\n' .. subcells[k]
elseif notempty(subcells[k]) then
if (k % 2) == 0 then
s = s .. subcells[k]
else
s = s .. '<tr><' .. tt .. ' colspan=2>\n' .. subcells[k] .. '</' .. tt .. '></tr>'
end
end
end
end
-- the next two lines add a newline at the end of lists for the PHP parser
-- https://en.wikipedia.org/w/index.php?title=Template_talk:Infobox_musical_artist&oldid=849054481
-- remove when [[:phab:T191516]] is fixed or OBE
s = mw.ustring.gsub(s, '([\r\n][%*#;:][^\r\n]*)$', '%1\n')
s = mw.ustring.gsub(s, '^([%*#;:][^\r\n]*)$', '%1\n')
s = mw.ustring.gsub(s, '^([%*#;:])', '\n%1')
s = mw.ustring.gsub(s, '^(%{%|)', '\n%1')
return s
else
return sval
end
end
▲local function union(t1, t2)
-- Returns the union of the values of two tables, as a sequence.
local vals = {}
Line 45 ⟶ 96:
if rowArgs.header then
root
:wikitext(fixChildBoxes(rowArgs.header, 'th'))
elseif rowArgs.data then
local row = root
row
row:cssText(rowArgs.rowstyle)
row:attr('id', rowArgs.rowid)
if rowArgs.label then
row
:done()
end
local dataCell = row
if not rowArgs.label then
dataCell
end
dataCell
:wikitext(fixChildBoxes(rowArgs.data, 'td'))
end
end
Line 84 ⟶ 144:
root
end
Line 94 ⟶ 154:
root
end
Line 109 ⟶ 169:
root
▲ .wikitext(args.below)
end
Line 130 ⟶ 189:
addRow({
data = args['subheader' .. tostring(num)],
datastyle = args.subheaderstyle
rowcellstyle = args['subheaderstyle' .. tostring(num)],
class = args.subheaderclass,
rowclass = args['subheaderrowclass' .. tostring(num)]
Line 147 ⟶ 207:
for k, num in ipairs(imagenums) do
local caption = args['caption' .. tostring(num)]
local data =
if caption then
data
▲ .cssText(args.captionstyle)
▲ .wikitext(caption)
end
addRow({
Line 177 ⟶ 235:
datastyle = args.datastyle,
class = args['class' .. tostring(num)],
rowclass = args['rowclass' .. tostring(num)],
rowstyle = args['rowstyle' .. tostring(num)],
rowcellstyle = args['rowcellstyle' .. tostring(num)],
dataid = args['dataid' .. tostring(num)],
labelid = args['labelid' .. tostring(num)],
headerid = args['headerid' .. tostring(num)],
rowid = args['rowid' .. tostring(num)]
})
end
Line 186 ⟶ 250:
root
}
end
Line 199 ⟶ 263:
local italicTitle = args['italic title'] and mw.ustring.lower(args['italic title'])
if italicTitle == '' or italicTitle == 'force' or italicTitle == 'yes' then
root
end
end
Line 205 ⟶ 269:
local function renderTrackingCategories()
if args.decat ~= 'yes' then
if #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then▼
if args.title then
root.wikitext('[[Category:Articles which use infobox templates with no data rows]]')▼
root
end
▲ if args.child == 'yes' and args.title then
▲ root.wikitext('[[Category:Articles which use embedded infobox templates with the title parameter]]')
end
end
Line 218 ⟶ 283:
-- if the infobox is used as a 'child' inside another infobox.
if args.child ~= 'yes' then
root =
root
▲ .css('border-spacing', '3px')
if args.subbox == 'yes' then
root
else
root
end
root
renderTitle()
renderAboveRow()
else
root =
root
end
Line 368 ⟶ 431:
{prefix = 'data', depend = {'label'}},
{prefix = 'rowclass'},
{prefix = '
{prefix = 'rowcellstyle'},
{prefix = 'class'},
{prefix = 'dataid'},
{prefix = 'labelid'},
{prefix = 'headerid'},
{prefix = 'rowid'}
}, 50)
preprocessSingleArg('headerclass')
preprocessSingleArg('headerstyle')
preprocessSingleArg('labelstyle')
|