* Add a special page to list active users
authorAaron Schulz <aaron@users.mediawiki.org>
Thu, 1 May 2008 21:30:05 +0000 (21:30 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Thu, 1 May 2008 21:30:05 +0000 (21:30 +0000)
* Might as well show block status in user list

includes/DefaultSettings.php
includes/SpecialActiveusers.php [new file with mode: 0644]
includes/SpecialListusers.php
includes/SpecialPage.php
languages/messages/MessagesEn.php
maintenance/language/messages.inc

index 43beaf3..b37ca44 100644 (file)
@@ -2592,6 +2592,7 @@ $wgSpecialPageGroups = array(
        'Filepath'                  => 'media',
 
        'Listusers'                 => 'users',
+       'Activeusers'               => 'users',
        'Listgrouprights'           => 'users',
        'Ipblocklist'               => 'users',
        'Contributions'             => 'users',
diff --git a/includes/SpecialActiveusers.php b/includes/SpecialActiveusers.php
new file mode 100644 (file)
index 0000000..f539093
--- /dev/null
@@ -0,0 +1,209 @@
+<?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
+/**
+ *
+ * @addtogroup SpecialPage
+ */
+
+/**
+ * This class is used to get a list of user. The ones with specials
+ * rights (sysop, bureaucrat, developer) will have them displayed
+ * next to their names.
+ *
+ * @addtogroup SpecialPage
+ */
+
+class ActiveUsersPager extends AlphabeticPager {
+
+       function __construct($group=null) {
+               global $wgRequest;
+               $un = $wgRequest->getText( 'username' );
+               $this->requestedUser = '';
+               if ( $un != '' ) {
+                       $username = Title::makeTitleSafe( NS_USER, $un );
+                       if( ! is_null( $username ) ) {
+                               $this->requestedUser = $username->getText();
+                       }
+               }
+               parent::__construct();
+       }
+
+
+       function getIndexField() {
+               return 'rc_user_text';
+       }
+
+       function getQueryInfo() {
+               $dbr = wfGetDB( DB_SLAVE );
+               $conds=array();
+               // don't show hidden names
+               $conds[]='ipb_deleted IS NULL OR ipb_deleted = 0';
+               $useIndex = $dbr->useIndexClause('rc_user_text');
+               if ($this->requestedUser != "") {
+                       $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser );
+               }
+
+               list ($recentchanges,$ipblocks) = $dbr->tableNamesN('recentchanges','ipblocks');
+
+               $query = array(
+                       'tables' => " $recentchanges $useIndex 
+                               LEFT JOIN $ipblocks ON rc_user=ipb_user AND ipb_auto=0 ",
+                       'fields' => array('rc_user_text',
+                               'MAX(rc_user) AS user_id',
+                               'COUNT(*) AS recentedits',
+                               'MAX(ipb_user) AS blocked'),
+                       'options' => array('GROUP BY' => 'rc_user_text'),
+                       'conds' => $conds
+               );
+
+               return $query;
+       }
+
+       function formatRow( $row ) {
+               $userPage = Title::makeTitle( NS_USER, $row->rc_user_text );
+               $name = $this->getSkin()->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
+
+               $list = array();
+               foreach( self::getGroups( $row->user_id ) as $group )
+                       $list[] = self::buildGroupLink( $group );
+               $groups = implode( ', ', $list );
+
+               $item = wfSpecialList( $name, $groups );
+               $count = wfMsgHtml( 'activeusers-count', $row->recentedits );
+               $blocked = $row->blocked ? ' '.wfMsg('listusers-blocked') : '';
+
+               return "<li>{$item} [{$count}]{$blocked}</li>";
+       }
+
+       function getBody() {
+               if (!$this->mQueryDone) {
+                       $this->doQuery();
+               }
+               $batch = new LinkBatch();
+
+               $this->mResult->rewind();
+               while ( $row = $this->mResult->fetchObject() ) {
+                       $batch->addObj( Title::makeTitleSafe( NS_USER, $row->rc_user_text ) );
+               }
+               $batch->execute();
+               $this->mResult->rewind();
+
+               return parent::getBody();
+       }
+
+       function getPageHeader( ) {
+               global $wgScript, $wgRequest;
+               $self = $this->getTitle();
+
+               # Form tag
+               $out  = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
+                       '<fieldset>' .
+                       Xml::element( 'legend', array(), wfMsg( 'activeusers' ) );
+               $out .= Xml::hidden( 'title', $self->getPrefixedDbKey() );
+
+               # Username field
+               $out .= Xml::label( wfMsg( 'activeusers-from' ), 'offset' ) . ' ' .
+                       Xml::input( 'username', 20, $this->requestedUser, array( 'id' => 'offset' ) ) . ' ';
+
+               # Submit button and form bottom
+               if( $this->mLimit )
+                       $out .= Xml::hidden( 'limit', $this->mLimit );
+               $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) );
+
+               $out .= '</fieldset>' .
+                       Xml::closeElement( 'form' );
+
+               return $out;
+       }
+
+       function getAllGroups() {
+               $result = array();
+               foreach( User::getAllGroups() as $group ) {
+                       $result[$group] = User::getGroupName( $group );
+               }
+               return $result;
+       }
+
+       /**
+        * Preserve group and username offset parameters when paging
+        * @return array
+        */
+       function getDefaultQuery() {
+               $query = parent::getDefaultQuery();
+               if( $this->requestedUser != '' )
+                       $query['username'] = $this->requestedUser;
+               return $query;
+       }
+
+       /**
+        * Get a list of groups the specified user belongs to
+        *
+        * @param int $uid
+        * @return array
+        */
+       protected static function getGroups( $uid ) {
+               $dbr = wfGetDB( DB_SLAVE );
+               $groups = array();
+               $res = $dbr->select( 'user_groups', 'ug_group', array( 'ug_user' => $uid ), __METHOD__ );
+               if( $res && $dbr->numRows( $res ) > 0 ) {
+                       while( $row = $dbr->fetchObject( $res ) )
+                               $groups[] = $row->ug_group;
+                       $dbr->freeResult( $res );
+               }
+               return $groups;
+       }
+
+       /**
+        * Format a link to a group description page
+        *
+        * @param string $group
+        * @return string
+        */
+       protected static function buildGroupLink( $group ) {
+               static $cache = array();
+               if( !isset( $cache[$group] ) )
+                       $cache[$group] = User::makeGroupLinkHtml( $group, User::getGroupMember( $group ) );
+               return $cache[$group];
+       }
+}
+
+/**
+ * constructor
+ * $par string (optional) A group to list users from
+ */
+function wfSpecialActiveusers( $par = null ) {
+       global $wgRequest, $wgOut;
+
+       $up = new ActiveUsersPager();
+
+       # getBody() first to check, if empty
+       $usersbody = $up->getBody();
+       $s = $up->getPageHeader();
+       if( $usersbody ) {
+               $s .=   $up->getNavigationBar();
+               $s .=   '<ul>' . $usersbody . '</ul>';
+               $s .=   $up->getNavigationBar() ;
+       } else {
+               $s .=   '<p>' . wfMsgHTML('activeusers-noresult') . '</p>';
+       };
+
+       $wgOut->addHTML( $s );
+}
index 8d99cf2..6c279bb 100644 (file)
@@ -78,7 +78,8 @@ class UsersPager extends AlphabeticPager {
                        'fields' => array('user_name',
                                'MAX(user_id) AS user_id',
                                'COUNT(ug_group) AS numgroups',
-                               'MAX(ug_group) AS singlegroup'),
+                               'MAX(ug_group) AS singlegroup',
+                               'MAX(ipb_user) AS blocked'),
                        'options' => array('GROUP BY' => 'user_name'),
                        'conds' => $conds
                );
@@ -103,8 +104,10 @@ class UsersPager extends AlphabeticPager {
                }
 
                $item = wfSpecialList( $name, $groups );
+               $blocked = $row->blocked ? ' '.wfMsg('listusers-blocked') : '';
+               
                wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) );
-               return "<li>{$item}</li>";
+               return "<li>{$item}{$blocked}</li>";
        }
 
        function getBody() {
index e8fe3ca..6dc4d64 100644 (file)
@@ -93,6 +93,7 @@ class SpecialPage
                'Imagelist'                 => array( 'SpecialPage', 'Imagelist' ),
                'Newimages'                 => array( 'IncludableSpecialPage', 'Newimages' ),
                'Listusers'                 => array( 'SpecialPage', 'Listusers' ),
+               'Activeusers'               => array( 'SpecialPage', 'Activeusers' ),
                'Listgrouprights'           => 'SpecialListGroupRights',
                'Statistics'                => array( 'SpecialPage', 'Statistics' ),
                'Randompage'                => 'Randompage',
index 704569c..6b6bb49 100644 (file)
@@ -1888,6 +1888,8 @@ A page is treated as disambiguation page if it uses a template which is linked f
 'protectedtitlesempty'            => 'No titles are currently protected with these parameters.',
 'listusers'                       => 'User list',
 'listusers-summary'               => '', # only translate this message to other languages if you have to change it
+'activeusers'                     => 'Active user list',
+'activeusers-summary'             => '', # only translate this message to other languages if you have to change it
 'specialpages'                    => 'Special pages',
 'specialpages-summary'            => '', # only translate this message to other languages if you have to change it
 'spheading'                       => 'Special pages for all users',
@@ -1951,9 +1953,16 @@ It may contain one or more characters which cannot be used in titles.',
 
 # Special:Listusers
 'listusersfrom'      => 'Display users starting at:',
+'listusers-blocked'   => '(account blocked)',
 'listusers-submit'   => 'Show',
 'listusers-noresult' => 'No user found.',
 
+# Special:Activeusers
+'activeusers-count'    => '$1 recent edits',
+'activeusers-from'     => 'Display users starting at:',
+'activeusers-submit'   => 'Show',
+'activeusers-noresult' => 'No user found.',
+
 # Special:Listgrouprights
 'listgrouprights'          => 'User group rights',
 'listgrouprights-summary'  => 'The following is a list of user groups defined on this wiki, with their associated access rights.
index 6787375..b97a10b 100644 (file)
@@ -1218,6 +1218,9 @@ $wgMessageStructure = array(
                'protectedtitlesempty',
                'listusers',
                'listusers-summary',
+               'ativeusers',
+               'ativeusers-summary',
+               
                'specialpages',
                'specialpages-summary',
                'spheading',
@@ -1281,6 +1284,13 @@ $wgMessageStructure = array(
                'listusersfrom',
                'listusers-submit',
                'listusers-noresult',
+               'listusers-blocked'
+       ),
+       'activeusers' => array(
+               'activeusers-count',
+               'activeusers-from',
+               'activeusers-submit',
+               'activeusers-noresult',
        ),
        'listgrouprights' => array(
                'listgrouprights',