MediaWiki  REL1_20
showStats.php
Go to the documentation of this file.
00001 <?php
00002 
00032 require_once( __DIR__ . '/Maintenance.php' );
00033 
00039 class ShowStats 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_images' => 'Number of images',
00052                 );
00053 
00054                 // Get cached stats from slave database
00055                 $dbr = wfGetDB( DB_SLAVE );
00056                 $stats = $dbr->selectRow( 'site_stats', '*', '', __METHOD__ );
00057 
00058                 // Get maximum size for each column
00059                 $max_length_value = $max_length_desc = 0;
00060                 foreach ( $fields as $field => $desc ) {
00061                         $max_length_value = max( $max_length_value, strlen( $stats->$field ) );
00062                         $max_length_desc  = max( $max_length_desc , strlen( $desc ) ) ;
00063                 }
00064 
00065                 // Show them
00066                 foreach ( $fields as $field => $desc ) {
00067                         $this->output( sprintf( "%-{$max_length_desc}s: %{$max_length_value}d\n", $desc, $stats->$field ) );
00068                 }
00069         }
00070 }
00071 
00072 $maintClass = "ShowStats";
00073 require_once( RUN_MAINTENANCE_IF_MAIN );
00074