From: mwjames Date: Mon, 5 Nov 2012 10:24:52 +0000 (+0900) Subject: Extend the SpecialStatsAddExtra hook for a more distinct display of extra items X-Git-Tag: 1.31.0-rc.0~20460 X-Git-Url: http://git.cyclocoop.org/%22%20%20.%20generer_url_ecrire%28%22mots_tous%22%29%20.%20%22?a=commitdiff_plain;h=90797afe5366458d37046c34f3a2583aade361f5;p=lhc%2Fweb%2Fwiklou.git Extend the SpecialStatsAddExtra hook for a more distinct display of extra items The current approach leaves not much room for a meaningful display of varying extra statistical items nor its ability to display a special page link as item name. The change proposed allows for varying header titles as well as item descriptions using the standard language parser. The proposed change uses is similar approach as in the InfoAction hook. A item now is specified as [][] = number Use === array() check instead of a count() and continue legacy support for the single array structure used prio 1.21. Change-Id: I78107c72953878c86d221fb6f83baff5f6c11f09 --- diff --git a/includes/specials/SpecialStatistics.php b/includes/specials/SpecialStatistics.php index f4bc66649f..7d6d90ed4d 100644 --- a/includes/specials/SpecialStatistics.php +++ b/includes/specials/SpecialStatistics.php @@ -277,21 +277,56 @@ 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' ) ); + $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' ); + } + + // 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' ); + } }