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 ) ) );
42 if( $wgRequest->getVal( 'action' ) == 'raw' ) {
43 # Depreciated, kept for backwards compatibility
44 # http://lists.wikimedia.org/pipermail/wikitech-l/2008-August/039202.html
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";
51 $text = Xml
::openElement( 'table', array( 'class' => 'mw-statistics-table' ) ) .
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 ) ) .
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 ) ) .
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 ) );
77 # Statistic - usergroups
78 foreach( $wgGroupPermissions as $group => $permissions ) {
79 # Skip generic * and implicit groups
80 if ( in_array( $group, $wgImplicitGroups ) ||
$group == '*' ) {
83 $groupname = htmlspecialchars( $group );
84 $msg = wfMsg( 'group-' . $groupname );
85 if ( wfEmptyMsg( 'group-' . $groupname, $msg ) ||
$msg == '' ) {
86 $groupnameLocalized = $groupname;
88 $groupnameLocalized = $msg;
90 $msg = wfMsgForContent( 'grouppage-' . $groupname );
91 if ( wfEmptyMsg( 'grouppage-' . $groupname, $msg ) ||
$msg == '' ) {
92 $grouppageLocalized = MWNamespace
::getCanonicalName( NS_PROJECT
) . ':' . $groupname;
94 $grouppageLocalized = $msg;
96 $grouppage = $sk->makeLink( $grouppageLocalized, $groupnameLocalized );
97 $grouplink = $sk->link( SpecialPage
::getTitleFor( 'Listusers' ),
98 wfMsgHtml( 'listgrouprights-members' ),
100 array( 'group' => $group ),
102 $text .= formatRow( $grouppage . ' ' . $grouplink,
103 $wgLang->formatNum( SiteStats
::numberingroup( $groupname ) ),
104 ' class="statistics-group-' . Sanitizer
::escapeClass( $group ) . '"' );
107 $text .= $viewsStats;
109 # Statistic - popular pages
110 if( !$wgDisableCounters && !$wgMiserMode ) {
119 'page_is_redirect' => 0,
124 'ORDER BY' => 'page_counter DESC',
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
) );
142 $text .= Xml
::closeElement( 'table' );
144 # Customizable footer
145 $footer = wfMsgExt( 'statistics-footer', array('parseinline') );
146 if( !wfEmptyMsg( 'statistics-footer', $footer ) && $footer != '' ) {
147 $text .= "\n" . $footer;
150 $wgOut->addHtml( $text );
156 * @param string $text description of the row
157 * @param float $number a number
158 * @return string table row in HTML format
160 function formatRow( $text, $number, $trExtraParams = '' ) {
161 return "<tr{$trExtraParams}>
165 <td class="mw-statistics-numbers">' .