7 function wfInitStats( $options=array() ) {
8 $dbr = wfGetDB( DB_SLAVE );
10 echo "Counting total edits...";
11 $edits = $dbr->selectField( 'revision', 'COUNT(*)', '', __METHOD__ );
12 $edits += $dbr->selectField( 'archive', 'COUNT(*)', '', __METHOD__ );
13 echo "{$edits}\nCounting number of articles...";
15 global $wgContentNamespaces;
16 $good = $dbr->selectField( 'page', 'COUNT(*)', array( 'page_namespace' => $wgContentNamespaces, 'page_is_redirect' => 0, 'page_len > 0' ), __METHOD__ );
17 echo "{$good}\nCounting total pages...";
19 $pages = $dbr->selectField( 'page', 'COUNT(*)', '', __METHOD__ );
20 echo "{$pages}\nCounting number of users...";
22 $users = $dbr->selectField( 'user', 'COUNT(*)', '', __METHOD__ );
23 echo "{$users}\nCounting number of admins...";
25 $admin = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), __METHOD__ );
26 echo "{$admin}\nCounting number of images...";
28 $image = $dbr->selectField( 'image', 'COUNT(*)', '', __METHOD__ );
31 if( !isset( $options['noviews'] ) ) {
32 echo "Counting total page views...";
33 $views = $dbr->selectField( 'page', 'SUM(page_counter)', '', __METHOD__ );
37 echo "\nUpdating site statistics...";
39 $dbw = wfGetDB( DB_MASTER );
40 $values = array( 'ss_total_edits' => $edits,
41 'ss_good_articles' => $good,
42 'ss_total_pages' => $pages,
44 'ss_admins' => $admin,
45 'ss_images' => $image );
46 $conds = array( 'ss_row_id' => 1 );
47 $views = array( 'ss_total_views' => isset( $views ) ? $views : 0 );
49 if( isset( $options['update'] ) ) {
50 $dbw->update( 'site_stats', $values, $conds, __METHOD__ );
52 $dbw->delete( 'site_stats', $conds, __METHOD__ );
53 $dbw->insert( 'site_stats', array_merge( $values, $conds, $views ), __METHOD__ );