Big oops - merged to wrong branch.
[lhc/web/wiklou.git] / includes / specials / SpecialStatistics.php
index e2d5bf6..46881ec 100644 (file)
  * @ingroup SpecialPage
  */
 class SpecialStatistics extends SpecialPage {
-       
+
        private $views, $edits, $good, $images, $total, $users,
-                       $activeUsers, $admins = 0;
-       
+                       $activeUsers = 0;
+
        public function __construct() {
                parent::__construct( 'Statistics' );
        }
-       
+
        public function execute( $par ) {
-               global $wgOut, $wgRequest, $wgMemc;
-               global $wgDisableCounters, $wgMiserMode;
-               
+               global $wgMemc, $wgDisableCounters, $wgMiserMode;
+
                $this->setHeaders();
-       
+               $this->getOutput()->addModuleStyles( 'mediawiki.special' );
+
                $this->views = SiteStats::views();
                $this->edits = SiteStats::edits();
                $this->good = SiteStats::articles();
@@ -49,15 +49,14 @@ class SpecialStatistics extends SpecialPage {
                $this->total = SiteStats::pages();
                $this->users = SiteStats::users();
                $this->activeUsers = SiteStats::activeUsers();
-               $this->admins = SiteStats::numberingroup('sysop');
                $this->hook = '';
-       
+
                # Staticic - views
                $viewsStats = '';
                if( !$wgDisableCounters ) {
                        $viewsStats = $this->getViewsStats();
                }
-               
+
                # Set active user count
                if( !$wgMiserMode ) {
                        $key = wfMemcKey( 'sitestats', 'activeusers-updated' );
@@ -88,7 +87,7 @@ class SpecialStatistics extends SpecialPage {
                if( !$wgDisableCounters && !$wgMiserMode ) {
                        $text .= $this->getMostViewedPages();
                }
-               
+
                # Statistic - other
                $extraStats = array();
                if( wfRunHooks( 'SpecialStatsAddExtra', array( &$extraStats ) ) ) {
@@ -98,12 +97,12 @@ class SpecialStatistics extends SpecialPage {
                $text .= Xml::closeElement( 'table' );
 
                # Customizable footer
-               $footer = wfMsgExt( 'statistics-footer', array('parseinline') );
-               if( !wfEmptyMsg( 'statistics-footer', $footer ) && $footer != '' ) {
-                       $text .= "\n" . $footer;
+               $footer = $this->msg( 'statistics-footer' );
+               if ( !$footer->isBlank() ) {
+                       $text .= "\n" . $footer->parse();
                }
 
-               $wgOut->addHTML( $text );
+               $this->getOutput()->addHTML( $text );
        }
 
        /**
@@ -117,79 +116,74 @@ class SpecialStatistics extends SpecialPage {
         */
        private function formatRow( $text, $number, $trExtraParams = array(), $descMsg = '', $descMsgParam = '' ) {
                if( $descMsg ) {
-                       $descriptionText = wfMsgExt( $descMsg, array( 'parseinline' ), $descMsgParam );
-                       if ( !wfEmptyMsg( $descMsg, $descriptionText ) ) {
-                               $descriptionText = " ($descriptionText)";
-                               $text .= "<br />" . Xml::element( 'small', array( 'class' => 'mw-statistic-desc'), 
-                                       $descriptionText );
+                       $msg = $this->msg( $descMsg, $descMsgParam );
+                       if ( $msg->exists() ) {
+                               $descriptionText = $this->msg( 'parentheses' )->rawParams( $msg->parse() )->escaped();
+                               $text .= "<br />" . Xml::element( 'small', array( 'class' => 'mw-statistic-desc'),
+                                       " $descriptionText" );
                        }
                }
-               return
-               Html::rawElement( 'tr', $trExtraParams,
+               return Html::rawElement( 'tr', $trExtraParams,
                        Html::rawElement( 'td', array(), $text ) .
                        Html::rawElement( 'td', array( 'class' => 'mw-statistics-numbers' ), $number )
                );
        }
-       
+
        /**
         * Each of these methods is pretty self-explanatory, get a particular
         * row for the table of statistics
         * @return string
         */
        private function getPageStats() {
-               global $wgLang;
                return Xml::openElement( 'tr' ) .
-                       Xml::tags( 'th', array( 'colspan' => '2' ), wfMsgExt( 'statistics-header-pages', array( 'parseinline' ) ) ) .
+                       Xml::tags( 'th', array( 'colspan' => '2' ), $this->msg( 'statistics-header-pages' )->parse() ) .
                        Xml::closeElement( 'tr' ) .
-                               $this->formatRow( wfMsgExt( 'statistics-articles', array( 'parseinline' ) ),
-                                               $wgLang->formatNum( $this->good ),
+                               $this->formatRow( Linker::linkKnown( SpecialPage::getTitleFor( 'Allpages' ),
+                                               $this->msg( 'statistics-articles' )->parse() ),
+                                               $this->getLanguage()->formatNum( $this->good ),
                                                array( 'class' => 'mw-statistics-articles' ) ) .
-                               $this->formatRow( wfMsgExt( 'statistics-pages', array( 'parseinline' ) ),
-                                               $wgLang->formatNum( $this->total ),
+                               $this->formatRow( $this->msg( 'statistics-pages' )->parse(),
+                                               $this->getLanguage()->formatNum( $this->total ),
                                                array( 'class' => 'mw-statistics-pages' ),
                                                'statistics-pages-desc' ) .
-                               $this->formatRow( wfMsgExt( 'statistics-files', array( 'parseinline' ) ),
-                                               $wgLang->formatNum( $this->images ),
+                               $this->formatRow( Linker::linkKnown( SpecialPage::getTitleFor( 'Listfiles' ),
+                                               $this->msg( 'statistics-files' )->parse() ),
+                                               $this->getLanguage()->formatNum( $this->images ),
                                                array( 'class' => 'mw-statistics-files' ) );
        }
        private function getEditStats() {
-               global $wgLang;
                return Xml::openElement( 'tr' ) .
-                       Xml::tags( 'th', array( 'colspan' => '2' ), wfMsgExt( 'statistics-header-edits', array( 'parseinline' ) ) ) .
+                       Xml::tags( 'th', array( 'colspan' => '2' ), $this->msg( 'statistics-header-edits' )->parse() ) .
                        Xml::closeElement( 'tr' ) .
-                               $this->formatRow( wfMsgExt( 'statistics-edits', array( 'parseinline' ) ),
-                                               $wgLang->formatNum( $this->edits ),
+                               $this->formatRow( $this->msg( 'statistics-edits' )->parse(),
+                                               $this->getLanguage()->formatNum( $this->edits ),
                                                array( 'class' => 'mw-statistics-edits' ) ) .
-                               $this->formatRow( wfMsgExt( 'statistics-edits-average', array( 'parseinline' ) ),
-                                               $wgLang->formatNum( sprintf( '%.2f', $this->total ? $this->edits / $this->total : 0 ) ),
+                               $this->formatRow( $this->msg( 'statistics-edits-average' )->parse(),
+                                               $this->getLanguage()->formatNum( sprintf( '%.2f', $this->total ? $this->edits / $this->total : 0 ) ),
                                                array( 'class' => 'mw-statistics-edits-average' ) );
        }
 
        private function getUserStats() {
-               global $wgLang, $wgUser, $wgActiveUserDays;
-               $sk = $wgUser->getSkin();
+               global $wgActiveUserDays;
                return Xml::openElement( 'tr' ) .
-                       Xml::tags( 'th', array( 'colspan' => '2' ), wfMsgExt( 'statistics-header-users', array( 'parseinline' ) ) ) .
+                       Xml::tags( 'th', array( 'colspan' => '2' ), $this->msg( 'statistics-header-users' )->parse() ) .
                        Xml::closeElement( 'tr' ) .
-                               $this->formatRow( wfMsgExt( 'statistics-users', array( 'parseinline' ) ),
-                                               $wgLang->formatNum( $this->users ),
+                               $this->formatRow( $this->msg( 'statistics-users' )->parse(),
+                                               $this->getLanguage()->formatNum( $this->users ),
                                                array( 'class' => 'mw-statistics-users' ) ) .
-                               $this->formatRow( wfMsgExt( 'statistics-users-active', array( 'parseinline' ) ) . ' ' .
-                                                       $sk->link(
+                               $this->formatRow( $this->msg( 'statistics-users-active' )->parse() . ' ' .
+                                                       Linker::linkKnown(
                                                                SpecialPage::getTitleFor( 'Activeusers' ),
-                                                               wfMsgHtml( 'listgrouprights-members' ),
-                                                               array(),
-                                                               array(),
-                                                               'known'
+                                                               $this->msg( 'listgrouprights-members' )->escaped()
                                                        ),
-                                               $wgLang->formatNum( $this->activeUsers ),
+                                               $this->getLanguage()->formatNum( $this->activeUsers ),
                                                array( 'class' => 'mw-statistics-users-active' ),
                                                'statistics-users-active-desc',
-                                               $wgLang->formatNum( $wgActiveUserDays ) );
+                                               $this->getLanguage()->formatNum( $wgActiveUserDays ) );
        }
+
        private function getGroupStats() {
-               global $wgGroupPermissions, $wgImplicitGroups, $wgLang, $wgUser;
-               $sk = $wgUser->getSkin();
+               global $wgGroupPermissions, $wgImplicitGroups;
                $text = '';
                foreach( $wgGroupPermissions as $group => $permissions ) {
                        # Skip generic * and implicit groups
@@ -197,29 +191,28 @@ class SpecialStatistics extends SpecialPage {
                                continue;
                        }
                        $groupname = htmlspecialchars( $group );
-                       $msg = wfMsg( 'group-' . $groupname );
-                       if ( wfEmptyMsg( 'group-' . $groupname, $msg ) || $msg == '' ) {
+                       $msg = $this->msg( 'group-' . $groupname );
+                       if ( $msg->isBlank() ) {
                                $groupnameLocalized = $groupname;
                        } else {
-                               $groupnameLocalized = $msg;
+                               $groupnameLocalized = $msg->text();
                        }
-                       $msg = wfMsgForContent( 'grouppage-' . $groupname );
-                       if ( wfEmptyMsg( 'grouppage-' . $groupname, $msg ) || $msg == '' ) {
+                       $msg = $this->msg( 'grouppage-' . $groupname )->inContentLanguage();
+                       if ( $msg->isBlank() ) {
                                $grouppageLocalized = MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
                        } else {
-                               $grouppageLocalized = $msg;
+                               $grouppageLocalized = $msg->text();
                        }
                        $linkTarget = Title::newFromText( $grouppageLocalized );
-                       $grouppage = $sk->link(
+                       $grouppage = Linker::link(
                                $linkTarget,
                                htmlspecialchars( $groupnameLocalized )
                        );
-                       $grouplink = $sk->link(
+                       $grouplink = Linker::linkKnown(
                                SpecialPage::getTitleFor( 'Listusers' ),
-                               wfMsgHtml( 'listgrouprights-members' ),
+                               $this->msg( 'listgrouprights-members' )->escaped(),
                                array(),
-                               array( 'group' => $group ),
-                               'known'
+                               array( 'group' => $group )
                        );
                        # Add a class when a usergroup contains no members to allow hiding these rows
                        $classZero = '';
@@ -228,29 +221,28 @@ class SpecialStatistics extends SpecialPage {
                                $classZero = ' statistics-group-zero';
                        }
                        $text .= $this->formatRow( $grouppage . ' ' . $grouplink,
-                               $wgLang->formatNum( $countUsers ),
+                               $this->getLanguage()->formatNum( $countUsers ),
                                array( 'class' => 'statistics-group-' . Sanitizer::escapeClass( $group ) . $classZero )  );
                }
                return $text;
        }
+
        private function getViewsStats() {
-               global $wgLang;
                return Xml::openElement( 'tr' ) .
-                       Xml::tags( 'th', array( 'colspan' => '2' ), wfMsgExt( 'statistics-header-views', array( 'parseinline' ) ) ) .
+                       Xml::tags( 'th', array( 'colspan' => '2' ), $this->msg( 'statistics-header-views' )->parse() ) .
                        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->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() {
-               global $wgLang, $wgUser;
                $text = '';
                $dbr = wfGetDB( DB_SLAVE );
-               $sk = $wgUser->getSkin();
                $res = $dbr->select(
                                'page',
                                array(
@@ -270,38 +262,36 @@ 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::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( $sk->link( $title ),
-                                                               $wgLang->formatNum( $row->page_counter ) );
-       
+                                               $text .= $this->formatRow( Linker::link( $title ),
+                                                               $this->getLanguage()->formatNum( $row->page_counter ) );
+
                                        }
                                }
                                $res->free();
                        }
                return $text;
        }
-       
-       private function getOtherStats( $stats ) {
-               global $wgLang;
 
+       private function getOtherStats( $stats ) {
                if ( !count( $stats ) )
                        return '';
 
                $return = Xml::openElement( 'tr' ) .
-                       Xml::tags( 'th', array( 'colspan' => '2' ), wfMsgExt( 'statistics-header-hooks', array( 'parseinline' ) ) ) .
+                       Xml::tags( 'th', array( 'colspan' => '2' ), $this->msg( 'statistics-header-hooks' )->parse() ) .
                        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 .= $this->formatRow( $name, $this->getLanguage()->formatNum( $number ), array( 'class' => 'mw-statistics-hook' ) );
                }
-               
+
                return $return;
        }
 }