4 * Special page lists various statistics, including the contents of
5 * `site_stats`, plus page view details if enabled
12 * Show the special page
14 * @param mixed $par (not used)
16 function wfSpecialStatistics( $par = '' ) {
17 global $wgOut, $wgLang, $wgRequest, $wgUser, $wgContLang, $wgMessageCache;
18 global $wgDisableCounters, $wgMiserMode, $wgImplicitGroups, $wgGroupPermissions;
19 $wgMessageCache->loadAllMessages();
20 $sk = $wgUser->getSkin();
21 $dbr = wfGetDB( DB_SLAVE
);
23 $views = SiteStats
::views();
24 $edits = SiteStats
::edits();
25 $good = SiteStats
::articles();
26 $images = SiteStats
::images();
27 $total = SiteStats
::pages();
28 $users = SiteStats
::users();
29 $activeUsers = SiteStats
::activeUsers();
30 $admins = SiteStats
::numberingroup('sysop');
31 $numJobs = SiteStats
::jobs();
34 ## Maybe re-enablable with new hitcounter infrastructure, plus more goodies like newly popular pages.
36 if( !$wgDisableCounters ) {
37 $viewsStats = Xml
::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-header-views' ) ) .
38 formatRow( wfMsgExt( 'statistics-views-total', array( 'parseinline' ) ),
39 $wgLang->formatNum( $views ),
40 ' class="mw-statistics-views-total"' ) .
41 formatRow( wfMsgExt( 'statistics-views-peredit', array( 'parseinline' ) ),
42 $wgLang->formatNum( sprintf( '%.2f', $edits ?
$views / $edits : 0 ) ),
43 ' class="mw-statistics-views-peredit"' );
45 # Set active user count
47 $dbw = wfGetDB( DB_MASTER
);
48 SiteStatsUpdate
::cacheUpdate( $dbw );
51 if( $wgRequest->getVal( 'action' ) == 'raw' ) {
52 # Depreciated, kept for backwards compatibility
53 # http://lists.wikimedia.org/pipermail/wikitech-l/2008-August/039202.html
55 header( 'Pragma: nocache' );
56 echo "total=$total;good=$good;views=$views;edits=$edits;users=$users;";
57 echo "activeusers=$activeUsers;admins=$admins;images=$images;jobs=$numJobs\n";
60 $text = Xml
::openElement( 'table', array( 'class' => 'mw-statistics-table' ) ) .
62 Xml
::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-header-pages' ) ) .
63 formatRow( wfMsgExt( 'statistics-articles', array( 'parseinline' ) ),
64 $wgLang->formatNum( $good ),
65 ' class="mw-statistics-articles"' ) .
66 formatRow( wfMsgExt( 'statistics-pages', array( 'parseinline' ) ),
67 $wgLang->formatNum( $total ),
68 ' class="mw-statistics-pages"',
69 'statistics-pages-tooltip' ) .
70 formatRow( wfMsgExt( 'statistics-files', array( 'parseinline' ) ),
71 $wgLang->formatNum( $images ),
72 ' class="mw-statistics-files"' ) .
75 Xml
::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-header-edits' ) ) .
76 formatRow( wfMsgExt( 'statistics-edits', array( 'parseinline' ) ),
77 $wgLang->formatNum( $edits ),
78 ' class="mw-statistics-edits"' ) .
79 formatRow( wfMsgExt( 'statistics-edits-average', array( 'parseinline' ) ),
80 $wgLang->formatNum( sprintf( '%.2f', $total ?
$edits / $total : 0 ) ),
81 ' class="mw-statistics-edits-average"' ) .
82 formatRow( wfMsgExt( 'statistics-jobqueue', array( 'parseinline' ) ),
83 $wgLang->formatNum( $numJobs ),
84 ' class="mw-statistics-jobqueue"' ) .
87 Xml
::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-header-users' ) ) .
88 formatRow( wfMsgExt( 'statistics-users', array( 'parseinline' ) ),
89 $wgLang->formatNum( $users ),
90 ' class="mw-statistics-users"' ) .
91 formatRow( wfMsgExt( 'statistics-users-active', array( 'parseinline' ) ),
92 $wgLang->formatNum( $activeUsers ),
93 ' class="mw-statistics-users-active"',
94 'statistics-users-active-tooltip' );
96 # Statistic - usergroups
97 foreach( $wgGroupPermissions as $group => $permissions ) {
98 # Skip generic * and implicit groups
99 if ( in_array( $group, $wgImplicitGroups ) ||
$group == '*' ) {
102 $groupname = htmlspecialchars( $group );
103 $msg = wfMsg( 'group-' . $groupname );
104 if ( wfEmptyMsg( 'group-' . $groupname, $msg ) ||
$msg == '' ) {
105 $groupnameLocalized = $groupname;
107 $groupnameLocalized = $msg;
109 $msg = wfMsgForContent( 'grouppage-' . $groupname );
110 if ( wfEmptyMsg( 'grouppage-' . $groupname, $msg ) ||
$msg == '' ) {
111 $grouppageLocalized = MWNamespace
::getCanonicalName( NS_PROJECT
) . ':' . $groupname;
113 $grouppageLocalized = $msg;
115 $grouppage = $sk->makeLink( $grouppageLocalized, $groupnameLocalized );
116 $grouplink = $sk->link( SpecialPage
::getTitleFor( 'Listusers' ),
117 wfMsgHtml( 'listgrouprights-members' ),
119 array( 'group' => $group ),
122 # Add a class when a usergroup contains no members to allow hiding these rows
124 $countUsers = SiteStats
::numberingroup( $groupname );
125 if( $countUsers == 0 ) {
126 $classZero = ' statistics-group-zero';
128 $text .= formatRow( $grouppage . ' ' . $grouplink,
129 $wgLang->formatNum( $countUsers ),
130 ' class="statistics-group-' . Sanitizer
::escapeClass( $group ) . $classZero . '"' );
133 $text .= $viewsStats;
135 # Statistic - popular pages
136 if( !$wgDisableCounters && !$wgMiserMode ) {
145 'page_is_redirect' => 0,
150 'ORDER BY' => 'page_counter DESC',
154 if( $res->numRows() > 0 ) {
155 $text .= Xml
::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-mostpopular' ) );
156 while( $row = $res->fetchObject() ) {
157 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
158 if( $title instanceof Title
) {
159 $text .= formatRow( $sk->link( $title ),
160 $wgLang->formatNum( $row->page_counter
) );
168 $text .= Xml
::closeElement( 'table' );
170 # Customizable footer
171 $footer = wfMsgExt( 'statistics-footer', array('parseinline') );
172 if( !wfEmptyMsg( 'statistics-footer', $footer ) && $footer != '' ) {
173 $text .= "\n" . $footer;
176 $wgOut->addHTML( $text );
182 * @param string $text description of the row
183 * @param float $number a number
184 * @return string table row in HTML format
186 function formatRow( $text, $number, $trExtraParams = '', $tooltip = '' ) {
188 $text = '<div title="' . wfMsg( $tooltip ) . '">' . $text . '<sup>*</sup></div>';
191 return "<tr{$trExtraParams}>
195 <td class="mw-statistics-numbers">' .