Extension:StringFunctionsEscaped
|
StringFunctionsEscaped Release status: stable |
|||
|---|---|---|---|
| Implementation | Parser function | ||
| Description | Defines a superset of string parser functions that allow character escaping in the 'search for' and 'replace with' arguments. | ||
| Author(s) | Jack D. Pond (jpondTalk) | ||
| Last version | 1.0.1 (2010-06-07) | ||
| MediaWiki | Tested with 1.14,1.15,1.16A, Should work with all | ||
| License | GNU Version 2 | ||
| Download | Download snapshot Subversion [Help] |
||
| Example | examples | ||
|
|||
|
|||
|
Check usage (experimental) |
|||
Contents |
[edit] What can this extension do?
Wikitext allows the imbedding of certain control characters (newline, tab, etc.). These parser functions allows the developer to find and manipulate standard c-type escape character sequence (\n,\t, etc.) within wikitext.
These parser functions can be used to make infoblox-type templates and/or forms much more WYSIWIG (see examples) for novice/non-technical users.
[edit] Usage
All parser functions are invoked exactly as their string parser functions would be (except with the '_e' appended). They can be used exactly as their counterparts are, even if there are no embedded special characters.
[edit] pos_e: (string position)
{{#pos_e:value|key|offset}}
Returns the first position of key inside the given value, or an empty string. If offset is defined, this method will not search the first offset characters.
See: http://php.net/manual/function.strpos.php
[edit] rpos_e: (string position, reverse)
{{#rpos_e:value|key}}
Returns the last position of key inside the given value, or -1 if the key is not found. When using this to search for the last delimiter, add +1 to the result to retreive position after the last delimiter. This also works when the delimiter is not found, because "-1 + 1" is zero, which is the beginning of the given value.
See: http://php.net/manual/function.strrpos.php
[edit] pad_e: (pad string)
{{#pad_e:value|length|with|direction}}
Returns the value padded to the certain length with the given with string. If the with string is not given, spaces are used for padding. The direction may be specified as: 'left', 'center' or 'right'.
See: http://php.net/manual/function.str-pad.php
[edit] replace_e: (string replace)
{{#replace_e:value|from|to}}
Returns the given value with all occurences of 'from' replaced with 'to'.
See: http://php.net/manual/function.str-replace.php
[edit] explode_e: (explode string)
{{#explode_e:value|delimiter|position}}
Splits the given value into pieces by the given delimiter and returns the position-th piece. Empty string is returned if there are not enough pieces.
Note: Pieces are counted from 0.
Note: A negative value can be used to count pieces from the end, instead of counting from the beginning. The last piece is at position -1.
See: http://php.net/manual/function.explode.php
[edit] stripnewlines: (remove multiple newlines)
{{#stripnewlines:value}}
Any time there is more than one newline in "value", they are changed to a single newline. This is useful for creating templates with complex but readable wiki text that wont impact on the layout of the calling page.
[edit] Download instructions
Download the extension from SVN and place it in $IP/extensions/StringFunctionsEscaped/StringFunctionsEscaped.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.
[edit] Installation
String functions were integrated into Extension:ParserFunctions extension as of r50997. This revision of Extension:ParserFunctions is designed for MediaWiki 1.16, but updating to the trunk version may work on previous versions. If you are using a prior version of Extension:ParserFunctions, you will also have to include Extension:StringFunctions.
Install and test Extension:ParserFunctions and (if necessary) Extension:StringFunctions prior to installing this extension.
This extension must be included AFTER the invocation of the string parser functions. To install this extension, add the following to LocalSettings.php:
[edit] For MediaWiki 1.15.1 and before
require_once("$IP/extensions/ParserFunctions/ParserFunctions.php"); require_once("$IP/extensions/StringFunctions/StringFunctions.php"); require_once("$IP/extensions/StringFunctionsEscaped/StringFunctionsEscaped.php");
[edit] For MediaWiki 1.16a and after
require_once("$IP/extensions/ParserFunctions/ParserFunctions.php"); $wgPFEnableStringFunctions = true; // Note: this must be after ParserFunctions and before StringFunctionsEscaped require_once("$IP/extensions/StringFunctionsEscaped/StringFunctionsEscaped.php");
[edit] Examples
[edit] pos_e
{{#pos_e:Line 1
Line 2
Line 3|\n|7}}
Returns:
13
[edit] rpos_e
{{#rpos_e:Line 1
Line 2
Line 3|\n}}
Returns:
13
[edit] pad_e
~~{{#pad_e:xox|9|\n|center}}~~
Returns:
~~
xox
~~
[edit] replace_e
{{#replace_e:Line 1
Line 2
Line 3|\n|<br>\n}}
Returns:
Line 1<br>
Line 2<br>
Line 3
Which would display as:
Line 1
Line 2
Line 3
Rather than the unescaped:
Line 1 Line 2 Line 3
[edit] explode_e
{{#explode_e:Line 1
Line 2
Line 3|\n|1}}
Returns:
Line 2
[edit] stripnewlines
{{#stripnewlines:Line 1
Line 2
Line 3}}
Returns:
Line 1
Line 2
Line 3
Printed version:
Line 1 Line 2 Line 3
[edit] See also
The following box claims this extension is used on wikimedia wikis. However, on which wiki is it used? The check usage does not know the extension at all and no information seems to be given (or perhaps I missed it?).
|
|
This extension is being used on one or more of Wikimedia's wikis. This means that the extension is stable and works well enough to be used by such high traffic websites. A full list of the extensions installed on a particular wiki can be seen on the wiki's Special:Version page. |