Followup to r59869, add to MySQL section, and copy patch to SQLite directory
[lhc/web/wiklou.git] / maintenance / initStats.php
1 <?php
2
3 /**
4 * Maintenance script to re-initialise or update the site statistics table
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * @ingroup Maintenance
22 * @author Brion Vibber
23 * @author Rob Church <robchur@gmail.com>
24 * @licence GNU General Public Licence 2.0 or later
25 */
26
27 require_once( dirname(__FILE__) . '/Maintenance.php' );
28
29 class InitStats extends Maintenance {
30 public function __construct() {
31 parent::__construct();
32 $this->mDescription = "Re-initialise the site statistics tables";
33 $this->addOption( 'update', 'Update the existing statistics (preserves the ss_total_views field)' );
34 $this->addOption( 'noviews', "Don't update the page view counter" );
35 $this->addOption( 'active', 'Also update active users count' );
36 $this->addOption( 'use-master', 'Count using the master database' );
37 }
38
39 public function execute() {
40 $this->output( "Refresh Site Statistics\n\n" );
41 $counter = new SiteStatsInit( $this->hasOption( 'use-master' ) );
42
43 $this->output( "Counting total edits..." );
44 $edits = $counter->edits();
45 $this->output( "{$edits}\nCounting number of articles..." );
46
47 $good = $counter->articles();
48 $this->output( "{$good}\nCounting total pages..." );
49
50 $pages = $counter->pages();
51 $this->output( "{$pages}\nCounting number of users..." );
52
53 $users = $counter->users();
54 $this->output( "{$users}\nCounting number of images..." );
55
56 $image = $counter->files();
57 $this->output( "{$image}\n" );
58
59 if( !$this->hasOption('noviews') ) {
60 $this->output( "Counting total page views..." );
61 $views = $counter->views();
62 $this->output( "{$views}\n" );
63 }
64
65 if( $this->hasOption( 'active' ) ) {
66 $this->output( "Counting active users..." );
67 $active = SiteStatsUpdate::cacheUpdate();
68 $this->output( "{$active}\n" );
69 }
70
71 $this->output( "\nUpdating site statistics..." );
72
73 if( $this->hasOption( 'update' ) ) {
74 $counter->update();
75 } else {
76 $counter->refresh();
77 }
78
79 $this->output( "done.\n" );
80 }
81 }
82
83 $maintClass = "InitStats";
84 require_once( DO_MAINTENANCE );