MediaWiki master
showSiteStats.php
Go to the documentation of this file.
1<?php
2
19
20// @codeCoverageIgnoreStart
21require_once __DIR__ . '/Maintenance.php';
22// @codeCoverageIgnoreEnd
23
30 public function __construct() {
31 parent::__construct();
32 $this->addDescription( 'Show the cached statistics' );
33 }
34
35 public function execute() {
36 $fields = [
37 'ss_total_edits' => 'Total edits',
38 'ss_good_articles' => 'Number of articles',
39 'ss_total_pages' => 'Total pages',
40 'ss_users' => 'Number of users',
41 'ss_active_users' => 'Active users',
42 'ss_images' => 'Number of images',
43 ];
44
45 // Get cached stats from a replica DB
46 $dbr = $this->getReplicaDB();
47 $stats = $dbr->newSelectQueryBuilder()
48 ->select( '*' )
49 ->from( 'site_stats' )
50 ->caller( __METHOD__ )->fetchRow();
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(
62 "%-{$max_length_desc}s: %{$max_length_value}d\n",
63 $desc,
64 $stats->$field
65 ) );
66 }
67 }
68}
69
70// @codeCoverageIgnoreStart
71$maintClass = ShowSiteStats::class;
72require_once RUN_MAINTENANCE_IF_MAIN;
73// @codeCoverageIgnoreEnd
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getReplicaDB(string|false $virtualDomain=false)
addDescription( $text)
Set the description text.
Maintenance script to show the cached statistics.
__construct()
Default constructor.
execute()
Do the actual work.
$maintClass