Module:Infobox/doc

Give your infobox a caption
Or don't.

Public functions
For the example snippets below,  is an arbitrary infobox initiated as:

Priority
Certain functions rely on information created by other functions, and thus must be run in a particular order:

nilParam
Returns the value of the placeholder value. This value is generally not seen, but it is used to fill switchbox data as  causes unwanted behaviour.

isDefined
Checks whether the value  can be considered as defined.

new
Creates a new infobox object with  as a   of values passed from the template invocation.

This function also creates the top-level wrapper and sets a metatable for the infobox.

create
Creates the HTML tags used for the infobox itself. Will run  if it has not been run already.

defineName
Defines the name of the infobox. This should be the base pagename; i.e. no "Template:" namespace prefix.

defineLinks
Defines any number of infobox bottom links in a  whose elements are   variables formatted as such:

and  should be   variables that will, in a basic sense, define.

In a more technical sense,  and   help form a   for , with the module using the equivalent of (but not exactly):

The template name itself can be called up to 5 times by using "%s", in either  or.

setMaxButtons
Changes the behaviour of buttons by defining the maximum number of buttons that are allowed to appear. If the version count exceeds the button count, their buttons will be replaced with a drop down menu. If not run, the maximum button count will be 5.

cleanParams
Parses the parameters with their mapped functions.

defineParams
Maps parameters to functions as defined by a  formatted as such:

should be a  that names the parameter as it will be in references for use in other functions.

should be a  or instructions on how to find a function.

is a meta configuration that allows the parameter to be duplicated in switch data. Normally, these duplicate values are not needed, and they will be deleted if they are the same as the default values after all parameters have been parsed. Some parameters require duplication to function properly, such as display altering parameters defined with.

If duplicates are not needed, this parameter should be deleted.

If  is a , then the module will attempt to use a predefined function.
 * Predefined functions

If  is a , then that function will be used to parse the parameter. User-defined functions allow for more robust formatting and guidelines.
 * User-defined functions

As a general practice, user-defined functions should be located under the  functions in the module. It is best to document these functions so that they may be changed by other editors if necessary.

In user-defined functions, circumstances where the edit button should be shown should return, which is automatically handled by the module.

Parameters may be mapped to functions in a straightforward manner by simply definining a name of or reference to a function, such as:
 * Simple and complex definitions

Simple definitions only pass the parameter from the master list named. Some parameters need more interaction with other parameters. To do this, we require a complex definition. Complex definitions point to a user-defined function and map what parameters to pass. Complex definitions can also pass literal values or the uncleaned value with the use of flags.

Complex functions are defined as  values formatted as such:

A basic example for complex functions is:

In this example, we have a parameter named "foo", but we use the parameters passed to the template named "bar" and "baz". Parameters are passed in the order listed, so in the above, the parameter  is used for , and   is used for.

Flags define the behaviour of the parameters named. The following flag behaviours exist:
 * - Looks for the cleaned and parsed version of the parameter. If not cleaned, it will use the value passed to the template. If neither exist, it will use . This is the default behaviour if no flag is defined.
 * - Looks only at the value passed to the template. If it does not exist, it will use.
 * or  - Uses the literal (or raw) value.

If  is a , then the behaviour defined by it will apply to every parameter passed. If  is a , then each flag will only define the behaviour of the respective parameter.

For example:

In the above snippet,  will use the default behaviour and   will only look for the value passed to the template. The third parameter will use the string literal.

Parameters are defined in the order that they are coded. If a parameter relies on the cleaned value of another parameter, then the parameter dependent on the other will need to be defined after in the definition table.
 * Definition order

addRow
Adds a new row to the template with columns and behaviour defined by, which should be a   that holds cells defined as   variables, formatted as such:

and  are   values that define the fundamental display of the cell.

The attributes are any of the available attributes defined inside the function. All functions that are ultimately run are documented in the Lua reference manual and are run on the tag for the specific table cell they are called on.

If the template is a switch infobox, then  will be added to the table cell.

This function will return the template, allowing further self functions to be performed.

addButtonsRow
Places the switch infobox buttons, if there are any, where this is called. The row is not generated if there are no switch infobox buttons. Overrides default button placement (which is just above the table - though because there are no wrappers this usually means they hover in the center of the page). Set the colspan to the total colspan of the infobox.

wikitext
Appends wikitext to the top-level wrapper. Templates, etc. passed directly from Lua code will need explicit preprocessing prior to display properly.

This function will return the template, allowing further self functions to be performed.

caption
Adds a caption to the infobox based off the subject name, using the following priority for the text:
 * parameter
 * parameter (if switch infobox)

If the template is a switch infobox, this will also add  to the.

This function will return the template, allowing further self functions to be performed.

addButtonsCaption
Places the switch infobox buttons, if there are any, into a caption. The caption is not generated if there are no switch infobox buttons. Overrides default button placement (which is just above the table - though because there are no wrappers this usually means they hover in the center of the page). The buttons are placed into a new caption - if used in conjunction with the above caption function, the new caption will be in the same relative position as the code (i.e. if caption is called before addButtonsCaption, the normal caption will be above the buttons caption.

attr
Passes  to.

This function will return the template, allowing further self functions to be performed.

float
Changes the direction of the CSS style  for the top level wrapper. By default, all infoboxes float.

This function will return the template, allowing further self functions to be performed.

css
Passes the arguments to.

This function will return the template, allowing further self functions to be performed.

addClass
Passes  to.

This function will return the template, allowing further self functions to be performed.

addClasses
Passes every argument to  individually.

This function will return the template, allowing further self functions to be performed.

tag
Passes  to.

This function will return the tag (not the template), allowing further self functions to be performed.

useSMW
Tells the module to create properties for parameters, as well as defining those mappings with, a   whose elements form an associated array formatted as such:

When defined, properties will be defined for two separate properties: both "Property: " and "Property:All ". The "All " properties exist to create storage for all applicable values. Keep this in mind, as "Property: " will only ever store the default value.

noSwitch
Forces the template to use only a single version, the default.

maxVersion
Returns the number of versions used by the infobox. When run the first time, this function will check and define the version count first. Subsequent calls will simply return the count.

linkParams
Links two parameters where one parameter is contents of a cell and   becomes classes of that cell's row. It will only have an effect on switch infoboxes. Both parameters will need to be defined in the infobox with. They should be functions of the parameter they operator on and include  in their definitions.

Example: grand exchange graphs do not make sense to display for untradeable items within switch infoboxes (e.g. ahrim's staff); one could use a linked param to add a class that will display:none table row when switching to untradeable items.

In the source code of the infobox, these will be added as such:

From this, the switch infobox javascript will add the contents of  to class attribute of the row of the table when the infobox is switched. You will also need to define the classes you are using in global CSS.

If the parameter is a th or td element, the class is added to the parent tr. Otherwise, it is added to the element directly (e.g. caption element).

finish
Finalises the template and adds remaining required HTML.


 * Creates hidden tag for switch infobox data (if needed)
 * Adds Category:Pages that contain switch infobox data if in the mainspace
 * Defines Property:Version count if in the mainspace
 * Adds Semantic MediaWiki Data in a hidden tag (if needed)
 * This data can be viewed on the page itself by using inspect element, but it is not normally visible
 * Adds infobox bottom links

param
Returns the value of the parameter named. The exact format and values are determined by the :


 * or empty - default value of the parameter
 * or  - all values of the parameter as a table
 * or  - table of all switch values
 * - switch value at index
 * - if defined, switch value 1, otherwise the default value

Note that this function returns the actual table used by the template. If a switch value is equal to  for flag , then   will be returned instead; however, when calling specific indices from the tables returned by   or  , the value of   will be returned without extra parsing.

paramDefined
Looks to see if the parameter named  is defined at any index, based on instructions from  :


 * or empty - default value of parameter
 * - value of switch at index
 * - true if the parameter is defined with a default or at any switch value

paramGrep
Performs a function or search on every possible value of the parameter named. can be either a, a  , or a. If a match is found or the function query returns true,  will end its search.

If  is a function, that function must pass a single argument (the parameter), and return either   or.

If  is a string, then that string will be compared to each value of the parameter. If they match exactly, disregarding casing, then  will be returned. To perform a pattern match on strings, you will need to define  as a function that returns a boolean value based on   or.

If  is a number (or any other type), then it will be compared to each value for a match.

Matches are only checked if the type of  matches the value of the parameter; e.g., it is not valid to search for a number (ex:  ) inside a string (ex:  ).

paramRead
Performs the same function as ; however, instead of   being a name of a parameter to look for, it is the table itself. Useful for functions where only the table of parameters is passed, but not the whole infobox.

categoryData
Returns fundamental category data collected during.

Fields in the category data include:
 * -  if at least one possible value of the parameter is defined
 * -  if at least one possible value of the parameter is not defined

Defined parameters
Parameters are to be considered "defined" if they meet all of the following criteria:


 * Is not
 * Contains at least one non-whitespace character (
 * Is not equal to
 * Does not contain the string

pt:Módulo:Infobox pt:Módulo:Infobox/doc