Handle invalid grouppage on Special:Statistics
[lhc/web/wiklou.git] / includes / specials / SpecialStatistics.php
index 67c96a7..1f339d1 100644 (file)
@@ -28,7 +28,7 @@
  * @ingroup SpecialPage
  */
 class SpecialStatistics extends SpecialPage {
-       private $views, $edits, $good, $images, $total, $users,
+       private $edits, $good, $images, $total, $users,
                $activeUsers = 0;
 
        public function __construct() {
@@ -38,13 +38,11 @@ class SpecialStatistics extends SpecialPage {
        public function execute( $par ) {
                global $wgMemc;
 
-               $disableCounters = $this->getConfig()->get( 'DisableCounters' );
                $miserMode = $this->getConfig()->get( 'MiserMode' );
 
                $this->setHeaders();
                $this->getOutput()->addModuleStyles( 'mediawiki.special' );
 
-               $this->views = SiteStats::views();
                $this->edits = SiteStats::edits();
                $this->good = SiteStats::articles();
                $this->images = SiteStats::images();
@@ -53,12 +51,6 @@ class SpecialStatistics extends SpecialPage {
                $this->activeUsers = SiteStats::activeUsers();
                $this->hook = '';
 
-               # Staticic - views
-               $viewsStats = '';
-               if ( !$disableCounters ) {
-                       $viewsStats = $this->getViewsStats();
-               }
-
                # Set active user count
                if ( !$miserMode ) {
                        $key = wfMemcKey( 'sitestats', 'activeusers-updated' );
@@ -83,16 +75,10 @@ class SpecialStatistics extends SpecialPage {
 
                # Statistic - usergroups
                $text .= $this->getGroupStats();
-               $text .= $viewsStats;
-
-               # Statistic - popular pages
-               if ( !$disableCounters && !$miserMode ) {
-                       $text .= $this->getMostViewedPages();
-               }
 
                # Statistic - other
                $extraStats = array();
-               if ( wfRunHooks( 'SpecialStatsAddExtra', array( &$extraStats ) ) ) {
+               if ( Hooks::run( 'SpecialStatsAddExtra', array( &$extraStats ) ) ) {
                        $text .= $this->getOtherStats( $extraStats );
                }
 
@@ -151,7 +137,7 @@ class SpecialStatistics extends SpecialPage {
                                        $this->getLanguage()->formatNum( $this->total ),
                                        array( 'class' => 'mw-statistics-pages' ),
                                        'statistics-pages-desc' ) .
-                               $this->formatRow( Linker::linkKnown( SpecialPage::getTitleFor( 'Listfiles' ),
+                               $this->formatRow( Linker::linkKnown( SpecialPage::getTitleFor( 'MediaStatistics' ),
                                        $this->msg( 'statistics-files' )->parse() ),
                                        $this->getLanguage()->formatNum( $this->images ),
                                        array( 'class' => 'mw-statistics-files' ) );
@@ -213,10 +199,16 @@ class SpecialStatistics extends SpecialPage {
                                $grouppageLocalized = $msg->text();
                        }
                        $linkTarget = Title::newFromText( $grouppageLocalized );
-                       $grouppage = Linker::link(
-                               $linkTarget,
-                               htmlspecialchars( $groupnameLocalized )
-                       );
+
+                       if ( $linkTarget ) {
+                               $grouppage = Linker::link(
+                                       $linkTarget,
+                                       htmlspecialchars( $groupnameLocalized )
+                               );
+                       } else {
+                               $grouppage = htmlspecialchars( $groupnameLocalized );
+                       }
+
                        $grouplink = Linker::linkKnown(
                                SpecialPage::getTitleFor( 'Listusers' ),
                                $this->msg( 'listgrouprights-members' )->escaped(),
@@ -237,63 +229,6 @@ class SpecialStatistics extends SpecialPage {
                return $text;
        }
 
-       private function getViewsStats() {
-               return Xml::openElement( 'tr' ) .
-                       Xml::tags( 'th', array( 'colspan' => '2' ), $this->msg( 'statistics-header-views' )->parse() ) .
-                       Xml::closeElement( 'tr' ) .
-                               $this->formatRow( $this->msg( 'statistics-views-total' )->parse(),
-                                       $this->getLanguage()->formatNum( $this->views ),
-                                               array( 'class' => 'mw-statistics-views-total' ), 'statistics-views-total-desc' ) .
-                               $this->formatRow( $this->msg( 'statistics-views-peredit' )->parse(),
-                                       $this->getLanguage()->formatNum( sprintf( '%.2f', $this->edits ?
-                                               $this->views / $this->edits : 0 ) ),
-                                               array( 'class' => 'mw-statistics-views-peredit' ) );
-       }
-
-       private function getMostViewedPages() {
-               $text = '';
-               $dbr = wfGetDB( DB_SLAVE );
-               $res = $dbr->select(
-                       'page',
-                       array(
-                               'page_namespace',
-                               'page_title',
-                               'page_counter',
-                       ),
-                       array(
-                               'page_is_redirect' => 0,
-                               'page_counter > 0',
-                       ),
-                       __METHOD__,
-                       array(
-                               'ORDER BY' => 'page_counter DESC',
-                               'LIMIT' => 10,
-                       )
-               );
-
-               if ( $res->numRows() > 0 ) {
-                       $text .= Xml::openElement( 'tr' );
-                       $text .= Xml::tags(
-                               'th',
-                               array( 'colspan' => '2' ),
-                               $this->msg( 'statistics-mostpopular' )->parse()
-                       );
-                       $text .= Xml::closeElement( 'tr' );
-
-                       foreach ( $res as $row ) {
-                               $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
-
-                               if ( $title instanceof Title ) {
-                                       $text .= $this->formatRow( Linker::link( $title ),
-                                               $this->getLanguage()->formatNum( $row->page_counter ) );
-                               }
-                       }
-                       $res->free();
-               }
-
-               return $text;
-       }
-
        /**
         * Conversion of external statistics into an internal representation
         * Following a ([<header-message>][<item-message>] = number) pattern