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