documentation
[lhc/web/wiklou.git] / includes / SpecialStatistics.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 * constructor
10 */
11 function wfSpecialStatistics() {
12 global $wgUser, $wgOut, $wgLang, $wgRequest;
13 $fname = 'wfSpecialStatistics';
14
15 $action = $wgRequest->getVal( 'action' );
16
17 $dbr =& wfGetDB( DB_SLAVE );
18 extract( $dbr->tableNames( 'page', 'site_stats', 'user', 'user_groups' ) );
19
20 $row = $dbr->selectRow( 'site_stats', '*', false, 'wfSpecialStatistics' );
21 $views = $row->ss_total_views;
22 $edits = $row->ss_total_edits;
23 $good = $row->ss_good_articles;
24
25 # This code is somewhat schema-agnostic, because I'm changing it in a minor release -- TS
26 if ( isset( $row->ss_total_pages ) && $row->ss_total_pages == -1 ) {
27 # Update schema
28 $u = new SiteStatsUpdate( 0, 0, 0 );
29 $u->doUpdate();
30 $row = $dbr->selectRow( 'site_stats', '*', false, 'wfSpecialStatistics' );
31 }
32
33 if ( isset( $row->ss_total_pages ) ) {
34 $total = $row->ss_total_pages;
35 } else {
36 $sql = "SELECT COUNT(page_namespace) AS total FROM $page";
37 $res = $dbr->query( $sql, $fname );
38 $pageRow = $dbr->fetchObject( $res );
39 $total = $pageRow->total;
40 }
41
42 if ( isset( $row->ss_users ) ) {
43 $users = $row->ss_users;
44 } else {
45 $sql = "SELECT MAX(user_id) AS total FROM $user";
46 $res = $dbr->query( $sql, $fname );
47 $userRow = $dbr->fetchObject( $res );
48 $users = $userRow->total;
49 }
50
51 $sql = "SELECT COUNT(*) AS total FROM $user_groups WHERE ug_group='sysop'";
52 $res = $dbr->query( $sql, $fname );
53 $row = $dbr->fetchObject( $res );
54 $admins = $row->total;
55
56 if ($action == 'raw') {
57 $wgOut->disable();
58 header( 'Pragma: nocache' );
59 echo "total=$total;good=$good;views=$views;edits=$edits;users=$users;admins=$admins\n";
60 return;
61 } else {
62 $text = '==' . wfMsg( 'sitestats' ) . "==\n" ;
63 $text .= wfMsg( 'sitestatstext',
64 $wgLang->formatNum( $total ),
65 $wgLang->formatNum( $good ),
66 $wgLang->formatNum( $views ),
67 $wgLang->formatNum( $edits ),
68 $wgLang->formatNum( sprintf( '%.2f', $total ? $edits / $total : 0 ) ),
69 $wgLang->formatNum( sprintf( '%.2f', $edits ? $views / $edits : 0 ) ) );
70
71 $text .= "\n==" . wfMsg( 'userstats' ) . "==\n";
72
73 $text .= wfMsg( 'userstatstext',
74 $wgLang->formatNum( $users ),
75 $wgLang->formatNum( $admins ),
76 '[[' . wfMsg( 'administrators' ) . ']]',
77 // should logically be after #admins, danm backwards compatability!
78 $wgLang->formatNum( round( $admins / $total * 100, 2 ) )
79 );
80
81 $wgOut->addWikiText( $text );
82 }
83 }
84 ?>