Modul:City/class
| This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
This is a Class Module. It implements a class in Lua using Module:Middleclass and the template class Module:Foundationclass. This class provides methods for PURPOSE.
Usage[Quelltext bearbeiten]
local name = args[1] or args.name or mw.title.getCurrentTitle().rootText
local Class = require('Module:City/class')
local me = Class:new(mw.title.getCurrentTitle().prefixedText)
me:initFromArgs(args)
me:storeData()
me:addInfobox()
me:addPageBody()
return me:render()
Data Storage
Semantic properties used in this class: |
|---|
|
Methods[Quelltext bearbeiten]
Constructor[Quelltext bearbeiten]
new(uid, superhandler)[Quelltext bearbeiten]
Creates a new Object for the class.
- uid
- variable, optional
- used to identify the object
- superhandler
- object of childclass of Foundationclass, optional
- supply the superhandler, if you instanciate this object within another object. the instanciated object will pass errors and warnings to the superhandler and forgo adding the object category
- return
- object, of the class
public methods[Quelltext bearbeiten]
addInfobox()[Quelltext bearbeiten]
If no errors and data is present, adds an infobox to the object's output.
- return
- boolean, whether adding was successful or not
addPageBody()[Quelltext bearbeiten]
Adds a page body (all content besides the infobox) to the object's output: Errors and Warnings, sample configuration, statistics, ... Of course, only if there is data.
- return
- boolean, whether adding was successful or not
myArgumentProcessing(coreData)[Quelltext bearbeiten]
Performs the individual argument processing in initFromArgs(args) right before inititializing it.
- coreData
- table, mandatory
- the core data of the object. the one to process individually before initialization
- return
- table, the new core data array to be used
myDataAdjustments(data)[Quelltext bearbeiten]
Performs a transformation form data (coming from the datastore) into data used for argument processing. This is called by initFromData(data) (for smw: after property to parameter conversion) and is directly passed to initFromArgs(args) and subsequently plausibility test.
- data
- table, mandatory
- a data table coming directly from the data store
- return
- table, the new data table suiteable for argument processing
myPlausibilityTest(args)[Quelltext bearbeiten]
Performs the individual plausibility tests in initFromArgs(args) before entering the initialization part. NOTE: The return value will be ignored. If this finds errors, it must add them to the list of errors via addError(errortext).
- args
- table, mandatory
- arguments passed to the template to be checked
- return
- boolean, whether the object is plausible or not.
myStashAdjustments(stash, storeType)[Quelltext bearbeiten]
Performs the adjusts the stash in storeData() right before storing it.
- stash
- table, mandatory
- the array of data to be saved (in the form fieldname: value)
- storeType
- string, mandatory
- type of storage method used with the current call (either 'cargo' or 'swm'). In case you use both stores and your stash adjustment differs with each of this methods
- return
- boolean, the new stash
static methods[Quelltext bearbeiten]
ClassCity:mySfDynamicFieldAttribute(fieldname, attribute, value)[Quelltext bearbeiten]
For some semantic form fields there are attribute values, that are not static, thus can not be provided at forehand in the configuration file. This method does the trick to adapt them at runtime shortly before the field is rendered. Essentially: the method checks, if it has a special rule for the pair fieldname:attribute and if so, calculates the new value. if not, the old value is returned. Note, that you can completely disable a form field with this when you return false on attribute "disable".
- fieldname
- string, mandatory
- the form field's name, needed to match current paring to an existing special treatment rule
- attribute
- string, mandatory
- the form field's attribute, needed to match current paring to an existing special treatment rule
- value
- variable, mandatory
- the value, that is already provided in the configuration file. this will be adapted by the method, if there is a special rule for the pair fieldname:attribute.
- return
- string, the value to be used forthwith (which can be the old one or a freshly calculated)
private methods[Quelltext bearbeiten]
_debug(self, level, text)[Quelltext bearbeiten]
Adds output to the internal debug log.
- self
- object, me
- level
- int; mandatory
- debug level for the message
- text
- string; mandatory
- debug message text
- return
- void
Properties[Quelltext bearbeiten]
static[Quelltext bearbeiten]
See also Static Properties
- ClassCity.myConfiguration
- this is your configuration. It is devided in several section, each a
- table, holds configuration data found in Module:City/config
- WARNING: This is a read only table and besides functions pairs() and ipairs() nothing else will work on it, especially not the functions of the table library!
- form, table, holds data used to create the form. here are some of them:
- formButtons, table, which buttons should be printed at the bottom
- fieldOrder, table, in which order the form fields should appear (note: only fields listed here will be added to the form)
- global, table, holds some global configuration data
- parameter, table, holds all data about all parameter used in the module (be they form only, data store only or normal). The table has the form paramname = { table of paramdata }. The tables for the parameter have data as follows:
- cardinality, string, mandatory, one of singe or list
- cargo_type, string, optional, if the parameter is to be stored in cargo, add the field type here (one of Page, Text, Integer, Float, Date, Datetime, Boolean (which should be provided as 1 or 0), Coordinates, Wikitext, File, String, URL, or Email)
- description, string, mandatory, a description of this parameter
- label, string, mandatory, the label used in the form and the template documentation
- property_name, string, optional, if the parameter is to be stored in smw, add the property name here
- property_type, string, optional, if the parameter is to be stored in smw, add the property type here (defaults to page)
- severity, string, optional, if provided one of mandatory, suggested
- sf, table, optional, used to add more attributes to the semantic forms field. ref Module:SFfield/config for all possible attributes. Note that the table is of type attribute_name : value. Value can be of type string, integer, boolean, and (in case of 'show on select') a table. Please note, that the attribute name cannot contain a " " (space). Use the underscore instead.
- td_default, string, optional, if you want a default value to be indicated in the template data section on the documentation page, add it here
- td_type, string, optional, if the parameter should be present in the template documentation page, fill this field. all possible values are listed here
- values, table, optional, if you want the possible values to be restricted to a specific set, fill this table
- template, table, holds some data used only in the template
- ClassCity.publicStaticProperty
- type, explanation
- _privateStaticProperty
- type, explanation
private[Quelltext bearbeiten]
Note: all private properties are stored in table _private[self]. _private is a static array that is indexed by self, so the table _private[self] holds all properties for instance self.
- dbg
- object, my instance of Module:Debug/class for debugging purposes. only present afer first call of _debug(self, level, text)
Configuration Data[Quelltext bearbeiten]
This class holds its control data in Module:City/config.
Inheritance[Quelltext bearbeiten]
Note: You still reference those either by self:publicMethod() or ClassCity:staticMethod() and ClassCity.staticProperty respectively!
Methods[Quelltext bearbeiten]
Constructor[Quelltext bearbeiten]
| Warning When you instantiate an object from another object, you have to supply the superhandler. Otherwise you might get categorized or defaultsorted! |
| Warning If you want to be able to use initMyself(), then you have to submit the correct uid-value here. The method must be able to identify itself by this value! |
new(uid, superhandler)[Quelltext bearbeiten]
Creates a new Object for the class.
- uid
- variable, suggested
- used to identify the object. defaults to mw.title.getCurrentTitle().prefixedText
- superhandler
- object of childclass of Foundationclass, optional
- supply the superhandler, if you instanciate an object within another object. the instanciated object will pass errors and warnings to the superhandler and forgo adding an object category
- return
- object, of the class
Abstract Methods
Warning You have to implement (thus overwriting) the following abstract methods in your childclass, otherwise the execution of most of your methods will fail! Take note: FoundationClass:mySfDynamicFieldAttribute(fieldname, attribute, value) is a static method, the rest must be declared public! |
myArgumentProcessing(coreData)[Quelltext bearbeiten]
Performs the individual argument processing in initFromArgs(args) right before inititializing it.
- coreData
- table, mandatory
- the core data of the object. the one to process individually before initialization
- return
- table, the new core data array to be used
myDataAdjustments(data)[Quelltext bearbeiten]
Performs a transformation form data (coming from the datastore) into data used for argument processing. This is called by initFromData(data) (for smw: after property to parameter conversion) and is directly passed to initFromArgs(args) and subsequently plausibility test.
- data
- table, mandatory
- a data table coming directly from the data store
- return
- table, the new data table suiteable for argument processing
myPlausibilityTest(args)[Quelltext bearbeiten]
Performs the individual plausibility tests in initFromArgs(args) before entering the initialization part. NOTE: The return value will be ignored. If this finds errors, it must add them to the list of errors via addError(errortext).
- args
- table, mandatory
- arguments passed to the template to be checked
- return
- boolean, whether the object is plausible or not.
myStashAdjustments(stash, storeType)[Quelltext bearbeiten]
Can adjusts the stash in storeData() right before storing it.
- stash
- table, mandatory
- the array of data to be saved (in the form fieldname: value)
- storeType
- string, mandatory
- type of storage method used with the current call (either 'cargo' or 'swm'). In case you use both stores and your stash adjustment differs with each of this methods
- return
- table, the new stash
FoundationClass:mySfDynamicFieldAttribute(fieldname, attribute, value)[Quelltext bearbeiten]
For some semantic form fields there are attribute values, that are not static, thus can not be provided at forehand in the configuration file. This method does the trick to adapt them at runtime shortly before the field is rendered. Essentially: the method checks, if it has a special rule for the pair fieldname:attribute and if so, calculates the new value. if not, the old value is returned. Note, that you can completely disable a form field with this when you return false on attribute "disable".
- fieldname
- string, mandatory
- the form field's name, needed to match current paring to an existing special treatment rule
- attribute
- string, mandatory
- the form field's attribute, needed to match current paring to an existing special treatment rule
- value
- variable, mandatory
- the value, that is already provided in the configuration file. this will be adapted by the method, if there is a special rule for the pair fieldname:attribute.
- return
- string, the value to be used forthwith (which can be the old one or a freshly calculated)
Public methods
addCategory(category)[Quelltext bearbeiten]
Prepares to add the page to category category. Note: until you actually call render() or renderCategories(), this will not be implemented
- category
- string, mandatory
- the name of the category, to add the page to
- return
- boolean, true
addError(errortext)[Quelltext bearbeiten]
adds errortext as new error to the list of errors, rendered at a later time.
- errortext
- string, mandatory
- text added to list of errors
- return
- boolean, whether adding was successful or not
addInfobox()[Quelltext bearbeiten]
If no errors and data is present, adds an infobox to the object's output. NOTE: This is a shell method and should be overwritten!
- return
- boolean, whether adding was successful or not
addOutput(content)[Quelltext bearbeiten]
Adds something to the page's output. Something can be of type string, int, or table (that needs to have __tostring() implemented)
- content
- string, int, or table; mandatory
- content element that is added to page's output
- return
- boolean, whether adding was successful or not
addPageBody()[Quelltext bearbeiten]
Adds a page body (all content besides the infobox) to the object's output: Errors and Warnings, sample configuration, statistics, ... Of course, only if there is data. NOTE: This is a shell method and should be overwritten!
- return
- boolean, whether adding was successful or not
addWarning(warning)[Quelltext bearbeiten]
adds warning as new warning to the list of warnings, to be rendered at a later time (with renderWarnings()).
- warning
- string, mandatory
- text added to list of warnings
- return
- boolean, whether adding was successful or not
getCoreData()[Quelltext bearbeiten]
Returns the table of coreData
- return
- table, the value for _private[self].coreData, emtpy if not initialized
getUid()[Quelltext bearbeiten]
Returns the object's uid, nil if not set
- return
- variable, the value for _private[self].uid
goodToGo()[Quelltext bearbeiten]
Is this a proper object (with data and no errors)
- return
- boolean, whether we are proper initialized
initFromArgs(args)[Quelltext bearbeiten]
Initializes the object with a data table, containing arguments (template parameter). Does plausibility tests and mangling of input and either fills list of errors or adds input to the object's data. {{{1}}}
initFromData(data)[Quelltext bearbeiten]
Initializes the object with a data table, coming from the datastore. Depending on datastore, that means that the table keys might be different than when using arguments form the template. Does plausibility tests and mangling of input and either fills list of errors or adds input to the object's data. {{{1}}}
initMyself(uid)[Quelltext bearbeiten]
Initializes the object with data from the data store. The method queries for the object's uid in the container defined by Foundationclass.globalConfig.uidFieldName (can be set to an infividual name in Module:Foundationclass/globalconfig) in either the class's table (in case of datastore cargo) or for objects that have Foundationclass.globalConfig.smwClassProperty set to class.name (in case of datastore smw). The uid was either passed to the method (priority) or submitted to the constructor. Does NOT do plausibility tests and mangling of input but assumes the data comes directly from the data store and thus can be trusted (i.e. passes _plausibilityTest())
- uid
- string, optional
- the data, the object can use to identify itself. This field can be omitted, in which case the uid that was submitted to the constructor will be used.
- return
- boolean, whether initialization was successful or not
render()[Quelltext bearbeiten]
Renders the object's output
- return
- string, the textual representation of the object (which can vary, depending on what add*-methods you called before)
renderCategories()[Quelltext bearbeiten]
Renders the object's categories (if any), thus adding them to the output stream and in turn sorting the page in it, if and only if render() is called on the object's page (when self:getUid == City/class).
- return
- object of type mw.html, the wikitext necessary to add the page to the categories
renderErrors()[Quelltext bearbeiten]
Renders the object's errors (if any)
- return
- object of type mw.html, the representation of the list of errors
renderWarnings()[Quelltext bearbeiten]
Renders the object's warnings (if any)
- return
- object of type mw.html, the representation of the list of warnings
setSortkey(sortkey)[Quelltext bearbeiten]
Sets a default sortkey for this page using the magic word DEFAULTSORT. Only applies, if no superhandler is given.
- sortkey
- string, mandatory
- new sortkey for this page
- return
- void
setUid(value)[Quelltext bearbeiten]
Sets my uid to the given value. normally this should be set by constructor
- value
- string/integer, mandatory
- new valued for my uid
- return
- boolean, true/false
storeData()[Quelltext bearbeiten]
If this was initialized with outside data and there are no errors, stores the arguments in an appropriate data store (smw or cargo). In case of cargo, also calls the necessary #cargo_declare parser function if in the template namespace.
- return
- boolean, whether store was successful or not
Static methods
FoundationClass:categorize()[Quelltext bearbeiten]
Placed on one to class's pages (usually not on the class object pages), this calculates the necessary (meta-) category, to put the page in, using pagetitle, subpagetitle, namespace, and so on. Your project's categories (defined in Module:Foundationclass/globalconfig) are used.
- return
- string, to be put on page, so that it will be categorized
FoundationClass:categoryPage()[Quelltext bearbeiten]
Procudes the output for our corresponding category page. Including the message box and the display of the data structure.
- return
- object of type mw.html, the representation of the category page's content
FoundationClass:cargoGenerateTableStructure()[Quelltext bearbeiten]
Produces a cargo table declaration array (fieldname => declaration of field) that can be used in method storeData() for cargo_declare.
- return
- table, data structure for cargo table
FoundationClass:explainDataStore()[Quelltext bearbeiten]
Produces a textual explanation of the used datastructure (table definition for cargo or property list and types for smw) that can be printed on various dodumentation pages
- return
- string, a textual explanation
FoundationClass:formRedlink(target, form, linktext, queryString)[Quelltext bearbeiten]
Takes a pagename (target) and a formname (form) and then generates a link to that page if the page exists. Otherwise it links to the form to create the page. Linktext is target per default, if you do not provide linktext
- target
- string, mandatory
- the pagename (including namespace) to link to
- form
- string, mandatory
- the name of the form (w/o the form namespace!!) to fallback to, if page does not exist
- linktext
- string, optional
- text you want to display instead of target
- queryString
- string, optional
- the query string provided to the form, e.g.
'Template[page]=' .. mw.title.getCurrentTitle().prefixedText - return
- string, the requested link
FoundationClass:gardeningCategoryPage()[Quelltext bearbeiten]
Procudes the output for the class' gardening category page (if any). Includung the message boxes.
- return
- object of type mw.html, the representation of the gardening category page's content
FoundationClass:mwLink(object)[Quelltext bearbeiten]
Takes object and links it (adding square brackets). If object is a table, it iterates over it with lua's mw.text.listToText()
- object
- mixed
- object to return as linked string(s)
- return
- string, with all elements of object mw-linked
FoundationClass:placeInNamespace(pagename, namespace)[Quelltext bearbeiten]
Makes sure, that (string) pagename resides in (string) namespace. Returns the pagename w/ new namespace and w/o any namespace
- pagename
- string
- name of page to be prepended with new namespace
- namespace
- string
- new namespace for page
- return
- string, full page name in new namespace
- string, base page name without any namespace
FoundationClass:sfGenerateForm()[Quelltext bearbeiten]
Generates all output necessary for a form, that can be used to create or maintain an object of this class. Note: this output is to be put inside the <includeonly>-tag on the Form page.
- return
- object of class mw.html, the representation of the form
FoundationClass:sfGenerateFormEntry()[Quelltext bearbeiten]
Generates the "teaser" text shown on the form page when accessing it to create a form (before you type in the name in the input field)
- return
- object of class mw.html, the representation of the form teaser
FoundationClass:sfGenerateFormInfoTag()[Quelltext bearbeiten]
Generates a form's info-tag, together with create and edit title and - if applicable - the query string (in case we have createLinkType formlink).
- return
- string, a semantic form info tag
FoundationClass:sfGenerateFormLink(params)[Quelltext bearbeiten]
Generates a form input field or a form link that links to the class's form (essentially calls the parser function #forminput or #formlink respectively).
- params
- table, data to pass to the form link/input generator. supported fields are: label and query string
- return
- string, the input field, that lints to the form
FoundationClass:sfGenerateFormTable(fieldlist)[Quelltext bearbeiten]
Generates a table that can be used in a form inside the {{{for template}}} tag. The table contains all fields, that are named in the table parameter fieldlist (which defaults to _CFG.form.fieldOrder) and that are present in _CFG.parameter.. All fields with attribute hidden are placed after the closing /table-tag
- fieldlist
- table, optional
- contains a list of fieldnames, to be processed and added to the return node.
- return
- object of class mw.html, the representation of the formtable
FoundationClass:sfInitField(fieldname)[Quelltext bearbeiten]
Creates a field object of Class SFfield and initializes it per myConfiguration.parameters[fieldname] if entry is present
- fieldname
- string, mandatory
- contains the name of the field to initialize
- return
- object of Class SFfield, the initialized field object. nil if fieldname is not present in parameter-array
FoundationClass:smwGetProperty2ParameterTranslationTable()[Quelltext bearbeiten]
Returns a translation table property-name => parametername, if data store smw is used.
- return
- table, for every property used in the class the corresponding parameter name
FoundationClass:templateDocumentation()[Quelltext bearbeiten]
Generates almost all the output, necessary to have a good documentation page for the corresponding template. Only missing the {{documentation subpage}} call at the top and the includeonly part at the bottom.
- return
- object of class mw.html, the representation of the template documentation
FoundationClass:usesDataStore(store)[Quelltext bearbeiten]
Returs true, if class uses store as datastore. Available stores are 'cargo' and 'smw'
- store
- string, mandatory
- store type to check against
- return
- bool, whether store store is used as data store
Static Properties[Quelltext bearbeiten]
- FoundationClass.globalConfig
- table, holds some global configuration (data, that applies to all classes the same way). See Module:Foundationclass/globalconfig for details.
- FoundationClass.myCargoUtil
- table, instance of Module:CargoUtil
- FoundationClass.mySwmUtil
- table, instance of Module:SmwUtil
- FoundationClass.myTableTools
- table, instance of Module:TableTools
- FoundationClass.myYesno
- table, instance of Module:Yesno
Maintenanace notes
This page was created by Module:Classgenerator and belongs to Class:City.
local FoundationClass = require('Module:Foundationclass')
local ClassDebug = require('Module:Debug/class')
-- ****************************************************************
-- * inheritance *
-- ****************************************************************
local ClassCity = FoundationClass:subclass('City')
-- setting class's configuration data
ClassCity.static.myConfiguration = mw.loadData('Module:City/config')
-- 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
-- ClassCity.static.myPropertyModule = require('Module:extern')
-- ClassCity.static.staticProperty = ' '
-- remember the static classes provided by Foundationclass:
-- ClassCity.globalConfig
-- ClassCity.myCargoUtil
-- ClassCity.mySmwUtil
-- ClassCity.myTableTools
-- ClassCity.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 ClassCity: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, ' ClassCity: done initializing object "' .. uid ..'", from ' .. tostring(self))
end
-- use use self.myConfiguration to access your configuration in a static method
function ClassCity.static:aStaticMethod(var)
_debug(self, 1, 'entering ClassCity.static:aStaticMethod() to do something, from ' .. tostring(self))
end
function ClassCity.static:mySfDynamicFieldAttribute(fieldname, attribute, value)
_debug(self, 1, 'entering ClassCity.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 ClassCity:addInfobox()
_debug(self, 1, 'entering ClassCity:addInfobox(), from ' .. tostring(self))
if self:goodToGo() then
local _CFG = self.class.myConfiguration
local coreData = self:getCoreData()
local ib_args = {
bodyclass = 'infobox_stadt',
aboveclass = 'objtitle titletext',
aboveclass = 'headertext typ_plain',
headerclass = 'headertext typ_plain',
labelstyle = 'width: 40%;',
datastyle = 'width: 60%;',
title = self:getUid(),
above = 'Stadt',
image = coreData.image and '[[' .. coreData.image ..'|300px|' .. self:getUid() .. ']]' or nil,
caption = coreData.image and self:getUid() or nil,
label1 = _CFG.parameter.sect.label,
data1 = coreData.sect and coreData.sect or nil,
label2 = _CFG.parameter.population.label,
data2 = coreData.population and coreData.population or nil,
--header1 = nil,
}
if coreData.officesAvailable and coreData.offices then
for i, office in pairs(coreData.officesAvailable) do
ib_args['label' .. (i+5)] = office
ib_args['data' .. (i+5)] = (coreData.offices[office] and '[[' .. mw.text.listToText(coreData.offices[office], ']], [[', ']] und [[') .. ']]' or nil)
end
end
self:addOutput(require('Module:Infobox').infobox(ib_args))
return true
end
return false
end
function ClassCity:addPageBody()
_debug(self, 1, 'entering ClassCity: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
local coreData = self:getCoreData()
if coreData.history then
local history = mw.html.create('')
history:wikitext('<h2>Geschehnisse vor Ort</h2>')
:newline()
for _, row in pairs(coreData.history) do
local cast = row.maincast or row.cast
history:wikitext('* ' .. row.start .. (row.stop and ' - ' .. row.stop or '') .. ': '
.. '[[' .. (row.page and (row.page .. '|' .. row.title) or row.MainLabel) .. ']]; Anwesend: '
.. '[[' .. mw.text.listToText(cast, ']], [[', ']] und [[') .. ']]; Geschehnisse: ' .. row.description)
:newline()
end
self:addOutput(history)
end
if coreData.locations then
local locations = mw.html.create('')
local headline = {
Zuflucht = 'Bekannte Zuflüchte',
Elysium = 'Ausgewiesene Elysien',
Gildehaus = 'Gildehäuser',
Wohnort = 'Wohnungen von relevanten Personen',
Sonstiges = 'Sonstiges'
}
headline['Besonderer Ort'] = 'Besondere Orte'
headline['Mundaner Ort'] = 'Mundane Orte'
local oldHeadline = ''
local widths = {
box = '800',
image = '300'
}
locations:wikitext('<h2>Bekannte Schauplätze</h2>')
:newline()
for _, row in pairs(coreData.locations) do
if oldHeadline ~= row['function'] then
oldHeadline = row['function']
if headline[row['function']] then
locations:wikitext('<h3>' .. headline[row['function']] .. '</h3>')
:newline()
else
locations:wikitext('<h3>' .. row['function'] .. '</h3>')
:newline()
end
end
-- local td2 = mw.html.create('div')
-- td2:css('display', 'table-cell')
local td2 = mw.html.create('td')
td2:css('vertical-align', 'top')
:css('padding', '0px')
:css('width', widths.image .. 'px')
if row.image then
td2:wikitext('[[' .. row.image .. '|' .. widths.image .. 'px|link=|' .. row.name .. ']]')
:newline()
end
-- local td1 = mw.html.create('div')
-- td1:css('display', 'table-cell')
local td1 = mw.html.create('td')
td1:css('vertical-align', 'top')
:css('padding', '10px')
:wikitext('<strong>[[' .. row.MainLabel .. '|' .. row.name .. ']]</strong>')
:newline()
if row.address then
td1:wikitext(';Adresse')
:newline()
:wikitext(':' .. row.address)
:newline()
end
if row.operator then
td1:wikitext(';Verantwortlich')
:newline()
:wikitext(':' .. row.operator)
:newline()
end
if row.residents then
td1:wikitext(';Anzutreffen')
:newline()
:wikitext(':' .. ((type(row.residents) == 'table') and ('[[' .. mw.text.listToText(row.residents, ']], [[', ']] und [[') .. ']]') or '[[' .. row.residents .. ']]'))
:newline()
end
td1:wikitext(row.description)
:newline()
-- :tag('div')
-- :css('clear', 'both')
-- :done()
-- local tr = mw.html.create('div')
-- tr:css('display', 'table-row')
local tr = mw.html.create('tr')
tr:node(td1)
:node(td2)
-- local css = {width=widths.box .. 'px', display='table'}
local css = {width=widths.box .. 'px'}
css['border-top'] = '2px black solid'
css['border-bottom'] = '2px grey solid'
css['margin-left'] = '20px'
css['margin-bottom'] = '20px'
-- local div = mw.html.create('div')
local t = mw.html.create('table')
t:attr('cellpadding', '0')
:attr('cellspacing', '0')
:css(css)
:node(tr)
locations:node(t)
end
self:addOutput(locations)
end
return true
end
return false
end
function ClassCity:myArgumentProcessing(coreData)
_debug(self, 1, 'entering ClassCity:myArgumentProcessing(args) to process coreData, from ' .. tostring(self))
-- function that performs some individual transformation args --&gt; 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
if coreData.image then
if mw.ustring.find(coreData.image, ':') then
coreData.image = mw.ustring.match(coreData.image, '^.*:([^:]+)$')
end
coreData.image = 'Bild:' .. coreData.image
end
-- now get the offices
local officePerSect = {
Camarilla = {
'Justikar',
'Archont',
'Prinz',
'Seneschall',
'Primogen',
'Major Urbanus',
'Sheriff',
'Geißel',
'Harpyie',
'Hüter des Elysiums',
'Monitor',
},
Sabbat = {
'Regent',
'Priscus',
'Inquisitor',
'Kardinal',
'Erzbischof',
'Bischof',
'Templer',
'Duktus',
'Priester',
'Monitor',
},
Anarchen = {
'Baron',
'Monitor',
},
}
local offices
local query = {
select = {'[[is_member_of_class::Person]] [[resides in::' .. self:getUid() .. ']] [[Holds the office of::+]]'},
fields = {'Holds the office of=office'}
}
local attributes = {
sort = 'Has_display_title',
order = 'asc',
}
local result = ClassCity.mySmwUtil.ask(query, attributes)
if result then
offices = {}
for _, row in pairs(result) do
if not offices[row.office] then
offices[row.office] = {}
end
table.insert(offices[row.office], row.MainLabel)
end
end
coreData.offices = offices
if coreData.sect then
coreData.officesAvailable = officePerSect[coreData.sect]
end
-- all history (chapter, events) that took place here
local history
local query = {
select = { '[[is_member_of_class::Event||Chapter]] [[Took_place_in::' .. self:getUid() .. ']] OR [[is_member_of_class::Chapter]] [[Has_auxilliary_settings::' .. self:getUid() .. ']]' },
fields = { 'took place on=start', 'took place until=stop', 'has maincast=maincast', 'has cast=cast', 'Is_associated_to_page=page', 'Is_titled=title', 'has short description=description' }
}
local attributes = {
sort = 'took place on',
order = 'asc',
}
coreData.history = ClassCity.mySmwUtil.ask(query, attributes)
-- and now all known locations in the city
local query = {
select = { '[[is_member_of_class::Location]] [[Is_located_in_city::' .. self:getUid() .. ']]' },
fields = { 'Bears_the_name=name', ' Has_address=address', 'Has_mainfunction=function', 'Has_resident=residents', 'Is_operated_by=operator', 'Uses_image=image', 'has short description=description' }
}
local attributes = {
sort = 'Has_mainfunction,Bears_the_name',
order = 'asc,asc',
}
coreData.locations = ClassCity.mySmwUtil.ask(query, attributes)
return coreData -- this is your new coreData.
end
function ClassCity:myDataAdjustments(data)
_debug(self, 1, 'entering ClassCity: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 ClassCity:myPlausibilityTest(args)
_debug(self, 1, 'entering ClassCity: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 ClassCity:myStashAdjustments(stash, storeType)
_debug(self, 1, 'entering ClassCity: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
if stash.sect == 'keine' then
stash.sect = nil
end
return stash -- this is your new stash. this will be stored. it has format (fieldname: value)
end
function ClassCity:method()
_debug(self, 1, 'entering ClassCity:method() to do something, from ' .. tostring(self))
return true
end
return ClassCity