Isarra has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/344804 )

Change subject: Add some common functions to BaseTemplate
......................................................................

Add some common functions to BaseTemplate

Breaks any skins with same-name functions with different
visibility.

* getPortlet: essentially renderPortlet from Vector,
  outputPortlet from Example, getPortlet from Timeless etc
* clear: returns a visualClear
* getFooter: wraps 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 some formatting fixes for related functions.

Change-Id: I5621f585b501e47b40ae80e9cb12e6a32da72275
---
M includes/skins/BaseTemplate.php
1 file changed, 170 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/04/344804/1

diff --git a/includes/skins/BaseTemplate.php b/includes/skins/BaseTemplate.php
index e571c58..785c851 100644
--- a/includes/skins/BaseTemplate.php
+++ b/includes/skins/BaseTemplate.php
@@ -291,7 +291,32 @@
                Hooks::run( 'BaseTemplateAfterPortlet', [ $this, $name, 
&$content ] );
 
                if ( $content !== '' ) {
-                       echo "<div class='after-portlet 
after-portlet-$name'>$content</div>";
+                       echo Html::rawElement(
+                               'div',
+                               [ 'class' => [ 'after-portlet', 
'after-portlet-' . $name ] ],
+                               $content
+                       );
+               }
+       }
+
+       /**
+        * The same as renderAfterPortlet(), but returns the content instead of
+        * printing it
+        *
+        * @param string $name
+        *
+        * @return string html
+        */
+       protected function getAfterPortlet( $name ) {
+               $content = '';
+               Hooks::run( 'BaseTemplateAfterPortlet', [ $this, $name, 
&$content ] );
+
+               if ( $content !== '' ) {
+                       return Html::rawElement(
+                               'div',
+                               [ 'class' => [ 'after-portlet', 
'after-portlet-' . $name ] ],
+                               $content
+                       );
                }
        }
 
@@ -499,6 +524,73 @@
                return Html::rawElement( isset( $options['tag'] ) ? 
$options['tag'] : 'li', $attrs, $html );
        }
 
+       /**
+        * Generates a block of navigation links with a header
+        *
+        * @param string $name
+        * @param array|string $content array of links for use with 
makeListItem, or a block of text
+        * @param null|string|array|bool $msg
+        *
+        * @return string html
+        */
+       private function getPortlet( $name, $content, $msg = null ) {
+               if ( $msg === null ) {
+                       $msg = $name;
+               } elseif ( is_array( $msg ) ) {
+                       $msgString = array_shift( $msg );
+                       $msgParams = $msg;
+                       $msg = $msgString;
+               }
+               $msgObj = wfMessage( $msg );
+               if ( $msgObj->exists() ) {
+                       if ( isset( $msgParams ) && !empty( $msgParams ) ) {
+                               $msgString = $this->getMsg( $msg, $msgParams 
)->parse();
+                       } else {
+                               $msgString = $msgObj->parse();
+                       }
+               } else {
+                       $msgString = htmlspecialchars( $msg );
+               }
+
+               $labelId = Sanitizer::escapeId( "p-$name-label" );
+
+               if ( is_array( $content ) ) {
+                       $contentText = Html::openElement( 'ul' );
+                       foreach ( $content as $key => $item ) {
+                               $contentText .= $this->makeListItem(
+                                       $key,
+                                       $item,
+                                       [ 'text-wrapper' => [ 'tag' => 'span' ] 
]
+                               );
+                       }
+                       $contentText .= Html::closeElement( 'ul' );
+               } else {
+                       $contentText = $content;
+               }
+
+               $html = Html::rawElement( 'div', [
+                               'role' => 'navigation',
+                               'class' => 'mw-portlet',
+                               'id' => Sanitizer::escapeId( 'p-' . $name ),
+                               'title' => Linker::titleAttrib( 'p-' . $name ),
+                               'aria-labelledby' => $labelId
+                       ],
+                       Html::rawElement( 'h3', [
+                                       'id' => $labelId,
+                                       'lang' => $this->get( 'userlang' ),
+                                       'dir' => $this->get( 'dir' )
+                               ],
+                               $msgString
+                       ) .
+                       Html::rawElement( 'div', [ 'class' => 'p-body' ],
+                               $contentText .
+                               $this->renderAfterPortlet( $name )
+                       )
+               );
+
+               return $html;
+       }
+
        function makeSearchInput( $attrs = [] ) {
                $realAttrs = [
                        'type' => 'search',
@@ -633,6 +725,67 @@
        }
 
        /**
+        * Wrapper for getFooterIcons and getFooterLinks
+        *
+        * @param string $iconStyle $option for getFooterIcons
+        * @param string $linkStyle $option for getFooterLinks
+        *
+        * @return string html
+        */
+       public 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
+        */
+       public 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.
         *
@@ -669,10 +822,21 @@
         * body and html tags.
         */
        function printTrail() {
-?>
-<?php echo MWDebug::getDebugHTML( $this->getSkin()->getContext() ); ?>
-<?php $this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?>
-<?php $this->html( 'reporttime' ) ?>
-<?php
+               echo MWDebug::getDebugHTML( $this->getSkin()->getContext() );
+               $this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook 
*/
+               $this->html( 'reporttime' );
+       }
+
+       /**
+        * The same as printTrail, but returns the content instead of directly 
printing
+        *
+        * @return string
+        */
+       function getTrail() {
+               $html = MWDebug::getDebugHTML( $this->getSkin()->getContext() );
+               $html .= $this->get( 'bottomscripts' );
+               $html .= $this->get( 'reporttime' );
+
+               return $html;
        }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/344804
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5621f585b501e47b40ae80e9cb12e6a32da72275
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Isarra <zhoris...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to