Background
Our menu code is complicated, and as part of our Q1 technical goal (T311647 as part of a larger effort to simplify skin code T263213) we will be simplifying this. This work is an important first step towards achieving the goal.
We've started the process of building components in core. This task will add menus as a core skin component.
Developer notes
- Add a new component called SkinComponentMenuLink (or something similar e.g. SkinComponentPortletLink)
- For now, the component should be a data array with a single html property. Use the existing Skin::makeLink to make it.
- Update the Skin::makeLink function to use the new SkinComponentMenuLink component
$link = new SkinComponentMenuLink( ... ); return $link->getTemplateData()['html']
Proposed patch generates footer data using the new menu components and removes the data generation methods from the Skin and SkinTemplate classes into the Footer component class which is added to the SkinComponentRegistry and thereby automatically included in Skin::getTemplateData.
The new menu components replace the menu link generation in the Skin class. Notably Skin::MakeLink and Skin::MakeListItem leverage the new MenuLink and MenuListItem components respectively.
SkinTemplate::getFooterIcons was moved into the Skin class to pre-empt polymorphic calls when invoking Skin methods (for data creation) from within the Footer component and to pass unit tests.
Note that this data will eventually be replaced by data generation delivered by the core menu api T315014 (see attached POC patch). Many of the methods moved/created for footer data generation in this ticket/patch are temporary, will be removed, and greatly simplified with a call to the MenuBuilder service once it's ready like so:
class SkinComponentFooter implements SkinComponent {
public function getTemplateData(): array {
return $this->getFooterData();
}
/**
* Returns the footer menu data.
*
* @return array
*/
private function getFooterData(): array {
$services = MediaWikiServices::getInstance();
$footerMenuDirector = $services->getService( 'Menu.Director' );
return $footerMenuDirector->getMenuData();
}
}QA/Sign off steps
- The SkinComponentMenuListItem component would be the next obvious task to scope out referring to the proof of concept patch in https://gerrit.wikimedia.org/r/c/mediawiki/core/+/749584 and https://gerrit.wikimedia.org/r/c/mediawiki/core/+/726995
- Consider making the Footer component to allow us to map the footer to the existing menu system and hooks
'html' => $this->makeLink( $this->key, $this->item, $this->options )
- Ensure that there are no visual regressions or changes in functionality in the footer or any of the menus in all skins (modern Vector, legacy Vector, web-maintained skins).