Index: branches/maintenance-work/maintenance/initStats.php |
— | — | @@ -18,11 +18,12 @@ |
19 | 19 | $this->mDescription = "Re-initialise the site statistics tables"; |
20 | 20 | $this->addOption( 'update', 'Update the existing statistics (preserves the ss_total_views field)' ); |
21 | 21 | $this->addOption( 'noviews', "Don't update the page view counter" ); |
| 22 | + $this->addOption( 'active', 'Also update active users count' ); |
22 | 23 | } |
23 | 24 | |
24 | 25 | public function execute() { |
25 | 26 | $this->output( "Refresh Site Statistics\n\n" ); |
26 | | - SiteStats::init( $this->hasOption('update'), $this->hasOption('noviews') ); |
| 27 | + SiteStats::init( $this->hasOption('update'), $this->hasOption('noviews'), $this->hasOption('active') ); |
27 | 28 | } |
28 | 29 | } |
29 | 30 | |
Index: branches/maintenance-work/includes/SiteStats.php |
— | — | @@ -180,35 +180,41 @@ |
181 | 181 | * @param $update bool Whether to update the current stats write fresh |
182 | 182 | * @param $noViews bool When true, do not update the number of page views |
183 | 183 | */ |
184 | | - public static function init( $update, $noViews = false ) { |
| 184 | + public static function init( $update, $noViews = false, $activeUsers = false ) { |
185 | 185 | $dbr = wfGetDB( DB_SLAVE ); |
186 | | - |
| 186 | + |
187 | 187 | wfOut( "Counting total edits..." ); |
188 | 188 | $edits = $dbr->selectField( 'revision', 'COUNT(*)', '', __METHOD__ ); |
189 | 189 | $edits += $dbr->selectField( 'archive', 'COUNT(*)', '', __METHOD__ ); |
190 | 190 | wfOut( "{$edits}\nCounting number of articles..." ); |
191 | | - |
| 191 | + |
192 | 192 | global $wgContentNamespaces; |
193 | 193 | $good = $dbr->selectField( 'page', 'COUNT(*)', array( 'page_namespace' => $wgContentNamespaces, 'page_is_redirect' => 0, 'page_len > 0' ), __METHOD__ ); |
194 | 194 | wfOut( "{$good}\nCounting total pages..." ); |
195 | | - |
| 195 | + |
196 | 196 | $pages = $dbr->selectField( 'page', 'COUNT(*)', '', __METHOD__ ); |
197 | 197 | wfOut( "{$pages}\nCounting number of users..." ); |
198 | 198 | |
199 | 199 | $users = $dbr->selectField( 'user', 'COUNT(*)', '', __METHOD__ ); |
200 | 200 | wfOut( "{$users}\nCounting number of admins..." ); |
201 | | - |
| 201 | + |
202 | 202 | $admin = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), __METHOD__ ); |
203 | 203 | wfOut( "{$admin}\nCounting number of images..." ); |
204 | 204 | |
205 | 205 | $image = $dbr->selectField( 'image', 'COUNT(*)', '', __METHOD__ ); |
206 | 206 | wfOut( "{$image}\n" ); |
207 | | - |
| 207 | + |
208 | 208 | if( !$noViews ) { |
209 | 209 | wfOut( "Counting total page views..." ); |
210 | 210 | $views = $dbr->selectField( 'page', 'SUM(page_counter)', '', __METHOD__ ); |
211 | 211 | wfOut( "{$views}\n" ); |
212 | 212 | } |
| 213 | + |
| 214 | + if( $activeUsers ) { |
| 215 | + wfOut( "Counting active users..." ); |
| 216 | + $active = SiteStatsUpdate::cacheUpdate(); |
| 217 | + wfOut( "{$active}\n" ); |
| 218 | + } |
213 | 219 | |
214 | 220 | wfOut( "\nUpdating site statistics..." ); |
215 | 221 | |
— | — | @@ -296,5 +302,6 @@ |
297 | 303 | array( 'ss_active_users' => intval($activeUsers) ), |
298 | 304 | array( 'ss_row_id' => 1 ), __METHOD__ |
299 | 305 | ); |
| 306 | + return $activeUsers; |
300 | 307 | } |
301 | 308 | } |