Manual:Hooks/SkinTemplateNavigation

SkinTemplateNavigation
Available from version 1.16.0
Removed in version 1.41.0 (Gerrit change 932019)
Alter the structured navigation links in SkinTemplates
Define function:
public static function onSkinTemplateNavigation( SkinTemplate $skinTemplate, array &$links ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"SkinTemplateNavigation": "MediaWiki\\Extension\\MyExtension\\Hooks::onSkinTemplateNavigation"
	}
}
Called from: File(s): skins/SkinTemplate.php
Interface: SkinTemplateNavigationHook.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, see the other two SkinTemplateNavigation hooks for other points tabs can be modified at.

In MediaWiki < 1.37, this hook is called only after tabs have been added, but before variants have been added. In 1.37 this hook is called after tabs AND variants have been added.

  • $skinTemplate: 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']
	);
}


An example you can paste into LocalSettings.php

$wgHooks['SkinTemplateNavigation'][] = function ( $template, &$links ) {
	// add a new namespace tab
	$links['namespaces']['new'] = [
		'class' => '',
		'href' => '#/SkinTemplateNavigation',
		'text' => 'SkinTemplateNavigationTab',
	];

	// add a new action
	$links['actions']['new'] = [
		'class' => '',
		'href' => '#/SkinTemplateNavigation',
		'text' => 'SkinTemplateNavigation action',
	];

	// add a new view
	$links['views']['new'] = [
		'class' => '',
		'href' => '#/SkinTemplateNavigation',
		'text' => 'SkinTemplateNavigation view',
	];
};

See also

edit