From 03224faa0983b6f9a67bd3ab3a0c5983779e2369 Mon Sep 17 00:00:00 2001 From: Isarra Date: Sat, 25 Mar 2017 20:57:37 +0000 Subject: [PATCH] Add some common functions to BaseTemplate Breaks any skins with same-name functions with different visibility/functionality. Should mostly only be anything based on Example, because that had everything set to private for some reason. Normal skin practice for most others is to use totally different names anyway. (eg 'render...' instead of 'get...', and visualClear output done directly) * clear: returns a visualClear * getFooter: calls getFooterIcons and getFooterLinks and handles all the output; format is common to nearly every skin since MonoBook * getAfterPortlet: same as renderAfterPortlet, but doesn't directly print content * getTrail: same as printTrail, but doesn't directly print content Also made the existing print versions for the last two use the new getters. Change-Id: I5621f585b501e47b40ae80e9cb12e6a32da72275 --- includes/skins/BaseTemplate.php | 108 +++++++++++++++++++++++++++++--- 1 file changed, 100 insertions(+), 8 deletions(-) diff --git a/includes/skins/BaseTemplate.php b/includes/skins/BaseTemplate.php index e571c58c32..dc0a703853 100644 --- a/includes/skins/BaseTemplate.php +++ b/includes/skins/BaseTemplate.php @@ -287,12 +287,31 @@ abstract class BaseTemplate extends QuickTemplate { * @param string $name */ protected function renderAfterPortlet( $name ) { + echo $this->getAfterPortlet( $name ); + } + + /** + * Allows extensions to hook into known portlets and add stuff to them + * + * @param string $name + * + * @return string html + * @since 1.29 + */ + protected function getAfterPortlet( $name ) { + $html = ''; $content = ''; Hooks::run( 'BaseTemplateAfterPortlet', [ $this, $name, &$content ] ); if ( $content !== '' ) { - echo "
$content
"; + $html = Html::rawElement( + 'div', + [ 'class' => [ 'after-portlet', 'after-portlet-' . $name ] ], + $content + ); } + + return $html; } /** @@ -632,6 +651,69 @@ abstract class BaseTemplate extends QuickTemplate { return $footericons; } + /** + * Renderer for getFooterIcons and getFooterLinks + * + * @param string $iconStyle $option for getFooterIcons: "icononly", "nocopyright" + * @param string $linkStyle $option for getFooterLinks: "flat" + * + * @return string html + * @since 1.29 + */ + protected function getFooter( $iconStyle = 'icononly', $linkStyle = 'flat' ) { + $validFooterIcons = $this->getFooterIcons( $iconStyle ); + $validFooterLinks = $this->getFooterLinks( $linkStyle ); + + $html = ''; + + if ( count( $validFooterIcons ) + count( $validFooterLinks ) > 0 ) { + $html .= Html::openElement( 'div', [ + 'id' => 'footer-bottom', + 'role' => 'contentinfo', + 'lang' => $this->get( 'userlang' ), + 'dir' => $this->get( 'dir' ) + ] ); + $footerEnd = Html::closeElement( 'div' ); + } else { + $footerEnd = ''; + } + foreach ( $validFooterIcons as $blockName => $footerIcons ) { + $html .= Html::openElement( 'div', [ + 'id' => 'f-' . Sanitizer::escapeId( $blockName ) . 'ico', + 'class' => 'footer-icons' + ] ); + foreach ( $footerIcons as $icon ) { + $html .= $this->getSkin()->makeFooterIcon( $icon ); + } + $html .= Html::closeElement( 'div' ); + } + if ( count( $validFooterLinks ) > 0 ) { + $html .= Html::openElement( 'ul', [ 'id' => 'f-list', 'class' => 'footer-places' ] ); + foreach ( $validFooterLinks as $aLink ) { + $html .= Html::rawElement( + 'li', + [ 'id' => Sanitizer::escapeId( $aLink ) ], + $this->get( $aLink ) + ); + } + $html .= Html::closeElement( 'ul' ); + } + + $html .= $this->clear() . $footerEnd; + + return $html; + } + + /** + * Get a div with the core visualClear class, for clearing floats + * + * @return string html + * @since 1.29 + */ + protected function clear() { + return Html::element( 'div', [ 'class' => 'visualClear' ] ); + } + /** * Get the suggested HTML for page status indicators: icons (or short text snippets) usually * displayed in the top-right corner of the page, outside of the main content. @@ -664,15 +746,25 @@ abstract class BaseTemplate extends QuickTemplate { } /** - * Output the basic end-page trail including bottomscripts, reporttime, and + * Output getTrail + */ + function printTrail() { + echo $this->getTrail(); + } + + /** + * Get the basic end-page trail including bottomscripts, reporttime, and * debug stuff. This should be called right before outputting the closing * body and html tags. + * + * @return string + * @since 1.29 */ - function printTrail() { -?> -getSkin()->getContext() ); ?> -html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?> -html( 'reporttime' ) ?> -getSkin()->getContext() ); + $html .= $this->get( 'bottomscripts' ); + $html .= $this->get( 'reporttime' ); + + return $html; } } -- 2.20.1