4 * Maintenance script to re-initialise or update the site statistics table
7 * @subpackage Maintenance
9 * @author Rob Church <robchur@gmail.com>
10 * @licence GNU General Public Licence 2.0 or later
13 $options = array( 'help', 'update', 'noviews' );
14 require_once( 'commandLine.inc' );
15 echo( "Refresh Site Statistics\n\n" );
16 $dbr =& wfGetDB( DB_SLAVE
);
19 if( isset( $options['help'] ) ) {
24 echo( "Counting total edits..." );
25 $edits = $dbr->selectField( 'revision', 'COUNT(*)', '', $fname );
26 echo( "{$edits}\nCounting number of articles..." );
28 $good = $dbr->selectField( 'page', 'COUNT(*)', array( 'page_namespace' => 0, 'page_is_redirect' => 0, 'page_len > 0' ), $fname );
29 echo( "{$good}\nCounting total pages..." );
31 $pages = $dbr->selectField( 'page', 'COUNT(*)', '', $fname );
32 echo( "{$pages}\nCounting number of users..." );
34 $users = $dbr->selectField( 'user', 'COUNT(*)', '', $fname );
35 echo( "{$users}\nCounting number of admins..." );
37 $admin = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), $fname );
38 echo( "{$admin}\nCounting number of images..." );
40 $image = $dbr->selectField( 'image', 'COUNT(*)', '', $fname );
43 if( !isset( $options['noviews'] ) ) {
44 echo( "Counting total page views..." );
45 $views = $dbr->selectField( 'page', 'SUM(page_counter)', '', $fname );
49 echo( "\nUpdating site statistics..." );
51 $dbw =& wfGetDB( DB_MASTER
);
52 $values = array( 'ss_total_edits' => $edits,
53 'ss_good_articles' => $good,
54 'ss_total_pages' => $pages,
56 'ss_admins' => $admin,
57 'ss_images' => $image );
58 $conds = array( 'ss_row_id' => 1 );
59 $views = array( 'ss_total_views' => isset( $views ) ?
$views : 0 );
61 if( isset( $options['update'] ) ) {
62 $dbw->update( 'site_stats', $values, $conds, $fname );
64 $dbw->delete( 'site_stats', $conds, $fname );
65 $dbw->insert( 'site_stats', array_merge( $values, $conds, $views ), $fname );
71 echo( "Re-initialise the site statistics tables.\n\n" );
72 echo( "Usage: php initStats.php [--update|--noviews]\n\n" );
73 echo( " --update : Update the existing statistics (preserves the ss_total_views field)\n" );
74 echo( "--noviews : Don't update the page view counter\n\n" );