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