]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/specials/SpecialStatistics.php
MediaWiki 1.16.0
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialStatistics.php
index 109c5c30259ee37e9f7a41c5e2884cca1db43e46..2e785b8b68dc0e0c3f6a75af81902f46ea3f7e57 100644 (file)
@@ -23,7 +23,7 @@ class SpecialStatistics extends SpecialPage {
        }
        
        public function execute( $par ) {
-               global $wgOut, $wgRequest, $wgMessageCache;
+               global $wgOut, $wgRequest, $wgMessageCache, $wgMemc;
                global $wgDisableCounters, $wgMiserMode;
                $wgMessageCache->loadAllMessages();
                
@@ -38,6 +38,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 +48,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 +62,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 +81,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' );
 
@@ -149,14 +161,22 @@ class SpecialStatistics extends SpecialPage {
                                                array( 'class' => 'mw-statistics-jobqueue' ) );
        }
        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',
@@ -184,13 +204,19 @@ class SpecialStatistics extends SpecialPage {
                        } else {
                                $grouppageLocalized = $msg;
                        }
-                       $grouppage = $sk->makeLink( $grouppageLocalized, htmlspecialchars( $groupnameLocalized ) );
-                       $grouplink = $sk->link( SpecialPage::getTitleFor( 'Listusers' ),
+                       $linkTarget = Title::newFromText( $grouppageLocalized );
+                       $grouppage = $sk->link(
+                               $linkTarget,
+                               htmlspecialchars( $groupnameLocalized )
+                       );
+                       $grouplink = $sk->link(
+                               SpecialPage::getTitleFor( 'Listusers' ),
                                wfMsgHtml( 'listgrouprights-members' ),
                                array(),
                                array( 'group' => $group ),
-                               'known' );
-                               # Add a class when a usergroup contains no members to allow hiding these rows
+                               'known'
+                       );
+                       # Add a class when a usergroup contains no members to allow hiding these rows
                        $classZero = '';
                        $countUsers = SiteStats::numberingroup( $groupname );
                        if( $countUsers == 0 ) {
@@ -238,7 +264,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 ) {
@@ -252,6 +280,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