Reconcept cl_raw_sortkey as cl_sortkey_prefix
[lhc/web/wiklou.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@altern.org>
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 $this->mDescription = "Show the cached statistics";
36 }
37 public function execute() {
38 $fields = array(
39 'ss_total_views' => 'Total views',
40 'ss_total_edits' => 'Total edits',
41 'ss_good_articles' => 'Number of articles',
42 'ss_total_pages' => 'Total pages',
43 'ss_users' => 'Number of users',
44 'ss_admins' => 'Number of admins',
45 'ss_images' => 'Number of images',
46 );
47
48 // Get cached stats from slave database
49 $dbr = wfGetDB( DB_SLAVE );
50 $stats = $dbr->selectRow( 'site_stats', '*', '', __METHOD__ );
51
52 // Get maximum size for each column
53 $max_length_value = $max_length_desc = 0;
54 foreach ( $fields as $field => $desc ) {
55 $max_length_value = max( $max_length_value, strlen( $stats->$field ) );
56 $max_length_desc = max( $max_length_desc , strlen( $desc ) ) ;
57 }
58
59 // Show them
60 foreach ( $fields as $field => $desc ) {
61 $this->output( sprintf( "%-{$max_length_desc}s: %{$max_length_value}d\n", $desc, $stats->$field ) );
62 }
63 }
64 }
65
66 $maintClass = "ShowStats";
67 require_once( DO_MAINTENANCE );
68