5 * @subpackage SpecialPage
11 function wfSpecialStatistics() {
12 global $wgOut, $wgLang, $wgRequest;
13 $fname = 'wfSpecialStatistics';
15 $action = $wgRequest->getVal( 'action' );
17 $dbr =& wfGetDB( DB_SLAVE
);
18 extract( $dbr->tableNames( 'page', 'site_stats', 'user', 'user_groups' ) );
20 $row = $dbr->selectRow( 'site_stats', '*', false, $fname );
21 $views = $row->ss_total_views
;
22 $edits = $row->ss_total_edits
;
23 $good = $row->ss_good_articles
;
24 $images = $row->ss_images
;
26 # This code is somewhat schema-agnostic, because I'm changing it in a minor release -- TS
27 if ( isset( $row->ss_total_pages
) && $row->ss_total_pages
== -1 ) {
29 $u = new SiteStatsUpdate( 0, 0, 0 );
31 $row = $dbr->selectRow( 'site_stats', '*', false, $fname );
34 if ( isset( $row->ss_total_pages
) ) {
35 $total = $row->ss_total_pages
;
37 $sql = "SELECT COUNT(page_namespace) AS total FROM $page";
38 $res = $dbr->query( $sql, $fname );
39 $pageRow = $dbr->fetchObject( $res );
40 $total = $pageRow->total
;
43 if ( isset( $row->ss_users
) ) {
44 $users = $row->ss_users
;
46 $sql = "SELECT MAX(user_id) AS total FROM $user";
47 $res = $dbr->query( $sql, $fname );
48 $userRow = $dbr->fetchObject( $res );
49 $users = $userRow->total
;
52 $admins = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), $fname );
53 $numJobs = $dbr->selectField( 'job', 'COUNT(*)', '', $fname );
55 if ($action == 'raw') {
57 header( 'Pragma: nocache' );
58 echo "total=$total;good=$good;views=$views;edits=$edits;users=$users;admins=$admins;images=$images;jobs=$numJobs\n";
61 $text = '==' . wfMsg( 'sitestats' ) . "==\n" ;
62 $text .= wfMsg( 'sitestatstext',
63 $wgLang->formatNum( $total ),
64 $wgLang->formatNum( $good ),
65 $wgLang->formatNum( $views ),
66 $wgLang->formatNum( $edits ),
67 $wgLang->formatNum( sprintf( '%.2f', $total ?
$edits / $total : 0 ) ),
68 $wgLang->formatNum( sprintf( '%.2f', $edits ?
$views / $edits : 0 ) ),
69 $wgLang->formatNum( $numJobs ),
70 $wgLang->formatNum( $images )
73 $text .= "\n==" . wfMsg( 'userstats' ) . "==\n";
75 $text .= wfMsg( 'userstatstext',
76 $wgLang->formatNum( $users ),
77 $wgLang->formatNum( $admins ),
78 '[[' . wfMsgForContent( 'administrators' ) . ']]',
79 // should logically be after #admins, damn backwards compatability!
80 $wgLang->formatNum( sprintf( '%.2f', $admins / $users * 100 ) )
83 $wgOut->addWikiText( $text );