49 $this->dbr = $database;
50 } elseif ( $database ) {
62 $this->
edits = $this->countTableRows(
'revision' );
63 $this->
edits += $this->countTableRows(
'archive' );
68 private function countTableRows(
string $tableName ) {
69 return (
int)$this->dbr->newSelectQueryBuilder()
70 ->select(
'COUNT(*)' )
72 ->caller( __METHOD__ )->fetchField();
80 $services = MediaWikiServices::getInstance();
81 $queryBuilder = $this->dbr->newSelectQueryBuilder()
82 ->select(
'COUNT(DISTINCT page_id)' )
85 'page_namespace' => $services->getNamespaceInfo()->getContentNamespaces(),
86 'page_is_redirect' => 0,
89 if ( $services->getMainConfig()->get( MainConfigNames::ArticleCountMethod ) ==
'link' ) {
90 $queryBuilder->join(
'pagelinks',
null,
'pl_from=page_id' );
93 $this->
articles = $queryBuilder->caller( __METHOD__ )->fetchField();
95 return $this->articles;
103 $this->
pages = $this->countTableRows(
'page' );
113 $this->
users = $this->countTableRows(
'user' );
123 $this->
files = $this->countTableRows(
'image' );
139 $options += [
'update' =>
false,
'activeUsers' => false ];
142 $counter =
new self( $database );
145 $counter->articles();
153 if ( $options[
'activeUsers'] ) {
154 SiteStatsUpdate::cacheUpdate( self::getDB(
DB_PRIMARY ) );
163 $exists = (bool)$dbw->selectField(
'site_stats',
'1', [
'ss_row_id' => 1 ], __METHOD__ );
174 private function getShardedValue( $value, $noShards, $rowId ) {
175 $remainder = $value % $noShards;
176 $quotient = (int)( ( $value - $remainder ) / $noShards );
178 if ( $rowId === 1 ) {
179 return $quotient + $remainder;
188 if ( MediaWikiServices::getInstance()->getMainConfig()->
get( MainConfigNames::MultiShardSiteStats ) ) {
189 $shardCnt = SiteStatsUpdate::SHARDS_ON;
190 for ( $i = 1; $i <= $shardCnt; $i++ ) {
192 'ss_total_edits' => $this->getShardedValue( $this->
edits ?? $this->
edits(), $shardCnt, $i ),
193 'ss_good_articles' => $this->getShardedValue( $this->
articles ?? $this->
articles(), $shardCnt, $i ),
194 'ss_total_pages' => $this->getShardedValue( $this->
pages ?? $this->
pages(), $shardCnt, $i ),
195 'ss_users' => $this->getShardedValue( $this->
users ?? $this->
users(), $shardCnt, $i ),
196 'ss_images' => $this->getShardedValue( $this->
files ?? $this->
files(), $shardCnt, $i ),
198 $row = [
'ss_row_id' => $i ] + $set;
210 'ss_total_edits' => $this->
edits ?? $this->
edits(),
212 'ss_total_pages' => $this->
pages ?? $this->
pages(),
214 'ss_images' => $this->
files ?? $this->
files(),
216 $row = [
'ss_row_id' => 1 ] + $set;
233 private static function getDB( $index, $groups = [] ) {
234 return MediaWikiServices::getInstance()
235 ->getDBLoadBalancer()
236 ->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)