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;
18 global $wgDisableCounters, $wgMiserMode, $wgImplicitGroups, $wgGroupPermissions;
19 $sk = $wgUser->getSkin();
20 $dbr = wfGetDB( DB_SLAVE
);
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();
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 ) ) );
41 # Set active user count
43 $dbw = wfGetDB( DB_MASTER
);
44 SiteStatsUpdate
::cacheUpdate( $dbw );
47 if( $wgRequest->getVal( 'action' ) == 'raw' ) {
48 # Depreciated, kept for backwards compatibility
49 # http://lists.wikimedia.org/pipermail/wikitech-l/2008-August/039202.html
51 header( 'Pragma: nocache' );
52 echo "total=$total;good=$good;views=$views;edits=$edits;users=$users;";
53 echo "activeusers=$activeUsers;admins=$admins;images=$images;jobs=$numJobs\n";
56 $text = Xml
::openElement( 'table', array( 'class' => 'mw-statistics-table' ) ) .
58 Xml
::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-header-pages' ) ) .
59 formatRow( wfMsgExt( 'statistics-articles', array( 'parseinline' ) ),
60 $wgLang->formatNum( $good ) ) .
61 formatRow( wfMsgExt( 'statistics-pages', array( 'parseinline' ) ),
62 $wgLang->formatNum( $total ), NULL, 'statistics-pages-tooltip' ) .
63 formatRow( wfMsgExt( 'statistics-files', array( 'parseinline' ) ),
64 $wgLang->formatNum( $images ) ) .
67 Xml
::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-header-edits' ) ) .
68 formatRow( wfMsgExt( 'statistics-edits', array( 'parseinline' ) ),
69 $wgLang->formatNum( $edits ) ) .
70 formatRow( wfMsgExt( 'statistics-edits-average', array( 'parseinline' ) ),
71 $wgLang->formatNum( sprintf( '%.2f', $total ?
$edits / $total : 0 ) ) ) .
72 formatRow( wfMsgExt( 'statistics-jobqueue', array( 'parseinline' ) ),
73 $wgLang->formatNum( $numJobs ) ) .
76 Xml
::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-header-users' ) ) .
77 formatRow( wfMsgExt( 'statistics-users', array( 'parseinline' ) ),
78 $wgLang->formatNum( $users ) ) .
79 formatRow( wfMsgExt( 'statistics-users-active', array( 'parseinline' ) ),
80 $wgLang->formatNum( $activeUsers ), NULL, 'statistics-users-active-tooltip' );
82 # Statistic - usergroups
83 foreach( $wgGroupPermissions as $group => $permissions ) {
84 # Skip generic * and implicit groups
85 if ( in_array( $group, $wgImplicitGroups ) ||
$group == '*' ) {
88 $groupname = htmlspecialchars( $group );
89 $msg = wfMsg( 'group-' . $groupname );
90 if ( wfEmptyMsg( 'group-' . $groupname, $msg ) ||
$msg == '' ) {
91 $groupnameLocalized = $groupname;
93 $groupnameLocalized = $msg;
95 $msg = wfMsgForContent( 'grouppage-' . $groupname );
96 if ( wfEmptyMsg( 'grouppage-' . $groupname, $msg ) ||
$msg == '' ) {
97 $grouppageLocalized = MWNamespace
::getCanonicalName( NS_PROJECT
) . ':' . $groupname;
99 $grouppageLocalized = $msg;
101 $grouppage = $sk->makeLink( $grouppageLocalized, $groupnameLocalized );
102 $grouplink = $sk->link( SpecialPage
::getTitleFor( 'Listusers' ),
103 wfMsgHtml( 'listgrouprights-members' ),
105 array( 'group' => $group ),
107 $text .= formatRow( $grouppage . ' ' . $grouplink,
108 $wgLang->formatNum( SiteStats
::numberingroup( $groupname ) ),
109 ' class="statistics-group-' . Sanitizer
::escapeClass( $group ) . '"' );
112 $text .= $viewsStats;
114 # Statistic - popular pages
115 if( !$wgDisableCounters && !$wgMiserMode ) {
124 'page_is_redirect' => 0,
129 'ORDER BY' => 'page_counter DESC',
133 if( $res->numRows() > 0 ) {
134 $text .= Xml
::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-mostpopular' ) );
135 while( $row = $res->fetchObject() ) {
136 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
137 if( $title instanceof Title
) {
138 $text .= formatRow( $sk->link( $title ),
139 $wgLang->formatNum( $row->page_counter
) );
147 $text .= Xml
::closeElement( 'table' );
149 # Customizable footer
150 $footer = wfMsgExt( 'statistics-footer', array('parseinline') );
151 if( !wfEmptyMsg( 'statistics-footer', $footer ) && $footer != '' ) {
152 $text .= "\n" . $footer;
155 $wgOut->addHtml( $text );
161 * @param string $text description of the row
162 * @param float $number a number
163 * @return string table row in HTML format
165 function formatRow( $text, $number, $trExtraParams = '', $tooltip = '' ) {
167 $text = '<div title="' . wfMsg( $tooltip ) . '">' . $text . '</div>';
170 return "<tr{$trExtraParams}>
174 <td class="mw-statistics-numbers">' .