- return true;
- }
-}
-
-/**
- * Class designed for counting of stats.
- */
-class SiteStatsInit {
-
- // Database connection
- private $db;
-
- // Various stats
- private $mEdits = null, $mArticles = null, $mPages = null;
- private $mUsers = null, $mFiles = null;
-
- /**
- * @param bool|IDatabase $database
- * - bool: Whether to use the master DB
- * - IDatabase: Database connection to use
- */
- public function __construct( $database = false ) {
- if ( $database instanceof IDatabase ) {
- $this->db = $database;
- } elseif ( $database ) {
- $this->db = wfGetDB( DB_MASTER );
- } else {
- $this->db = wfGetDB( DB_REPLICA, 'vslow' );
- }
- }
-
- /**
- * Count the total number of edits
- * @return int
- */
- public function edits() {
- $this->mEdits = $this->db->selectField( 'revision', 'COUNT(*)', '', __METHOD__ );
- $this->mEdits += $this->db->selectField( 'archive', 'COUNT(*)', '', __METHOD__ );
- return $this->mEdits;
- }
-
- /**
- * Count pages in article space(s)
- * @return int
- */
- public function articles() {
- global $wgArticleCountMethod;
-
- $tables = [ 'page' ];
- $conds = [
- 'page_namespace' => MWNamespace::getContentNamespaces(),
- 'page_is_redirect' => 0,
- ];
-
- if ( $wgArticleCountMethod == 'link' ) {
- $tables[] = 'pagelinks';
- $conds[] = 'pl_from=page_id';
- } elseif ( $wgArticleCountMethod == 'comma' ) {
- // To make a correct check for this, we would need, for each page,
- // to load the text, maybe uncompress it, maybe decode it and then
- // check if there's one comma.
- // But one thing we are sure is that if the page is empty, it can't
- // contain a comma :)
- $conds[] = 'page_len > 0';
- }
-
- $this->mArticles = $this->db->selectField( $tables, 'COUNT(DISTINCT page_id)',
- $conds, __METHOD__ );
- return $this->mArticles;
- }