X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialStatistics.php;h=6b85db66fad1dd151a022ba9108915103ed61cfd;hb=cc6425fc95dd32ece5585bcfa6e4d43728183825;hp=f4bc66649f87fbf892edebf27cadaadb2b2db360;hpb=a36d5d29a183ae1c824888351dffba132f67d86d;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialStatistics.php b/includes/specials/SpecialStatistics.php index f4bc66649f..6b85db66fa 100644 --- a/includes/specials/SpecialStatistics.php +++ b/includes/specials/SpecialStatistics.php @@ -111,7 +111,7 @@ class SpecialStatistics extends SpecialPage { * @param $number Float: a statistical number * @param $trExtraParams Array: params to table row, see Html::elememt * @param $descMsg String: message key - * @param $descMsgParam Array: message params + * @param array|string $descMsgParam Message parameters * @return string table row in HTML format */ private function formatRow( $text, $number, $trExtraParams = array(), $descMsg = '', $descMsgParam = '' ) { @@ -277,21 +277,60 @@ class SpecialStatistics extends SpecialPage { return $text; } - private function getOtherStats( $stats ) { - if ( !count( $stats ) ) - return ''; + /** + * Conversion of external statistics into an internal representation + * Following a ([][] = number) pattern + * + * @param array $stats + * @return string + */ + private function getOtherStats( array $stats ) { + $return = ''; - $return = Xml::openElement( 'tr' ) . - Xml::tags( 'th', array( 'colspan' => '2' ), $this->msg( 'statistics-header-hooks' )->parse() ) . - Xml::closeElement( 'tr' ); + foreach( $stats as $header => $items ) { + + // Identify the structure used + if ( is_array( $items ) ) { - foreach( $stats as $name => $number ) { - $name = htmlspecialchars( $name ); - $number = htmlspecialchars( $number ); + // Ignore headers that are recursively set as legacy header + if ( $header !== 'statistics-header-hooks' ) { + $return .= $this->formatRowHeader( $header ); + } + + // Collect all items that belong to the same header + foreach( $items as $key => $value ) { + $name = $this->msg( $key )->inContentLanguage()->parse(); + $number = htmlspecialchars( $value ); + + $return .= $this->formatRow( $name, $this->getLanguage()->formatNum( $number ), array( 'class' => 'mw-statistics-hook' ) ); + } + } else { + // Create the legacy header only once + if ( $return === '' ) { + $return .= $this->formatRowHeader( 'statistics-header-hooks' ); + } - $return .= $this->formatRow( $name, $this->getLanguage()->formatNum( $number ), array( 'class' => 'mw-statistics-hook' ) ); + // Recursively remap the legacy structure + $return .= $this->getOtherStats( array( 'statistics-header-hooks' => array( $header => $items ) ) ); + } } return $return; } + + /** + * Format row header + * + * @param string $header + * @return string + */ + private function formatRowHeader( $header ) { + return Xml::openElement( 'tr' ) . + Xml::tags( 'th', array( 'colspan' => '2' ), $this->msg( $header )->parse() ) . + Xml::closeElement( 'tr' ); + } + + protected function getGroupName() { + return 'wiki'; + } }