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:

In extension.json:

{
	"Hooks": {
		"SkinBuildSidebar": [
			"MyExtensionHooks::onSkinBuildSidebar"
		]
	}
}

For MediaWiki ≤1.25:

$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;
}


// example working

$wgHooks['SkinBuildSidebar'][] = 'fnNewSidebarItem';

function fnNewSidebarItem( $skin, &$bar ) {
 
        $bar[ 'name of heading' ] =  array(
				array(
					'text'   => 'TestPage',
					'href'   => 'http://192.168.2.122/wiki/index.php/TestPage',
					'id'     => 'n-login',
					'active' => ''
				),
			);
        
        return true;
}