* (bug 23276) Add hook to Special:NewPages to modify query
[lhc/web/wiklou.git] / includes / specials / SpecialStatistics.php
index 5431eb8..6afba12 100644 (file)
@@ -9,9 +9,7 @@
  */
 
 /**
- * Show the special page
- *
- * @param mixed $par (not used)
+ * Some statistics about the wiki
  */
 class SpecialStatistics extends SpecialPage {
        
@@ -23,9 +21,8 @@ class SpecialStatistics extends SpecialPage {
        }
        
        public function execute( $par ) {
-               global $wgOut, $wgRequest, $wgMessageCache;
+               global $wgOut, $wgRequest, $wgMessageCache, $wgMemc;
                global $wgDisableCounters, $wgMiserMode;
-               $wgMessageCache->loadAllMessages();
                
                $this->setHeaders();
        
@@ -38,6 +35,7 @@ class SpecialStatistics extends SpecialPage {
                $this->activeUsers = SiteStats::activeUsers();
                $this->admins = SiteStats::numberingroup('sysop');
                $this->numJobs = SiteStats::jobs();
+               $this->hook = '';
        
                # Staticic - views
                $viewsStats = '';
@@ -47,8 +45,13 @@ class SpecialStatistics extends SpecialPage {
                
                # Set active user count
                if( !$wgMiserMode ) {
-                       $dbw = wfGetDB( DB_MASTER );
-                       SiteStatsUpdate::cacheUpdate( $dbw );
+                       $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
+                       }
                }
        
                # Do raw output
@@ -56,10 +59,10 @@ class SpecialStatistics extends SpecialPage {
                        $this->doRawOutput();
                }
 
-               $text = Xml::openElement( 'table', array( 'class' => 'mw-statistics-table' ) );
+               $text = Xml::openElement( 'table', array( 'class' => 'wikitable mw-statistics-table' ) );
 
                # Statistic - pages
-               $text .= $this->getPageStats();         
+               $text .= $this->getPageStats();
 
                # Statistic - edits
                $text .= $this->getEditStats();
@@ -75,6 +78,12 @@ class SpecialStatistics extends SpecialPage {
                if( !$wgDisableCounters && !$wgMiserMode ) {
                        $text .= $this->getMostViewedPages();
                }
+               
+               # Statistic - other
+               $extraStats = array();
+               if( wfRunHooks( 'SpecialStatsAddExtra', array( &$extraStats ) ) ) {
+                       $text .= $this->getOtherStats( $extraStats );
+               }
 
                $text .= Xml::closeElement( 'table' );
 
@@ -89,11 +98,11 @@ 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 = '' ) {
@@ -106,10 +115,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 )
+               );
        }
        
        /**
@@ -143,20 +153,26 @@ 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, $wgRCMaxAge;
+               $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',
@@ -244,7 +260,9 @@ class SpecialStatistics extends SpecialPage {
                                )
                        );
                        if( $res->numRows() > 0 ) {
+                               $text .= Xml::openElement( 'tr' );
                                $text .= Xml::tags( 'th', array( 'colspan' => '2' ), wfMsgExt( 'statistics-mostpopular', array( 'parseinline' ) ) );
+                               $text .= Xml::closeElement( 'tr' );
                                while( $row = $res->fetchObject() ) {
                                        $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
                                        if( $title instanceof Title ) {
@@ -258,6 +276,26 @@ class SpecialStatistics extends SpecialPage {
                return $text;
        }
        
+       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( $stats as $name => $number ) {
+                       $name = htmlspecialchars( $name );
+                       $number = htmlspecialchars( $number );
+                       
+                       $return .= $this->formatRow( $name, $wgLang->formatNum( $number ), array( 'class' => 'mw-statistics-hook' ) );
+               }
+               
+               return $return;
+       }
+       
        /**
         * Do the action=raw output for this page. Legacy, but we support
         * it for backwards compatibility