Extension:WSArrays

The WSArrays (or ComplexArrays) extension creates an additional set of parser functions that operate on multidimensional and associative arrays.

Functions
This extension defines several parser functions:

complexarraydefine
This function creates a new array, identified by 'key'. The syntax used to define a new array is called WSON, an MediaWiki friendly version of JSON. The syntax of WSON is exactly the same as that of JSON, however, in WSON all { and } are replaced with respectively (( and )).

An example:

(( "foo": "bar", "baz": ["qux", "quux"] ))

Explanation

 * key (required): The name of the array;
 * wson (required): The array in WSON (see above).

complexarrayprint
This function prints the values of the array in a custom format.

Explanation

 * key (required): The name of the (sub)array that should be printed;
 * options (optional):
 * ordered: Print the result as an ordered list;
 * map: Map the result in a string;
 * markup: Print the result as WSON.
 * map (optional, required when option is map): The string the result should be mapped on;
 * subject (optional, default is @@): The string that should be replaced in the map.

Examples
We have an array called 'foobar':


 * 0
 * foo: bar
 * baz: quz
 * 1
 * foo: quz
 * baz: bar
 * 2
 * baz: bar
 * foo: bar

complexarraysize
This parser function returns the size of a (sub)array.

Explanation

 * key (required): The name of the (sub)array;
 * options (optional):
 * top: Only count the number of items in the top array (not recursively).

Examples
We have an array called 'foobar':


 * 0
 * foo: bar
 * baz: quz
 * 1
 * foo: quz
 * baz: bar
 * 2
 * baz: bar
 * foo: bar

complexarrayslice
This parser function can extract a slice from an array.

Explanation

 * new_key (required): The name of the array that is going to be created;
 * key (required): The name of the array that needs to be sliced;
 * offset (required): For a positive offset, the new array will start at that offset in the first array. For a negative offset, the new array will start that far from the end of the first array;
 * length (optional): The length of the new array.

Examples
We have an array called foobar:


 * 0
 * foo: bar
 * baz: quz
 * 1
 * baz: bar
 * foo: bar
 * 2
 * boo: bar
 * far: quz
 * 3
 * foo: quux
 * bar: bar

complexarraysearch
This parser function searches through an array for a keyword and returns the corresponding key of the first match. If there are no matches, it will return 0.

Explanation

 * key (required): The name of the array that is going to be searched;
 * keyword (required): The keyword that is going to get searched for.

Examples
We have an array called foobar:


 * 0
 * foo: bar
 * baz: quz
 * 1
 * baz: bar
 * foo: bar
 * 2
 * boo: bar
 * far: quz
 * 3
 * foo: quux
 * bar: bar

complexarraysearcharray
This parser function searches through an array for a keyword and creates a new array with the corresponding keys of the matches. If there are no matches, it will return 0.

Explanation

 * new_key (required): The name of the array that is going to be created containing all the keys;
 * key (required): The name of the array that is going to be searched;
 * keyword (required): The keyword that is going to get searched for.

Examples
We have an array called foobar:


 * 0
 * foo: bar
 * baz: quz
 * 1
 * baz: bar
 * foo: bar
 * 2
 * boo: bar
 * far: quz
 * 3
 * foo: quux
 * bar: bar

complexarrayaddvalue
This parser function adds a value or subarray to an existing array or replaces an existing subarray with that value.

Explanation

 * key (required): The name of the subarray that will be created;
 * value (required): A value in plaintext or a subarray in WSON.

Examples
We have an array called 'foobar':


 * 0
 * foo: bar
 * baz: quz
 * 1
 * foo: quz
 * baz: bar
 * 2
 * baz: bar
 * foo: bar

complexarrayreset
This parser function resets all arrays or one array.

Explanation

 * key (optional): The name of the array that must be unset, when empty, all arrays will be unset.

complexarraysort
This parser function sorts an array.

Explanation

 * key (required): The array that needs to be sorted;
 * options (optional):
 * multisort: Sort the array using multisort;
 * asort: Sort the array using asort;
 * arsort: Sort the array using arsort;
 * krsort: Sort the array using krsort;
 * natcasesort: Sort the array using natcasesort;
 * natsort: Sort the array using natsort;
 * rsort: Sort the array using rsort;
 * shuffle: Shuffle the array;
 * keysort: Sort a two-dimensional array according to the values of a key in the second array. You can change the order to descending by appending ",desc" in options (so "keysort,desc").
 * sortingkey (optional, required when using keysort): The key with which the array must be sorted when using keysort.

See the PHP documentation for the sorting algorithms.

Examples
We have an array called 'foobar':


 * 0
 * foo: bar
 * baz: quz
 * 1
 * foo: quz
 * baz: bar
 * 2
 * baz: bar
 * foo: bar

complexarrayunique
This parser function removes duplicate keys and values from a array.

Explanation

 * key (required): The name of the array.

complexarraypush
This parser function pushes a new value or subarray to the end of an existing (sub)array.

Explanation

 * key (required): The name of the (sub)array;
 * value (required): A value in plaintext or a subarray in WSON.

Examples
We have an array called 'foobar':


 * 0
 * foo: bar
 * baz: quz
 * 1
 * foo: quz
 * baz: bar
 * 2
 * baz: bar
 * foo: bar

complexarrayextract
This parser function creates a new array from a subarray.

Explanation

 * new_key (required): The name of the array that is going to be created;
 * subarray (required): The subarray that needs to be extracted.

Examples
We have an array called 'foobar':


 * 0
 * foo: bar
 * baz: quz
 * 1
 * baz: bar
 * foo: bar

complexarraymerge
This parser function creates a new array by merging two or more arrays.

Explanation

 * new_key (required): The name of the array that is going to be created;
 * key1 (required): The name of the first array;
 * key2 (required): The name of the second array;
 * keyn (optional): The name of the n'th array;
 * options
 * recursive: Merge recursively
 * recursive: Merge recursively

Examples
We have an array called 'foobar':


 * 0
 * foo: bar
 * baz: quz
 * 1
 * baz: bar
 * foo: bar

and an array called 'boofar':


 * 0
 * boo: bar
 * far: quz
 * 1
 * foo: quux
 * bar: bar

complexarraypusharray
This parser function creates a new array by pushing one or more arrays to the end of another array.

Explanation

 * new_key (required): The name of the array that is going to be created;
 * key1 (required): The name of the first array;
 * key2 (required): The name of the second array;
 * keyn (optional): The name of the n'th array;
 * keyn (optional): The name of the n'th array;

Examples
We have an array called 'foobar':


 * 0
 * foo: bar
 * baz: quz
 * 1
 * baz: bar
 * foo: bar

and an array called 'boofar':


 * 0
 * boo: bar
 * far: quz
 * 1
 * foo: quux
 * bar: bar

complexarraymap
This parser function iterates over an array and maps values of the array onto a mapping key.

Explanation

 * key (required): The name of the array that is going to be mapped;
 * mapping_key (required): The keyword that will be replaced in the subject;
 * subject (required): The string on which the mapping will be applied;
 * hide (optional): Set this to 'true' in order to hide the mapping key when no string value for it exists.

Examples
We have an array called foobar:


 * 0
 * bar
 * quz
 * 1
 * bar
 * bar
 * 2
 * bar
 * quz
 * 3
 * quux

complexarraymaptemplate
This parser function maps the contents of an array in a template.

Explanation

 * key (required): The name of the array that needs to be mapped;
 * template (required): The name of the template the array must be mapped to.

Examples
We have an array called 'foobar', an array called 'boofar' and an array called 'bazbar', resp.:

foobar:
 * 0
 * foo: bar
 * baz: quz
 * 1
 * baz: bar
 * foo: bar
 * 2
 * foo: quz
 * baz: bar
 * bar
 * bex
 * box

boofar:
 * foobar
 * bazbar
 * boofar

bazbar:
 * foo: bar
 * boo: far

Arrays of mixed types are sometimes not handled properly.

Semantic MediaWiki
This extension introduces a new format for displaying Semantic MediaWiki results. In order to use the new format, use. Because the result printer defines a new complexarray, you need to provide a name for that array using ; if   is left empty, the result printer will print the array as WSON.

Semantic variables
A list of semantic variables is included in the complexarray when you query a list of pages. The following variables are included:


 * catitle: The title of the page
 * cafullurl: The full URL of the page
 * canamespace: The namespace the page lives in
 * caexists: Whether or not the page exists (0/1)
 * cadisplaytitle: The displaytitle of the page

Additional parameters
WSArrays defines three new parameters:


 * name: The name of the array that is going to be created
 * hide: Option to hide semantic variables from the result (yes/no)
 * unassociative: Option to display the result in an unassociative array (yes/no)
 * simple: Option to hide Semantic variables from page results as well as hiding mailto: prefixes on email results (yes/no, default: yes)

Configuration
WSArrays has 2 configuration parameters.


 * The maximum number of arrays defined at any given time. Accepts any positive integer (-1 to disable).
 * The maximum number of arrays defined at any given time. Accepts any positive integer (-1 to disable).


 * Options to skip version control and force the initialization of WSArrays, accepts a boolean.
 * Options to skip version control and force the initialization of WSArrays, accepts a boolean.