Manual:Hooks/SkinTemplateNavigation
File:OOjs UI icon alert-destructive.svg | <translate> This feature was removed completely in version <tvar name=ver>1.41.0</tvar> (after being deprecated in <tvar name=4>1.39</tvar>).</translate> Please use Universal instead of this hook if possible. See <translate> task <tvar name=1>T255319</tvar></translate> |
SkinTemplateNavigation | |
---|---|
<translate> Available from <tvar name=1><translate> version <tvar </tvar></translate> <translate> Removed in <tvar name=1><translate> version <tvar (Gerrit change 932019)</tvar></translate> Alter the structured navigation links in SkinTemplates | |
<translate> Define function:</translate> | public static function onSkinTemplateNavigation( SkinTemplate $skinTemplate, array &$links ) { ... }
|
<translate> Attach hook:</translate> | <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
"Hooks": {
"SkinTemplateNavigation": "MediaWiki\\Extension\\MyExtension\\Hooks::onSkinTemplateNavigation"
}
}
|
<translate> Called from:</translate> | <translate> File(s):</translate> SkinTemplate.php |
<translate> Interface:</translate> | SkinTemplateNavigationHook.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:SkinTemplateNavigation extensions</tvar>.</translate>
Details
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
// 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
- SpecialPage — Called on special pages, after the special tab, but before variants.
- Universal — Called on all types of pages, after all tabs and variants have been added