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' );
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 );
41 echo( "{$image}\n\nUpdating site statistics..." );
43 $dbw =& wfGetDB( DB_MASTER
);
44 $values = array( 'ss_total_edits' => $edits,
45 'ss_good_articles' => $good,
46 'ss_total_pages' => $pages,
48 'ss_admins' => $admin,
49 'ss_images' => $image );
50 $conds = array( 'ss_row_id' => 1 );
51 $views = array( 'ss_total_views' => 0 );
53 if( isset( $options['update'] ) ) {
54 $dbw->update( 'site_stats', $values, $conds, $fname );
56 $dbw->delete( 'site_stats', $conds, $fname );
57 $dbw->insert( 'site_stats', array_merge( $values, $conds, $views ), $fname );
63 echo( "Re-initialise the site statistics tables.\n\n" );
64 echo( "Usage: php initStats.php [--update]\n\n" );
65 echo( " --update : Update the existing statistics (preserves the ss_total_views field)\n\n" );