Parse error
[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 if( isset( $options['help'] ) ) {
20 showHelp();
21 exit();
22 }
23
24 echo( "Counting total edits..." );
25 $edits = $dbr->selectField( 'revision', 'COUNT(*)', '', $fname );
26 echo( "{$edits}\nCounting number of articles..." );
27
28 $good = $dbr->selectField( 'page', 'COUNT(*)', array( 'page_namespace' => 0, 'page_is_redirect' => 0, 'page_len > 0' ), $fname );
29 echo( "{$good}\nCounting total pages..." );
30
31 $pages = $dbr->selectField( 'page', 'COUNT(*)', '', $fname );
32 echo( "{$pages}\nCounting number of users..." );
33
34 $users = $dbr->selectField( 'user', 'COUNT(*)', '', $fname );
35 echo( "{$users}\nCounting number of admins..." );
36
37 $admin = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), $fname );
38 echo( "{$admin}\nCounting number of images..." );
39
40 $image = $dbr->selectField( 'image', 'COUNT(*)', '', $fname );
41 echo( "{$image}\n\nUpdating site statistics..." );
42
43 $dbw =& wfGetDB( DB_MASTER );
44 $values = array( 'ss_total_edits' => $edits,
45 'ss_good_articles' => $good,
46 'ss_total_pages' => $pages,
47 'ss_users' => $users,
48 'ss_admins' => $admin,
49 'ss_images' => $image );
50 $conds = array( 'ss_row_id' => 1 );
51 $views = array( 'ss_total_views' => 0 );
52
53 if( isset( $options['update'] ) ) {
54 $dbw->update( 'site_stats', $values, $conds, $fname );
55 } else {
56 $dbw->delete( 'site_stats', $conds, $fname );
57 $dbw->insert( 'site_stats', array_merge( $values, $conds, $views ), $fname );
58 }
59
60 echo( "done.\n\n" );
61
62 function showHelp() {
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" );
66 }
67
68 ?>