Manual:Hooks/OutputPageBeforeHTML
OutputPageBeforeHTML | |
---|---|
Available from version 1.6.0 Called every time wikitext is added to the OutputPage, after it is parsed but before it is added. | |
Define function: | public static function onOutputPageBeforeHTML( OutputPage $out, &$text ) { ... }
|
Attach hook: | In extension.json:
{
"Hooks": {
"OutputPageBeforeHTML": "MediaWiki\\Extension\\MyExtension\\Hooks::onOutputPageBeforeHTML"
}
}
|
Called from: | File(s): Output/OutputPage.php |
Interface: | OutputPageBeforeHTMLHook.php |
For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:OutputPageBeforeHTML extensions.
Details
edit$out
: the OutputPage (object) to which wikitext is added$text
: the HTML text (string) that is being added
This is probably not the hook you want to use.
If you want to do something on every page exactly once and it doesn't depend on the page content, consider using the BeforePageDisplay hook instead.
If you want to transform the HTML generated by the parser, consider using the ParserAfterTidy hook instead. The results of that hook will be cached in parser cache. You only need this hook if your transformation depends on the current user, or it depends on the current language and you don't want to split the cache, or if you don't want it to be cached for some reason.
Caveats
editThis hook can be executed more than once per page view if the page content is composed from multiple sources. For example, if the MediaWiki:Talkpageheader localisation message is defined, it is inserted at the top of all talk pages, and the hook is called twice: once for the content from the message and once for the content from the page's wikitext.
If you call an OutputPage method that ends up calling this hook again (such as addParserOutput
oder wrapWikiMsg
), you might end up with an infinite loop. addHTML
is safe to call.
The result of this hook isn't cached in the parser cache, so don't do anything slow in it (consider using the ParserAfterTidy hook instead).