Merge maintenance-work branch:
[lhc/web/wiklou.git] / maintenance / showStats.php
1 <?php
2
3 /**
4 * Maintenance script to show the cached statistics.
5 * Give out the same output as [[Special:Statistics]]
6 *
7 * @file
8 * @ingroup Maintenance
9 * @author Ashar Voultoiz <hashar@altern.org>
10 * Based on initStats.php by:
11 * @author Brion Vibber
12 * @author Rob Church <robchur@gmail.com>
13 *
14 * @license GNU General Public License 2.0 or later
15 */
16
17 require_once( "Maintenance.php" );
18
19 class ShowStats extends Maintenance {
20 public function __construct() {
21 $this->mDescription = "Show the cached statistics";
22 }
23 public function execute() {
24 $fields = array(
25 'ss_total_views' => 'Total views',
26 'ss_total_edits' => 'Total edits',
27 'ss_good_articles' => 'Number of articles',
28 'ss_total_pages' => 'Total pages',
29 'ss_users' => 'Number of users',
30 'ss_admins' => 'Number of admins',
31 'ss_images' => 'Number of images',
32 );
33
34 // Get cached stats from slave database
35 $dbr = wfGetDB( DB_SLAVE );
36 $stats = $dbr->selectRow( 'site_stats', '*', '', __METHOD__ );
37
38 // Get maximum size for each column
39 $max_length_value = $max_length_desc = 0;
40 foreach( $fields as $field => $desc ) {
41 $max_length_value = max( $max_length_value, strlen( $stats->$field ) );
42 $max_length_desc = max( $max_length_desc , strlen( $desc )) ;
43 }
44
45 // Show them
46 foreach( $fields as $field => $desc ) {
47 $this->output( sprintf( "%-{$max_length_desc}s: %{$max_length_value}d\n", $desc, $stats->$field ) );
48 }
49 }
50 }
51
52 $maintClass = "ShowStats";
53 require_once( DO_MAINTENANCE );
54