Replaced all @fixme with "@todo Fixme" since doxygen doesn't have a @fixme command
[lhc/web/wiklou.git] / includes / specials / SpecialActiveusers.php
index eb23c23..a5f1b3c 100644 (file)
@@ -29,7 +29,9 @@
 class ActiveUsersPager extends UsersPager {
 
        function __construct( $group = null ) {
-               global $wgRequest;
+               global $wgRequest, $wgRCMaxAge;
+               $this->RCMaxAge = ceil( $wgRCMaxAge / ( 3600 * 24 ) ); // Constant
+
                $un = $wgRequest->getText( 'username' );
                $this->requestedUser = '';
                if ( $un != '' ) {
@@ -38,78 +40,113 @@ class ActiveUsersPager extends UsersPager {
                                $this->requestedUser = $username->getText();
                        }
                }
+               
+               $this->setupOptions();
+               
                parent::__construct();
        }
 
+       public function setupOptions() {
+               global $wgRequest;
+               
+               $this->opts = new FormOptions();
+
+               $this->opts->add( 'hidebots', false, FormOptions::BOOL );
+               $this->opts->add( 'hidesysops', false, FormOptions::BOOL );
+
+               $this->opts->fetchValuesFromRequest( $wgRequest );
+
+               $this->groups = array();
+               if ($this->opts->getValue('hidebots') == 1)
+                       $this->groups['bot'] = true;
+               if ($this->opts->getValue('hidesysops') == 1)
+                       $this->groups['sysop'] = true;
+       }
+
        function getIndexField() {
                return 'rc_user_text';
        }
 
        function getQueryInfo() {
+               global $wgDBtype;
+
                $dbr = wfGetDB( DB_SLAVE );
-               $conds = array('rc_user > 0'); // Users - no anons
+               $conds = array( 'rc_user > 0' ); // Users - no anons
                $conds[] = 'ipb_deleted IS NULL'; // don't show hidden names
-               $conds[] = 'rc_log_type IS NULL OR rc_log_type != "newusers"';
-               $useIndex = $dbr->useIndexClause( 'rc_user_text' );
+               $conds[] = "rc_log_type IS NULL OR rc_log_type != 'newusers'";
+               
                if( $this->requestedUser != '' ) {
                        $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser );
                }
 
-               list( $recentchanges, $ipblocks, $user ) = $dbr->tableNamesN( 'recentchanges', 'ipblocks', 'user' );
-
                $query = array(
-                       'tables' => "$recentchanges $useIndex 
-                               INNER JOIN $user ON rc_user_text=user_name
-                               LEFT JOIN $ipblocks ON user_id=ipb_user AND ipb_auto=0 AND ipb_deleted=1 ",
+                       'tables' => array( 'recentchanges', 'user', 'ipblocks' ),
                        'fields' => array( 'rc_user_text AS user_name', // inheritance
                                'rc_user_text', // for Pager
-                               'user_id',
+                               'MAX(user_id) AS user_id',
                                'COUNT(*) AS recentedits',
-                               'MAX(ipb_user) AS blocked' ),
-                       'options' => array( 'GROUP BY' => 'rc_user_text' ),
+                               'MAX(ipb_user) AS blocked'
+                       ),
+                       'options' => array(
+                               'GROUP BY' => ( $dbr->implicitGroupby() || $wgDBtype == 'sqlite' ) ? 'rc_user_text' : 'rc_user_text, user_id',
+                               'USE INDEX' => array( 'recentchanges' => 'rc_user_text' )
+                       ),
+                       'join_conds' => array(
+                               'user' => array( 'INNER JOIN', 'rc_user_text=user_name' ),
+                               'ipblocks' => array( 'LEFT JOIN', 'user_id=ipb_user AND ipb_auto=0 AND ipb_deleted=1' ),
+                       ),
                        'conds' => $conds
                );
                return $query;
        }
 
        function formatRow( $row ) {
-               $userName = $row->rc_user_text;
-               $userPage = Title::makeTitle( NS_USER, $userName );
-               $name = $this->getSkin()->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
+               global $wgLang;
+               $userName = $row->user_name;
+               
+               $ulinks = $this->getSkin()->userLink( $row->user_id, $userName );
+               $ulinks .= $this->getSkin()->userToolLinks( $row->user_id, $userName );
 
                $list = array();
-               foreach( self::getGroups( $row->user_id ) as $group )
+               foreach( self::getGroups( $row->user_id ) as $group ) {
+                       if (isset($this->groups[$group]))
+                               return;
                        $list[] = self::buildGroupLink( $group );
-               $groups = implode( ', ', $list );
-
-               $item = wfSpecialList( $name, $groups );
-               $count = wfMsgExt( 'activeusers-count', array( 'parsemag' ), $row->recentedits, $userName );
+               }
+               $groups = $wgLang->commaList( $list );
+
+               $item = wfSpecialList( $ulinks, $groups );
+               $count = wfMsgExt( 'activeusers-count',
+                       array( 'parsemag' ),
+                       $wgLang->formatNum( $row->recentedits ),
+                       $userName,
+                       $wgLang->formatNum ( $this->RCMaxAge )
+               );
                $blocked = $row->blocked ? ' ' . wfMsgExt( 'listusers-blocked', array( 'parsemag' ), $userName ) : '';
 
-               return "<li>{$item} [{$count}]{$blocked}</li>";
+               return Html::rawElement( 'li', array(), "{$item} [{$count}]{$blocked}" );
        }
 
        function getPageHeader() {
                global $wgScript, $wgRequest;
+
                $self = $this->getTitle();
+               $limit = $this->mLimit ? Xml::hidden( 'limit', $this->mLimit ) : '';
 
-               # Form tag
-               $out  = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
-                       '<fieldset>' .
-                       Xml::element( 'legend', array(), wfMsg( 'activeusers' ) );
-               $out .= Xml::hidden( 'title', $self->getPrefixedDBkey() );
+               $out  = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); # Form tag
+               $out .= Xml::fieldset( wfMsg( 'activeusers' ) ) . "\n";
+               $out .= Xml::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n";
 
-               # Username field
-               $out .= Xml::label( wfMsg( 'activeusers-from' ), 'offset' ) . ' ' .
-                       Xml::input( 'username', 20, $this->requestedUser, array( 'id' => 'offset' ) ) . ' ';
+               $out .= Xml::inputLabel( wfMsg( 'activeusers-from' ), 'username', 'offset', 20, $this->requestedUser ) . '<br />';# Username field
 
-               # Submit button and form bottom
-               if( $this->mLimit )
-                       $out .= Xml::hidden( 'limit', $this->mLimit );
-               $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) );
+               $out .= Xml::checkLabel( wfMsg('activeusers-hidebots'), 'hidebots', 'hidebots', $this->opts->getValue( 'hidebots' ) );
 
-               $out .= '</fieldset>' . Xml::closeElement( 'form' );
+               $out .= Xml::checkLabel( wfMsg('activeusers-hidesysops'), 'hidesysops', 'hidesysops', $this->opts->getValue( 'hidesysops' ) ) . '<br />';
 
+               $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .  "\n";# Submit button and form bottom
+               $out .= Xml::closeElement( 'fieldset' );
+               $out .= Xml::closeElement( 'form' );
+               
                return $out;
        }
 }
@@ -123,7 +160,7 @@ class SpecialActiveUsers extends SpecialPage {
         * Constructor
         */
        public function  __construct() {
-               parent::__construct( 'ActiveUsers' );
+               parent::__construct( 'Activeusers' );
        }
 
        /**
@@ -132,7 +169,7 @@ class SpecialActiveUsers extends SpecialPage {
         * @param $par Mixed: parameter passed to the page or null
         */
        public function execute( $par ) {
-               global $wgOut;
+               global $wgOut, $wgLang, $wgRCMaxAge;
 
                $this->setHeaders();
 
@@ -140,16 +177,21 @@ class SpecialActiveUsers extends SpecialPage {
 
                # getBody() first to check, if empty
                $usersbody = $up->getBody();
-               $s = $up->getPageHeader();
+
+                $s = Html::rawElement( 'div', array( 'class' => 'mw-activeusers-intro' ),
+                        wfMsgExt( 'activeusers-intro', array( 'parsemag', 'escape' ), $wgLang->formatNum( ceil( $wgRCMaxAge / 86400 ) ) )
+                );
+
+               $s .= $up->getPageHeader();
                if( $usersbody ) {
                        $s .= $up->getNavigationBar();
-                       $s .= '<ul>' . $usersbody . '</ul>';
+                       $s .= Html::rawElement( 'ul', array(), $usersbody );
                        $s .= $up->getNavigationBar();
                } else {
-                       $s .= '<p>' . wfMsgHtml( 'activeusers-noresult' ) . '</p>';
+                       $s .= Html::element( 'p', array(), wfMsg( 'activeusers-noresult' ) );
                }
 
                $wgOut->addHTML( $s );
        }
 
-}
\ No newline at end of file
+}