More ancient deprecated functions:
[lhc/web/wiklou.git] / includes / specials / SpecialStatistics.php
index 81542b3..b0d0246 100644 (file)
@@ -1,31 +1,44 @@
 <?php
-
 /**
- * Special page lists various statistics, including the contents of
- * `site_stats`, plus page view details if enabled
+ * Implements Special:Statistics
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
  *
  * @file
  * @ingroup SpecialPage
  */
 
 /**
- * Show the special page
+ * Special page lists various statistics, including the contents of
+ * `site_stats`, plus page view details if enabled
  *
- * @param mixed $par (not used)
+ * @ingroup SpecialPage
  */
 class SpecialStatistics extends SpecialPage {
        
        private $views, $edits, $good, $images, $total, $users,
-                       $activeUsers, $admins, $numJobs = 0;
+                       $activeUsers, $admins = 0;
        
        public function __construct() {
                parent::__construct( 'Statistics' );
        }
        
        public function execute( $par ) {
-               global $wgOut, $wgRequest, $wgMessageCache;
+               global $wgOut, $wgMemc;
                global $wgDisableCounters, $wgMiserMode;
-               $wgMessageCache->loadAllMessages();
                
                $this->setHeaders();
        
@@ -37,7 +50,6 @@ class SpecialStatistics extends SpecialPage {
                $this->users = SiteStats::users();
                $this->activeUsers = SiteStats::activeUsers();
                $this->admins = SiteStats::numberingroup('sysop');
-               $this->numJobs = SiteStats::jobs();
                $this->hook = '';
        
                # Staticic - views
@@ -48,19 +60,19 @@ class SpecialStatistics extends SpecialPage {
                
                # Set active user count
                if( !$wgMiserMode ) {
-                       $dbw = wfGetDB( DB_MASTER );
-                       SiteStatsUpdate::cacheUpdate( $dbw );
-               }
-       
-               # Do raw output
-               if( $wgRequest->getVal( 'action' ) == 'raw' ) {
-                       $this->doRawOutput();
+                       $key = wfMemcKey( 'sitestats', 'activeusers-updated' );
+                       // Re-calculate the count if the last tally is old...
+                       if( !$wgMemc->get($key) ) {
+                               $dbw = wfGetDB( DB_MASTER );
+                               SiteStatsUpdate::cacheUpdate( $dbw );
+                               $wgMemc->set( $key, '1', 24*3600 ); // don't update for 1 day
+                       }
                }
 
                $text = Xml::openElement( 'table', array( 'class' => 'wikitable mw-statistics-table' ) );
 
                # Statistic - pages
-               $text .= $this->getPageStats();         
+               $text .= $this->getPageStats();
 
                # Statistic - edits
                $text .= $this->getEditStats();
@@ -78,7 +90,10 @@ class SpecialStatistics extends SpecialPage {
                }
                
                # Statistic - other
-               $text .= $this->getOtherStats();
+               $extraStats = array();
+               if( wfRunHooks( 'SpecialStatsAddExtra', array( &$extraStats ) ) ) {
+                       $text .= $this->getOtherStats( $extraStats );
+               }
 
                $text .= Xml::closeElement( 'table' );
 
@@ -93,15 +108,14 @@ class SpecialStatistics extends SpecialPage {
 
        /**
         * Format a row
-        * @param string $text description of the row
-        * @param float $number a number
-        * @param array $trExtraParams
-        * @param string $descMsg
-        * @param string $descMsgParam
+        * @param $text  String: description of the row
+        * @param $number  Float: a statistical number
+        * @param $trExtraParams  Array: params to table row, see Html::elememt
+        * @param $descMsg  String: message key
+        * @param $descMsgParam  Array: message params
         * @return string table row in HTML format
         */
        private function formatRow( $text, $number, $trExtraParams = array(), $descMsg = '', $descMsgParam = '' ) {
-               global $wgStylePath;
                if( $descMsg ) {
                        $descriptionText = wfMsgExt( $descMsg, array( 'parseinline' ), $descMsgParam );
                        if ( !wfEmptyMsg( $descMsg, $descriptionText ) ) {
@@ -110,10 +124,11 @@ class SpecialStatistics extends SpecialPage {
                                        $descriptionText );
                        }
                }
-               return Xml::openElement( 'tr', $trExtraParams ) .
-                       Xml::openElement( 'td' ) . $text . Xml::closeElement( 'td' ) .
-                       Xml::openElement( 'td', array( 'class' => 'mw-statistics-numbers' ) ) . $number . Xml::closeElement( 'td' ) .
-                       Xml::closeElement( 'tr' );
+               return
+               Html::rawElement( 'tr', $trExtraParams,
+                       Html::rawElement( 'td', array(), $text ) .
+                       Html::rawElement( 'td', array( 'class' => 'mw-statistics-numbers' ), $number )
+               );
        }
        
        /**
@@ -147,25 +162,32 @@ class SpecialStatistics extends SpecialPage {
                                                array( 'class' => 'mw-statistics-edits' ) ) .
                                $this->formatRow( wfMsgExt( 'statistics-edits-average', array( 'parseinline' ) ),
                                                $wgLang->formatNum( sprintf( '%.2f', $this->total ? $this->edits / $this->total : 0 ) ),
-                                               array( 'class' => 'mw-statistics-edits-average' ) ) .
-                               $this->formatRow( wfMsgExt( 'statistics-jobqueue', array( 'parseinline' ) ),
-                                               $wgLang->formatNum( $this->numJobs ),
-                                               array( 'class' => 'mw-statistics-jobqueue' ) );
+                                               array( 'class' => 'mw-statistics-edits-average' ) );
        }
+
        private function getUserStats() {
-               global $wgLang, $wgRCMaxAge;
+               global $wgLang, $wgUser, $wgActiveUserDays;
+               $sk = $wgUser->getSkin();
                return Xml::openElement( 'tr' ) .
                        Xml::tags( 'th', array( 'colspan' => '2' ), wfMsgExt( 'statistics-header-users', array( 'parseinline' ) ) ) .
                        Xml::closeElement( 'tr' ) .
                                $this->formatRow( wfMsgExt( 'statistics-users', array( 'parseinline' ) ),
                                                $wgLang->formatNum( $this->users ),
                                                array( 'class' => 'mw-statistics-users' ) ) .
-                               $this->formatRow( wfMsgExt( 'statistics-users-active', array( 'parseinline' ) ),
+                               $this->formatRow( wfMsgExt( 'statistics-users-active', array( 'parseinline' ) ) . ' ' .
+                                                       $sk->link(
+                                                               SpecialPage::getTitleFor( 'Activeusers' ),
+                                                               wfMsgHtml( 'listgrouprights-members' ),
+                                                               array(),
+                                                               array(),
+                                                               'known'
+                                                       ),
                                                $wgLang->formatNum( $this->activeUsers ),
                                                array( 'class' => 'mw-statistics-users-active' ),
                                                'statistics-users-active-desc',
-                                               $wgLang->formatNum( ceil( $wgRCMaxAge / ( 3600 * 24 ) ) ) );
+                                               $wgLang->formatNum( $wgActiveUserDays ) );
        }
+
        private function getGroupStats() {
                global $wgGroupPermissions, $wgImplicitGroups, $wgLang, $wgUser;
                $sk = $wgUser->getSkin();
@@ -212,6 +234,7 @@ class SpecialStatistics extends SpecialPage {
                }
                return $text;
        }
+
        private function getViewsStats() {
                global $wgLang;
                return Xml::openElement( 'tr' ) .
@@ -219,12 +242,13 @@ class SpecialStatistics extends SpecialPage {
                        Xml::closeElement( 'tr' ) .
                                $this->formatRow( wfMsgExt( 'statistics-views-total', array( 'parseinline' ) ),
                                        $wgLang->formatNum( $this->views ),
-                                               array ( 'class' => 'mw-statistics-views-total' ) ) .
+                                               array ( 'class' => 'mw-statistics-views-total' ), 'statistics-views-total-desc' ) .
                                $this->formatRow( wfMsgExt( 'statistics-views-peredit', array( 'parseinline' ) ),
                                        $wgLang->formatNum( sprintf( '%.2f', $this->edits ? 
                                                $this->views / $this->edits : 0 ) ),
                                                array ( 'class' => 'mw-statistics-views-peredit' ) );
        }
+
        private function getMostViewedPages() {
                global $wgLang, $wgUser;
                $text = '';
@@ -248,8 +272,10 @@ class SpecialStatistics extends SpecialPage {
                                )
                        );
                        if( $res->numRows() > 0 ) {
+                               $text .= Xml::openElement( 'tr' );
                                $text .= Xml::tags( 'th', array( 'colspan' => '2' ), wfMsgExt( 'statistics-mostpopular', array( 'parseinline' ) ) );
-                               while( $row = $res->fetchObject() ) {
+                               $text .= Xml::closeElement( 'tr' );
+                               foreach ( $res as $row ) {
                                        $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
                                        if( $title instanceof Title ) {
                                                $text .= $this->formatRow( $sk->link( $title ),
@@ -261,19 +287,18 @@ class SpecialStatistics extends SpecialPage {
                        }
                return $text;
        }
-       
-       private function getOtherStats() {
-               global $wgLang, $wgAllowStatsOther, $wgStatsOther;
-               
-               if( !$wgAllowStatsOther ) return;
-               
-               if ( count( $wgStatsOther ) < 1 ) return;
-               
+
+       private function getOtherStats( $stats ) {
+               global $wgLang;
+
+               if ( !count( $stats ) )
+                       return '';
+
                $return = Xml::openElement( 'tr' ) .
                        Xml::tags( 'th', array( 'colspan' => '2' ), wfMsgExt( 'statistics-header-hooks', array( 'parseinline' ) ) ) .
                        Xml::closeElement( 'tr' );
                        
-               foreach( $wgStatsOther as $name => $number ) {
+               foreach( $stats as $name => $number ) {
                        $name = htmlspecialchars( $name );
                        $number = htmlspecialchars( $number );
                        
@@ -282,20 +307,4 @@ class SpecialStatistics extends SpecialPage {
                
                return $return;
        }
-       
-       /**
-        * Do the action=raw output for this page. Legacy, but we support
-        * it for backwards compatibility
-        * http://lists.wikimedia.org/pipermail/wikitech-l/2008-August/039202.html
-        */
-       private function doRawOutput() {
-               global $wgOut;
-               $wgOut->disable();
-               header( 'Pragma: nocache' );
-               echo "total=" . $this->total . ";good=" . $this->good . ";views=" . 
-                               $this->views . ";edits=" . $this->edits . ";users=" . $this->users . ";";
-               echo "activeusers=" . $this->activeUsers . ";admins=" . $this->admins . 
-                               ";images=" . $this->images . ";jobs=" . $this->numJobs . "\n";
-               return;
-       }
-}
\ No newline at end of file
+}