Localisation updates from https://translatewiki.net.
[lhc/web/wiklou.git] / includes / deferred / SiteStatsUpdate.php
index 09ff87d..97a17c3 100644 (file)
  * Class for handling updates to the site_stats table
  */
 class SiteStatsUpdate implements DeferrableUpdate {
-       protected $views = 0;
+       /** @var int */
        protected $edits = 0;
+
+       /** @var int */
        protected $pages = 0;
+
+       /** @var int */
        protected $articles = 0;
+
+       /** @var int */
        protected $users = 0;
+
+       /** @var int */
        protected $images = 0;
 
        // @todo deprecate this constructor
        function __construct( $views, $edits, $good, $pages = 0, $users = 0 ) {
-               $this->views = $views;
                $this->edits = $edits;
                $this->articles = $good;
                $this->pages = $pages;
@@ -39,7 +46,7 @@ class SiteStatsUpdate implements DeferrableUpdate {
        }
 
        /**
-        * @param $deltas Array
+        * @param array $deltas
         * @return SiteStatsUpdate
         */
        public static function factory( array $deltas ) {
@@ -71,25 +78,24 @@ class SiteStatsUpdate implements DeferrableUpdate {
 
        /**
         * Do not call this outside of SiteStatsUpdate
-        *
-        * @return void
         */
        public function tryDBUpdateInternal() {
                global $wgSiteStatsAsyncFactor;
 
                $dbw = wfGetDB( DB_MASTER );
                $lockKey = wfMemcKey( 'site_stats' ); // prepend wiki ID
+               $pd = array();
                if ( $wgSiteStatsAsyncFactor ) {
                        // Lock the table so we don't have double DB/memcached updates
                        if ( !$dbw->lockIsFree( $lockKey, __METHOD__ )
                                || !$dbw->lock( $lockKey, __METHOD__, 1 ) // 1 sec timeout
                        ) {
                                $this->doUpdatePendingDeltas();
+
                                return;
                        }
                        $pd = $this->getPendingDeltas();
                        // Piggy-back the async deltas onto those of this stats update....
-                       $this->views += ( $pd['ss_total_views']['+'] - $pd['ss_total_views']['-'] );
                        $this->edits += ( $pd['ss_total_edits']['+'] - $pd['ss_total_edits']['-'] );
                        $this->articles += ( $pd['ss_good_articles']['+'] - $pd['ss_good_articles']['-'] );
                        $this->pages += ( $pd['ss_total_pages']['+'] - $pd['ss_total_pages']['-'] );
@@ -99,7 +105,6 @@ class SiteStatsUpdate implements DeferrableUpdate {
 
                // Build up an SQL query of deltas and apply them...
                $updates = '';
-               $this->appendUpdate( $updates, 'ss_total_views', $this->views );
                $this->appendUpdate( $updates, 'ss_total_edits', $this->edits );
                $this->appendUpdate( $updates, 'ss_good_articles', $this->articles );
                $this->appendUpdate( $updates, 'ss_total_pages', $this->pages );
@@ -118,7 +123,7 @@ class SiteStatsUpdate implements DeferrableUpdate {
        }
 
        /**
-        * @param $dbw DatabaseBase
+        * @param DatabaseBase $dbw
         * @return bool|mixed
         */
        public static function cacheUpdate( $dbw ) {
@@ -133,7 +138,8 @@ class SiteStatsUpdate implements DeferrableUpdate {
                                'rc_user != 0',
                                'rc_bot' => 0,
                                'rc_log_type != ' . $dbr->addQuotes( 'newusers' ) . ' OR rc_log_type IS NULL',
-                               'rc_timestamp >= ' . $dbr->addQuotes( $dbr->timestamp( wfTimestamp( TS_UNIX ) - $wgActiveUserDays * 24 * 3600 ) ),
+                               'rc_timestamp >= ' . $dbr->addQuotes( $dbr->timestamp( wfTimestamp( TS_UNIX )
+                                       - $wgActiveUserDays * 24 * 3600 ) ),
                        ),
                        __METHOD__
                );
@@ -143,11 +149,11 @@ class SiteStatsUpdate implements DeferrableUpdate {
                        array( 'ss_row_id' => 1 ),
                        __METHOD__
                );
+
                return $activeUsers;
        }
 
        protected function doUpdatePendingDeltas() {
-               $this->adjustPending( 'ss_total_views', $this->views );
                $this->adjustPending( 'ss_total_edits', $this->edits );
                $this->adjustPending( 'ss_good_articles', $this->articles );
                $this->adjustPending( 'ss_total_pages', $this->pages );
@@ -156,9 +162,9 @@ class SiteStatsUpdate implements DeferrableUpdate {
        }
 
        /**
-        * @param $sql string
-        * @param $field string
-        * @param $delta integer
+        * @param string $sql
+        * @param string $field
+        * @param int $delta
         */
        protected function appendUpdate( &$sql, $field, $delta ) {
                if ( $delta ) {
@@ -174,7 +180,7 @@ class SiteStatsUpdate implements DeferrableUpdate {
        }
 
        /**
-        * @param $type string
+        * @param string $type
         * @param string $sign ('+' or '-')
         * @return string
         */
@@ -185,9 +191,8 @@ class SiteStatsUpdate implements DeferrableUpdate {
        /**
         * Adjust the pending deltas for a stat type.
         * Each stat type has two pending counters, one for increments and decrements
-        * @param $type string
-        * @param $delta integer Delta (positive or negative)
-        * @return void
+        * @param string $type
+        * @param int $delta Delta (positive or negative)
         */
        protected function adjustPending( $type, $delta ) {
                global $wgMemc;
@@ -208,16 +213,15 @@ class SiteStatsUpdate implements DeferrableUpdate {
 
        /**
         * Get pending delta counters for each stat type
-        * @return Array Positive and negative deltas for each type
-        * @return void
+        * @return array Positive and negative deltas for each type
         */
        protected function getPendingDeltas() {
                global $wgMemc;
 
                $pending = array();
-               foreach ( array( 'ss_total_views', 'ss_total_edits',
-                       'ss_good_articles', 'ss_total_pages', 'ss_users', 'ss_images' ) as $type )
-               {
+               foreach ( array( 'ss_total_edits',
+                       'ss_good_articles', 'ss_total_pages', 'ss_users', 'ss_images' ) as $type
+               {
                        // Get pending increments and pending decrements
                        $pending[$type]['+'] = (int)$wgMemc->get( $this->getTypeCacheKey( $type, '+' ) );
                        $pending[$type]['-'] = (int)$wgMemc->get( $this->getTypeCacheKey( $type, '-' ) );
@@ -229,7 +233,6 @@ class SiteStatsUpdate implements DeferrableUpdate {
        /**
         * Reduce pending delta counters after updates have been applied
         * @param array $pd Result of getPendingDeltas(), used for DB update
-        * @return void
         */
        protected function removePendingDeltas( array $pd ) {
                global $wgMemc;
@@ -242,4 +245,3 @@ class SiteStatsUpdate implements DeferrableUpdate {
                }
        }
 }
-