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