Template:ParseInputValues/doc

ParseInputValues is a utility function that processes a generic list of arguments to determine which ones match a list of allowed/expected values. It is intended for use only within other templates, to allow those templates to process their input data.

Syntax
Standard initialization:

Standard usage:

Complete argument list:

An example of typical usage within another template would be to take input data ( ) ), see whether it matches any of Parsnip, Potato, Tulip, and store results in array named $cleaned_input:

Parameters
There are two unnamed arguments (input_values, allowed_values). All other parameters are named and optional. Default value for all arguments is empty unless specified otherwise.


 * input_values:
 * First unnamed argument. Required except on initialization.
 * The user input that needs to be processed. Should be a comma-separated list of one or more values.
 * Links (i.e., square brackets surrounding a word) will be automatically stripped, as will '' (italics).
 * The processing is non-case-sensitive; return values will always match the case used in allowed_values (unless the case parameter is used).


 * allowed_values
 * Second unnamed argument.
 * A comma-separated list of the allowed and/or expected values.
 * Typically the allowed values are initialized in one call to ParseInputValues, using code to store the processed data for later use.
 * The order of the provided values is important. Within a single list of synonyms:
 * The first value is the standard english version of the term. This is the value that is returned by default.
 * The second value is the standard local version of the term (e.g., translated into the current wiki's language). This is the value that is returned when translate=true is set. On the english wiki the second value normally matches the first value (and can be omitted if there are no synonyms).
 * All other values are allowed synonyms, both english and local.
 * Multiple lists of synonyms can be specified simultaneously. An empty entry is used to separate each set of synonyms (for ease of reading, a line break is often included in the empty entry, but the only requirement for the separator is that it contain nothing except spaces).


 * code = code
 * A unique identifier assigned to a set of allowed values.
 * When using this parameter, the first call to ParseInputValues</tt> should be an initialization call, providing a list of allowed values that are processed and stored.
 * Subsequent calls to ParseInputValues</tt> can omit the allowed values list, and instead use code</tt> to retrieve previously-stored data.
 * Use of this parameter makes it easier to reuse a set of allowed values repeatedly within a template. It also creates more efficient templates, especially on wiki articles that end up calling a template multiple times. The overhead associated with processing a set of allowed values only needs to happen once on a wiki article, because defined arrays are effectively global variables.


 * exclude = exclude_values
 * A comma-separated list of values to exclude from the final output.
 * Entries are processed the same way as input_values</tt>.


 * default = true;values
 * A default value that should be used only if no input_values match.
 * Set to true</tt> if the original input_values</tt> should be used. Implies exclude</tt>, translate</tt>, and case</tt> should be ignored -- original values are returned exactly as is.
 * Otherwise should be a comma-separated list of entries that exactly match values found in allowed_values. Note that in this case exclude values are applied AFTER default is set.


 * translate = true;index
 * Set to true if the return values should be translated, i.e., replace entries from allowed_values with the corresponding entry in alt_allowed. If the alt_allowed entry is missing, the entry is deleted.
 * Set to index</tt> if the return value should be a number specifying the array index of the matching value


 * case = uc;lc
 * Set to one of lc or uc to convert the case of all return values
 * uc: all upper case
 * lc: all lower case
 * All other values of case are ignored (meaning returned values match the case provided in allowed_values)


 * vary_end = true
 * Set to true if variations in the final characters of the return text should be allowed, in particular for support of gender- and/or plural-specific versions of the return text.
 * Only relevant if translate=true</tt> is also set.
 * When this option is set, the input value may be returned instead of the standard translated term, but only if the input value also appears in the allowed list and the input value is identical (including case) to the standard term except for the last three characters.

Return Value
A comma-separated list of values.

(This value is printed into the page HTML. Depending upon the calling function, it may might become part of the displayed page, or a template function such as #arraydefine can be used to assign it to a variable)

Examples
Only matching words are returned; return values use same case and order as allowed_values. (Double commas are necessary to have each entry treated as a different term, instead of all being one set of synonyms.) Returns: </tt>

Demonstrating use of code</tt> to initialize a list of english and spanish terms for weather (copied from es:Template:Weather inline). Each line provides one set of synonyms (note the commas at the start and end of each line; these pairs of commas produce an empty entry at each line break which tells the code a new set of synonyms is starting). Has no return value: </tt>

Use previously-stored weather data. Demonstrating synonyms, automatic case-conversion, link removal. Returns:

Translate (return second value on each line instead of first). Note that both wind terms return the same word -- although the english terms are unique, the translated terms do not have to be. Plus automatic italics removal. Returns: </tt>

Demonstrating exclude -- with same flexbility as input values. Returns: </tt>

Initialize a new list and use it simultaneously. Default translated return value is masculine version. Returns: <tt></tt>

Use feminine version if <tt>vary_end=true</tt> and input value matches. Returns: <tt></tt>