]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - maintenance/showStats.php
MediaWiki 1.17.1-scripts
[autoinstalls/mediawiki.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  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  * http://www.gnu.org/copyleft/gpl.html
21  *
22  * @ingroup Maintenance
23  * @author Ashar Voultoiz <hashar at free dot fr>
24  * Based on initStats.php by:
25  * @author Brion Vibber
26  * @author Rob Church <robchur@gmail.com>
27  *
28  * @license GNU General Public License 2.0 or later
29  */
30
31 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
32
33 class ShowStats extends Maintenance {
34         public function __construct() {
35                 parent::__construct();
36                 $this->mDescription = "Show the cached statistics";
37         }
38         public function execute() {
39                 $fields = array(
40                         'ss_total_views' => 'Total views',
41                         'ss_total_edits' => 'Total edits',
42                         'ss_good_articles' => 'Number of articles',
43                         'ss_total_pages' => 'Total pages',
44                         'ss_users' => 'Number of users',
45                         'ss_admins' => 'Number of admins',
46                         'ss_images' => 'Number of images',
47                 );
48
49                 // Get cached stats from slave database
50                 $dbr = wfGetDB( DB_SLAVE );
51                 $stats = $dbr->selectRow( 'site_stats', '*', '', __METHOD__ );
52
53                 // Get maximum size for each column
54                 $max_length_value = $max_length_desc = 0;
55                 foreach ( $fields as $field => $desc ) {
56                         $max_length_value = max( $max_length_value, strlen( $stats->$field ) );
57                         $max_length_desc  = max( $max_length_desc , strlen( $desc ) ) ;
58                 }
59
60                 // Show them
61                 foreach ( $fields as $field => $desc ) {
62                         $this->output( sprintf( "%-{$max_length_desc}s: %{$max_length_value}d\n", $desc, $stats->$field ) );
63                 }
64         }
65 }
66
67 $maintClass = "ShowStats";
68 require_once( RUN_MAINTENANCE_IF_MAIN );
69