Extension:Arrays

ArrayExtension defines an additional set of parser functions that operate on arrays.

Functions
This module defines these functions:

arraydefine
This function constructs an array (identified by 'key') using a list of 'values' separated by the 'delimiter'. The variable can be accessed by other functions later.

Syntax:

Note(s):
 * 'values' is a list of strings separated by 'delimiter'
 * the resulting array is an array of strings.
 * the default delimiter is ',' if not specified
 * the white-spaces surrounding delimiter will be trimmed
 * this function shows nothing
 * users can define an empty array, or reset an array by leaving the 'values' empty (see example)

Example(s):

arrayprint
This function prints the values of an array in comtomizable format.

Syntax:

The customizable output format is: prefix  suffix delimiter prefix  suffix ... prefix  suffix

Note(s): [ => \[  {  => \{  }  => \}  \  => \\
 * the following characters are escaped
 * there should be at least a white space between escaped  '\}'   and the end of template '}}'

Example(s):

arraysize
This function returns the size (number of elements) of an array. See: http://www.php.net/manual/en/function.count.php

Syntax:

Example(s):

arraymember
This function checks if 'value' is member of the array (identified by 'key'), and returns '1' (yes), '0' (no). See: http://www.php.net/manual/en/function.in-array.php

Syntax:

Example(s):

arrayindex
This function print the value of an array (identified by 'key') at position 'index'. See: http://www.php.net/manual/en/function.in-array.php

Syntax:

Note(s):
 * invalid index (non-number, out of bound) will result in printing an empty string.
 * the index is 0-based, i.e. the first element's index is 0.

Example(s):

arraysort
This function sorts an array in the following order. See: http://www.php.net/manual/en/function.sort.php http://www.php.net/manual/en/function.rsort.php
 * none (default) - no sort
 * desc - in descending order
 * asce - in ascending order

Syntax:

Note(s):
 * each array element is a string

Example(s):

arrayunique
This function converts an array (identified by 'key') into a set (no duplicated members). see: http://www.php.net/manual/en/function.array-unique.php

Syntax:

Example(s):

arraypush
This function pushes a set of values at the end of an array (identified by 'key'). See: http://www.php.net/manual/en/function.array-push.php

Syntax:

Note(s):
 * this function helps add elements to an array (identified by 'key')

Example(s):

arraypop
This function popes a positive 'number' (default 1) of values from the end of an array (identified by 'key'). See: http://www.php.net/manual/en/function.array-pop.php

Syntax:

Note(s):
 * if the 'number' is larger than the size of the array, the array will be emptied
 * setting 'number' to a non-number or a non-positive number will not cause any operation.

Example(s):

arraymerge
This function merges values of two arrayes (identified by 'key1' and 'key2') into a new array (identified by 'key'). See: http://www.php.net/manual/en/function.in-array.php

Syntax:

Note(s):
 * this merge is different from array_merge offerred by PHP because it merges values instead of keys

Example(s):

arrayintersect
This function computes the set theoretic interesection of two given arrays (identified by 'key1' and 'key2'), and the result array is identified by 'key'. See: http://www.php.net/manual/en/function.array-intersect.php

Syntax:

Note(s):
 * this is a set operator, i.e., the returned array is a set without duplicated values.

Example(s):

arrayunion
This function computes the set theoretic union of two given arrays (identified by 'key1' and 'key2'), and the result array is identified by 'key'. See: http://www.php.net/manual/en/function.array-union.php

Syntax:

Note(s):
 * this is a set operator, i.e., the returned array is a set without duplicated values.
 * similar to arraymerge, this union operation works on values.

Example(s):

arraydiff
This function computes the (set theoretic) difference of two given arrays (identified by 'key1' and 'key2'), and the result array is identified by 'key'. The returned array (identified by 'key') is a set that contains elements in an array (identified by 'key1') but not in the other array (identified by 'key2'). See: http://www.php.net/manual/en/function.array-diff.php

Syntax:

Note(s):
 * this is a set operator, i.e., the returned array is a set without duplicated values.
 * this function can be used to test sub-class relation

Example(s):

Installation
This extension has been tested on MediaWiki 1.13+ and PHP 5. But most of its functions are compatible with PHP 4, so it is reasonable to try this extension on earlier versions of MediaWiki. Please use the following instructions to install this extension.

1. Install source code svn co http://smwbp.googlecode.com/svn/trunk/mediawiki/extensions/ArrayExtension/
 * you can copy the source code from SVN, and put them under "WIKI-PATH/extentions/ArrayExtension"
 * or if you have shell access, you can install using svn

2. Append the following to LocalSettings.php (near the bottom) of your MediaWiki installation:

work with Extension:SemanticMediaWiki
ArrayExtension allows users to populate an array using a SMW query result.

Example A. to create a list of instances of the class 'Color'

Example B. to create a unique list of values of property 'has color'

Note(s)
 * semantic query parameters
 * 'limit=1000' option is used to exhaust all returned results of the semantic query
 * 'sep=,' option is used to set the separator for entries of the results
 * 'mainlable=-' option cut of the page column

work with Extension:SemanticQueryFormTool
ArrayExtension allows users to populate an array using a SemanticQueryFormTool query result.

to create a list of instances of the class 'Color'

source: thanks for zehetner@molgen.mpg.de

Related MediaWiki Extensions

 * ParserFunctions
 * VariablesExtension
 * StringFunctions

Change Log
ArrayExtension 1.0 has been tested on MediaWiki versions 1.13.3.

History:
 * Jan 28, 2009 -- v1.0.2 -- fix #arraypop to support pop multiple elements; add #arrayindex
 * Jan 27, 2009 -- v1.0.1 -- fix #arraydefine to support defining an empty string
 * Jan 27, 2009 -- v1.0 -- First release(alpha).