* 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 );
}
/**
- * @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
+ * @param string $group Name of group
+ * @return int
*/
static function numberingroup( $group ) {
if ( !isset( self::$groupMemberCounts[$group] ) ) {
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;
}
}
/**
- * @param $ns int
+ * @param int $ns
*
* @return int
*/
*
* Checks only fields which are filled by SiteStatsInit::refresh.
*
- * @param $row
+ * @param bool|object $row
*
* @return bool
*/
private $db;
// Various stats
- private $mEdits, $mArticles, $mPages, $mUsers, $mViews, $mFiles = 0;
+ private $mEdits = null, $mArticles = null, $mPages = null;
+ private $mUsers = null, $mViews = null, $mFiles = null;
/**
* 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
+ * @param array $options Array of options, may contain the following values
* - 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)
*/
}
/**
- * Refresh site_stats.
+ * Refresh site_stats. If you want ss_total_views to be updated, be sure to
+ * call views() first.
*/
- 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,
+ '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 ),
) + (
$this->mViews ? array( 'ss_total_views' => $this->mViews ) : array()
);