MediaWiki  REL1_24
initSiteStats.php
Go to the documentation of this file.
00001 <?php
00026 require_once __DIR__ . '/Maintenance.php';
00027 
00033 class InitSiteStats extends Maintenance {
00034     public function __construct() {
00035         parent::__construct();
00036         $this->mDescription = "Re-initialise the site statistics tables";
00037         $this->addOption(
00038             'update',
00039             'Update the existing statistics (preserves the ss_total_views field)'
00040         );
00041         $this->addOption( 'noviews', "Don't update the page view counter" );
00042         $this->addOption( 'active', 'Also update active users count' );
00043         $this->addOption( 'use-master', 'Count using the master database' );
00044     }
00045 
00046     public function execute() {
00047         $this->output( "Refresh Site Statistics\n\n" );
00048         $counter = new SiteStatsInit( $this->hasOption( 'use-master' ) );
00049 
00050         $this->output( "Counting total edits..." );
00051         $edits = $counter->edits();
00052         $this->output( "{$edits}\nCounting number of articles..." );
00053 
00054         $good = $counter->articles();
00055         $this->output( "{$good}\nCounting total pages..." );
00056 
00057         $pages = $counter->pages();
00058         $this->output( "{$pages}\nCounting number of users..." );
00059 
00060         $users = $counter->users();
00061         $this->output( "{$users}\nCounting number of images..." );
00062 
00063         $image = $counter->files();
00064         $this->output( "{$image}\n" );
00065 
00066         if ( !$this->hasOption( 'noviews' ) ) {
00067             $this->output( "Counting total page views..." );
00068             $views = $counter->views();
00069             $this->output( "{$views}\n" );
00070         }
00071 
00072         if ( $this->hasOption( 'update' ) ) {
00073             $this->output( "\nUpdating site statistics..." );
00074             $counter->refresh();
00075             $this->output( "done.\n" );
00076         }
00077 
00078         if ( $this->hasOption( 'active' ) ) {
00079             $this->output( "\nCounting and updating active users..." );
00080             $active = SiteStatsUpdate::cacheUpdate( wfGetDB( DB_MASTER ) );
00081             $this->output( "{$active}\n" );
00082         }
00083 
00084         $this->output( "\nDone.\n" );
00085     }
00086 }
00087 
00088 $maintClass = "InitSiteStats";
00089 require_once RUN_MAINTENANCE_IF_MAIN;