2,693
次編輯
(新頁面: -- -- This module implements {{Infobox}} -- 中文的此模塊對比英文維基多解析了overimage, overcaption, -- overimagerowclass以及header/labal/data*style參數。 -- local...) 標籤:wikipedia text |
(從維基百科更新) |
||
-- overimagerowclass以及header/labal/data*style參數。
--
local p = {}
local
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
:cssText(rowArgs.headerstyle)
:wikitext(rowArgs.header)
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(rowArgs.data)
end
end
if not args.overimage then return end
local row = root
if args.overcaption then
topImage.wikitext(args.overimage)▼
topImage:wikitext(args.overimage .. '<br />' .. args.overcaption)
else
end
end
end
local function renderTitle()
if not args.title then return end
root
end
local function renderAboveRow()
if not args.above then return end
root
end
local function renderBelowRow()
if not args.below then return end
root
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 =
if caption then
data
▲ .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)],
label = args['label' .. tostring(num)],
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
}
end
local italicTitle = args['italic title'] and mw.ustring.lower(args['italic title'])
if italicTitle == '' or italicTitle == 'force' or italicTitle == 'yes' then
root
end
end
if args.decat ~= 'yes' then
if #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then
root
end
if args.child == 'yes' and args.title then
root
end
end
-- if the infobox is used as a 'child' inside another infobox.
if args.child ~= 'yes' then
root =
root
if args.subbox == 'yes' then
root
else
root
end
root
renderTitle()
renderAboveRow()
else
root =
root
end
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 = '
{prefix = 'class'},
{prefix = 'dataid'},
{prefix = 'labelid'},
{prefix = 'headerid'},
{prefix = 'rowid'}
}, 80)
preprocessSpecificStyle({
{arg = 'data'}
}, 80)
preprocessSingleArg('headerstyle')
preprocessSingleArg('labelstyle')
args['italic title'] = origArgs['italic title'] -- different behaviour if blank or absent
preprocessSingleArg('decat')
return _infobox()
end
return p
|