Extension:UserSidebar

Developer Info
To add / register a custom Widget, the following steps have to be done.

Register hooks

 * Add the following two hooks in extension.json (replace MyExtension with your class name):

"BSUserSidebarDefaultWidgets": "MyExtension::onBSUserSidebarDefaultWidgets", "BSWidgetListHelperInitKeyWords": "MyExtension::onBSWidgetListHelperInitKeyWords"


 * Define callback functions in "MyExtension"

public function onBSUserSidebarDefaultWidgets( &$aViews, $oUser, $oTitle ) { $aViews['MYKEYWORD'] = self::getViewWidget; return true; }

public static function onWidgetListKeyword { return self::getViewWidget; }


 * Define view creator

public static function getViewWidget{ $context = new RequestContext; $oUser = $context->getUser; if($oUser->getId == 0){ return; }

$dbr = wfGetDB( DB_SLAVE ); $res = $dbr->select(		 [ 'my_table' ], //table		  [ 'my_table_page_name', 'my_table_page_namespace', 'my_table_page_owner' ],//selected field		  [ 'my_table_page_owner' => $oUser->getName ],//filter		  __METHOD__,		  [ 'LIMIT' => 10, 'ORDER BY' => 'my_table_page_name' ]//options		); $aData = array; foreach ( $res as $row ) { $oTitle = Title::makeTitle( $row->my_table_page_namespace, $row->my_table_page_name ); $sLink = Html::element(				'a', [				 'href' => $oTitle->getLinkURL,				  'title' => $oTitle->getText				], $oTitle->getText			); $aData[] = "". $sLink. ""; }

$oViewWidget= new ViewWidget; $oViewWidget ->setAdditionalBodyClasses( array( 'bs-nav-links' ) ) ->setTitle( wfMessage( 'myextension-widget-title' )->plain ) ->setBody( "".implode("\n", $aData)."" ) ;		return $oViewWidget; }
 * define i18n key "myextension-widget-title"
 * the widget should be visible for logged in users in UserSidebar now