CategoryViewer: Do opportunistic category recounts for mismatched file counts, too
authorBartosz Dziewoński <matma.rex@gmail.com>
Mon, 29 Feb 2016 22:05:32 +0000 (23:05 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Mon, 29 Feb 2016 22:05:32 +0000 (23:05 +0100)
There are some categories on Commons that have no files, but are
recorded to have some, e.g. [1] appears to have 15 files [2]. We have
logic to fix these, but it wasn't being checked for file counts (only
pages and subcats).

[1] https://commons.wikimedia.org/wiki/Category:Police_of_Mexico,_D._F._vehicles
[2] https://commons.wikimedia.org/w/index.php?title=Category:Police_of_Mexico,_D._F._vehicles&action=info

Change-Id: If88fc15347eb592e957452884c2179d7c237bd2c

includes/CategoryViewer.php

index b912603..f749003 100644 (file)
@@ -387,6 +387,7 @@ class CategoryViewer extends ContextSource {
                $r = '';
                $rescnt = count( $this->children );
                $dbcnt = $this->cat->getSubcatCount();
+               // This function should be called even if the result isn't used, it has side-effects
                $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'subcat' );
 
                if ( $rescnt > 0 ) {
@@ -417,6 +418,7 @@ class CategoryViewer extends ContextSource {
                $dbcnt = $this->cat->getPageCount() - $this->cat->getSubcatCount()
                        - $this->cat->getFileCount();
                $rescnt = count( $this->articles );
+               // This function should be called even if the result isn't used, it has side-effects
                $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'article' );
 
                if ( $rescnt > 0 ) {
@@ -437,10 +439,11 @@ class CategoryViewer extends ContextSource {
        function getImageSection() {
                $r = '';
                $rescnt = $this->showGallery ? $this->gallery->count() : count( $this->imgsNoGallery );
-               if ( $rescnt > 0 ) {
-                       $dbcnt = $this->cat->getFileCount();
-                       $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'file' );
+               $dbcnt = $this->cat->getFileCount();
+               // This function should be called even if the result isn't used, it has side-effects
+               $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'file' );
 
+               if ( $rescnt > 0 ) {
                        $r .= "<div id=\"mw-category-media\">\n";
                        $r .= '<h2>' .
                                $this->msg(