「模組:Infobox」:修訂間差異

跳至導覽 跳至搜尋
增加 1,072 位元組 、​ 2019年10月4日 (星期五)
從維基百科更新
(新頁面: -- -- This module implements {{Infobox}} -- 中文的此模塊對比英文維基多解析了overimage, overcaption, -- overimagerowclass以及header/labal/data*style參數。 -- local...)
標籤wikipedia text
 
(從維基百科更新)
 
-- overimagerowclass以及header/labal/data*style參數。
--
 
local p = {}
 
local HtmlBuildernavbar = require('Module:HtmlBuilderNavbar')._navbar
 
local args = {}
local root
 
local function union(t1, t2)
-- Returns the union of the values of two tables, as a sequence.
local vals = {}
for k, v in pairs(t1) do
vals[v] = true
end
for k, v in pairs(t2) do
vals[v] = true
end
local ret = {}
for k, v in pairs(vals) do
table.insert(ret, k)
end
-- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
local nums = {}
for k, v in pairs(args) do
local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
if num then table.insert(nums, tonumber(num)) end
if rowArgs.header then
root
.:tag('tr')
.:addClass(rowArgs.rowclass)
.tag:cssText('th'rowArgs.rowstyle)
.:attr('colspanid', 2rowArgs.rowid)
.addClass:tag(rowArgs.class'th')
.css:attr('text-aligncolspan', 'center'2)
.cssText:attr('id', rowArgs.headerstyleheaderid)
.wikitext:addClass(rowArgs.headerclass)
.cssText:addClass(args.captionstyleheaderclass)
.wikitext:css(caption'text-align', 'center')
:cssText(rowArgs.headerstyle)
:wikitext(rowArgs.header)
elseif rowArgs.data then
local row = root.:tag('tr')
row.:addClass(rowArgs.rowclass)
row:cssText(rowArgs.rowstyle)
row:attr('id', rowArgs.rowid)
if rowArgs.label then
row
.:tag('th')
.:attr('scope', 'row')
.:css('text-align', 'left')
.cssText:attr('id', rowArgs.labelstylelabelid)
.wikitext:cssText(rowArgs.labellabelstyle)
.done:wikitext(rowArgs.label)
:done()
end
 
local dataCell = row.:tag('td')
if not rowArgs.label then
dataCell
.:attr('colspan', 2)
.:css('text-align', 'center')
end
dataCell
.addClass:attr('id', rowArgs.classdataid)
.cssText:addClass(rowArgs.datastyleclass)
.newline:cssText(rowArgs.datastyle)
.wikitext:newline(rowArgs.data)
:wikitext(rowArgs.data)
end
end
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.classimageclass)
topImage.:cssText(args.datastyleimagestyle)
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)
topImage:wikitext(args.overimage .. '<br />' .. args.overcaption)
end
else
topImage.:wikitext(args.overimage)
end
end
end
 
local function renderTitle()
if not args.title then return end
 
root
.:tag('caption')
.:addClass(args.titleclass)
.:cssText(args.titlestyle)
.:wikitext('\'\'\'' .. args.title .. '\'\'\'')
end
 
local function renderAboveRow()
if not args.above then return end
root
.:tag('tr')
.:tag('th')
.:attr('colspan', 2)
.:addClass(args.aboveclass)
.:css('text-align', 'center')
.:css('font-size', '125%')
.:css('font-weight', 'bold')
.:cssText(args.abovestyle)
.:wikitext(args.above)
end
 
local function renderBelowRow()
if not args.below then return end
 
root
.:tag('tr')
.:tag('td')
.:attr('colspan', '2')
.:addClass(args.belowclass)
.:css('text-align', 'center')
.:cssText(args.belowstyle)
.:newline()
.:wikitext(args.below)
end
 
end
local subheadernums = getArgNums('subheader')
for k, num in ipairs(subheadernums) do
addRow({
data = args['subheader' .. tostring(num)],
end
local imagenums = getArgNums('image')
for k, num in ipairs(imagenums) do
local caption = args['caption' .. tostring(num)]
local data = HtmlBuildermw.html.create().:wikitext(args['image' .. tostring(num)])
if caption then
data
.:tag('brdiv', {selfClosing = true})
.done:cssText(args.captionstyle)
.tag :wikitext('div'caption)
.cssText(args.captionstyle)
.wikitext(caption)
end
addRow({
local rownums = union(getArgNums('header'), getArgNums('data'))
table.sort(rownums)
for k, num in ipairs(rownums) do
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)],
dataid = args['dataid' .. tostring(num)],
labelid = args['labelid' .. tostring(num)],
headerid = args['headerid' .. tostring(num)],
rowid = args['rowid' .. tostring(num)]
})
end
local function renderNavBar()
if not args.name then return end
root
.:tag('tr')
.:tag('td')
.:attr('colspan', '2')
.:css('text-align', 'right')
.:wikitext(mw.getCurrentFrame():expandTemplate(navbar{
title = 'navbar'args.name,
args = { args.name, mini = 1 },
}))
end
 
local italicTitle = args['italic title'] and mw.ustring.lower(args['italic title'])
if italicTitle == '' or italicTitle == 'force' or italicTitle == 'yes' then
root.:wikitext(mw.getCurrentFrame():expandTemplate({title = 'italic title'}))
end
end
if args.decat ~= 'yes' then
if #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then
root.:wikitext('[[Category:使用無數據行信息框模板的條目]]')
end
if args.child == 'yes' and args.title then
root.:wikitext('[[Category:使用帶有標題參數的嵌入式信息框模板的條目]]')
end
end
-- if the infobox is used as a 'child' inside another infobox.
if args.child ~= 'yes' then
root = HtmlBuildermw.html.create('table')
 
root
.:addClass('infobox')
.:addClass(args.bodyclass)
.:attr('cellspacing', 3)
.:css('border-spacing', '3px')
 
if args.subbox == 'yes' then
root
.:css('padding', '0')
.:css('border', 'none')
.:css('margin', '-3px')
.:css('width', 'auto')
.:css('min-width', '100%')
.:css('font-size', 'small')
.:css('clear', 'none')
.:css('float', 'none')
.:css('background-color', 'transparent')
else
root
.:css('width', '22em')
.:css('text-align', 'left')
.:css('font-size', 'small')
.:css('line-height', '1.5em')
end
root
.:cssText(args.bodystyle)
 
renderTitle()
renderAboveRow()
else
root = HtmlBuildermw.html.create()
 
root
.:wikitext(args.title)
end
 
renderOverImage()
renderSubheaders()
renderImages()
renderItalicTitle()
renderTrackingCategories()
 
return tostring(root)
end
error("Invalid step value detected", 2)
end
 
-- Get arguments without a number suffix, and check for bad input.
for i,v in ipairs(prefixTable) do
-- Only parse the depend parameter if the prefix parameter is present and not blank.
if args[v.prefix] and v.depend then
for j, dependValue in ipairs(v.depend) do
if type(dependValue) ~= 'string' then
error('Invalid "depend" parameter value detected in preprocessArgs')
end
end
 
function p.infobox(frame)
-- If called via #invoke, use the args passed into the invoking template.
origArgs = frame
end
 
-- Parse the data parameters in the same order that the old {{infobox}} did, so that
-- references etc. will display in the expected places. Parameters that depend on
preprocessSingleArg('aboveclass')
preprocessSingleArg('abovestyle')
preprocessSingleArg('aboverowclass')
preprocessArgs({
{prefix = 'subheader', depend = {'subheaderstyle', 'subheaderrowclass'}}
{prefix = 'data', depend = {'label'}},
{prefix = 'rowclass'},
{prefix = 'classrowstyle'},
{prefix = 'class'},
{prefix = 'dataid'},
{prefix = 'labelid'},
{prefix = 'headerid'},
{prefix = 'rowid'}
}, 80)
preprocessSpecificStyle({
{arg = 'data'}
}, 80)
preprocessSingleArg('aboverowclassheaderclass')
preprocessSingleArg('headerstyle')
preprocessSingleArg('labelstyle')
args['italic title'] = origArgs['italic title'] -- different behaviour if blank or absent
preprocessSingleArg('decat')
 
return _infobox()
end
 
return p
2,693

次編輯

導覽選單