Foxtrott has uploaded a new change for review. https://gerrit.wikimedia.org/r/173514
Change subject: Refactor PageTools.php ...................................................................... Refactor PageTools.php Change-Id: I874d3a25b900c876b8219582570c5f00765e3e4d --- M src/Components/PageTools.php 1 file changed, 96 insertions(+), 57 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/skins/chameleon refs/changes/14/173514/1 diff --git a/src/Components/PageTools.php b/src/Components/PageTools.php index 59ce785..18b79ee 100644 --- a/src/Components/PageTools.php +++ b/src/Components/PageTools.php @@ -63,73 +63,28 @@ $navigation = $this->getSkinTemplate()->data[ 'content_navigation' ]; - $hideSelectedNameSpace = false; - if ( $this->getDomElement() !== null ) { - $hideSelectedNameSpace = filter_var( $this->getDomElement()->getAttribute( 'hideSelectedNameSpace' ), FILTER_VALIDATE_BOOLEAN ); - } - - if ( $hideSelectedNameSpace ) { - $namespacekey = $this->getNamespaceKey(); - unset( $navigation['namespaces'][ $namespacekey ] ); + if ( $this->hideSelectedNamespace() ) { + unset( $navigation['namespaces'][ $this->getNamespaceKey() ] ); } $ret = ''; $this->indent( 2 ); foreach ( $navigation as $category => $tabs ) { - - // TODO: visually group all links of one category (e.g. some space between categories) - - if ( empty( $tabs ) ) { - continue; - } - - $ret .= $this->indent() . '<!-- ' . $category . ' -->'; - - if ( !$this->mFlat ) { - // output the name of the current category (e.g. 'namespaces', 'views', ...) - $ret .= $this->indent() . - \Html::openElement( 'li', array( 'id' => IdRegistry::getRegistry()->getId( 'p-' . $category ) ) ) . - $this->indent( 1 ) . '<ul class="list-inline" >'; - - $this->indent( 1 ); - } - - foreach ( $tabs as $key => $tab ) { - - // skip redundant links (i.e. the 'view' link) - // TODO: make this dependent on an option - if ( array_key_exists( 'redundant', $tab ) && $tab[ 'redundant' ] === true ) { - continue; - } - - // apply a link class if specified, e.g. for the currently active namespace - $options = array(); - if ( array_key_exists( 'class', $tab ) ) { - $options[ 'link-class' ] = $tab[ 'class' ]; - } - - $ret .= $this->indent() . $this->getSkinTemplate()->makeListItem( $key, $tab, $options ); - - } - - if ( !$this->mFlat ) { - $ret .= $this->indent( -1 ) . '</ul>' . - $this->indent( -1 ) . '</li>'; - } + $ret .= $this->buildTabGroup( $category, $tabs ); } $this->indent( -2 ); if ( $ret !== '' ){ - $ret = $this->indent( 1 ) . '<!-- Content navigation -->' . - $this->indent() . - \Html::openElement( 'ul', - array( - 'class' => 'p-contentnavigation ' . $this->getClassString(), - 'id' => IdRegistry::getRegistry()->getId( 'p-contentnavigation' ), - ) ) . - $ret . - $this->indent() . '</ul>'; + $ret = + $this->indent( 1 ) . '<!-- Content navigation -->' . + $this->indent() . \Html::openElement( 'ul', + array( + 'class' => 'p-contentnavigation ' . $this->getClassString(), + 'id' => IdRegistry::getRegistry()->getId( 'p-contentnavigation' ), + ) ) . + $ret . + $this->indent() . '</ul>'; } return $ret; @@ -182,5 +137,89 @@ return $namespaceKey; } + /** + * @param $tab + * @param $key + * @return string + */ + protected function buildTab( $tab, $key ) { + + // skip redundant links (i.e. the 'view' link) + // TODO: make this dependent on an option + if ( array_key_exists( 'redundant', $tab ) && $tab[ 'redundant' ] === true ) { + return ''; + } + + // apply a link class if specified, e.g. for the currently active namespace + $options = array(); + if ( array_key_exists( 'class', $tab ) ) { + $options[ 'link-class' ] = $tab[ 'class' ]; + } + + return $this->indent() . $this->getSkinTemplate()->makeListItem( $key, $tab, $options ); + + } + + /** + * @param string $category + * @param $tabs + * + * @return string + */ + protected function buildTabGroup( $category, $tabs ) { + // TODO: visually group all links of one category (e.g. some space between categories) + + if ( empty( $tabs ) ) { + return ''; + } + + $ret = $this->indent() . '<!-- ' . $category . ' -->'; + + if ( !$this->mFlat ) { + $ret .= $this->buildTabGroupOpeningTags( $category ); + + } + + foreach ( $tabs as $key => $tab ) { + $ret .= $this->buildTab( $tab, $key ); + } + + if ( !$this->mFlat ) { + $ret .= $this->buildTabGroupClosingTags(); + } + return $ret; + } + + /** + * @return bool + */ + protected function hideSelectedNamespace() { + return + $this->getDomElement() !== null && + filter_var( $this->getDomElement()->getAttribute( 'hideSelectedNameSpace' ), FILTER_VALIDATE_BOOLEAN ); + } + + /** + * @param $category + * @return string + */ + protected function buildTabGroupOpeningTags( $category ) { + // output the name of the current category (e.g. 'namespaces', 'views', ...) + $ret = $this->indent() . + \Html::openElement( 'li', array( 'id' => IdRegistry::getRegistry()->getId( 'p-' . $category ) ) ) . + $this->indent( 1 ) . '<ul class="list-inline" >'; + + $this->indent( 1 ); + return $ret; + } + + /** + * @return string + */ + protected function buildTabGroupClosingTags() { + return $this->indent( -1 ) . '</ul>' . + $this->indent( -1 ) . '</li>'; + } + } -- To view, visit https://gerrit.wikimedia.org/r/173514 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I874d3a25b900c876b8219582570c5f00765e3e4d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/skins/chameleon Gerrit-Branch: master Gerrit-Owner: Foxtrott <s7ep...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits