Manual:Hooks/SidebarBeforeOutput

Category:MediaWiki hooks#SidebarBeforeOutput Category:Hooks added in MediaWiki 1.24.0#SidebarBeforeOutput
SidebarBeforeOutput
Available from version 1.24.0
Called at the end of Skin::buildSidebar(), done to be used in order to alter the sidebar content just before the display
Define function:
public static function onSidebarBeforeOutput( Skin $skin, &$sidebar ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"SidebarBeforeOutput": "MediaWiki\\Extension\\MyExtension\\Hooks::onSidebarBeforeOutput"
	}
}
Called from: File(s): skins/Skin.phpCategory:MediaWiki hooks included in Skin.php#SidebarBeforeOutput
Interface: SidebarBeforeOutputHook.php

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

Details

  • $skin: Skin object
  • &$sidebar: Sidebar contents, in the same format as SkinBuildSidebar

Modify $sidebar to add or modify sidebar portlets.

Warning: You should probably use SkinBuildSidebar instead, in order to use the caching system. This hook is run on each display and should only be used if the contents of the sidebar vary on a per-request basis (e.g. Extension:DynamicSidebar).

Caveats

Currently languages and toolbox menus are available for modification in this hook, however whether they display or not will be determined by the skin that is rendering.

More information can be found in T253783.

Examples

The following example allows you to add a new menu to the sidebar:

$wgHooks['SidebarBeforeOutput'][] = function ( $skin, &$bar ) {
	# note: heading can be either a message key. If no message exists it will be treated as a plain text.
	$heading = 'msg-heading';
	$bar[ $heading ] = [
		[
			'msg' => 'my-label-message',
			'href' => '//example.com'
		]
	];
};

To add a new menu

$wgHooks['SidebarBeforeOutput'][] = function ( Skin $skin, &$sidebar ) {
	foreach ( $sidebar as $key => $data ) {
		$sidebar[$key][] = [
			"text" => "SidebarBeforeOutput link",
			"href" => '#SidebarBeforeOutputLocalSettings.php',
		];
	}
};

If you want append a single item in the default 'toolbox' section, use 'TOOLBOX' string as the array key

$wgHooks['SidebarBeforeOutput'][] = function ( Skin $skin, &$sidebar ) {
	$sidebar['TOOLBOX'][] = [
		"text" => "My custom label",
		"href" => '#SidebarBeforeOutputLocalSettings.php',
	];
};

Note about extending TOOLBOX

When extending the TOOLBOX menu, as a general rule, please ensure that the link relates to the current page in someway e.g. contains the page title in the URL. The expectation is that this menu only contains items relating to the current page.

Category:Hooks added in MediaWiki 1.24.0 Category:MediaWiki hooks Category:MediaWiki hooks included in Skin.php