Manual:Hooks/CategoryPageView

From Linux Web Expert

The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
CategoryPageView
<translate> Available from <tvar name=1><translate> version <tvar </tvar></translate>
Called before viewing a categorypage in CategoryPage::view
<translate> Define function:</translate>
public static function onCategoryPageView( &$categoryPage ) { ... }
<translate> Attach hook:</translate> <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
	"Hooks": {
		"CategoryPageView": "MediaWiki\\Extension\\MyExtension\\Hooks::onCategoryPageView"
	}
}
<translate> Called from:</translate> <translate> File(s):</translate> CategoryPage.php
<translate> Interface:</translate> CategoryPageViewHook.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:CategoryPageView extensions</tvar>.</translate>

Details

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

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

Notes

  • 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.