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 variable using a list of 'values' deliminated by 'delimiter'. The variable can be accessed by other functions later.

Syntax:

Notes:
 * the default delimiter is ',' if not specified
 * the white space surrouding delimiter is trimmed

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

Notes: [ => \[  {  => \{  }  => \}  \  => \\
 * 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 'yes', 'no'. See: http://www.php.net/manual/en/function.in-array.php

Syntax:

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:

Notes:
 * this merge is different from array_merge offerred by PHP because it merges values instead of keys

Example(s):

#arrayunique
This function converts an array into a set (all values are unique). see: http://www.php.net/manual/en/function.array-unique.php

Syntax:

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, large to small
 * asce - in ascending order, small to large

Syntax:

Example(s):

#arrayintersect
This function computes the (set theoretic) interesection of two given arrays. See: http://www.php.net/manual/en/function.array-intersect.php

Syntax:

Example(s):

#arrayunion
This function computes the (set theoretic) union of two given arrays. See: http://www.php.net/manual/en/function.array-union.php

Syntax:

Note:
 * similar to arraymerge, this union operation works on values.

Example(s):

#arraydiff
This function computes the (set theoretic) difference of two given arrays. The returned array 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:
 * this function can be used to test sub-class relation

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:

Example(s):

#arraypop
This function popes a set of values at the end of an array (identified by key). See: http://www.php.net/manual/en/function.array-pop.php

Syntax:

Example(s):

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

Instructions
Do the following to install these functions as an extension to MediaWiki.

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:

ChangeLog
ArrayExtension 1.0 has been tested on MediaWiki versions 1.13.3.

History:
 * Jan 27, 2009 -- v1.0 -- First release(alpha).