MediaWiki
master
Toggle main menu visibility
showSiteStats.php
Go to the documentation of this file.
1
<?php
2
17
18
use
MediaWiki\Maintenance\Maintenance
;
19
20
// @codeCoverageIgnoreStart
21
require_once __DIR__ .
'/Maintenance.php'
;
22
// @codeCoverageIgnoreEnd
23
29
class
ShowSiteStats
extends
Maintenance
{
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;
72
require_once RUN_MAINTENANCE_IF_MAIN;
73
// @codeCoverageIgnoreEnd
$maintClass
$maintClass
Definition
addChangeTag.php:56
ShowSiteStats
Maintenance script to show the cached statistics.
Definition
showSiteStats.php:29
ShowSiteStats\__construct
__construct()
Definition
showSiteStats.php:30
ShowSiteStats\execute
execute()
Definition
showSiteStats.php:35
MediaWiki\Maintenance
Definition
applyChangeTag.php:11
maintenance
showSiteStats.php
Generated on
for MediaWiki by
1.18.0