Open main menu

Extension:Parser Fun

MediaWiki extensions manual
OOjs UI icon advanced.svg
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 (Danwetalk)
Latest version 0.5.0 (2017-07-25)
MediaWiki 1.23+
Database changes No
License ISC License
Download
README
Parameters
  • $egParserFunEnabledFunctions
Hooks used
ParserFirstCallInit
MagicWordwgVariableIDs
ParserGetVariableValueSwitch
Translate the Parser Fun extension if it is available at translatewiki.net
Check usage and version matrix.

The Parser Fun extension Enhances MediaWiki with the following features:

Contents

The "THIS:" prefixEdit

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

#parse parser functionEdit

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

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 functionEdit

{{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 return 0. Defined in a template directly used by the main page, the same would return 1.
list - will return a list of all sites in the stack, including the page where CALLER is defined.
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 0 represents the stacks top (page where CALLER is defined on). Default is 0. If negative, the list starts that far from the stacks top. This also works as limiter in count mode (default 1 in 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 DevelopersEdit

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.

InstallationEdit

  • Prerequisites:
  • Download and place the file(s) in a directory called ParserFun in your extensions/ folder.

ConfigurationEdit

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 alsoEdit

  • 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.