Manual:Hooks/InternalParseBeforeLinks

From MediaWiki.org
Jump to: navigation, search
InternalParseBeforeLinks
Available from version 1.10.0
Used to process the expanded wiki code after <nowiki>, HTML-comments, and templates have been treated.

*Define function:
function fnMyHook( Parser &$parser, &$text ) { ... }

*Attach hook:
$wgHooks['InternalParseBeforeLinks'][] = 'MyExtensionHooks::someExample';
Called from: Parser.php

*For more information about attaching hooks, see Manual:Hooks.
*For examples of extensions using this hook, see Category:InternalParseBeforeLinks extensions.


[edit] Details

$text will hold the text for the page. To change the page text, modify this value, just as explained in ParserBeforeStrip. Note that you should not access certain global variables during this hook, as is documented in Parser.php.

This hook is intended to enable extensions that provide additional syntax features. It is usually desirable that those features interact with templates, comments, and other special functions of wiki code. For instance, assume that some extension implements automatic linking of certain key-words, say names of known users. So whenever someone types "Markus Krötzsch" the extension transforms this into "[[User:Markus Krötzsch|Markus Krötzsch]]". Now consider the following example text:

1 Markus Krötzsch
2 <nowiki>Markus Krötzsch</nowiki>
3 Markus <!-- some comment --> Krötzsch
4 {{Inserttext|Markus}} Krötzsch

Where we assume that the template "Inserttext" just pastes the first parameter. In this case, users might expect the extension to transform line 1, 3, and 4, but not line 2. However, other parser hooks (e.g. ParserBeforeStrip and ParserAfterStrip) run before the wiki code is processed, such that lines 1 and 2 would be transformed instead. This parser hook fixes this issue to some extent.

The downside is that some processing steps have been done before, and will no longer be performed on the output of the hook. So the hook should insert only simple wiki code with links, and safe HTML code that is allowed for any user.

Also note that this hook is called any time some parsing happens, not just for displaying article contents. For instance, edit disclaimer or image galleries also are piped through a parser. Thus, the hook must be very careful when adding contents to the text. For further discussion, see ParserBeforeStrip.

[edit] See also

Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox