]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/SpecialStatistics.php
MediaWiki 1.11.0
[autoinstalls/mediawiki.git] / includes / 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  * @addtogroup SpecialPage
8  */
9
10 /**
11  * Show the special page
12  *
13  * @param mixed $par (not used)
14  */
15 function wfSpecialStatistics( $par = '' ) {
16         global $wgOut, $wgLang, $wgRequest;
17         $dbr = wfGetDB( DB_SLAVE );
18
19         $views = SiteStats::views();
20         $edits = SiteStats::edits();
21         $good = SiteStats::articles();
22         $images = SiteStats::images();
23         $total = SiteStats::pages();
24         $users = SiteStats::users();
25         $admins = SiteStats::admins();
26         $numJobs = SiteStats::jobs();
27
28         if( $wgRequest->getVal( 'action' ) == 'raw' ) {
29                 $wgOut->disable();
30                 header( 'Pragma: nocache' );
31                 echo "total=$total;good=$good;views=$views;edits=$edits;users=$users;admins=$admins;images=$images;jobs=$numJobs\n";
32                 return;
33         } else {
34                 $text = "__NOTOC__\n";
35                 $text .= '==' . wfMsg( 'sitestats' ) . "==\n";
36                 $text .= wfMsgExt( 'sitestatstext', array( 'parsemag' ),
37                         $wgLang->formatNum( $total ),
38                         $wgLang->formatNum( $good ),
39                         $wgLang->formatNum( $views ),
40                         $wgLang->formatNum( $edits ),
41                         $wgLang->formatNum( sprintf( '%.2f', $total ? $edits / $total : 0 ) ),
42                         $wgLang->formatNum( sprintf( '%.2f', $edits ? $views / $edits : 0 ) ),
43                         $wgLang->formatNum( $numJobs ),
44                         $wgLang->formatNum( $images )
45                 )."\n";
46
47                 $text .= "==" . wfMsg( 'userstats' ) . "==\n";
48                 $text .= wfMsgExt( 'userstatstext', array ( 'parsemag' ),
49                         $wgLang->formatNum( $users ),
50                         $wgLang->formatNum( $admins ),
51                         '[[' . wfMsgForContent( 'grouppage-sysop' ) . ']]', # TODO somehow remove, kept for backwards compatibility
52                         $wgLang->formatNum( sprintf( '%.2f', $admins / $users * 100 ) ),
53                         User::makeGroupLinkWiki( 'sysop' )
54                 )."\n";
55
56                 global $wgDisableCounters, $wgMiserMode, $wgUser, $wgLang, $wgContLang;
57                 if( !$wgDisableCounters && !$wgMiserMode ) {
58                         $res = $dbr->select(
59                                 'page',
60                                 array(
61                                         'page_namespace',
62                                         'page_title',
63                                         'page_counter',
64                                 ),
65                                 array(
66                                         'page_is_redirect' => 0,
67                                         'page_counter > 0',
68                                 ),
69                                 __METHOD__,
70                                 array(
71                                         'ORDER BY' => 'page_counter DESC',
72                                         'LIMIT' => 10,
73                                 )
74                         );
75                         if( $res->numRows() > 0 ) {
76                                 $text .= "==" . wfMsg( 'statistics-mostpopular' ) . "==\n";
77                                 while( $row = $res->fetchObject() ) {
78                                         $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
79                                         if( $title instanceof Title )
80                                                 $text .= '* [[:' . $title->getPrefixedText() . ']] (' . $wgLang->formatNum( $row->page_counter ) . ")\n";
81                                 }
82                                 $res->free();
83                         }
84                 }
85                 
86                 $footer = wfMsg( 'statistics-footer' );
87                 if( !wfEmptyMsg( 'statistics-footer', $footer ) && $footer != '' )
88                         $text .= "\n" . $footer;
89                         
90                 $wgOut->addWikiText( $text );           
91         }
92         
93 }