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();
35 if( !$wgDisableCounters ) {
36 $viewsStats = Xml
::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-header-views' ) ) .
37 formatRow( wfMsgExt( 'statistics-views-total', array( 'parseinline' ) ),
38 $wgLang->formatNum( $views ),
39 ' class="mw-statistics-views-total"' ) .
40 formatRow( wfMsgExt( 'statistics-views-peredit', array( 'parseinline' ) ),
41 $wgLang->formatNum( sprintf( '%.2f', $edits ?
$views / $edits : 0 ) ),
42 ' class="mw-statistics-views-peredit"' );
44 # Set active user count
46 $dbw = wfGetDB( DB_MASTER
);
47 SiteStatsUpdate
::cacheUpdate( $dbw );
50 if( $wgRequest->getVal( 'action' ) == 'raw' ) {
51 # Depreciated, kept for backwards compatibility
52 # http://lists.wikimedia.org/pipermail/wikitech-l/2008-August/039202.html
54 header( 'Pragma: nocache' );
55 echo "total=$total;good=$good;views=$views;edits=$edits;users=$users;";
56 echo "activeusers=$activeUsers;admins=$admins;images=$images;jobs=$numJobs\n";
59 $text = Xml
::openElement( 'table', array( 'class' => 'mw-statistics-table' ) ) .
61 Xml
::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-header-pages' ) ) .
62 formatRow( wfMsgExt( 'statistics-articles', array( 'parseinline' ) ),
63 $wgLang->formatNum( $good ),
64 ' class="mw-statistics-articles"' ) .
65 formatRow( wfMsgExt( 'statistics-pages', array( 'parseinline' ) ),
66 $wgLang->formatNum( $total ),
67 ' class="mw-statistics-pages"',
68 'statistics-pages-tooltip' ) .
69 formatRow( wfMsgExt( 'statistics-files', array( 'parseinline' ) ),
70 $wgLang->formatNum( $images ),
71 ' class="mw-statistics-files"' ) .
74 Xml
::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-header-edits' ) ) .
75 formatRow( wfMsgExt( 'statistics-edits', array( 'parseinline' ) ),
76 $wgLang->formatNum( $edits ),
77 ' class="mw-statistics-edits"' ) .
78 formatRow( wfMsgExt( 'statistics-edits-average', array( 'parseinline' ) ),
79 $wgLang->formatNum( sprintf( '%.2f', $total ?
$edits / $total : 0 ) ),
80 ' class="mw-statistics-edits-average"' ) .
81 formatRow( wfMsgExt( 'statistics-jobqueue', array( 'parseinline' ) ),
82 $wgLang->formatNum( $numJobs ),
83 ' class="mw-statistics-jobqueue"' ) .
86 Xml
::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-header-users' ) ) .
87 formatRow( wfMsgExt( 'statistics-users', array( 'parseinline' ) ),
88 $wgLang->formatNum( $users ),
89 ' class="mw-statistics-users"' ) .
90 formatRow( wfMsgExt( 'statistics-users-active', array( 'parseinline' ) ),
91 $wgLang->formatNum( $activeUsers ),
92 ' class="mw-statistics-users-active"',
93 'statistics-users-active-tooltip' );
95 # Statistic - usergroups
96 foreach( $wgGroupPermissions as $group => $permissions ) {
97 # Skip generic * and implicit groups
98 if ( in_array( $group, $wgImplicitGroups ) ||
$group == '*' ) {
101 $groupname = htmlspecialchars( $group );
102 $msg = wfMsg( 'group-' . $groupname );
103 if ( wfEmptyMsg( 'group-' . $groupname, $msg ) ||
$msg == '' ) {
104 $groupnameLocalized = $groupname;
106 $groupnameLocalized = $msg;
108 $msg = wfMsgForContent( 'grouppage-' . $groupname );
109 if ( wfEmptyMsg( 'grouppage-' . $groupname, $msg ) ||
$msg == '' ) {
110 $grouppageLocalized = MWNamespace
::getCanonicalName( NS_PROJECT
) . ':' . $groupname;
112 $grouppageLocalized = $msg;
114 $grouppage = $sk->makeLink( $grouppageLocalized, $groupnameLocalized );
115 $grouplink = $sk->link( SpecialPage
::getTitleFor( 'Listusers' ),
116 wfMsgHtml( 'listgrouprights-members' ),
118 array( 'group' => $group ),
120 $text .= formatRow( $grouppage . ' ' . $grouplink,
121 $wgLang->formatNum( SiteStats
::numberingroup( $groupname ) ),
122 ' class="statistics-group-' . Sanitizer
::escapeClass( $group ) . '"' );
125 $text .= $viewsStats;
127 # Statistic - popular pages
128 if( !$wgDisableCounters && !$wgMiserMode ) {
137 'page_is_redirect' => 0,
142 'ORDER BY' => 'page_counter DESC',
146 if( $res->numRows() > 0 ) {
147 $text .= Xml
::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-mostpopular' ) );
148 while( $row = $res->fetchObject() ) {
149 $title = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
150 if( $title instanceof Title
) {
151 $text .= formatRow( $sk->link( $title ),
152 $wgLang->formatNum( $row->page_counter
) );
160 $text .= Xml
::closeElement( 'table' );
162 # Customizable footer
163 $footer = wfMsgExt( 'statistics-footer', array('parseinline') );
164 if( !wfEmptyMsg( 'statistics-footer', $footer ) && $footer != '' ) {
165 $text .= "\n" . $footer;
168 $wgOut->addHtml( $text );
174 * @param string $text description of the row
175 * @param float $number a number
176 * @return string table row in HTML format
178 function formatRow( $text, $number, $trExtraParams = '', $tooltip = '' ) {
180 $text = '<div title="' . wfMsg( $tooltip ) . '">' . $text . '<sup>*</sup></div>';
183 return "<tr{$trExtraParams}>
187 <td class="mw-statistics-numbers">' .