Module:Infobox: Difference between revisions

no edit summary
(Replaced content with "--[=[ -- For documentation, see Module:Infobox/doc --]=] -- <nowiki> local Infobox = {} --[[ Infobox class -- args : parameters from frame to pass through -- Sets a meta table and creates a <div> tag wrapper -- other fields are initialized in other functions --]] function Infobox.new(args) local obj = setmetatable({ args = args, -- parameters (uncleaned) params = {}, -- param definition infobox_name = nil, -- template name }, Infobox) r...")
Tag: Replaced
No edit summary
Line 4:
 
-- <nowiki>
local smw = require('Module:SMW Utils')
 
local Infobox = {}
Infobox.__index = Infobox
 
--[[
Line 15 ⟶ 18:
local obj = setmetatable({
args = args, -- parameters (uncleaned)
params = {}, -- param definition
infobox_name = nil, -- template name
param_names = {}, -- ordered param list
params = {}, -- param definitiondefinitions
versions = nil, -- number of versions
version_names = {}, -- title of each version (for selection and SMW)
errors = {} -- list of errors
},
Infobox)
obj:parse_versions()
return obj
end
Line 56 ⟶ 64:
end
self.params[v.name] = param
table.insert(self.param_names, v.name)
end
end
return self
end
 
--[[
Counts the number of versions in the infobox
Also validates the names of all the versions to be valid SMW subobjects
--]]
function Infobox:parse_versions()
-- Count the versions
local i = 1
while self.args['version'..i] do
-- Validate and register the version name
local version_name = self.args['version'..i]
if not smw.valid_subobject_name(version_name) then
table.insert(self.errors, 'Invalid Version Name (must not be "0", "" or contain a "." in the first 5 characters): version'..i..'='..version_name)
version_name = '###'..i..'_'..version_name
end
table.insert(self.version_names, version_name)
i = i + 1
end
self.versions = i - 1
end
 
 
function Infobox.param(paramname)
Line 74 ⟶ 105:
}
return param
end
 
function Infobox:dump()
mw.log(mw.dumpObject(self))
end