Extension:WSArrays

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
WSArrays
Release status: beta
Implementation Parser function
Description Adds parser functions to allow the creation and traversing of associative and multidimensional arrays.
Author(s) Marijn van Wezel (Wikibase Solutions)
Latest version 2.0 (2019-11-9)
MediaWiki 1.31+
PHP 5.3+
Database changes No
License GNU General Public License 2.0 or later
Download
  • $wfSkipVersionControl
  • $wfEnableResultPrinter
  • $wfEscapeEntitiesInArrays
Translate the WSArrays extension if it is available at translatewiki.net
Check usage and version matrix.

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

Contents

Functions[edit]

This extension defines several parser functions:

Function name Aliases
#complexarraydefine #cadefine
#complexarrayprint #caprint
#complexarraypush #capush
#complexarraysize #casize
#complexarrayaddvalue #caaddvalue, #caadd, #caaddv
#complexarrayreset #careset, #caclear
#complexarraysort #casort
#complexarraymap #camap
#complexarraymaptemplate #camaptemplate, #camapt, #catemplate
#complexarrayextract #caextract
#complexarrayunique #caunique
#complexarraymerge #camerge
#complexarraypusharray #capusharray
#complexarrayslice #caslice
#complexarraysearch #casearch
#complexarraysearcharray #casearcharray, #casearcha
#complexarraydefinedarrays #cadefinedarrays, #cadefined, #cad
#complexarrayarraymap #caamap, #camapa
#complexarrayparent #caparent, #capapa, #camama
#complexarrayunset #caunset, #caremove

Constructing arrays[edit]

complexarraydefine[edit]

This function creates a new array, identified by 'key'. Arrays are made using the Archie Markup Language (ArchieML.org).

Syntax[edit]

{{#complexarraydefine:key|array|delimiter|noparse}}

Explanation[edit]

  • key (required): The name of the array;
  • array (required): The array in ArchieML (see above), as WSON, or using a delimiter.
  • delimiter (optional, default: ,): The delimiter used when defining a simple array.
  • noparse (optional, default: 0): Set this to the correct level to tell the parser what to parse in the 'array' (see #Manipulating the parser).

Examples[edit]

Define a one-dimensional, associative array called 'foobar'
{{#cadefine:foobar|
foo: bar
bar: baz
}}
Define a multidimensional array called 'baz'
{{#cadefine:baz|(("foo":(("bar":"baz"))))}}
Define a simple array called 'bex'
{{#cadefine:bex|foo; bar; baz|;}}

complexarraydefinedarrays[edit]

This debug function creates a new array containing the keys of all currently defined arrays.

Syntax[edit]

{{#complexarraydefinedarrays: key}}

Explanation[edit]

  • key (required): The name of the array that will contain the keys of the currently defined arrays

Working with arrays[edit]

Extraction[edit]

complexarrayprint[edit]

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

Syntax[edit]
{{#complexarrayprint:key|options|map|subject|noparse}}
Explanation[edit]
  • 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 the option is map): The string the result should be mapped on;
  • subject (optional, default is @@): The string that should be replaced on the map.
  • noparse (optional, default: 0): Set this to the correct level to tell the parser what to parse in the 'subject' (see #Manipulating the parser).
Examples[edit]

We have an array called 'foobar':

  • 0
    • foo: bar
    • baz: quz
  • 1
    • foo: quz
    • baz: bar
  • 2
    • baz: bar
    • foo: bar
  • 3
    • baz: {{Example|Test}}. <nowiki>{{Example|Test}}</nowiki>
If you defined the array with noparse, the behaviour is different.
Function Result
{{#caprint: foobar}}
  • 0
    • foo: bar
    • baz: quz
  • 1
    • foo: quz
    • baz: bar
  • 2
    • baz: bar
    • foo: bar
  • 3
    • baz: Test. {{Example|Test}}
{{#caprint: foobar[0]}}
  • foo: bar
  • baz: quz
{{#caprint: foobar[3]}}
  • Test. {{Example|Test}}
{{#caprint: foobar[0]|ordered}}
  1. foo: bar
  2. baz: quz
{{#caprint: foobar[0][foo]}}
bar
{{#caprint: foobar[0]|map|[[$$]]|$$}}
barquz ([[bar]][[quz]])

complexarraysize[edit]

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

Syntax[edit]
{{#complexarraysize:key|options}}
Explanation[edit]
  • key (required): The name of the (sub)array;
  • options (optional):
    • top: Only count the number of items in the top array (not recursively).
Examples[edit]

We have an array called 'foobar':

  • 0
    • foo: bar
    • baz: quz
  • 1
    • foo: quz
    • baz: bar
  • 2
    • baz: bar
    • foo: bar
Function Result
{{#casize: foobar}}
9
{{#casize: foobar[1]}}
2
{{#casize: foobar|top}}
3

complexarrayslice[edit]

This parser function can extract a slice from an array.

Syntax[edit]
{{#complexarrayslice:new_key|key|offset|length}}
Explanation[edit]
  • 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[edit]

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
Function Result
{{#caslice: boofar | foobar | 2 | 1 }}

This gives the third element of the array.

boofar:

  • 0
    • boo: bar
    • far: quz
{{#caslice: boofar | foobar | -1 }}

This gives the last element of the array:

boofar:

  • 0
    • foo: quux
    • bar: bar

complexarraysearch[edit]

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.

Syntax[edit]
{{#complexarraysearch:key|keyword}}
Explanation[edit]
  • 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[edit]

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
Function Result
{{#casearch: foobar | quux }}
WSArray[3][foo]
{{#casearch: foobar | bar }}
WSArray[0][foo]

complexarraysearcharray[edit]

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.

Syntax[edit]
{{#complexarraysearcharray:new_key|key|keyword}}
Explanation[edit]
  • 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[edit]

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
Function Result
{{#casearcha: boofar | foobar | bar }}

boofar:

  • WSArray[0][foo]
  • WSArray[1][baz]
  • WSArray[1][foo]
  • WSArray[2][boo]
  • WSArray[3][bar]
{{#casearcha: boofar | foobar | quux }}

boofar:

WSArray[3][foo]

Alteration[edit]

complexarrayunset[edit]

This function unsets the given key.

Syntax[edit]
{{#complexarrayparent: key }}
Explanation[edit]
  • key (required): The key which should be unset
Examples[edit]

Suppose we have an array called "foobar":

  • foo
    • bar
    • qux
  • baz
Function Result
{{#caunset: foobar[foo][1] }}

foobar:

  • foo
    • bar
  • baz

complexarrayaddvalue[edit]

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

Syntax[edit]
{{#complexarrayaddvalue:key|value}}
Explanation[edit]
  • key (required): The name of the subarray that will be created;
  • value (required): A value in plaintext or a subarray in WSON.
Examples[edit]

We have an array called 'foobar':

  • 0
    • foo: bar
    • baz: quz
  • 1
    • foo: quz
    • baz: bar
  • 2
    • baz: bar
    • foo: bar
Function Result
{{#caadd: foobar[0][bex]|["abc","123"]}}
  • 0
    • foo: bar
    • baz: quz
    • bex
      • abc
      • 123
  • 1
    • foo: quz
    • baz: bar
  • 2
    • baz: bar
    • foo: bar
{{#caadd: foobar[3][foo][bar][baz]|bex}}
  • 0
    • foo: bar
    • baz: quz
  • 1
    • foo: quz
    • baz: bar
  • 2
    • baz: bar
    • foo: bar
  • 3
    • foo
      • bar
        • baz: bex
{{#caadd: foobar[0]|["abc","123"]}}
  • 0
    • abc
    • 123
  • 1
    • foo: quz
    • baz: bar
  • 2
    • baz: bar
    • foo: bar

complexarrayreset[edit]

This parser function resets all arrays or one array.

Syntax[edit]
{{#complexarrayreset:key}}
Explanation[edit]
  • key (optional): The name of the array that must be unset, when empty, all arrays will be unset.

complexarraysort[edit]

This parser function sorts an array.

Syntax[edit]
{{#complexarraysort:key|options|sortingkey}}
Explanation[edit]
  • 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[edit]

We have an array called 'foobar':

  • 0
    • foo: bar
    • baz: quz
  • 1
    • foo: quz
    • baz: bar
  • 2
    • baz: bar
    • foo: bar
Function Result
{{#casort: foobar|keysort|foo}}
  • 0
    • foo: bar
    • baz: quz
  • 1
    • baz: bar
    • foo: bar
  • 2
    • foo: quz
    • baz: bar
{{#casort: foobar|keysort,desc|foo}}
  • 0
    • foo: quz
    • baz: bar
  • 1
    • foo: bar
    • baz: quz
  • 2
    • baz: bar
    • foo: bar
{{#casort: foobar|shuffle}}
  • 0
    • foo: bar
    • baz: quz
  • 1
    • foo: quz
    • baz: bar
  • 2
    • baz: bar
    • foo: bar

complexarrayunique[edit]

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

Syntax[edit]
{{#complexarrayunique:key}}
Explanation[edit]
  • key (required): The name of the array.

Interaction[edit]

complexarraypush[edit]

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

Syntax[edit]
{{#complexarraypush:key|value|noparse}}
Explanation[edit]
  • key (required): The name of the (sub)array;
  • value (required): A value in plaintext or a subarray in WSON.
  • noparse (optional, default: 0): Set this to the correct level to tell the parser what to parse in 'value' (see #Manipulating the parser).
Examples[edit]

We have an array called 'foobar':

  • 0
    • foo: bar
    • baz: quz
  • 1
    • foo: quz
    • baz: bar
  • 2
    • baz: bar
    • foo: bar
Function Result
{{#capush: foobar|bex}}
  • 0
    • foo: bar
    • baz: quz
  • 1
    • foo: quz
    • baz: bar
  • 2
    • baz: bar
    • foo: bar
  • test
{{#capush: foobar[1]|bex}}
  • 0
    • foo: bar
    • baz: quz
  • 1
    • foo: quz
    • baz: bar
    • bex
  • 2
    • baz: bar
    • foo: bar
{{#capush: foobar|(("bex":"baz"))}}
  • 0
    • foo: bar
    • baz: quz
  • 1
    • foo: quz
    • baz: bar
    • bex
  • 2
    • baz: bar
    • foo: bar
  • 3
    • bex: baz

complexarrayextract[edit]

This parser function creates a new array from a subarray.

Syntax[edit]
{{#complexarrayextract:new_key|subarray}}
Explanation[edit]
  • new_key (required): The name of the array that is going to be created;
  • subarray (required): The subarray that needs to be extracted.
Examples[edit]

We have an array called 'foobar':

  • 0
    • foo: bar
    • baz: quz
  • 1
    • baz: bar
    • foo: bar
Function Result
{{#caextract: boofar|foobar[0]}}

boofar:

  • 0
    • foo: bar
    • baz: quz

complexarraymerge[edit]

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

Syntax[edit]
{{#complexarraymerge:new_key|key1|key2|...|keyn|options}}
Explanation[edit]
  • 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
Examples[edit]

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
Function Result
{{#camerge: farboo | foobar | boofar}}

farboo:

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

complexarraypusharray[edit]

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

Syntax[edit]
{{#complexarraypusharray:new_key|key1|key2|...|keyn}}
Explanation[edit]
  • 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;
Examples[edit]

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
Function Result
{{#capusharray: farboo | foobar | boofar}}

farboo:

  • 0
    • 0
      • foo: bar
      • baz: quz
    • 1
      • baz: bar
      • foo: bar
  • 1
    • 0
      • boo: bar
      • far: quz
    • 1
      • foo: quux
      • bar: bar

Iteration[edit]

complexarraymap[edit]

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

Syntax[edit]
{{#complexarraymap:key|mapping_key|subject|delimiter|hide}}
Explanation[edit]
  • 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;
  • delimiter (optional): The delimiter appended to every line, except the last;
  • hide (optional): Set this to 'true' in order to hide the mapping key when no string value for it exists.
Examples[edit]

We have an array called foobar:

  • 0
    • bar
    • quz
  • 1
    • bar
    • bar
  • 2
    • bar
    • quz
  • 3
    • quux
Function Result
{{#camap: foobar | @@@ | What the @@@[0] is this @@@[1]<br/> }}

What the bar is this quz
What the bar is this bar
What the bar is this quz
What the quux is this @@@[1]

{{#camap: foobar | @@@ | What the @@@[0] is this @@@[1]<br/> | true }}

What the bar is this quz
What the bar is this bar
What the bar is this quz
What the quux is this

{{#camap: foobar | @@@ | What the @@@[0] is this @@@[1] | <br/> | true }}

What the bar is this quz
What the bar is this bar
What the bar is this quz
What the quux is this

complexarraymaptemplate[edit]

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

Syntax[edit]
{{#complexarraymaptemplate:key|template}}
Explanation[edit]
  • 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[edit]

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
Function Result
{{#catemplate: foobar|Template}}
{{Template|foo=bar|baz=quz}}
{{Template|baz=bar|foo=bar}}
{{Template|foo=quz|baz=bar|bar=["bex","box"]}}
{{#catemplate: boofar|Template}}
{{Template|foobar|bazbar|boofar}}
{{#catemplate: bazbar|Template}}
{{Template|foo=bar|boo=far}}

Anonymous[edit]

These functions use anonymous arrays. The function handles both the definition and output of the array. You do not have to define an array beforehand.

complexarrayarraymap[edit]

This parser function is very similar to #complexarraymap, but the input and output is handled in the same function (which makes it anonymous).

Syntax[edit]
{{#complexarrayarraymap: value | delimiter | variable | formula | new_delimiter }}
Explanation[edit]
  • value (required): The value to be split;
  • delimiter (required): The delimiter to split value on;
  • variable (required): String to be replaced in 'formula';
  • formula (required): String where 'variable' is replaced;
  • new_delimiter (required): The delimiter between results.
Examples[edit]
Function Result
{{#caamap: a, b, c | , | @@ | Current variable: @@ | !<br/>}}
Current variable: a!<br/>
Current variable: b!<br/>
Current variable: c
{{#caamap: a; b; c | ; | ! | Just ! test | <br/>}}
Just a test<br/>
Just b test<br/>
Just c test

complexarrayparent[edit]

This function returns the key of the parent of the given key.

Syntax[edit]
{{#complexarrayparent: key }}
Explanation[edit]
  • key (required): The key from which the parent key should be returned
Examples[edit]
Function Result
{{#caparent: foobar[0][1][test] }}
foobar[0][1]

Wairudokado operator[edit]

The Wairudokado operator (Japanese: ワイルドカード, pronounced Wairudokādo, meaning wildcard; a tribute to the Scope Resolution Operator in PHP) is a powerful operator that gives users the ability to use wildcards when manipulating or printing subarrays.

Example[edit]

This operator can be used on every parser function that supports subarrays (such as #complexarrayprint). Suppose we have the array foobar:

  • 0
    • name: Foo
  • 1
    • name: Bar
  • 2
    • name: Baz
  • 3
    • name: Bex

And we want to print every value of "name". We could use a #complexarraymap to iterate over the array and print each value seperately, but we can also use a Wairudokado operator in the #complexarrayprint function.

Function Result
{{#caprint: foobar[*][name]}}
  • Foo
  • Bar
  • Baz
  • Bex
When a Wairudokado operator is at the end of the pointer, it is ignored. Sequential Wairudokado operators are interpreted as one.

Semantic MediaWiki[edit]

Please make sure you have completed step three of the installation process (see below).
This result printer requires Semantic MediaWiki 3.0 or higher.

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

Semantic variables[edit]

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[edit]

WSArrays defines three new parameters:

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

Writing extensions[edit]

While WSArrays provides many functions for manipulating and showing arrays, sometimes these are not enough. For this reason, we provide an interface to easily extend the functionality of WSArrays with new parser functions.

Extensions are placed in the extensions/ directory. Each extension is implemented as a derived class from Extension.php. The name of the file in which this class will be located, must be the same as the class name (case-sensitive). An example for the class ExampleClass would be ExampleClass.php. The class must implement at least the following methods:

<?php

class ExampleClass extends Extension {
    /**
     * Returns the name of this parser function.
     *
     * @return string
     */
    public function getName() {
        return 'exampleclass';
    }

    /**
     * Should return an array containing aliases of this parser function.
     *
     * @return array
     */
    public function getAliases() {
        return [
            'caexample',
            'caexampleclass'
        ];
    }

    /** 
     * Should return either 'sfh' or 'normal'. 
     * When 'sfh' is returned, the setFunctionHook function is called with Parser::SFH_OBJECT_ARGS
     * as a parameter, allowing for a deeper integration with the parser.
     *
     * @return string
     */
    public function getType() {
        return 'sfh';
    }

    /**
     * This function is called by the parser.
     *
     * @return mixed
     */
    public static function getResult( Parser $parser, $arg1, $arg2, ...) {
        return 'Foobar';
    }
}

?>

Returning the result[edit]

getResult() is executed by the parser hook. You can read how to write parser functions here. The documentation below is specific to WSArrays.

Manipulating arrays[edit]

All arrays in WSArrays must be stored as a SafeComplexArray object. If you want to manipulate an existing array, you must convert the SafeComplexArray object to an array, manipulate the array and then convert it back to a SafeComplexArray object.

public static function getResult( Parser $parser, $arg1, $arg2, $arg3 ) {
    // $arg1 contains the name of an existing array;
    // getUnsafeArray() will return the array without escaping it first. Use getArray() to get the escaped array (recommended when printing an array).
    $array = WSArrays::$arrays[$arg1]->getUnsafeArray();

    // Manipulate array...

    // Arrays are stored in the variable $arrays, located in the WSArrays class.
    // If you do not save the array as a SafeComplexArray, existing parser functions will not work with this array.
    WSArrays::$arrays[$arg1] = new SafeComplexArray( $array );

    return null;
}

or when using SFH_OBJECT_ARGS:

public static function getResult( Parser $parser, $frame, $args ) {
    // Convert the first element in the $args array into a string.
    // Omit PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES if you need the parser to first parse the arguments.
    // You can also use GlobalFunctions::getSFHValue() and GlobalFunctions::rawValue().
    if ( isset( $args[0] ) ) {
        $arg1 = trim( $frame->expand( $args[0], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES ) );
    }

    // $arg1 contains the name of an existing array.
    // getUnsafeArray() will return the array without escaping it first. Use getArray() to get the escaped array (recommended when printing an array).
    $array = WSArrays::$arrays[$arg1]->getUnsafeArray();

    // Manipulate array...

    // Arrays are stored in the variable $arrays, located in the WSArrays class.
    // If you do not save the array as a SafeComplexArray, existing parser functions will not work with this array.
    WSArrays::$arrays[$arg1] = new SafeComplexArray($array);

    return null;
}

Registering the extension[edit]

In order to enable the extension, you must add the extension name and aliases to WSArrays.i18n.php.

Add the following to $magicWords['en']:

'<extensionname>' => [ 0, '<extensionname>' ],
'<alias1>' => [ 0, '<alias1>' ],
'<alias2>' => [ 0, '<alias2>' ],
...

Manipulation of the parser[edit]

WSArrays manipulates the Parser in several ways. In order to use WSArrays to its fullest extend, it is important to know about this. This only applies to the following parser functions:

How WSArrays manipulates the parser[edit]

WSArrays manipulates the parser by using SFH_OBJECT_ARGS. This way, the parser arguments are passed as PPNode objects instead of plain text. This allows for conditional expansion of the parse tree (see doc.wikimedia.org for more information). Using SFH_OBJECT_ARGS we can tell the parser to not parse the elements and return the raw text inputted by the user, which we can then parse in WSArrays.

How to control the manipulation[edit]

Different people have different needs, which is why we allow you to control the manipulation of the parser. Again, this documentation only applies to the parser functions listed above.

By default, all input is automatically parsed by the parser before it is passed over to WSArrays (except for the 'map' in #complexarraymap and #complexarrayprint.) This allows you to use template parameters as well as magic words and templates when manipulating or defining arrays. This is however not always what you want. For instance, when you want to use a very complex template inside of an array, and you don't want to completely break when you use #complexarrayprint on it, you can tell WSArrays to not parse the input. If you then print the array, the template is printed as if it were enclosed with nowiki tags.

What if I want to parse the template later on?[edit]

Not parsing the template entirely is probably not what you want. WSArrays tells the parser to parse the element when necessary, such as when using it in a map or when printing it as a value.

Parser levels[edit]

WSArrays has five parser levels.

Parser level Result
0 Have the parser parse the string completely before passing it on to WSArrays (default).
1 Include the constant PPFrame::NO_IGNORE in the frame expansion
2 Include the constant PPFrame::NO_IGNORE and PPFrame::NO_ARGS in the frame expansion.
3 Include the constant PPFrame::NO_IGNORE, PPFrame::NO_ARGS and PPFrame::NO_TEMPLATES in the frame expansion, which tells the parser not to parse templates.
4 Include the constant PPFrame::NO_IGNORE, PPFrame::NO_ARGS and PPFrame::NO_TAGS in the frame expansion, which tells the parser not to parse tags.
5 Include the constant PPFrame::NO_IGNORE, PPFrame::NO_ARGS, PPFrame::NO_TAGS and PPFrame::NO_TEMPLATES in the frame expansion, which tells the parser not to parse tags or templates.

Installation[edit]

  • Download and place the file(s) in a directory called WSArrays in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    wfLoadExtension( 'WSArrays' );
    
  • If you have Semantic MediaWiki installed, move the ComplexArrayPrinter.php file from extensions/WSArrays/ to extensions/SemanticMediaWiki/src/Query/ResultPrinters/ and set $wfEnableResultPrinter to true in your LocalSettings.php to enable the custom format.
  • Configure as required.
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Configuration[edit]

WSArrays has 3 configuration parameters.

$wfSkipVersionControl
Option to skip version control and force the initialization of WSArrays, accepts a boolean (default: false).
$wfEnableResultPrinter
Option to enable the Semantic MediaWiki result printer, accepts a boolean (default: false).
$wfEscapeEntitiesInArrays
Option to escape HTML characters in arrays, accepts a boolean (default: false).

See also[edit]