Manual:Hooks/ArticleViewHeader
ArticleViewHeader | |
---|---|
<translate> Available from <tvar name=1><translate> version <tvar </tvar></translate> Use this hook to control article output. This hook is called before the parser cache is about to be tried for article viewing. | |
<translate> Define function:</translate> | public static function onArticleViewHeader( Article &$article, bool|ParserOutput|null &$outputDone, bool &$pcache ) { ... }
|
<translate> Attach hook:</translate> | <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
"Hooks": {
"ArticleViewHeader": "MediaWiki\\Extension\\MyExtension\\Hooks::onArticleViewHeader"
}
}
|
<translate> Called from:</translate> | <translate> File(s):</translate> includes/page/Article.php |
<translate> Interface:</translate> | ArticleViewHeaderHook.php |
<translate> For more information about attaching hooks, see <tvar name=1>Manual:Hooks </tvar>.</translate>
<translate> For examples of extensions using this hook, see <tvar name=cat>Category:ArticleViewHeader extensions</tvar>.</translate>
Details
- $article: (Article) the article (object)
- $outputDone: (boolean, ParserOutput, or null) Set to true to prevent the article content from being output. It can also be set to an instance of ParserOutput. However, the HTML output has been set already at this stage, and it will be used instead of the internal parser output to adjust the displayed title.
- $pcache: (boolean) Whether to use the parser cache for rendering the article content.
This hook is called just prior to outputting the page content, but after the usual header content (page title, site sub-title, redirect message, etc.) have been output. It allows you to add additional content as part of this article header, e.g. a breadcrumb trail.
If you want to add custom output, you can get an OutputPage object from $article then use that object to output your content (e.g. $article->getContext()->getOutput()->addHTML('<div>This is the page header.</div>');
).
Note that this hook is not called on non-article pages (including edit pages) and it is also not called prior to outputting the edit preview.