Ir para o conteúdo

Módulo:Cargo/doc

De DropWiki PoE 2
Revisão de 21h03min de 29 de janeiro de 2025 por 2804:7f0:b342:7285:2d1e:1c01:abfd:fada (discussão) (Criou página com '{{Documentation subpage}} {{Meta module}} {{Lua|Module:Arguments|Module:Util|Module:Cargo/config}} ==Functions== ===m_cargo.declare=== This function is a simple wrapper around cargo_declare. ===m_cargo.attach=== This function is a simple wrapper around cargo_attach. ===m_cargo.store=== This function is a wrapper around mediawikiwi...')
(dif) ← Edição anterior | Revisão atual (dif) | Versão posterior → (dif)

Esta é a página de documentação para Módulo:Cargo

This subpage provides documentation for Módulo:Cargo.

This is a meta module.

This module is meant to be used only by other modules. It should not be invoked in wikitext.

Lua logo

This module depends on the following other modules:

Functions

m_cargo.declare

This function is a simple wrapper around cargo_declare.

m_cargo.attach

This function is a simple wrapper around cargo_attach.

m_cargo.store

This function is a wrapper around cargo_store.

It will cast certain native lua to acceptable values for the store. In particular:

  • booleans -> cast to 1 or 0
  • tables -> cast to a list separated by a delimiter (default is comma)

It will also avoid calling the store function if no values are passed.

Parameters

Parameter Type Description Required Default
values assoc. table Table containing key-value pairs to store in the table.

It works exactly like cargo_store, expecting the key to be the of the field and the value the value to be stored.

The _table field must be supplied as well.

Sim
args assoc table Additional parameters for this function Não
args.sep assoc table Table mapping the desired delimiter/separator for fields as value to the fields in question as key. Não
args.store_empty boolean Allows the storing of empty rows Não false
args.debug assoc table If set, log the values written by this function to console Não false

m_cargo.query

m_cargo.table_query

Function parameters

Parameter Type Description Required Default
tpl_args table Parsed template arguments.

Please note those will be used/parsed by the function itself, see the template arguments section below. These will also be processed for selecting eligible display columns and passed to display functions.

Sim
frame table Frame object Sim
main_table string The name of the main cargo table Sim
row_unique_fields array table List of fields that identify a result as "unique". By default the page id is used. Não <main_table>._pageID
empty_cell string HTML to use for empty fields Não — by default
table_css string CSS class to add to table Não
data table Data table governing the display of table columns. For details see below. Sim

Data parameters

Unless specified, each data entry is an array.

Parameter Type Description Required Default
data.tables assoc table table containing any extra conditions for tables as the "join" key. Não
args array table List of arguments that can be specified to display this column. The column will be shown if ANY of the parameter matches.

If left empty, the column will always be shown.

Não
header string or

function

Table header to display. Não
fields array table List of fully-qualified field names for this function (table + field). Fields will be automatically queried; if the table in the field is not the main table, a join clause must be added to the tables parameter.

If a field is empty upon return, the cell will be considered empty.

Please note that this behavior can be overridden in various ways with the options parameter.

Não
display function Display function.

The function will receive the following parameters (in this order):

  • tpl_args - tpl_args as passed to this function
  • frame - frame as passed to this function
  • tr - HTML tr object
  • rows - result rows for this cell
  • rowinfo - this object (info for the current column)
Não
order int Number to order this display cell by. Higher numbers will be shown at the end of the table, lower numbers will be shown first. Não
sort_type string Sort-type to use by table-sorter plugin Não number
options table array Extra options for the fields. The index used here refers to the order in which the fields were specified. Não

Field option parameters

Placed at data[1 ... n].options[1 ... m]

Parameter Type Description Required Default
optional boolean If set to true, the field will not count as required for the display. Não false

Template parameters consumed/used

Parameter Type Description Required Default
q_<cargo_lua_parameter> string Cargo parameter passed into the query function. Please note this is not exclusive and my be altered by the function itself.

It is advised that at least q_where is specified, but not required.

q_limit will not work currently.

Não
default string Default text to display if no results are found. Não No results found.
before string Text to prepend before the table. Não
after string Text to append after the table. Não

m_cargo.store_mapped_args

Parses, and casts template arguments and maps them to a cargo argument table (i.e. the ones used in m_cargo.declare_factory).

The currently supported field types are:

  • FLOAT, NUMBER - cast to number
  • BOOLEAN - cast to boolean
  • LIST OF ... - cast to table

Arguments

All arguments here are expected to be passed in single table to the function.

Parameter Type Description Required Default
tpl_args assoc table arguments passed to template after preprecessing Sim
table_map assoc table Table mapping for the arguments. See the relevant section below for more information. Sim
rtr boolean If set return cargo key-value pairs instead of storing them into the database. Não false

Map arguments

All arguments supplied here are for the mapping object. Some arguments are shared with m_cargo.declare_factory.

Parameter Type Description Required Default
order array table Array table for the order in which the arguments in map.fields will be parsed by their id.

If a field is not present, it will not be parsed.

Sim
table string name of the table the fields belong to Sim
fields assoc table Table containing the fields using their id as key and containing another assoc table containing the various options. The id used in the order. Sim
fields[<id>].field string Name of the field in cargo table Sim
fields[<id>].type string Type of the field in cargo table Sim
fields[<id>].func function Function to handle the arguments.The function should return the parsed value.

The function will be passed the following arguments in order:

  • tpl_args - template arguments object
  • value - parsed value of the field
Não
fields[<id>].default Default value if the value is not set or returned as nil

If default is a function, the function will be passed tpl_args and expected to return a default value for the field.

Não
fields[<id>].name string Name of the field in tpl_args if it differs from the id in map.fields.

For example used to internationalize names for example while keeping the code in English.

Não
fields[<id>].required boolean Whether a value for the field is required or whether it can be left empty; essentially if whether storing NULL values is acceptable

Note: With a default value the field will never be empty

Não false
fields[<id>].skip boolean Skip field if missing from order and don't raise an error Não false

m_cargo.declare_factory

m_cargo.attach_factory

m_cargo.map_results_to_id

Maps the results passed to a table containing the specified field as key and a table of rows for the particular page as values.

Arguments

All arguments here are expected to be passed in single table to the function.

Parameter Type Description Required Default
results assoc table table of results returned from mw.ext.cargo.query or m_cargo.query to map to the specified id field Sim
field string name of the id field to map results to

the field has to be in the fields list of the original query or it will cause errors

Sim
keep_id_field boolean If set, the id field won't be deleted from the result set.

Note: The reason this is the default behavior is because the field is used as key already and doesn't need to be duplicated.

Não false

m_cargo.array_query

Performs a long OR query from the given array and field validating that there is only exactly one match returned

Arguments

All arguments here are expected to be passed in single table to the function.

Parameter Type Description Required Default
tables array table List of tables (see also m_cargo.query) Sim
fields array table List of fields (see also m_cargo.query) Sim
id_array array table List of id values to query for. Sim
id_field string The id field to query for Sim
query table table containing cargo sql clauses [optional] (see m_cargo.query) Não
ignore_missing boolean skip the check for missing fields entirely Não
warning_on_missing boolean issue warning to log/console instead of error if missing values Não

Return values

Type Description
table results as given by mw.ext.cargo.query
string any error messages if it was used as warning

m_cargo.replace_holds

Replaces a "HOLDS" cargo query (which is currently bugged/broken) with a LIKE or REGEXP equivalent.

Arguments

All arguments here are expected to be passed in single table to the function.

Parameter Type Description Required Default
string string String to replace Sim
mode like or

regex

Either of the specified modes:
  • like: Replaces the holds query with a LIKE equivalent.
  • regex: Replaces the holds query with a REGEXP equivalent. HOLDS LIKE is currently not supported though.
Não regex
field sting Field lua pattern to use. A different pattern from the default can be used to match only specific fields for replacement for example. Não
[%w_\.]+
separator string Separator for field entries to use in the REGEXP mode (corresponding to list declaration) Não ,

m_cargo.parse_field

Parse a cargo field declaration and returns a table containing the results

Arguments

All arguments here are expected to be passed in single table to the function.

Parameter Type Description Required Default
field string the field declaration string to parse Sim

Return format

A table will be returned containing the following fields:

Parameter Type Description
type string type string of the field
list string Separator of the list, if the field is a "list" type.

Nil otherwise

parameters table Table containing any parameters as keys and their values as values.

Parameters that do not have a value will be set to "true".