* Maintain active user count for Special:Statistics (bug 13585)
[lhc/web/wiklou.git] / includes / specials / SpecialStatistics.php
1 <?php
2
3 /**
4 * Special page lists various statistics, including the contents of
5 * `site_stats`, plus page view details if enabled
6 *
7 * @file
8 * @ingroup SpecialPage
9 */
10
11 /**
12 * Show the special page
13 *
14 * @param mixed $par (not used)
15 */
16 function wfSpecialStatistics( $par = '' ) {
17 global $wgOut, $wgLang, $wgRequest;
18 $dbr = wfGetDB( DB_SLAVE );
19
20 $views = SiteStats::views();
21 $edits = SiteStats::edits();
22 $good = SiteStats::articles();
23 $images = SiteStats::images();
24 $total = SiteStats::pages();
25 $users = SiteStats::users();
26 $activeUsers = SiteStats::activeUsers();
27 $admins = SiteStats::numberingroup('sysop');
28 $numJobs = SiteStats::jobs();
29
30 if( $wgRequest->getVal( 'action' ) == 'raw' ) {
31 $wgOut->disable();
32 header( 'Pragma: nocache' );
33 echo "total=$total;good=$good;views=$views;edits=$edits;users=$users;";
34 echo "activeusers=$activeusers;admins=$admins;images=$images;jobs=$numJobs\n";
35 return;
36 } else {
37 $text = "__NOTOC__\n";
38 $text .= '==' . wfMsgNoTrans( 'sitestats' ) . "==\n";
39 $text .= wfMsgExt( 'sitestatstext', array( 'parsemag' ),
40 $wgLang->formatNum( $total ),
41 $wgLang->formatNum( $good ),
42 $wgLang->formatNum( $views ),
43 $wgLang->formatNum( $edits ),
44 $wgLang->formatNum( sprintf( '%.2f', $total ? $edits / $total : 0 ) ),
45 $wgLang->formatNum( sprintf( '%.2f', $edits ? $views / $edits : 0 ) ),
46 $wgLang->formatNum( $numJobs ),
47 $wgLang->formatNum( $images )
48 )."\n";
49
50 $text .= "==" . wfMsgNoTrans( 'userstats' ) . "==\n";
51 $text .= wfMsgExt( 'userstatstext', array ( 'parsemag' ),
52 $wgLang->formatNum( $users ),
53 $wgLang->formatNum( $admins ),
54 '[[' . wfMsgForContent( 'grouppage-sysop' ) . ']]', # TODO somehow remove, kept for backwards compatibility
55 $wgLang->formatNum( @sprintf( '%.2f', $admins / $users * 100 ) ),
56 User::makeGroupLinkWiki( 'sysop' ),
57 $wgLang->formatNum( $activeUsers )
58 )."\n";
59
60 global $wgDisableCounters, $wgMiserMode, $wgUser, $wgLang, $wgContLang;
61 if( !$wgDisableCounters && !$wgMiserMode ) {
62 $res = $dbr->select(
63 'page',
64 array(
65 'page_namespace',
66 'page_title',
67 'page_counter',
68 ),
69 array(
70 'page_is_redirect' => 0,
71 'page_counter > 0',
72 ),
73 __METHOD__,
74 array(
75 'ORDER BY' => 'page_counter DESC',
76 'LIMIT' => 10,
77 )
78 );
79 if( $res->numRows() > 0 ) {
80 $text .= "==" . wfMsgNoTrans( 'statistics-mostpopular' ) . "==\n";
81 while( $row = $res->fetchObject() ) {
82 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
83 if( $title instanceof Title )
84 $text .= '* [[:' . $title->getPrefixedText() . ']] (' . $wgLang->formatNum( $row->page_counter ) . ")\n";
85 }
86 $res->free();
87 }
88 }
89
90 $footer = wfMsgNoTrans( 'statistics-footer' );
91 if( !wfEmptyMsg( 'statistics-footer', $footer ) && $footer != '' )
92 $text .= "\n" . $footer;
93
94 $wgOut->addWikiText( $text );
95 }
96 }