* 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 );
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;
}
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
}
/**
- * 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()
);