Manual:Hooks/SkinBuildSidebar

From MediaWiki.org
Jump to: navigation, search
SkinBuildSidebar
Available from version 1.14.0
At the end of Skin::buildSidebar().
Define function:
public static function onSkinBuildSidebar( Skin $skin, &$bar ) { ... }
Attach hook:
$wgHooks['SkinBuildSidebar'][] = 'MyExtensionHooks::onSkinBuildSidebar';
Called from: File(s): Skin.php

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

Details[edit]

  • $skin: Skin object
  • &$bar: Sidebar contents

Modify $bar to add or modify sidebar portlets.

Simple Example[edit]

/**
 * @param Skin $skin
 * @param array $sidebar
 * @return bool
 */
$wgHooks['SkinBuildSidebar'][] = 'onSkinBuildSidebar';
function onSkinBuildSidebar( $skin, &$sidebar ) {
	$sidebar['navigation'][] = [
		'text'  => $skin->msg( 'wikimediashoplink-linktext' ),
		'href'  => '//shop.wikimedia.org',
		'title' => $skin->msg( 'wikimediashoplink-link-tooltip' ),
		'id'    => 'n-shoplink',
	];
	return true;
};
$wgHooks['SkinBuildSidebar'][] = 'fnNewSidebarItem';

function fnNewSidebarItem( $skin, &$bar ) {
        $out = "<ul>\n";
        $out .= "<li>Test</li>\n";
        $out .= "</ul>\n";
        $bar[ 'name of heading' ] = $out;
        return true;
}