MediaWiki  REL1_22
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( 'update', 'Update the existing statistics (preserves the ss_total_views field)' );
00038         $this->addOption( 'noviews', "Don't update the page view counter" );
00039         $this->addOption( 'active', 'Also update active users count' );
00040         $this->addOption( 'use-master', 'Count using the master database' );
00041     }
00042 
00043     public function execute() {
00044         $this->output( "Refresh Site Statistics\n\n" );
00045         $counter = new SiteStatsInit( $this->hasOption( 'use-master' ) );
00046 
00047         $this->output( "Counting total edits..." );
00048         $edits = $counter->edits();
00049         $this->output( "{$edits}\nCounting number of articles..." );
00050 
00051         $good = $counter->articles();
00052         $this->output( "{$good}\nCounting total pages..." );
00053 
00054         $pages = $counter->pages();
00055         $this->output( "{$pages}\nCounting number of users..." );
00056 
00057         $users = $counter->users();
00058         $this->output( "{$users}\nCounting number of images..." );
00059 
00060         $image = $counter->files();
00061         $this->output( "{$image}\n" );
00062 
00063         if ( !$this->hasOption( 'noviews' ) ) {
00064             $this->output( "Counting total page views..." );
00065             $views = $counter->views();
00066             $this->output( "{$views}\n" );
00067         }
00068 
00069         if ( $this->hasOption( 'active' ) ) {
00070             $this->output( "Counting active users..." );
00071             $active = SiteStatsUpdate::cacheUpdate( wfGetDB( DB_MASTER ) );
00072             $this->output( "{$active}\n" );
00073         }
00074 
00075         $this->output( "\nUpdating site statistics..." );
00076 
00077         if ( $this->hasOption( 'update' ) ) {
00078             $counter->update();
00079         } else {
00080             $counter->refresh();
00081         }
00082 
00083         $this->output( "done.\n" );
00084     }
00085 }
00086 
00087 $maintClass = "InitSiteStats";
00088 require_once RUN_MAINTENANCE_IF_MAIN;