Add class to rows so admins can hide groups from Special:Statistics.
[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, $wgUser, $wgContLang;
18 global $wgDisableCounters, $wgMiserMode, $wgImplicitGroups, $wgGroupPermissions;
19 $sk = $wgUser->getSkin();
20 $dbr = wfGetDB( DB_SLAVE );
21
22 $views = SiteStats::views();
23 $edits = SiteStats::edits();
24 $good = SiteStats::articles();
25 $images = SiteStats::images();
26 $total = SiteStats::pages();
27 $users = SiteStats::users();
28 $activeUsers = SiteStats::activeUsers();
29 $admins = SiteStats::numberingroup('sysop');
30 $numJobs = SiteStats::jobs();
31
32 # Staticic - views
33 $viewsStats = '';
34 if( !$wgDisableCounters ) {
35 $viewsStats = Xml::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-header-views' ) ) .
36 formatRow( wfMsgExt( 'statistics-views-total', array( 'parseinline' ) ),
37 $wgLang->formatNum( $views ) ) .
38 formatRow( wfMsgExt( 'statistics-views-peredit', array( 'parseinline' ) ),
39 $wgLang->formatNum( sprintf( '%.2f', $edits ? $views / $edits : 0 ) ) );
40 }
41
42 if( $wgRequest->getVal( 'action' ) == 'raw' ) {
43 # Depreciated, kept for backwards compatibility
44 # http://lists.wikimedia.org/pipermail/wikitech-l/2008-August/039202.html
45 $wgOut->disable();
46 header( 'Pragma: nocache' );
47 echo "total=$total;good=$good;views=$views;edits=$edits;users=$users;";
48 echo "activeusers=$activeUsers;admins=$admins;images=$images;jobs=$numJobs\n";
49 return;
50 } else {
51 $text = Xml::openElement( 'table', array( 'class' => 'mw-statistics-table' ) ) .
52 # Statistic - pages
53 Xml::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-header-pages' ) ) .
54 formatRow( wfMsgExt( 'statistics-articles', array( 'parseinline' ) ),
55 $wgLang->formatNum( $good ) ) .
56 formatRow( wfMsgExt( 'statistics-pages', array( 'parseinline' ) ),
57 $wgLang->formatNum( $total ) ) .
58 formatRow( wfMsgExt( 'statistics-files', array( 'parseinline' ) ),
59 $wgLang->formatNum( $images ) ) .
60
61 # Statistic - edits
62 Xml::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-header-edits' ) ) .
63 formatRow( wfMsgExt( 'statistics-edits', array( 'parseinline' ) ),
64 $wgLang->formatNum( $edits ) ) .
65 formatRow( wfMsgExt( 'statistics-edits-average', array( 'parseinline' ) ),
66 $wgLang->formatNum( sprintf( '%.2f', $total ? $edits / $total : 0 ) ) ) .
67 formatRow( wfMsgExt( 'statistics-jobqueue', array( 'parseinline' ) ),
68 $wgLang->formatNum( $numJobs ) ) .
69
70 # Statistic - users
71 Xml::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-header-users' ) ) .
72 formatRow( wfMsgExt( 'statistics-users', array( 'parseinline' ) ),
73 $wgLang->formatNum( $users ) ) .
74 formatRow( wfMsgExt( 'statistics-users-active', array( 'parseinline' ) ),
75 $wgLang->formatNum( $activeUsers ) );
76
77 # Statistic - usergroups
78 foreach( $wgGroupPermissions as $group => $permissions ) {
79 # Skip generic * and implicit groups
80 if ( in_array( $group, $wgImplicitGroups ) || $group == '*' ) {
81 continue;
82 }
83 $groupname = htmlspecialchars( $group );
84 $msg = wfMsg( 'group-' . $groupname );
85 if ( wfEmptyMsg( 'group-' . $groupname, $msg ) || $msg == '' ) {
86 $groupnameLocalized = $groupname;
87 } else {
88 $groupnameLocalized = $msg;
89 }
90 $msg = wfMsgForContent( 'grouppage-' . $groupname );
91 if ( wfEmptyMsg( 'grouppage-' . $groupname, $msg ) || $msg == '' ) {
92 $grouppageLocalized = MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
93 } else {
94 $grouppageLocalized = $msg;
95 }
96 $grouppage = $sk->makeLink( $grouppageLocalized, $groupnameLocalized );
97 $grouplink = $sk->link( SpecialPage::getTitleFor( 'Listusers' ),
98 wfMsgHtml( 'listgrouprights-members' ),
99 array(),
100 array( 'group' => $group ),
101 'known' );
102 $text .= formatRow( $grouppage . ' ' . $grouplink,
103 $wgLang->formatNum( SiteStats::numberingroup( $groupname ) ),
104 ' class="statistics-group-' . Sanitizer::escapeClass( $group ) . '"' );
105 }
106 }
107 $text .= $viewsStats;
108
109 # Statistic - popular pages
110 if( !$wgDisableCounters && !$wgMiserMode ) {
111 $res = $dbr->select(
112 'page',
113 array(
114 'page_namespace',
115 'page_title',
116 'page_counter',
117 ),
118 array(
119 'page_is_redirect' => 0,
120 'page_counter > 0',
121 ),
122 __METHOD__,
123 array(
124 'ORDER BY' => 'page_counter DESC',
125 'LIMIT' => 10,
126 )
127 );
128 if( $res->numRows() > 0 ) {
129 $text .= Xml::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-mostpopular' ) );
130 while( $row = $res->fetchObject() ) {
131 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
132 if( $title instanceof Title ) {
133 $text .= formatRow( $sk->link( $title ),
134 $wgLang->formatNum( $row->page_counter ) );
135
136 }
137 }
138 $res->free();
139 }
140 }
141
142 $text .= Xml::closeElement( 'table' );
143
144 # Customizable footer
145 $footer = wfMsgExt( 'statistics-footer', array('parseinline') );
146 if( !wfEmptyMsg( 'statistics-footer', $footer ) && $footer != '' ) {
147 $text .= "\n" . $footer;
148 }
149
150 $wgOut->addHtml( $text );
151 }
152
153 /**
154 * Format a row
155 *
156 * @param string $text description of the row
157 * @param float $number a number
158 * @return string table row in HTML format
159 */
160 function formatRow( $text, $number, $trExtraParams = '' ) {
161 return "<tr{$trExtraParams}>
162 <td>" .
163 $text .
164 '</td>
165 <td class="mw-statistics-numbers">' .
166 $number .
167 '</td>
168 </tr>';
169 }