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 + includes/SpecialActiveusers.php | 209 ++++++++++++++++++++++++++++++ includes/SpecialListusers.php | 7 +- includes/SpecialPage.php | 1 + languages/messages/MessagesEn.php | 9 ++ maintenance/language/messages.inc | 10 ++ 6 files changed, 235 insertions(+), 2 deletions(-) create mode 100644 includes/SpecialActiveusers.php diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 43beaf328f..b37ca449f3 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/SpecialActiveusers.php b/includes/SpecialActiveusers.php new file mode 100644 index 0000000000..f5390938b8 --- /dev/null +++ b/includes/SpecialActiveusers.php @@ -0,0 +1,209 @@ +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 "
  • {$item} [{$count}]{$blocked}
  • "; + } + + 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 ) ) . + '
    ' . + 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 .= '
    ' . + 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 .= ''; + $s .= $up->getNavigationBar() ; + } else { + $s .= '

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

    '; + }; + + $wgOut->addHTML( $s ); +} diff --git a/includes/SpecialListusers.php b/includes/SpecialListusers.php index 8d99cf21a4..6c279bbfff 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 e8fe3ca64b..6dc4d64a0d 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 704569c0aa..6b6bb49b6c 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 678737526b..b97a10b5b1 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.20.1