MediaWiki master
initSiteStats.php
Go to the documentation of this file.
1<?php
29
30// @codeCoverageIgnoreStart
31require_once __DIR__ . '/Maintenance.php';
32// @codeCoverageIgnoreEnd
33
40 public function __construct() {
41 parent::__construct();
42 $this->addDescription( 'Re-initialise the site statistics tables' );
43 $this->addOption( 'update', 'Update the existing statistics' );
44 $this->addOption( 'active', 'Also update active users count' );
45 $this->addOption( 'use-master', 'Count using the primary database' );
46 }
47
48 public function execute() {
49 $this->output( "Refresh Site Statistics\n\n" );
50 $counter = new SiteStatsInit( $this->hasOption( 'use-master' ) );
51
52 $this->output( "Counting total edits..." );
53 $edits = $counter->edits();
54 $this->output( "{$edits}\nCounting number of articles..." );
55
56 $good = $counter->articles();
57 $this->output( "{$good}\nCounting total pages..." );
58
59 $pages = $counter->pages();
60 $this->output( "{$pages}\nCounting number of users..." );
61
62 $users = $counter->users();
63 $this->output( "{$users}\nCounting number of images..." );
64
65 $image = $counter->files();
66 $this->output( "{$image}\n" );
67
68 if ( $this->hasOption( 'update' ) ) {
69 $this->output( "\nUpdating site statistics..." );
70 $counter->refresh();
71 $this->output( "done.\n" );
72 } else {
73 $this->output( "\nTo update the site statistics table, run the script "
74 . "with the --update option.\n" );
75 }
76
77 if ( $this->hasOption( 'active' ) ) {
78 $this->output( "\nCounting and updating active users..." );
79 $active = SiteStatsUpdate::cacheUpdate( $this->getPrimaryDB() );
80 $this->output( "{$active}\n" );
81 }
82
83 $this->output( "\nDone.\n" );
84 }
85}
86
87// @codeCoverageIgnoreStart
88$maintClass = InitSiteStats::class;
89require_once RUN_MAINTENANCE_IF_MAIN;
90// @codeCoverageIgnoreEnd
Maintenance script to re-initialise or update the site statistics table.
execute()
Do the actual work.
__construct()
Default constructor.
Class for handling updates to the site_stats table.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
Class designed for counting of stats.
$maintClass