求真百科歡迎當事人提供第一手真實資料,洗刷冤屈,終結網路霸凌。

變更

前往: 導覽搜尋

模块:Infobox

移除 521 位元組, 6 年前
infobox class not needed for subbox since the parent box will set the class (and causes problems on mobile)
--
-- This module implements {{Infobox}}
-- 中文的此模块对比英文维基多解析了overimage, overcaption,
-- overimagerowclass以及header/labal/data*style参数。
--
local origArgs
local root
 
local function notempty( s ) return s and s:match( '%S' ) end
 
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
return s
else
return sval
end
end
local function union(t1, t2)
:addClass(args.headerclass)
:css('text-align', 'center')
:cssText(args.headerstyle) :cssText(rowArgs.headerstylerowcellstyle) :wikitext(fixChildBoxes(rowArgs.header, 'th'))
elseif rowArgs.data then
local row = root:tag('tr')
:tag('th')
:attr('scope', 'row')
:css('text-align', 'left')
:attr('id', rowArgs.labelid)
:cssText(args.labelstyle) :cssText(rowArgs.labelstylerowcellstyle)
:wikitext(rowArgs.label)
:done()
:addClass(rowArgs.class)
:cssText(rowArgs.datastyle)
:cssText(rowArgs.rowcellstyle)
:newline()
:wikitext(fixChildBoxes(rowArgs.data, 'td'))
end
end
 
local function renderOverImage()
if not args.overimage then return end
 
local row = root:tag('tr')
row:addClass(args.overimagerowclass)
local topImage = row:tag('td')
topImage:attr('colspan', 2)
topImage:addClass(args.imageclass)
topImage:cssText(args.imagestyle)
topImage:css('text-align', 'center')
if args.overcaption and args.captionstyle then
topImage:wikitext(args.overimage .. '<br /><span style=\"' .. args.captionstyle .. '\">' .. args.overcaption .. '</span>')
else
if args.overcaption then
topImage:wikitext(args.overimage .. '<br />' .. args.overcaption)
else
topImage:wikitext(args.overimage)
end
end
end
:addClass(args.titleclass)
:cssText(args.titlestyle)
:wikitext('\'\'\'' .. args.title .. '\'\'\'')
end
:css('font-weight', 'bold')
:cssText(args.abovestyle)
:wikitext(fixChildBoxes(args.above,'th'))
end
:cssText(args.belowstyle)
:newline()
:wikitext(fixChildBoxes(args.below,'td'))
end
addRow({
header = args['header' .. tostring(num)],
headerstyle = (args.headerstyle or '') .. (args.headerstyle and ';' or '') .. (args['header' .. tostring(num) .. 'style'] or ''),
label = args['label' .. tostring(num)],
labelstyle = (args.labelstyle or '') .. (args.labelstyle and ';' or '') .. (args['label' .. tostring(num) .. 'style'] or ''),
data = args['data' .. tostring(num)],
datastyle = (args.datastyle or '') .. (args.datastyle and ';' or '') .. (args['data' .. tostring(num) .. 'style'] or ''),
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)],
if args.decat ~= 'yes' then
if #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then
root:wikitext('[[Category: 使用无数据行信息框模板的条目Articles which use infobox templates with no data rows]]')
end
if args.child == 'yes' and args.title then
root:wikitext('[[Category: 使用带有标题参数的嵌入式信息框模板的条目Pages which use embedded infobox templates with the title parameter]]')
end
end
root
:addClass((args.subbox ~= 'yes') and 'infobox'or nil)
:addClass(args.bodyclass)
:attr('cellspacing', 3)
:css('border-spacing', '3px')
if args.subbox == 'yes' then
:css('width', 'auto')
:css('min-width', '100%')
:css('font-size', 'small100%')
:css('clear', 'none')
:css('float', 'none')
root
:css('width', '22em')
:css('text-align', 'left')
:css('font-size', 'small')
:css('line-height', '1.5em')
end
root
end
renderOverImage()
renderSubheaders()
renderImages()
preprocessSingleArg(dependArgName)
end
end
end
end
a = a + step
end
end
 
function preprocessSpecificStyle(styleTable, step)
-- Assign the parameters *style to the args table
local a = 1 -- Counter variable.
local moreArgumentsExist = true
while moreArgumentsExist == true do
moreArgumentsExist = false
for i = a,a + step - 1 do
for j,v in ipairs(styleTable) do
local styleArgName = v.arg .. tostring(i) .. 'style'
if origArgs[styleArgName] then
moreArgumentsExist = true -- Do another loop if any arguments are found, even blank ones.
preprocessSingleArg(styleArgName)
end
end
preprocessSingleArg('subbox')
preprocessSingleArg('bodystyle')
preprocessSingleArg('overimage')
preprocessSingleArg('overcaption')
preprocessSingleArg('overimagerowclass')
preprocessSingleArg('title')
preprocessSingleArg('titleclass')
{prefix = 'rowclass'},
{prefix = 'rowstyle'},
{prefix = 'rowcellstyle'},
{prefix = 'class'},
{prefix = 'dataid'},
{prefix = 'headerid'},
{prefix = 'rowid'}
}, 80) preprocessSpecificStyle({ {arg = 'header'}, {arg = 'label'}, {arg = 'data'} }, 8050)
preprocessSingleArg('headerclass')
preprocessSingleArg('headerstyle')