Extension:Parser Fun
|
Parser Fun Release status: stable |
|||
|---|---|---|---|
| Implementation | Parser function | ||
| Description | Adds a parser function #parse for parsing wikitext and introduces the THIS: prefix for page information related magic variables. |
||
| Author(s) | Daniel Werner | ||
| Last version | 0.2 (2011-12-09) | ||
| MediaWiki | Tested with 1.17+ | ||
| License | ISC license | ||
| Download |
README |
||
|
|||
|
|||
| Check usage and version matrix | |||
Contents |
Usage [edit]
The Parser Fun extension Enhances MediaWiki with the following features:
The "THIS:" prefix [edit]
THIS: is a prefix for site information related magic words. With PAGENAME for example it can be used as {{THIS:PAGENAME}}. This allows to get the information from the page the phrase actually is literally defined on instead of the page which is being parsed and where the phrase was expanded into. {{THIS}} is a synonym for {{THIS:FULLPAGENAME}}. If THIS: is being used with an unsupported variable it will be interpreted as template call. Currently the following functions are supported:
- FULLPAGENAME
- PAGENAME
- BASEPAGENAME
- SUBPAGENAME
- SUBJECTPAGENAME
- TALKPAGENAME
- NAMESPACE
- SUBJECTSPACE
- ARTICLESPACE
- TALKSPACE
as well as their URL-encoded equivalents ending with EE. It is possible for other extensions to support the THIS: prefix, currently it is supported by
- All Subpage Fun extension variables.
#parse parser function [edit]
#parse is a new parser function to do several parser tasks manually on wikitext. The following can be achieved by the parse parser function:
- Parsing wikitext
- Unstripping
<nowiki>and general stripped text
By default parse will simply parse the wikitext it receives within its first parameter. There are other parameters to fulfill certain tasks as well:
- 1
- First parameter is the text which should be parsed and/or unstripped. Don't use
1=, it will ignore all=always and can't be omitted. The parameter value will always be expanded, so it makes sense to use certain templates to escape wikitext first. E.g.:{{#parse: {{((}}template {{!}}one {{!}}two {{))}} }} - parse
- Boolean value whether the input text should really be parsed (can be used to just unstrip some text).
- unstrip
- Defines whether and what kind of content should be unstripped (restored). The following values are allowed:
- none - nothing will be unstripped (default)
- nowiki - content within
<nowiki></nowiki>will be unstripped. Note: certain characters will be escaped after outstripping, so it might not be very useful for parsing that unstripped text. - general - everything else than
<nowiki></nowiki>will be unstripped. This can be content which is intended to be HTML for example. - all - will unstrip both, nowiki and general content.
{{CALLER}} variable / parser function [edit]
{{CALLER}} is a new variable and parser function introduced in Parser Fun 0.2. This basically is a template call-stack accessors. Used within a template which is included in a page, this will return the name of the page which has included the template where {{CALLER}} is defined at. It is also possible to return the caller of the caller or a even more distant caller by giving an explicit index like {{CALLER:2}}. {{CALLER:0}} on the other hand would return the same as {{THIS}} would return. It is possible to give a negative index as well, {{CALLER:-1}} for example would return the top-level page, equally to {{FULLPAGENAME}}. If the index is not represented within the stack, an empty string will be returned.
In addition, there are the following parameters which can be used with the parser function variant of CALLER:
- 1 / mode
- can be the level of the call stack to return (see explanation above). Instead of a number one of the following modes can be set:
-
- count - in this mode the current callstack level will be returned. For example
{{CALLER:count}} defined on the main page would return0. Defined in a template directly used by the main page, the same would return1. - list - will return a list of all sites in the stack, including the page where
CALLERis defined.
- count - in this mode the current callstack level will be returned. For example
- linked
- boolean whether page(s) should be returned linked.
- sep
- separator between pages in list mode. '
,' by default. Since ',' is an allowed character in page names, you might want to use '|' as delimiter in case you are planning on further processing this data. - offset
- first stack item to return in list mode, where
0represents the stacks top (page whereCALLERis defined on). Default is0. If negative, the list starts that far from the stacks top. This also works as limiter in count mode (default1in count mode). - limit
- how many items to return in list mode. If negative the list will end that far from the stacks top. This also works as limiter in count mode.
Information for Developers [edit]
If you are developer of an magic words or parser function extension such as Extension:Subpage Fun, you can adjust your extension to work with Parser Funs This: as well. Parser Fun provides a hook called GetThisVariableValueSwitch:
- Define Function
function fnMyHook( Parser &$parser, Title $title, &$magicWordId, &$ret, PPFrame $frame, array $args ){ ... }- Attach Hook
$wgHooks['GetThisVariableValueSwitch'][] = 'MyExtensionHooks::someExample';
The hook works similar to the ParserGetVariableValueSwitch. For more information on hooks, see Manual:Hooks.
Installation [edit]
This extension requires the Validator extension which has to be included first.
Once you have downloaded the code, place the ParserFun directory within your MediaWiki extensions directory. Then add the following code near the bottom of your LocalSettings.php file:
# Parser Fun require_once( "$IP/extensions/ParserFun/ParserFun.php" );
Configuration [edit]
These configuration variables have to be set in the LocalSettings file after inclusion of Parser Fun.
- $egParserFunEnabledFunctions
- Configuration variable (array) to define which Parser Fun functions should be enabled. To disable parse parser function and only enable the this prefix, one can use:
$egParserFunEnabledFunctions = array( 'this' );
See also [edit]
- Parser Functions - helpful parser functions like
#if - Subpage Fun - allows to get helpful subpage related information via parser functions or magic words. Subpage Fun is supporting the
THIS:prefix.