Manual:Hooks/ArticleViewHeader

From MediaWiki.org
Jump to navigation Jump to search
ArticleViewHeader
Available from version 1.6.0
Occurs when an articleheader is shown
Define function:
public static function onArticleViewHeader( &$article, &$outputDone, &$pcache ) { ... }
Attach hook:

In extension.json:

{
	"Hooks": {
		"ArticleViewHeader": "MyExtensionHooks::onArticleViewHeader"
	}
}

For MediaWiki ≤1.25:

$wgHooks['ArticleViewHeader'][] = 'MyExtensionHooks::onArticleViewHeader';
Called from:File(s): Article.php

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

Details[edit]

  • $article: (Article) the article (object)
  • $outputDone: (boolean) Set to true to prevent the article content from being output.
  • $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.

See also[edit]