Module:Infobox: Difference between revisions
Appearance
m 82 revisions imported from wikipedia:Module:Infobox |
No edit summary Tag: Manual revert |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local args = {} | local args = {} | ||
local origArgs = {} | local origArgs = {} | ||
Line 12: | Line 6: | ||
local category_in_empty_row_pattern = '%[%[%s*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]%s*:[^]]*]]' | local category_in_empty_row_pattern = '%[%[%s*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]%s*:[^]]*]]' | ||
local has_rows = false | local has_rows = false | ||
local lists = { | |||
plainlist_t = { | |||
patterns = { | |||
'^plainlist$', | |||
'%splainlist$', | |||
'^plainlist%s', | |||
'%splainlist%s' | |||
}, | |||
found = false, | |||
styles = 'Plainlist/styles.css' | |||
}, | |||
hlist_t = { | |||
patterns = { | |||
'^hlist$', | |||
'%shlist$', | |||
'^hlist%s', | |||
'%shlist%s' | |||
}, | |||
found = false, | |||
styles = 'Hlist/styles.css' | |||
} | |||
} | |||
local function has_list_class(args_to_check) | local function has_list_class(args_to_check) | ||
for _, list in pairs(lists) do | |||
if not list.found then | |||
for _, arg in pairs(args_to_check) do | |||
for _, pattern in ipairs(list.patterns) do | |||
if mw.ustring.find(arg or '', pattern) then | |||
list.found = true | |||
break | |||
end | |||
end | |||
if list.found then break end | |||
end | |||
end | |||
end | |||
end | end | ||
local function fixChildBoxes(sval, tt) | |||
local function | local function notempty( s ) return s and s:match( '%S' ) end | ||
if notempty(sval) then | |||
local marker = '<span class=special_infobox_marker>' | |||
local s = sval | |||
-- start moving templatestyles and categories inside of table rows | |||
local slast = '' | |||
while slast ~= s do | |||
slast = s | |||
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>%s*)(%[%[%s*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]%s*:[^]]*%]%])', '%2%1') | |||
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>%s*)(\127[^\127]*UNIQ%-%-templatestyles%-%x+%-QINU[^\127]*\127)', '%2%1') | |||
end | |||
-- end moving templatestyles and categories inside of table rows | |||
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 | |||
-- [[Special:Diff/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 | end | ||