}
/**
- * @param $recache bool
+ * @param bool $recache
*/
static function load( $recache = false ) {
if ( self::$loaded && !$recache ) {
}
/**
- * @return Bool|ResultWrapper
+ * @return bool|ResultWrapper
*/
static function loadAndLazyInit() {
wfDebug( __METHOD__ . ": reading site_stats from slave\n" );
}
/**
- * @param $db DatabaseBase
- * @return Bool|ResultWrapper
+ * @param DatabaseBase $db
+ * @return bool|ResultWrapper
*/
static function doLoad( $db ) {
return $db->selectRow( 'site_stats', array(
/**
* Find the number of users in a given user group.
* @param string $group name of group
- * @return Integer
+ * @return int
*/
static function numberingroup( $group ) {
if ( !isset( self::$groupMemberCounts[$group] ) ) {
}
/**
- * @param $ns int
+ * @param int $ns
*
* @return int
*/
/**
* Is the provided row of site stats sane, or should it be regenerated?
*
- * @param $row
+ * Checks only fields which are filled by SiteStatsInit::refresh.
+ *
+ * @param bool|object $row
*
* @return bool
*/
if ( $row === false
|| $row->ss_total_pages < $row->ss_good_articles
|| $row->ss_total_edits < $row->ss_total_pages
- || $row->ss_users < $row->ss_active_users
) {
return false;
}
'ss_good_articles',
'ss_total_pages',
'ss_users',
- 'ss_active_users',
'ss_images',
) as $member ) {
if ( $row->$member > 2000000000 || $row->$member < 0 ) {
/**
* Constructor
- * @param $database Boolean or DatabaseBase:
+ * @param bool|DatabaseBase $database
* - Boolean: whether to use the master DB
* - DatabaseBase: database connection to use
*/
/**
* Count the total number of edits
- * @return Integer
+ * @return int
*/
public function edits() {
$this->mEdits = $this->db->selectField( 'revision', 'COUNT(*)', '', __METHOD__ );
/**
* Count pages in article space(s)
- * @return Integer
+ * @return int
*/
public function articles() {
global $wgArticleCountMethod;
/**
* Count total pages
- * @return Integer
+ * @return int
*/
public function pages() {
$this->mPages = $this->db->selectField( 'page', 'COUNT(*)', '', __METHOD__ );
/**
* Count total users
- * @return Integer
+ * @return int
*/
public function users() {
$this->mUsers = $this->db->selectField( 'user', 'COUNT(*)', '', __METHOD__ );
/**
* Count views
- * @return Integer
+ * @return int
*/
public function views() {
$this->mViews = $this->db->selectField( 'page', 'SUM(page_counter)', '', __METHOD__ );
/**
* Count total files
- * @return Integer
+ * @return int
*/
public function files() {
$this->mFiles = $this->db->selectField( 'image', 'COUNT(*)', '', __METHOD__ );
* Do all updates and commit them. More or less a replacement
* for the original initStats, but without output.
*
- * @param $database DatabaseBase|bool
+ * @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
- * - update Boolean: whether to update the current stats (true) or write fresh (false) (default: false)
* - views Boolean: when true, do not update the number of page views (default: true)
* - activeUsers Boolean: whether to update the number of active users (default: false)
*/
$counter->views();
}
- // Update/refresh
- if ( $options['update'] ) {
- $counter->update();
- } else {
- $counter->refresh();
- }
+ $counter->refresh();
// Count active users if need be
if ( $options['activeUsers'] ) {
}
/**
- * Update the current row with the selected values
- */
- public function update() {
- list( $values, $conds ) = $this->getDbParams();
- $dbw = wfGetDB( DB_MASTER );
- $dbw->update( 'site_stats', $values, $conds, __METHOD__ );
- }
-
- /**
- * Refresh site_stats. Erase the current record and save all
- * the new values.
+ * Refresh site_stats.
*/
- public function refresh() {
- list( $values, $conds, $views ) = $this->getDbParams();
- $dbw = wfGetDB( DB_MASTER );
- $dbw->delete( 'site_stats', $conds, __METHOD__ );
- $dbw->insert( 'site_stats', array_merge( $values, $conds, $views ), __METHOD__ );
- }
-
- /**
- * Return three arrays of params for the db queries
- * @return Array
- */
- private function getDbParams() {
+ protected 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
+ 'ss_images' => $this->mFiles,
+ ) + (
+ $this->mViews ? array( 'ss_total_views' => $this->mViews ) : array()
);
- $conds = array( 'ss_row_id' => 1 );
- $views = array( 'ss_total_views' => $this->mViews );
- return array( $values, $conds, $views );
+
+ $dbw = wfGetDB( DB_MASTER );
+ $dbw->upsert( 'site_stats', $values, array( 'ss_row_id' ), $values, __METHOD__ );
}
}