refactor(core): ♻️ use MW footer data and add onto it

This commit is contained in:
alistair3149 2022-10-04 21:41:42 -04:00
parent 4c9aa17bb2
commit ac12ff0444
No known key found for this signature in database
3 changed files with 13 additions and 43 deletions

View file

@ -31,39 +31,18 @@ namespace MediaWiki\Skins\Citizen\Partials;
final class Footer extends Partial {
/**
* Get rows that make up the footer
* Decorate footer template data
*
* @param array $footerData original data-footer
* @return array for use in Mustache template describing the footer elements.
*/
public function getFooterData(): array {
$skin = $this->skin;
$data = [];
$footerLinks = $skin->getFooterLinksPublic();
// Based on SkinMustache
// Backported because of 1.35 support
foreach ( $footerLinks as $category => $links ) {
$items = [];
$rowId = "footer-$category";
foreach ( $links as $key => $link ) {
if ( $link ) {
$items[] = [
'id' => "$rowId-$key",
'html' => $link,
// This is not great, need to reimplemented when we move to 1.39
'label' => $skin->msg( "citizen-page-info-$key" )
];
}
}
$data['data-citizen-' . $category] = [
'id' => $rowId,
'className' => null,
'array-items' => $items
];
public function decorateFooterData( $footerData ): array {
// Add label to footer-info to use in ContentFooter
foreach ( $footerData['data-info']['array-items'] as &$item ) {
$msgKey = 'citizen-page-info-' . $item['name'];
$item['label'] = $this->skin->msg( $msgKey )->text();
}
return $data;
return $footerData;
}
}

View file

@ -99,7 +99,7 @@ class SkinCitizen extends SkinMustache {
'data-personal-menu' => $header->buildPersonalMenu(),
'data-search-box' => $header->buildSearchProps(),
],
'data-citizen-footer' => $footer->getFooterData(),
'data-footer' => $footer->decorateFooterData( $parentData['data-footer'] ),
// HTML strings
'html-title-heading--formatted' => $pageTitle->buildTitle( $parentData, $title ),
'html-citizen-jumptotop' => $this->msg( 'citizen-jumptotop' )->text() . ' [home]',
@ -131,15 +131,6 @@ class SkinCitizen extends SkinMustache {
return parent::buildPersonalUrls();
}
/**
* Change access to public, as it is used in partials
*
* @return array
*/
final public function getFooterLinksPublic() {
return parent::getFooterLinks();
}
/**
* Change access to public, as it is used in partials
*

View file

@ -3,7 +3,7 @@
}}
<footer class="mw-body-footer">
{{{html-categories}}}
{{#data-citizen-footer}}
{{#data-citizen-info}}{{>ContentFooter__item}}{{/data-citizen-info}}
{{/data-citizen-footer}}
{{#data-footer}}
{{#data-info}}{{>ContentFooter__item}}{{/data-info}}
{{/data-footer}}
</footer>