MediaWiki  REL1_22
showSiteStats.php
Go to the documentation of this file.
00001 <?php
00002 
00032 require_once __DIR__ . '/Maintenance.php';
00033 
00039 class ShowSiteStats extends Maintenance {
00040     public function __construct() {
00041         parent::__construct();
00042         $this->mDescription = "Show the cached statistics";
00043     }
00044     public function execute() {
00045         $fields = array(
00046             'ss_total_views' => 'Total views',
00047             'ss_total_edits' => 'Total edits',
00048             'ss_good_articles' => 'Number of articles',
00049             'ss_total_pages' => 'Total pages',
00050             'ss_users' => 'Number of users',
00051             'ss_active_users' => 'Active users',
00052             'ss_images' => 'Number of images',
00053         );
00054 
00055         // Get cached stats from slave database
00056         $dbr = wfGetDB( DB_SLAVE );
00057         $stats = $dbr->selectRow( 'site_stats', '*', '', __METHOD__ );
00058 
00059         // Get maximum size for each column
00060         $max_length_value = $max_length_desc = 0;
00061         foreach ( $fields as $field => $desc ) {
00062             $max_length_value = max( $max_length_value, strlen( $stats->$field ) );
00063             $max_length_desc = max( $max_length_desc, strlen( $desc ) );
00064         }
00065 
00066         // Show them
00067         foreach ( $fields as $field => $desc ) {
00068             $this->output( sprintf( "%-{$max_length_desc}s: %{$max_length_value}d\n", $desc, $stats->$field ) );
00069         }
00070     }
00071 }
00072 
00073 $maintClass = "ShowSiteStats";
00074 require_once RUN_MAINTENANCE_IF_MAIN;