MediaWiki  REL1_24
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 
00045     public function execute() {
00046         $fields = array(
00047             'ss_total_views' => 'Total views',
00048             'ss_total_edits' => 'Total edits',
00049             'ss_good_articles' => 'Number of articles',
00050             'ss_total_pages' => 'Total pages',
00051             'ss_users' => 'Number of users',
00052             'ss_active_users' => 'Active users',
00053             'ss_images' => 'Number of images',
00054         );
00055 
00056         // Get cached stats from slave database
00057         $dbr = wfGetDB( DB_SLAVE );
00058         $stats = $dbr->selectRow( 'site_stats', '*', '', __METHOD__ );
00059 
00060         // Get maximum size for each column
00061         $max_length_value = $max_length_desc = 0;
00062         foreach ( $fields as $field => $desc ) {
00063             $max_length_value = max( $max_length_value, strlen( $stats->$field ) );
00064             $max_length_desc = max( $max_length_desc, strlen( $desc ) );
00065         }
00066 
00067         // Show them
00068         foreach ( $fields as $field => $desc ) {
00069             $this->output( sprintf(
00070                 "%-{$max_length_desc}s: %{$max_length_value}d\n",
00071                 $desc,
00072                 $stats->$field
00073             ) );
00074         }
00075     }
00076 }
00077 
00078 $maintClass = "ShowSiteStats";
00079 require_once RUN_MAINTENANCE_IF_MAIN;