Merge "Always use the canonical extension name to link the license file"
[lhc/web/wiklou.git] / includes / SiteStats.php
index 4685c3e..32c6761 100644 (file)
  * Static accessor class for site_stats and related things
  */
 class SiteStats {
-       static $row, $loaded = false;
-       static $jobs;
-       static $pageCount = array();
-       static $groupMemberCounts = array();
+       /** @var bool|ResultWrapper */
+       private static $row;
+
+       /** @var bool */
+       private static $loaded = false;
+
+       /** @var int */
+       private static $jobs;
+
+       /** @var int[] */
+       private static $pageCount = array();
+
+       /** @var int[] */
+       private static $groupMemberCounts = array();
 
        static function recache() {
                self::load( true );
@@ -92,7 +102,6 @@ class SiteStats {
        static function doLoad( $db ) {
                return $db->selectRow( 'site_stats', array(
                                'ss_row_id',
-                               'ss_total_views',
                                'ss_total_edits',
                                'ss_good_articles',
                                'ss_total_pages',
@@ -103,11 +112,16 @@ class SiteStats {
        }
 
        /**
+        * Return the total number of page views. Except we don't track those anymore.
+        * Stop calling this function, it will be removed some time in the future. It's
+        * kept here simply to prevent fatal errors.
+        *
+        * @deprecated since 1.25
         * @return int
         */
        static function views() {
-               self::load();
-               return self::$row->ss_total_views;
+               wfDeprecated( __METHOD__, '1.25' );
+               return 0;
        }
 
        /**
@@ -160,7 +174,7 @@ class SiteStats {
 
        /**
         * Find the number of users in a given user group.
-        * @param string $group name of group
+        * @param string $group Name of group
         * @return int
         */
        static function numberingroup( $group ) {
@@ -190,7 +204,10 @@ class SiteStats {
                if ( !isset( self::$jobs ) ) {
                        $dbr = wfGetDB( DB_SLAVE );
                        self::$jobs = array_sum( JobQueueGroup::singleton()->getQueueSizes() );
-                       /* Zero rows still do single row read for row that doesn't exist, but people are annoyed by that */
+                       /**
+                        * Zero rows still do single row read for row that doesn't exist,
+                        * but people are annoyed by that
+                        */
                        if ( self::$jobs == 1 ) {
                                self::$jobs = 0;
                        }
@@ -236,7 +253,6 @@ class SiteStats {
                }
                // Now check for underflow/overflow
                foreach ( array(
-                       'ss_total_views',
                        'ss_total_edits',
                        'ss_good_articles',
                        'ss_total_pages',
@@ -260,7 +276,8 @@ class SiteStatsInit {
        private $db;
 
        // Various stats
-       private $mEdits, $mArticles, $mPages, $mUsers, $mViews, $mFiles = 0;
+       private $mEdits = null, $mArticles = null, $mPages = null;
+       private $mUsers = null, $mFiles = null;
 
        /**
         * Constructor
@@ -334,15 +351,6 @@ class SiteStatsInit {
                return $this->mUsers;
        }
 
-       /**
-        * Count views
-        * @return int
-        */
-       public function views() {
-               $this->mViews = $this->db->selectField( 'page', 'SUM(page_counter)', '', __METHOD__ );
-               return $this->mViews;
-       }
-
        /**
         * Count total files
         * @return int
@@ -359,12 +367,11 @@ class SiteStatsInit {
         * @param DatabaseBase|bool $database
         * - Boolean: whether to use the master DB
         * - DatabaseBase: database connection to use
-        * @param array $options of options, may contain the following values
-        * - views Boolean: when true, do not update the number of page views (default: true)
+        * @param array $options Array of options, may contain the following values
         * - activeUsers Boolean: whether to update the number of active users (default: false)
         */
        public static function doAllAndCommit( $database, array $options = array() ) {
-               $options += array( 'update' => false, 'views' => true, 'activeUsers' => false );
+               $options += array( 'update' => false, 'activeUsers' => false );
 
                // Grab the object and count everything
                $counter = new SiteStatsInit( $database );
@@ -375,11 +382,6 @@ class SiteStatsInit {
                $counter->users();
                $counter->files();
 
-               // Only do views if we don't want to not count them
-               if ( $options['views'] ) {
-                       $counter->views();
-               }
-
                $counter->refresh();
 
                // Count active users if need be
@@ -389,18 +391,16 @@ class SiteStatsInit {
        }
 
        /**
-        * Refresh site_stats.
+        * Refresh site_stats
         */
-       protected function refresh() {
+       public function refresh() {
                $values = array(
                        'ss_row_id' => 1,
-                       'ss_total_edits' => $this->mEdits,
-                       'ss_good_articles' => $this->mArticles,
-                       'ss_total_pages' => $this->mPages,
-                       'ss_users' => $this->mUsers,
-                       'ss_images' => $this->mFiles,
-               ) + (
-                       $this->mViews ? array( 'ss_total_views' => $this->mViews ) : array()
+                       'ss_total_edits' => ( $this->mEdits === null ? $this->edits() : $this->mEdits ),
+                       'ss_good_articles' => ( $this->mArticles === null ? $this->articles() : $this->mArticles ),
+                       'ss_total_pages' => ( $this->mPages === null ? $this->pages() : $this->mPages ),
+                       'ss_users' => ( $this->mUsers === null ? $this->users() : $this->mUsers ),
+                       'ss_images' => ( $this->mFiles === null ? $this->files() : $this->mFiles ),
                );
 
                $dbw = wfGetDB( DB_MASTER );