From 8b813f59b4a6b49f38b45c6d9ead8517f80e6c07 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 1 May 2008 21:30:05 +0000 Subject: [PATCH] * Add a special page to list active users * Might as well show block status in user list --- includes/DefaultSettings.php | 1 + ...SpecialListusers.php => SpecialActiveusers.php} | 89 ++++++++-------------- includes/SpecialListusers.php | 7 +- includes/SpecialPage.php | 1 + languages/messages/MessagesEn.php | 9 +++ maintenance/language/messages.inc | 10 +++ 6 files changed, 57 insertions(+), 60 deletions(-) copy includes/{SpecialListusers.php => SpecialActiveusers.php} (62%) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 43beaf328f7..b37ca449f38 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -2592,6 +2592,7 @@ $wgSpecialPageGroups = array( 'Filepath' => 'media', 'Listusers' => 'users', + 'Activeusers' => 'users', 'Listgrouprights' => 'users', 'Ipblocklist' => 'users', 'Contributions' => 'users', diff --git a/includes/SpecialListusers.php b/includes/SpecialActiveusers.php similarity index 62% copy from includes/SpecialListusers.php copy to includes/SpecialActiveusers.php index 8d99cf21a46..f5390938b80 100644 --- a/includes/SpecialListusers.php +++ b/includes/SpecialActiveusers.php @@ -1,9 +1,6 @@ +# Copyright (C) 2008 Aaron Schulz # # http://www.mediawiki.org/ # @@ -34,11 +31,10 @@ * @addtogroup SpecialPage */ -class UsersPager extends AlphabeticPager { +class ActiveUsersPager extends AlphabeticPager { function __construct($group=null) { global $wgRequest; - $this->requestedGroup = $group != "" ? $group : $wgRequest->getVal( 'group' ); $un = $wgRequest->getText( 'username' ); $this->requestedUser = ''; if ( $un != '' ) { @@ -52,7 +48,7 @@ class UsersPager extends AlphabeticPager { function getIndexField() { - return 'user_name'; + return 'rc_user_text'; } function getQueryInfo() { @@ -60,66 +56,56 @@ class UsersPager extends AlphabeticPager { $conds=array(); // don't show hidden names $conds[]='ipb_deleted IS NULL OR ipb_deleted = 0'; - if ($this->requestedGroup != "") { - $conds['ug_group'] = $this->requestedGroup; - $useIndex = ''; - } else { - $useIndex = $dbr->useIndexClause('user_name'); - } + $useIndex = $dbr->useIndexClause('rc_user_text'); if ($this->requestedUser != "") { - $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser ); + $conds[] = 'rc_user_text >= ' . $dbr->addQuotes( $this->requestedUser ); } - list ($user,$user_groups,$ipblocks) = $dbr->tableNamesN('user','user_groups','ipblocks'); + list ($recentchanges,$ipblocks) = $dbr->tableNamesN('recentchanges','ipblocks'); $query = array( - 'tables' => " $user $useIndex LEFT JOIN $user_groups ON user_id=ug_user - LEFT JOIN $ipblocks ON user_id=ipb_user AND ipb_auto=0 ", - 'fields' => array('user_name', - 'MAX(user_id) AS user_id', - 'COUNT(ug_group) AS numgroups', - 'MAX(ug_group) AS singlegroup'), - 'options' => array('GROUP BY' => 'user_name'), + '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 ); - wfRunHooks( 'SpecialListusersQueryInfo', array( $this, &$query ) ); return $query; } function formatRow( $row ) { - $userPage = Title::makeTitle( NS_USER, $row->user_name ); + $userPage = Title::makeTitle( NS_USER, $row->rc_user_text ); $name = $this->getSkin()->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) ); - if( $row->numgroups > 1 || ( $this->requestedGroup && $row->numgroups == 1 ) ) { - $list = array(); - foreach( self::getGroups( $row->user_id ) as $group ) - $list[] = self::buildGroupLink( $group ); - $groups = implode( ', ', $list ); - } elseif( $row->numgroups == 1 ) { - $groups = self::buildGroupLink( $row->singlegroup ); - } else { - $groups = ''; - } + $list = array(); + foreach( self::getGroups( $row->user_id ) as $group ) + $list[] = self::buildGroupLink( $group ); + $groups = implode( ', ', $list ); $item = wfSpecialList( $name, $groups ); - wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) ); - return "
  • {$item}
  • "; + $count = wfMsgHtml( 'activeusers-count', $row->recentedits ); + $blocked = $row->blocked ? ' '.wfMsg('listusers-blocked') : ''; + + return "
  • {$item} [{$count}]{$blocked}
  • "; } function getBody() { if (!$this->mQueryDone) { $this->doQuery(); } - $batch = new LinkBatch; + $batch = new LinkBatch(); $this->mResult->rewind(); - while ( $row = $this->mResult->fetchObject() ) { - $batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) ); + $batch->addObj( Title::makeTitleSafe( NS_USER, $row->rc_user_text ) ); } $batch->execute(); $this->mResult->rewind(); + return parent::getBody(); } @@ -130,28 +116,18 @@ class UsersPager extends AlphabeticPager { # Form tag $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) . '
    ' . - Xml::element( 'legend', array(), wfMsg( 'listusers' ) ); + Xml::element( 'legend', array(), wfMsg( 'activeusers' ) ); $out .= Xml::hidden( 'title', $self->getPrefixedDbKey() ); # Username field - $out .= Xml::label( wfMsg( 'listusersfrom' ), 'offset' ) . ' ' . + $out .= Xml::label( wfMsg( 'activeusers-from' ), 'offset' ) . ' ' . Xml::input( 'username', 20, $this->requestedUser, array( 'id' => 'offset' ) ) . ' '; - # Group drop-down list - $out .= Xml::label( wfMsg( 'group' ), 'group' ) . ' ' . - Xml::openElement('select', array( 'name' => 'group', 'id' => 'group' ) ) . - Xml::option( wfMsg( 'group-all' ), '' ); - foreach( $this->getAllGroups() as $group => $groupText ) - $out .= Xml::option( $groupText, $group, $group == $this->requestedGroup ); - $out .= Xml::closeElement( 'select' ) . ' '; - - wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) ); - # Submit button and form bottom if( $this->mLimit ) $out .= Xml::hidden( 'limit', $this->mLimit ); $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) ); - wfRunHooks( 'SpecialListusersHeader', array( $this, &$out ) ); + $out .= '
    ' . Xml::closeElement( 'form' ); @@ -172,11 +148,8 @@ class UsersPager extends AlphabeticPager { */ function getDefaultQuery() { $query = parent::getDefaultQuery(); - if( $this->requestedGroup != '' ) - $query['group'] = $this->requestedGroup; if( $this->requestedUser != '' ) $query['username'] = $this->requestedUser; - wfRunHooks( 'SpecialListusersDefaultQuery', array( $this, &$query ) ); return $query; } @@ -216,10 +189,10 @@ class UsersPager extends AlphabeticPager { * constructor * $par string (optional) A group to list users from */ -function wfSpecialListusers( $par = null ) { +function wfSpecialActiveusers( $par = null ) { global $wgRequest, $wgOut; - $up = new UsersPager($par); + $up = new ActiveUsersPager(); # getBody() first to check, if empty $usersbody = $up->getBody(); @@ -229,7 +202,7 @@ function wfSpecialListusers( $par = null ) { $s .= ''; $s .= $up->getNavigationBar() ; } else { - $s .= '

    ' . wfMsgHTML('listusers-noresult') . '

    '; + $s .= '

    ' . wfMsgHTML('activeusers-noresult') . '

    '; }; $wgOut->addHTML( $s ); diff --git a/includes/SpecialListusers.php b/includes/SpecialListusers.php index 8d99cf21a46..6c279bbfff1 100644 --- a/includes/SpecialListusers.php +++ b/includes/SpecialListusers.php @@ -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 "
  • {$item}
  • "; + return "
  • {$item}{$blocked}
  • "; } function getBody() { diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index e8fe3ca64b1..6dc4d64a0dc 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -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', diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 704569c0aa7..6b6bb49b6ce 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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. diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 678737526b2..b97a10b5b13 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -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', -- 2.11.4.GIT