* Updated initStats maintenance script
[lhc/web/wiklou.git] / maintenance / initStats.php
1 <?php
2
3 /**
4 * Maintenance script to re-initialise or update the site statistics table
5 *
6 * @package MediaWiki
7 * @subpackage Maintenance
8 * @author Brion Vibber
9 * @author Rob Church <robchur@gmail.com>
10 * @licence GNU General Public Licence 2.0 or later
11 */
12
13 $options = array( 'help', 'update' );
14 require_once( 'commandLine.inc' );
15 echo( "Refresh Site Statistics\n\n" );
16 $dbr =& wfGetDB( DB_SLAVE );
17 $fname = 'initStats';
18
19 echo( "Counting total edits..." );
20 $edits = $dbr->selectField( 'revision', 'COUNT(*)', '', $fname );
21 echo( "{$edits}\nCounting number of articles..." );
22
23 $good = $dbr->selectField( 'page', 'COUNT(*)', array( 'page_namespace' => 0, 'page_is_redirect' => 0, 'page_len > 0' ), $fname );
24 echo( "{$good}\nCounting total pages..." );
25
26 $pages = $dbr->selectField( 'page', 'COUNT(*)', '', $fname );
27 echo( "{$pages}\nCounting number of users..." );
28
29 $users = $dbr->selectField( 'user', 'COUNT(*)', '', $fname );
30 echo( "{$users}\nCounting number of admins..." );
31
32 $admin = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), $fname );
33 echo( "{$admin}\nCounting number of images..." );
34
35 $image = $dbr->selectField( 'image', 'COUNT(*)', '', $fname );
36 echo( "{$image}\n\nUpdating site statistics..." );
37
38 $dbw =& wfGetDB( DB_MASTER );
39 $values = array( 'ss_total_edits' => $edits,
40 'ss_good_articles' => $good,
41 'ss_total_pages' => $pages,
42 'ss_users' => $users,
43 'ss_admins' => $admin,
44 'ss_images' => $image );
45 $conds = array( 'ss_row_id' => 1 );
46 $views = array( 'ss_total_views' => 0 );
47
48 if( isset( $options['update'] ) ) {
49 $dbw->update( 'site_stats', $values, $conds, $fname );
50 } else {
51 $dbw->delete( 'site_stats', $conds, $fname );
52 $dbw->insert( 'site_stats', array_merge( $values, $conds, $views ), $fname );
53 }
54
55 echo( "done.\n\n" );
56
57 ?>