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 echo( "Counting total edits..." );
20 $edits = $dbr->selectField( 'revision', 'COUNT(*)', '', $fname );
21 echo( "{$edits}\nCounting number of articles..." );
23 $good = $dbr->selectField( 'page', 'COUNT(*)', array( 'page_namespace' => 0, 'page_is_redirect' => 0, 'page_len > 0' ), $fname );
24 echo( "{$good}\nCounting total pages..." );
26 $pages = $dbr->selectField( 'page', 'COUNT(*)', '', $fname );
27 echo( "{$pages}\nCounting number of users..." );
29 $users = $dbr->selectField( 'user', 'COUNT(*)', '', $fname );
30 echo( "{$users}\nCounting number of admins..." );
32 $admin = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), $fname );
33 echo( "{$admin}\nCounting number of images..." );
35 $image = $dbr->selectField( 'image', 'COUNT(*)', '', $fname );
36 echo( "{$image}\n\nUpdating site statistics..." );
38 $dbw =& wfGetDB( DB_MASTER
);
39 $values = array( 'ss_total_edits' => $edits,
40 'ss_good_articles' => $good,
41 'ss_total_pages' => $pages,
43 'ss_admins' => $admin,
44 'ss_images' => $image );
45 $conds = array( 'ss_row_id' => 1 );
46 $views = array( 'ss_total_views' => 0 );
48 if( isset( $options['update'] ) ) {
49 $dbw->update( 'site_stats', $values, $conds, $fname );
51 $dbw->delete( 'site_stats', $conds, $fname );
52 $dbw->insert( 'site_stats', array_merge( $values, $conds, $views ), $fname );