Use proper nosuchuser msg (fix for r86482)
[lhc/web/wiklou.git] / includes / specials / SpecialActiveusers.php
index 1a315e3..e4bf42d 100644 (file)
@@ -1,35 +1,50 @@
 <?php
-# Copyright (C) 2008 Aaron Schulz
-#
-# http://www.mediawiki.org/
-#
-# 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
+/**
+ * Implements Special:Activeusers
+ *
+ * Copyright © 2008 Aaron Schulz
+ *
+ * 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
+ */
 
 /**
  * This class is used to get a list of active users. The ones with specials
  * rights (sysop, bureaucrat, developer) will have them displayed
  * next to their names.
  *
- * @file
  * @ingroup SpecialPage
  */
 class ActiveUsersPager extends UsersPager {
 
+       /**
+        * @var FormOptions
+        */
+       protected $opts;
+
+       /**
+        * @var Array
+        */
+       protected $groups;
+
        function __construct( $group = null ) {
-               global $wgRequest;
+               global $wgRequest, $wgActiveUserDays;
+               $this->RCMaxAge = $wgActiveUserDays;
                $un = $wgRequest->getText( 'username' );
                $this->requestedUser = '';
                if ( $un != '' ) {
@@ -38,9 +53,35 @@ class ActiveUsersPager extends UsersPager {
                                $this->requestedUser = $username->getText();
                        }
                }
+
+               $this->setupOptions();
+
                parent::__construct();
        }
 
+       function getTitle() {
+               return SpecialPage::getTitleFor( 'Activeusers' );
+       }
+
+       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';
        }
@@ -49,7 +90,9 @@ class ActiveUsersPager extends UsersPager {
                $dbr = wfGetDB( DB_SLAVE );
                $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"';
+               $conds[] = "rc_log_type IS NULL OR rc_log_type != 'newusers'";
+               $conds[] = "rc_timestamp >= '{$dbr->timestamp( wfTimestamp( TS_UNIX ) - $this->RCMaxAge*24*3600 )}'";
+
                if( $this->requestedUser != '' ) {
                        $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser );
                }
@@ -63,7 +106,7 @@ class ActiveUsersPager extends UsersPager {
                                'MAX(ipb_user) AS blocked'
                        ),
                        'options' => array(
-                               'GROUP BY' => 'rc_user_text',
+                               'GROUP BY' => 'rc_user_text, user_id',
                                'USE INDEX' => array( 'recentchanges' => 'rc_user_text' )
                        ),
                        'join_conds' => array(
@@ -76,42 +119,52 @@ class ActiveUsersPager extends UsersPager {
        }
 
        function formatRow( $row ) {
+               global $wgLang;
                $userName = $row->user_name;
-               $userPage = Title::makeTitle( NS_USER, $userName );
-               $name = $this->getSkin()->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
+
+               $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;
+               global $wgScript;
+
                $self = $this->getTitle();
+               $limit = $this->mLimit ? Html::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 .= Html::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;
        }
@@ -125,7 +178,7 @@ class SpecialActiveUsers extends SpecialPage {
        /**
         * Constructor
         */
-       public function  __construct() {
+       public function __construct() {
                parent::__construct( 'Activeusers' );
        }
 
@@ -135,24 +188,30 @@ class SpecialActiveUsers extends SpecialPage {
         * @param $par Mixed: parameter passed to the page or null
         */
        public function execute( $par ) {
-               global $wgOut;
+               global $wgOut, $wgLang, $wgActiveUserDays;
 
                $this->setHeaders();
+               $this->outputHeader();
 
                $up = new ActiveUsersPager();
 
                # 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( $wgActiveUserDays ) )
+               );
+
+               $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
+}