Manual:Hooks/SkinTemplateNavigation

From MediaWiki.org
Jump to: navigation, search
SkinTemplateNavigation
Available from version 1.16.0
Alter the structured navigation links in SkinTemplates
Define function:
public static function onSkinTemplateNavigation( SkinTemplate &$sktemplate, array &$links ) { ... }
Attach hook:
$wgHooks['SkinTemplateNavigation'][] = 'MyExtensionHooks::onSkinTemplateNavigation';
Called from: File(s): SkinTemplate.php

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

Details[edit]

This hook alters the navigation for skins which use buildNavigationUrls such as Vector in pre-1.18 skins. In 1.18 this hook is used to generate the tabs for all skins.

This hook is called on content pages only after tabs have been added, but before variants have been added, see the other two SkinTemplateNavigation hooks for other points tabs can be modified at.

  • &$sktemplate: SkinTemplate object
  • &$links: Structured navigation links
    • From the buildContentNavigationUrls function:
    • a structured array of links usually used for the tabs in a skin
    • There are 4 standard sections:
      • namespaces: Used for namespace tabs like special, page, and talk namespaces
      • views: Used for primary page views like read, edit, history
      • actions: Used for most extra page actions like deletion, protection, etc...
      • variants: Used to list the language variants for the page
    • Each section's value is a key/value array of links for that section. The links themselves have these common keys:
      • class: The css classes to apply to the tab
      • text: The text to display on the tab
      • href: The href for the tab to point to
      • rel: An optional rel= for the tab's link
      • redundant: If true the tab will be dropped in skins using content_actions this is useful for tabs like "Read" which only have meaning in skins that take special meaning from the grouped structure of content_navigation

Example[edit]

// Add a "Chat" tab with action=chat
public static function onSkinTemplateNavigation( SkinTemplate &$skinTemplate, array &$links ) {
	$request = $skinTemplate->getRequest();
	$action = $request->getText( 'action' );
	$links['views']['chat'] = array(
		'class' => ( $action == 'chat') ? 'selected' : false,
		'text' => "Chat",
		'href' => $skinTemplate->makeArticleUrlDetails(
			$skinTemplate->getTitle()->getFullText(), 'action=chat' )['href']
	);
	return true;
}

See Also[edit]