X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FinitStats.php;h=35918bbdb5db520787b5fbe43ae89e9f94ae806b;hb=b9e64226096bb17d005f7c53913119f9f7997dc9;hp=06bb7671014aaa9c10e32f5f59b834965d82e015;hpb=daef9b5b34f50f2278a7b725b83c12b4914589c5;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/initStats.php b/maintenance/initStats.php index 06bb767101..35918bbdb5 100644 --- a/maintenance/initStats.php +++ b/maintenance/initStats.php @@ -1,77 +1,88 @@ - * @licence GNU General Public Licence 2.0 or later */ - -$options = array( 'help', 'update', 'noviews' ); -require_once( 'commandLine.inc' ); -echo( "Refresh Site Statistics\n\n" ); -$dbr =& wfGetDB( DB_SLAVE ); -$fname = 'initStats'; -if( isset( $options['help'] ) ) { - showHelp(); - exit(); -} +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); -echo( "Counting total edits..." ); -$edits = $dbr->selectField( 'revision', 'COUNT(*)', '', $fname ); -echo( "{$edits}\nCounting number of articles..." ); +/** + * Maintenance script to re-initialise or update the site statistics table + * + * @ingroup Maintenance + */ +class InitStats extends Maintenance { + public function __construct() { + parent::__construct(); + $this->mDescription = "Re-initialise the site statistics tables"; + $this->addOption( 'update', 'Update the existing statistics (preserves the ss_total_views field)' ); + $this->addOption( 'noviews', "Don't update the page view counter" ); + $this->addOption( 'active', 'Also update active users count' ); + $this->addOption( 'use-master', 'Count using the master database' ); + } -$good = $dbr->selectField( 'page', 'COUNT(*)', array( 'page_namespace' => 0, 'page_is_redirect' => 0, 'page_len > 0' ), $fname ); -echo( "{$good}\nCounting total pages..." ); + public function execute() { + $this->output( "Refresh Site Statistics\n\n" ); + $counter = new SiteStatsInit( $this->hasOption( 'use-master' ) ); -$pages = $dbr->selectField( 'page', 'COUNT(*)', '', $fname ); -echo( "{$pages}\nCounting number of users..." ); + $this->output( "Counting total edits..." ); + $edits = $counter->edits(); + $this->output( "{$edits}\nCounting number of articles..." ); -$users = $dbr->selectField( 'user', 'COUNT(*)', '', $fname ); -echo( "{$users}\nCounting number of admins..." ); + $good = $counter->articles(); + $this->output( "{$good}\nCounting total pages..." ); -$admin = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), $fname ); -echo( "{$admin}\nCounting number of images..." ); + $pages = $counter->pages(); + $this->output( "{$pages}\nCounting number of users..." ); -$image = $dbr->selectField( 'image', 'COUNT(*)', '', $fname ); -echo( "{$image}\n" ); + $users = $counter->users(); + $this->output( "{$users}\nCounting number of images..." ); -if( !isset( $options['noviews'] ) ) { - echo( "Counting total page views..." ); - $views = $dbr->selectField( 'page', 'SUM(page_counter)', '', $fname ); - echo( "{$views}\n" ); -} + $image = $counter->files(); + $this->output( "{$image}\n" ); -echo( "\nUpdating site statistics..." ); + if ( !$this->hasOption( 'noviews' ) ) { + $this->output( "Counting total page views..." ); + $views = $counter->views(); + $this->output( "{$views}\n" ); + } -$dbw =& wfGetDB( DB_MASTER ); -$values = array( 'ss_total_edits' => $edits, - 'ss_good_articles' => $good, - 'ss_total_pages' => $pages, - 'ss_users' => $users, - 'ss_admins' => $admin, - 'ss_images' => $image ); -$conds = array( 'ss_row_id' => 1 ); -$views = array( 'ss_total_views' => isset( $views ) ? $views : 0 ); - -if( isset( $options['update'] ) ) { - $dbw->update( 'site_stats', $values, $conds, $fname ); -} else { - $dbw->delete( 'site_stats', $conds, $fname ); - $dbw->insert( 'site_stats', array_merge( $values, $conds, $views ), $fname ); -} + if ( $this->hasOption( 'active' ) ) { + $this->output( "Counting active users..." ); + $active = SiteStatsUpdate::cacheUpdate( wfGetDB( DB_MASTER ) ); + $this->output( "{$active}\n" ); + } + + $this->output( "\nUpdating site statistics..." ); -echo( "done.\n\n" ); + if ( $this->hasOption( 'update' ) ) { + $counter->update(); + } else { + $counter->refresh(); + } -function showHelp() { - echo( "Re-initialise the site statistics tables.\n\n" ); - echo( "Usage: php initStats.php [--update|--noviews]\n\n" ); - echo( " --update : Update the existing statistics (preserves the ss_total_views field)\n" ); - echo( "--noviews : Don't update the page view counter\n\n" ); + $this->output( "done.\n" ); + } } -?> \ No newline at end of file +$maintClass = "InitStats"; +require_once( RUN_MAINTENANCE_IF_MAIN );