MediaWiki:Classengine-template-module-class-page

This is [[MediaWiki:Tagline]]. Set to <code>display:none</code> by chameleon skin.
Wechseln zu:Navigation, Suche

local FoundationClass = require('Module:Foundationclass') local ClassDebug = require('Module:Debug/class')

-- **************************************************************** -- * inheritance * -- **************************************************************** local $2 = FoundationClass:subclass('$1') -- setting class's configuration data $2.static.myConfiguration = mw.loadData('Module:$1/config') -- this means, modules on subpages have a / in their names -- being in a static method, use self.myConfiguration -- being in a private method, that knows self or in a public method, use self.class.myConfiguration

-- **************************************************************** -- * properties * -- ****************************************************************

-- **************** initialization of table for private properties local _private = setmetatable({}, {__mode = 'k'}) -- weak table storing all private attributes

-- **************** declaration of public static properties -- $2.static.myPropertyModule = require('Module:extern') -- $2.static.staticProperty = ' '

-- remember the static classes provided by Foundationclass: -- $2.globalConfig -- $2.myCargoUtil -- $2.mySmwUtil -- $2.myTableTools -- $2.myYesno

-- **************** declaration of (global) private properties -- for properties you should rather use constructor and _private[self]. this only, if you need a private class property -- you should, however predeclare private methods here local _debug -- private method declared later local _privateMethodAhead -- declaration ahead, so this private method can be used in the constructor and in other private methods

-- *************************************************************** -- * methods * -- ***************************************************************

-- **************** declaration of static methods function $2:initialize(uid, superhandler) local _CFG = self.class.myConfiguration FoundationClass.initialize(self, uid, superhandler) _private[self] = { dbg = ClassDebug:new(tostring(self.class) .. ': id ' .. uid), } _debug(self, 1, ' $2: done initializing object "' .. uid ..'", from ' .. tostring(self)) end

-- use use self.myConfiguration to access your configuration in a static method function $2.static:aStaticMethod(var) _debug(self, 1, 'entering $2.static:aStaticMethod() to do something, from ' .. tostring(self)) end

function $2.static:mySfDynamicFieldAttribute(fieldname, attribute, value) _debug(self, 1, 'entering $2.static:mySfDynamicFieldAttribute(fieldname, attribute, value), from ' .. tostring(self)) _debug(self, 2, ' with parameters "' .. fieldname .. '", "' .. attribute .. '" and a ' .. type(value) .. ' value') -- function that can process any attribute/value pair just before rendering the semantic forms field -- usually done, to generate a dynamic 'default' value -- keep in mind: you can completely disable a form field, if you return true on attribute "disable". -- however, this causes the parameter to not show at all, neither in the form, nor in processing local val = value if fieldname == 'this' and attribute == 'that' then val = 'whatever ' .. val end return val -- this value will be used as new value for field's attribute end

-- **************** declaration of private methods -- use self.class.myConfiguration to access your configuration in a public or a private method that is called by a public method _debug = function (self, level, text) if _private[self] and _private[self].dbg then local debugLevel = FoundationClass.globalConfig.debugLevel or self.class.myConfiguration.global.debugLevel if debugLevel and level <= debugLevel then _private[self].dbg:log(level, text) end else local debugLevel = FoundationClass.globalConfig.debugLevel or self.myConfiguration.global.debugLevel if debugLevel and level <= debugLevel then ClassDebug:log(level, text, tostring(self) .. '.static') end end end

local _privateMethod = function (self) _debug(self, 1, 'entering private _privateMethod() to do something, from ' .. tostring(self)) end

-- **************** declaration of public methods -- use self.class.myConfiguration to access your configuration in a public method function $2:addInfobox() _debug(self, 1, 'entering $2:addInfobox(), from ' .. tostring(self)) if self:goodToGo() then local _CFG = self.class.myConfiguration local coreData = self:getCoreData() local ib_args = { bodyclass = 'infobox_name', aboveclass = 'objtitle titletext', headerclass = 'headertext', labelstyle = 'width: 30%;', datastyle = 'width: 70%;', title = self:getUid(), subheader = nil, label1 = _CFG.parameter.name.label, data1 = coreData.name and coreData.name or nil, header1 = nil, } self:addOutput(require('Module:Infobox').infobox(ib_args)) return true end return false end

function $2:addPageBody() _debug(self, 1, 'entering $2:addPageBody(), from ' .. tostring(self)) _debug(self, 2, ' rendering errors and warnings and adding them to output') local frame = mw.getCurrentFrame() self:addOutput(self:renderErrors()) self:addOutput(self:renderWarnings()) if self:goodToGo() then self:addOutput('No output yet') return true end return false end

function $2:myArgumentProcessing(coreData) _debug(self, 1, 'entering $2:myArgumentProcessing(args) to process coreData, from ' .. tostring(self)) -- function that performs some individual transformation args --> coreData -- remember: you can add warnings to your output with self:addWarning(warning). the page, however, will not be put in any gardening category. for that, use self:addError() -- hint: for conversion bool values, this is useful: FoundationClass.myYesno local coreData = coreData return coreData -- this is your new coreData. end

function $2:myDataAdjustments(data) _debug(self, 1, 'entering $2:myDataAdjustments(data) to convert data from data store into data suitable for argument processing, from ' .. tostring(self)) -- function that performs some individual transformation datastore data into argument data -- keep in mind, when using smw data store, that data is indexed by parameter names, not properties -- hint: for conversion bool values, this is useful: FoundationClass.myYesno local data = data return data -- this is your new data table, being passed on to initFromArgs and subsequently to plausibility testing end

function $2:myPlausibilityTest(args) _debug(self, 1, 'entering $2:myPlausibilityTest(args) to test arguments, from ' .. tostring(self)) -- function that performs the individual plausibility tests -- note: before you access a field args.fieldname you should check for existance -- use self:addError(text); this also puts the page in its class's gardening category return false -- return value will be ignored. but if you add any error, the object's initialization will fail with the error end

function $2:myStashAdjustments(stash, storeType) _debug(self, 1, 'entering $2:myStashAdjustments(stash) to do some minor adjustments on data before storing, from ' .. tostring(self)) -- function that alters the stash before storing the data. if necessary, you can complate skip storing this stash, if you return false or the empty table {} -- storeType is the actual method of storage for this call. either 'cargo', or 'smw' -- hint: for conversion bool values, this is useful: FoundationClass.myYesno local stash = stash return stash -- this is your new stash. this will be stored. it has format (fieldname: value) end

function $2:method() _debug(self, 1, 'entering $2:method() to do something, from ' .. tostring(self)) return true end

return $2