]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/specials/SpecialStatistics.php
MediaWiki 1.17.0
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialStatistics.php
index 2e785b8b68dc0e0c3f6a75af81902f46ea3f7e57..b0d0246e370587e21f7198ad743cc20ead079a8d 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, $wgMemc;
+               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
@@ -56,11 +68,6 @@ class SpecialStatistics extends SpecialPage {
                                $wgMemc->set( $key, '1', 24*3600 ); // don't update for 1 day
                        }
                }
-       
-               # Do raw output
-               if( $wgRequest->getVal( 'action' ) == 'raw' ) {
-                       $this->doRawOutput();
-               }
 
                $text = Xml::openElement( 'table', array( 'class' => 'wikitable mw-statistics-table' ) );
 
@@ -101,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 ) ) {
@@ -118,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 )
+               );
        }
        
        /**
@@ -155,13 +162,11 @@ 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, $wgUser, $wgRCMaxAge;
+               global $wgLang, $wgUser, $wgActiveUserDays;
                $sk = $wgUser->getSkin();
                return Xml::openElement( 'tr' ) .
                        Xml::tags( 'th', array( 'colspan' => '2' ), wfMsgExt( 'statistics-header-users', array( 'parseinline' ) ) ) .
@@ -180,8 +185,9 @@ class SpecialStatistics extends SpecialPage {
                                                $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();
@@ -228,6 +234,7 @@ class SpecialStatistics extends SpecialPage {
                }
                return $text;
        }
+
        private function getViewsStats() {
                global $wgLang;
                return Xml::openElement( 'tr' ) .
@@ -235,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 = '';
@@ -267,7 +275,7 @@ class SpecialStatistics extends SpecialPage {
                                $text .= Xml::openElement( 'tr' );
                                $text .= Xml::tags( 'th', array( 'colspan' => '2' ), wfMsgExt( 'statistics-mostpopular', array( 'parseinline' ) ) );
                                $text .= Xml::closeElement( 'tr' );
-                               while( $row = $res->fetchObject() ) {
+                               foreach ( $res as $row ) {
                                        $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
                                        if( $title instanceof Title ) {
                                                $text .= $this->formatRow( $sk->link( $title ),
@@ -279,7 +287,7 @@ class SpecialStatistics extends SpecialPage {
                        }
                return $text;
        }
-       
+
        private function getOtherStats( $stats ) {
                global $wgLang;
 
@@ -299,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
+}