Special:Watchlist: Add user preference to "Show last" options, fix float comparison
[lhc/web/wiklou.git] / includes / specials / SpecialMediaStatistics.php
index 1084482..e5ba8c6 100644 (file)
@@ -36,7 +36,7 @@ class MediaStatisticsPage extends QueryPage {
                $this->shownavigation = false;
        }
 
-       function isExpensive() {
+       public function isExpensive() {
                return true;
        }
 
@@ -73,6 +73,10 @@ class MediaStatisticsPage extends QueryPage {
                                'namespace' => NS_MEDIA, /* needs to be something */
                                'value' => '1'
                        ),
+                       'conds' => array(
+                               // WMF has a random null row in the db
+                               'img_media_type IS NOT NULL'
+                       ),
                        'options' => array(
                                'GROUP BY' => array(
                                        'img_media_type',
@@ -99,7 +103,7 @@ class MediaStatisticsPage extends QueryPage {
         *
         * @param $out OutputPage
         * @param $skin Skin (deprecated presumably)
-        * @param $dbr DatabaseBase
+        * @param $dbr IDatabase
         * @param $res ResultWrapper Results from query
         * @param $num integer Number of results
         * @param $offset integer Paging offset (Should always be 0 in our case)
@@ -107,7 +111,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
@@ -228,7 +236,7 @@ class MediaStatisticsPage extends QueryPage {
                                        'mw-mediastats-table-' . strtolower( $mediaType ),
                                        'sortable',
                                        'wikitable'
-                               ))
+                               ) )
                        )
                );
                $this->getOutput()->addHTML( $this->getTableHeaderRow() );
@@ -267,7 +275,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,
@@ -306,6 +314,8 @@ class MediaStatisticsPage extends QueryPage {
         *
         * @param $skin Skin
         * @param $result stdObject Result row
+        * @return bool|string|void
+        * @throws MWException
         */
        public function formatResult( $skin, $result ) {
                throw new MWException( "unimplemented" );
@@ -314,15 +324,15 @@ class MediaStatisticsPage extends QueryPage {
        /**
         * Initialize total values so we can figure out percentages later.
         *
-        * @param $dbr DatabaseBase
+        * @param $dbr IDatabase
         * @param $res ResultWrapper
         */
        public function preprocessResults( $dbr, $res ) {
                $this->totalCount = $this->totalBytes = 0;
                foreach ( $res as $row ) {
-                       list( , , $count, $bytes ) = $this->splitFakeTitle( $row->title );
-                       $this->totalCount += $count;
-                       $this->totalBytes += $bytes;
+                       $mediaStats = $this->splitFakeTitle( $row->title );
+                       $this->totalCount += isset( $mediaStats[2] ) ? $mediaStats[2] : 0;
+                       $this->totalBytes += isset( $mediaStats[3] ) ? $mediaStats[3] : 0;
                }
                $res->seek( 0 );
        }