Merge "Make Special:MediaStatistics show a total count of file sizes"
[lhc/web/wiklou.git] / includes / specials / SpecialMediaStatistics.php
index b62de5d..aeebc42 100644 (file)
  */
 class MediaStatisticsPage extends QueryPage {
        protected $totalCount = 0, $totalBytes = 0;
+       /**
+       * @var integer $totalPerType Combined file size of all files in a section
+       */
+       protected $totalPerType = 0;
+       /**
+       * @var integer $totalSize Combined file size of all files
+       */
+       protected $totalSize = 0;
 
        function __construct( $name = 'MediaStatistics' ) {
                parent::__construct( $name );
@@ -36,7 +44,7 @@ class MediaStatisticsPage extends QueryPage {
                $this->shownavigation = false;
        }
 
-       function isExpensive() {
+       public function isExpensive() {
                return true;
        }
 
@@ -111,7 +119,11 @@ class MediaStatisticsPage extends QueryPage {
        protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) {
                $prevMediaType = null;
                foreach ( $res as $row ) {
-                       list( $mediaType, $mime, $totalCount, $totalBytes ) = $this->splitFakeTitle( $row->title );
+                       $mediaStats = $this->splitFakeTitle( $row->title );
+                       if ( count( $mediaStats ) < 4 ) {
+                               continue;
+                       }
+                       list( $mediaType, $mime, $totalCount, $totalBytes ) = $mediaStats;
                        if ( $prevMediaType !== $mediaType ) {
                                if ( $prevMediaType !== null ) {
                                        // We're not at beginning, so we have to
@@ -119,6 +131,7 @@ class MediaStatisticsPage extends QueryPage {
                                        $this->outputTableEnd();
                                }
                                $this->outputMediaType( $mediaType );
+                               $this->totalPerType = 0;
                                $this->outputTableStart( $mediaType );
                                $prevMediaType = $mediaType;
                        }
@@ -126,6 +139,11 @@ class MediaStatisticsPage extends QueryPage {
                }
                if ( $prevMediaType !== null ) {
                        $this->outputTableEnd();
+                       $this->getOutput()->addWikiText(
+                               $this->msg( 'mediastatistics-allbytes' )
+                                       ->numParams( $this->totalSize )
+                                       ->text()
+                       );
                }
        }
 
@@ -134,6 +152,12 @@ class MediaStatisticsPage extends QueryPage {
         */
        protected function outputTableEnd() {
                $this->getOutput()->addHtml( Html::closeElement( 'table' ) );
+               $this->getOutput()->addWikiText(
+                               $this->msg( 'mediastatistics-bytespertype' )
+                                       ->numParams( $this->totalPerType )
+                                       ->text()
+               );
+               $this->totalSize += $this->totalPerType;
        }
 
        /**
@@ -176,7 +200,7 @@ class MediaStatisticsPage extends QueryPage {
                                ->numParams( $this->makePercentPretty( $bytes / $this->totalBytes ) )
                                ->parse()
                );
-
+               $this->totalPerType += $bytes;
                $this->getOutput()->addHTML( Html::rawElement( 'tr', array(), $row ) );
        }
 
@@ -232,7 +256,7 @@ class MediaStatisticsPage extends QueryPage {
                                        'mw-mediastats-table-' . strtolower( $mediaType ),
                                        'sortable',
                                        'wikitable'
-                               ))
+                               ) )
                        )
                );
                $this->getOutput()->addHTML( $this->getTableHeaderRow() );
@@ -271,7 +295,7 @@ class MediaStatisticsPage extends QueryPage {
                                array( 'class' => array(
                                        'mw-mediastats-mediatype',
                                        'mw-mediastats-mediatype-' . strtolower( $mediaType )
-                               )),
+                               ) ),
                                // for grep
                                // mediastatistics-header-unknown, mediastatistics-header-bitmap,
                                // mediastatistics-header-drawing, mediastatistics-header-audio,