Manual:Hooks/CategoryPageView

From MediaWiki.org
Jump to: navigation, search
CategoryPageView
Available from version 1.4.3
Called before viewing a categorypage in CategoryPage::view
Define function:
public static function onCategoryPageView( &$categoryArticle ) { ... }
Attach hook:

In extension.json:

{
	"Hooks": {
		"CategoryPageView": [
			"MyExtensionHooks::onCategoryPageView"
		]
	}
}

For MediaWiki ≤1.25:

$wgHooks['CategoryPageView'][] = 'MyExtensionHooks::onCategoryPageView';
Called from: File(s): CategoryPage.php

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

Details[edit]

  • $categoryArticle: CategoryPage instance (CategoryPage is a subclass of Article)

If this method returns false, then the default behavior of CategoryPage::view will be skipped.

Notes[edit]

  • If there is a diff and $diffOnly is set, then the diff would be displayed and this hook won't be reached.
  • This hook is never accessed when previewing a page. The category listing is generated via EditPage::showPreview() instead of CategoryPage:view().
  • An alternative way to modify the appearance of a category page is to use the ArticleFromTitle hook, and create a new Article object using a custom class derived from CategoryPage. This method allows the category page to be customized in both preview and standard view mode. See the CategoryTree extension for an example.