MediaWiki master
showSiteStats.php
Go to the documentation of this file.
1<?php
2
33
34// @codeCoverageIgnoreStart
35require_once __DIR__ . '/Maintenance.php';
36// @codeCoverageIgnoreEnd
37
44 public function __construct() {
45 parent::__construct();
46 $this->addDescription( 'Show the cached statistics' );
47 }
48
49 public function execute() {
50 $fields = [
51 'ss_total_edits' => 'Total edits',
52 'ss_good_articles' => 'Number of articles',
53 'ss_total_pages' => 'Total pages',
54 'ss_users' => 'Number of users',
55 'ss_active_users' => 'Active users',
56 'ss_images' => 'Number of images',
57 ];
58
59 // Get cached stats from a replica DB
60 $dbr = $this->getReplicaDB();
61 $stats = $dbr->newSelectQueryBuilder()
62 ->select( '*' )
63 ->from( 'site_stats' )
64 ->caller( __METHOD__ )->fetchRow();
65
66 // Get maximum size for each column
67 $max_length_value = $max_length_desc = 0;
68 foreach ( $fields as $field => $desc ) {
69 $max_length_value = max( $max_length_value, strlen( $stats->$field ) );
70 $max_length_desc = max( $max_length_desc, strlen( $desc ) );
71 }
72
73 // Show them
74 foreach ( $fields as $field => $desc ) {
75 $this->output( sprintf(
76 "%-{$max_length_desc}s: %{$max_length_value}d\n",
77 $desc,
78 $stats->$field
79 ) );
80 }
81 }
82}
83
84// @codeCoverageIgnoreStart
85$maintClass = ShowSiteStats::class;
86require_once RUN_MAINTENANCE_IF_MAIN;
87// @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.
addDescription( $text)
Set the description text.
Maintenance script to show the cached statistics.
__construct()
Default constructor.
execute()
Do the actual work.
$maintClass