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