From b46ff19b3fb036bbb62065a336fe99b509c16924 Mon Sep 17 00:00:00 2001 From: Isarra Date: Tue, 2 Jun 2020 20:35:16 +0000 Subject: [PATCH] Use getFooterBlock instead of getFooter to avoid weird overflows on mobile Apparently getFooterBlock never actually made it into core, so copied out of Example. Bug: T254266 Change-Id: Id62319314937080b99f2b93fd7b7fa62527d8fe7 --- includes/TimelessTemplate.php | 112 +++++++++++++++++++++++++++++++++- resources/screen-common.less | 10 +-- resources/screen-mobile.less | 5 ++ 3 files changed, 119 insertions(+), 8 deletions(-) diff --git a/includes/TimelessTemplate.php b/includes/TimelessTemplate.php index bec7ebe..cd413b0 100644 --- a/includes/TimelessTemplate.php +++ b/includes/TimelessTemplate.php @@ -97,7 +97,7 @@ class TimelessTemplate extends BaseTemplate { $html .= Html::rawElement( 'div', [ 'id' => 'mw-footer-container', 'class' => 'mw-footer-container ts-container' ], Html::rawElement( 'div', [ 'id' => 'mw-footer', 'class' => 'mw-footer ts-inner' ], - $this->getFooter() + $this->getFooterBlock() ) ); @@ -319,6 +319,116 @@ class TimelessTemplate extends BaseTemplate { return array_merge( $class, $extraClasses ); } + /** + * Better renderer for getFooterIcons and getFooterLinks, based on Vector's HTML output + * (as of 2016) + * + * @param array $setOptions Miscellaneous other options + * * 'id' for footer id + * * 'class' for footer class + * * 'order' to determine whether icons or links appear first: 'iconsfirst' or links, though in + * practice we currently only check if it is or isn't 'iconsfirst' + * * 'link-prefix' to set the prefix for all link and block ids; most skins use 'f' or 'footer', + * as in id='f-whatever' vs id='footer-whatever' + * * 'icon-style' to pass to getFooterIcons: "icononly", "nocopyright" + * * 'link-style' to pass to getFooterLinks: "flat" to disable categorisation of links in a + * nested array + * + * @return string html + */ + protected function getFooterBlock( $setOptions = [] ) { + // Set options and fill in defaults + $options = $setOptions + [ + 'id' => 'footer', + 'class' => 'mw-footer', + 'order' => 'iconsfirst', + 'link-prefix' => 'footer', + 'icon-style' => 'icononly', + 'link-style' => null + ]; + + // phpcs:ignore Generic.Files.LineLength.TooLong + '@phan-var array{id:string,class:string,order:string,link-prefix:string,icon-style:string,link-style:?string} $options'; + $validFooterIcons = $this->getFooterIcons( $options['icon-style'] ); + $validFooterLinks = $this->getFooterLinks( $options['link-style'] ); + + $html = ''; + + $html .= Html::openElement( 'div', [ + 'id' => $options['id'], + 'class' => $options['class'], + 'role' => 'contentinfo', + 'lang' => $this->get( 'userlang' ), + 'dir' => $this->get( 'dir' ) + ] ); + + $iconsHTML = ''; + if ( count( $validFooterIcons ) > 0 ) { + $iconsHTML .= Html::openElement( 'ul', [ 'id' => "{$options['link-prefix']}-icons" ] ); + foreach ( $validFooterIcons as $blockName => $footerIcons ) { + $iconsHTML .= Html::openElement( 'li', [ + 'id' => Sanitizer::escapeIdForAttribute( + "{$options['link-prefix']}-{$blockName}ico" + ), + 'class' => 'footer-icons' + ] ); + foreach ( $footerIcons as $icon ) { + $iconsHTML .= $this->getSkin()->makeFooterIcon( $icon ); + } + $iconsHTML .= Html::closeElement( 'li' ); + } + $iconsHTML .= Html::closeElement( 'ul' ); + } + + $linksHTML = ''; + if ( count( $validFooterLinks ) > 0 ) { + if ( $options['link-style'] === 'flat' ) { + $linksHTML .= Html::openElement( 'ul', [ + 'id' => "{$options['link-prefix']}-list", + 'class' => 'footer-places' + ] ); + foreach ( $validFooterLinks as $link ) { + $linksHTML .= Html::rawElement( + 'li', + [ 'id' => Sanitizer::escapeIdForAttribute( $link ) ], + $this->get( $link ) + ); + } + $linksHTML .= Html::closeElement( 'ul' ); + } else { + $linksHTML .= Html::openElement( 'div', [ 'id' => "{$options['link-prefix']}-list" ] ); + foreach ( $validFooterLinks as $category => $links ) { + $linksHTML .= Html::openElement( 'ul', + [ 'id' => Sanitizer::escapeIdForAttribute( + "{$options['link-prefix']}-{$category}" + ) ] + ); + foreach ( $links as $link ) { + $linksHTML .= Html::rawElement( + 'li', + [ 'id' => Sanitizer::escapeIdForAttribute( + "{$options['link-prefix']}-{$category}-{$link}" + ) ], + $this->get( $link ) + ); + } + $linksHTML .= Html::closeElement( 'ul' ); + } + $linksHTML .= Html::closeElement( 'div' ); + } + } + + if ( $options['order'] === 'iconsfirst' ) { + $html .= $iconsHTML . $linksHTML; + } else { + $html .= $linksHTML . $iconsHTML; + } + + $html .= $this->getClear() . Html::closeElement( 'div' ); + + return $html; + } + /** * Sidebar chunk containing one or more portlets * diff --git a/resources/screen-common.less b/resources/screen-common.less index 03d38f2..e9528bc 100644 --- a/resources/screen-common.less +++ b/resources/screen-common.less @@ -168,15 +168,11 @@ body { .footer-icons { float: right; margin: 0 0 0 1em; - - li { - margin: 0 0 1em 0; - } } - .footer-places li { - display: inline; - padding-right: 1em; + #footer-places li { + display: inline-block; + margin: 0 1em 0 0; } #lastmod, diff --git a/resources/screen-mobile.less b/resources/screen-mobile.less index 52648c4..6a7614a 100644 --- a/resources/screen-mobile.less +++ b/resources/screen-mobile.less @@ -10,6 +10,11 @@ padding: 0 @content-padding; } +#mw-footer .footer-icons { + clear: both; + margin-bottom: 0.5em; +} + .color-middle { margin: auto; width: 34%;