49 $this->dbr = $database;
50 } elseif ( $database ) {
62 $this->
edits = $this->dbr->selectField(
'revision',
'COUNT(*)',
'', __METHOD__ );
63 $this->
edits += $this->dbr->selectField(
'archive',
'COUNT(*)',
'', __METHOD__ );
73 $services = MediaWikiServices::getInstance();
77 'page_namespace' => $services->getNamespaceInfo()->getContentNamespaces(),
78 'page_is_redirect' => 0,
81 if ( $services->getMainConfig()->get( MainConfigNames::ArticleCountMethod ) ==
'link' ) {
82 $tables[] =
'pagelinks';
83 $conds[] =
'pl_from=page_id';
86 $this->
articles = $this->dbr->selectField(
88 'COUNT(DISTINCT page_id)',
93 return $this->articles;
101 $this->
pages = $this->dbr->selectField(
'page',
'COUNT(*)',
'', __METHOD__ );
111 $this->
users = $this->dbr->selectField(
'user',
'COUNT(*)',
'', __METHOD__ );
121 $this->
files = $this->dbr->selectField(
'image',
'COUNT(*)',
'', __METHOD__ );
137 $options += [
'update' =>
false,
'activeUsers' => false ];
140 $counter =
new self( $database );
143 $counter->articles();
151 if ( $options[
'activeUsers'] ) {
152 SiteStatsUpdate::cacheUpdate( self::getDB(
DB_PRIMARY ) );
161 $exists = (bool)$dbw->selectField(
'site_stats',
'1', [
'ss_row_id' => 1 ], __METHOD__ );
172 private function getShardedValue( $value, $noShards, $rowId ) {
173 $remainder = $value % $noShards;
174 $quotient = (int)( ( $value - $remainder ) / $noShards );
176 if ( $rowId === 1 ) {
177 return $quotient + $remainder;
186 if ( MediaWikiServices::getInstance()->getMainConfig()->
get( MainConfigNames::MultiShardSiteStats ) ) {
187 $shardCnt = SiteStatsUpdate::SHARDS_ON;
188 for ( $i = 1; $i <= $shardCnt; $i++ ) {
190 'ss_total_edits' => $this->getShardedValue( $this->
edits ?? $this->
edits(), $shardCnt, $i ),
191 'ss_good_articles' => $this->getShardedValue( $this->
articles ?? $this->
articles(), $shardCnt, $i ),
192 'ss_total_pages' => $this->getShardedValue( $this->
pages ?? $this->
pages(), $shardCnt, $i ),
193 'ss_users' => $this->getShardedValue( $this->
users ?? $this->
users(), $shardCnt, $i ),
194 'ss_images' => $this->getShardedValue( $this->
files ?? $this->
files(), $shardCnt, $i ),
196 $row = [
'ss_row_id' => $i ] + $set;
208 'ss_total_edits' => $this->
edits ?? $this->
edits(),
210 'ss_total_pages' => $this->
pages ?? $this->
pages(),
212 'ss_images' => $this->
files ?? $this->
files(),
214 $row = [
'ss_row_id' => 1 ] + $set;
231 private static function getDB( $index, $groups = [] ) {
232 return MediaWikiServices::getInstance()
233 ->getDBLoadBalancer()
234 ->getConnectionRef( $index, $groups );
A class containing constants representing the names of configuration variables.
Class designed for counting of stats.
edits()
Count the total number of edits.
pages()
Count total pages.
articles()
Count pages in article space(s)
static doAllAndCommit( $database, array $options=[])
Do all updates and commit them.
static doPlaceholderInit()
Insert a dummy row with all zeroes if no row is present.
files()
Count total files.
refresh()
Refresh site_stats.
users()
Count total users.
__construct( $database=false)