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
 * an empty array can be created (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):

#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):

#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):

#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):

#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):

#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 set of values at the end of an array (identified by 'key'). See: http://www.php.net/manual/en/function.array-pop.php

Syntax:

Note(s):
 * this function helps remove an element from an array (identified by 'key')

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:

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

History:
 * Jan 27, 2009 -- v1.0.1 -- fix #arraydefine to support defining an empty string
 * Jan 27, 2009 -- v1.0 -- First release(alpha).