* (bug 20362) Special:Statistics now produces valid HTML when view counters are enabled
[lhc/web/wiklou.git] / includes / specials / SpecialStatistics.php
index 54c9c5b..c4725dc 100644 (file)
@@ -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 = '';
@@ -56,7 +57,7 @@ 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();         
@@ -75,6 +76,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' );
 
@@ -91,23 +98,25 @@ 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
         * @return string table row in HTML format
         */
-       private function formatRow( $text, $number, $trExtraParams = array(), $descMsg = '' ) {
+       private function formatRow( $text, $number, $trExtraParams = array(), $descMsg = '', $descMsgParam = '' ) {
                global $wgStylePath;
-       
                if( $descMsg ) {
-                       $descriptionText = wfMsg( $descMsg );
+                       $descriptionText = wfMsgExt( $descMsg, array( 'parseinline' ), $descMsgParam );
                        if ( !wfEmptyMsg( $descMsg, $descriptionText ) ) {
                                $descriptionText = " ($descriptionText)";
-                               $text = $text . "<br />" . Xml::element( 'small', array( 'class' => 'mw-statistic-desc'), $descriptionText );
+                               $text .= "<br />" . Xml::element( 'small', array( 'class' => 'mw-statistic-desc'), 
+                                       $descriptionText );
                        }
                }
-               
                return Xml::openElement( 'tr', $trExtraParams ) .
-                               Xml::openElement( 'td' ) . $text . Xml::closeElement( 'td' ) .
-                               Xml::openElement( 'td' ) . $number . Xml::closeElement( 'td' ) .
-                               Xml::closeElement( 'tr' );
+                       Xml::openElement( 'td' ) . $text . Xml::closeElement( 'td' ) .
+                       Xml::openElement( 'td', array( 'class' => 'mw-statistics-numbers' ) ) . $number . Xml::closeElement( 'td' ) .
+                       Xml::closeElement( 'tr' );
        }
        
        /**
@@ -117,7 +126,9 @@ class SpecialStatistics extends SpecialPage {
         */
        private function getPageStats() {
                global $wgLang;
-               return Xml::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-header-pages' ) ) .
+               return Xml::openElement( 'tr' ) .
+                       Xml::tags( 'th', array( 'colspan' => '2' ), wfMsgExt( 'statistics-header-pages', array( 'parseinline' ) ) ) .
+                       Xml::closeElement( 'tr' ) .
                                $this->formatRow( wfMsgExt( 'statistics-articles', array( 'parseinline' ) ),
                                                $wgLang->formatNum( $this->good ),
                                                array( 'class' => 'mw-statistics-articles' ) ) .
@@ -131,7 +142,9 @@ class SpecialStatistics extends SpecialPage {
        }
        private function getEditStats() {
                global $wgLang;
-               return Xml::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-header-edits' ) ) .
+               return Xml::openElement( 'tr' ) .
+                       Xml::tags( 'th', array( 'colspan' => '2' ), wfMsgExt( 'statistics-header-edits', array( 'parseinline' ) ) ) .
+                       Xml::closeElement( 'tr' ) .
                                $this->formatRow( wfMsgExt( 'statistics-edits', array( 'parseinline' ) ),
                                                $wgLang->formatNum( $this->edits ),
                                                array( 'class' => 'mw-statistics-edits' ) ) .
@@ -143,15 +156,18 @@ class SpecialStatistics extends SpecialPage {
                                                array( 'class' => 'mw-statistics-jobqueue' ) );
        }
        private function getUserStats() {
-               global $wgLang;
-               return Xml::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-header-users' ) ) .
+               global $wgLang, $wgRCMaxAge;
+               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' ) ),
                                                $wgLang->formatNum( $this->activeUsers ),
                                                array( 'class' => 'mw-statistics-users-active' ),
-                                               'statistics-users-active-desc' );
+                                               'statistics-users-active-desc',
+                                               $wgLang->formatNum( ceil( $wgRCMaxAge / ( 3600 * 24 ) ) ) );
        }
        private function getGroupStats() {
                global $wgGroupPermissions, $wgImplicitGroups, $wgLang, $wgUser;
@@ -175,13 +191,19 @@ class SpecialStatistics extends SpecialPage {
                        } else {
                                $grouppageLocalized = $msg;
                        }
-                       $grouppage = $sk->makeLink( $grouppageLocalized, $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 ) {
@@ -195,14 +217,16 @@ class SpecialStatistics extends SpecialPage {
        }
        private function getViewsStats() {
                global $wgLang;
-               return Xml::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-header-views' ) ) .
-                                       $this->formatRow( wfMsgExt( 'statistics-views-total', array( 'parseinline' ) ),
-                                                       $wgLang->formatNum( $this->views ),
-                                                       array ( 'class' => 'mw-statistics-views-total' ) ) .
-                                       $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' ) );
+               return Xml::openElement( 'tr' ) .
+                       Xml::tags( 'th', array( 'colspan' => '2' ), wfMsgExt( 'statistics-header-views', array( 'parseinline' ) ) ) .
+                       Xml::closeElement( 'tr' ) .
+                               $this->formatRow( wfMsgExt( 'statistics-views-total', array( 'parseinline' ) ),
+                                       $wgLang->formatNum( $this->views ),
+                                               array ( 'class' => 'mw-statistics-views-total' ) ) .
+                               $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;
@@ -227,7 +251,9 @@ class SpecialStatistics extends SpecialPage {
                                )
                        );
                        if( $res->numRows() > 0 ) {
-                               $text .= Xml::tags( 'th', array( 'colspan' => '2' ), wfMsg( 'statistics-mostpopular' ) );
+                               $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 ) {
@@ -241,6 +267,23 @@ class SpecialStatistics extends SpecialPage {
                return $text;
        }
        
+       private function getOtherStats( $stats ) {
+               global $wgLang;
+               
+               $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