diff options
Diffstat (limited to 'includes/specials/SpecialListusers.php')
-rw-r--r-- | includes/specials/SpecialListusers.php | 151 |
1 files changed, 108 insertions, 43 deletions
diff --git a/includes/specials/SpecialListusers.php b/includes/specials/SpecialListusers.php index 1089fbbe..8cd9173c 100644 --- a/includes/specials/SpecialListusers.php +++ b/includes/specials/SpecialListusers.php @@ -36,7 +36,9 @@ class UsersPager extends AlphabeticPager { /** * @param $context IContextSource - * @param $par null|array + * @param array $par (Default null) + * @param $including boolean Whether this page is being transcluded in + * another page */ function __construct( IContextSource $context = null, $par = null, $including = null ) { if ( $context ) { @@ -47,7 +49,10 @@ class UsersPager extends AlphabeticPager { $par = ( $par !== null ) ? $par : ''; $parms = explode( '/', $par ); $symsForAll = array( '*', 'user' ); - if ( $parms[0] != '' && ( in_array( $par, User::getAllGroups() ) || in_array( $par, $symsForAll ) ) ) { + + if ( $parms[0] != '' && + ( in_array( $par, User::getAllGroups() ) || in_array( $par, $symsForAll ) ) + ) { $this->requestedGroup = $par; $un = $request->getText( 'username' ); } elseif ( count( $parms ) == 2 ) { @@ -57,20 +62,25 @@ class UsersPager extends AlphabeticPager { $this->requestedGroup = $request->getVal( 'group' ); $un = ( $par != '' ) ? $par : $request->getText( 'username' ); } + if ( in_array( $this->requestedGroup, $symsForAll ) ) { $this->requestedGroup = ''; } $this->editsOnly = $request->getBool( 'editsOnly' ); $this->creationSort = $request->getBool( 'creationSort' ); $this->including = $including; + $this->mDefaultDirection = $request->getBool( 'desc' ); $this->requestedUser = ''; + if ( $un != '' ) { $username = Title::makeTitleSafe( NS_USER, $un ); - if( ! is_null( $username ) ) { + + if ( !is_null( $username ) ) { $this->requestedUser = $username->getText(); } } + parent::__construct(); } @@ -87,34 +97,35 @@ class UsersPager extends AlphabeticPager { function getQueryInfo() { $dbr = wfGetDB( DB_SLAVE ); $conds = array(); + // Don't show hidden names - if( !$this->getUser()->isAllowed( 'hideuser' ) ) { - $conds[] = 'ipb_deleted IS NULL'; + if ( !$this->getUser()->isAllowed( 'hideuser' ) ) { + $conds[] = 'ipb_deleted IS NULL OR ipb_deleted = 0'; } $options = array(); - if( $this->requestedGroup != '' ) { + if ( $this->requestedGroup != '' ) { $conds['ug_group'] = $this->requestedGroup; - } else { - //$options['USE INDEX'] = $this->creationSort ? 'PRIMARY' : 'user_name'; } - if( $this->requestedUser != '' ) { + + if ( $this->requestedUser != '' ) { # Sorted either by account creation or name - if( $this->creationSort ) { + if ( $this->creationSort ) { $conds[] = 'user_id >= ' . intval( User::idFromName( $this->requestedUser ) ); } else { $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser ); } } - if( $this->editsOnly ) { + + if ( $this->editsOnly ) { $conds[] = 'user_editcount > 0'; } $options['GROUP BY'] = $this->creationSort ? 'user_id' : 'user_name'; $query = array( - 'tables' => array( 'user', 'user_groups', 'ipblocks'), + 'tables' => array( 'user', 'user_groups', 'ipblocks' ), 'fields' => array( 'user_name' => $this->creationSort ? 'MAX(user_name)' : 'user_name', 'user_id' => $this->creationSort ? 'user_id' : 'MAX(user_id)', @@ -127,16 +138,18 @@ class UsersPager extends AlphabeticPager { 'options' => $options, 'join_conds' => array( 'user_groups' => array( 'LEFT JOIN', 'user_id=ug_user' ), - 'ipblocks' => array( 'LEFT JOIN', array( - 'user_id=ipb_user', - 'ipb_deleted' => 1, - 'ipb_auto' => 0 - )), + 'ipblocks' => array( + 'LEFT JOIN', array( + 'user_id=ipb_user', + 'ipb_auto' => 0 + ) + ), ), 'conds' => $conds ); wfRunHooks( 'SpecialListusersQueryInfo', array( $this, &$query ) ); + return $query; } @@ -152,42 +165,56 @@ class UsersPager extends AlphabeticPager { $userName = $row->user_name; $ulinks = Linker::userLink( $row->user_id, $userName ); - $ulinks .= Linker::userToolLinks( $row->user_id, $userName ); + $ulinks .= Linker::userToolLinksRedContribs( + $row->user_id, + $userName, + (int)$row->edits + ); $lang = $this->getLanguage(); $groups = ''; $groups_list = self::getGroups( $row->user_id ); - if( !$this->including && count( $groups_list ) > 0 ) { + + if ( !$this->including && count( $groups_list ) > 0 ) { $list = array(); - foreach( $groups_list as $group ) + foreach ( $groups_list as $group ) { $list[] = self::buildGroupLink( $group, $userName ); + } $groups = $lang->commaList( $list ); } $item = $lang->specialList( $ulinks, $groups ); - if( $row->ipb_deleted ) { + + if ( $row->ipb_deleted ) { $item = "<span class=\"deleted\">$item</span>"; } $edits = ''; global $wgEdititis; if ( !$this->including && $wgEdititis ) { - $edits = ' [' . $this->msg( 'usereditcount' )->numParams( $row->edits )->escaped() . ']'; + // @fixme i18n issue: Hardcoded square brackets. + $edits = ' [' . + $this->msg( 'usereditcount' )->numParams( $row->edits )->escaped() . + ']'; } $created = ''; - # Some rows may be NULL - if( !$this->including && $row->creation ) { + # Some rows may be null + if ( !$this->including && $row->creation ) { $user = $this->getUser(); $d = $lang->userDate( $row->creation, $user ); $t = $lang->userTime( $row->creation, $user ); $created = $this->msg( 'usercreated', $d, $t, $row->user_name )->escaped(); $created = ' ' . $this->msg( 'parentheses' )->rawParams( $created )->escaped(); } + $blocked = !is_null( $row->ipb_deleted ) ? + ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() : + ''; wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) ); - return Html::rawElement( 'li', array(), "{$item}{$edits}{$created}" ); + + return Html::rawElement( 'li', array(), "{$item}{$edits}{$created}{$blocked}" ); } function doBatchLookups() { @@ -204,30 +231,60 @@ class UsersPager extends AlphabeticPager { /** * @return string */ - function getPageHeader( ) { + function getPageHeader() { global $wgScript; list( $self ) = explode( '/', $this->getTitle()->getPrefixedDBkey() ); # Form tag - $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listusers-form' ) ) . + $out = Xml::openElement( + 'form', + array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listusers-form' ) + ) . Xml::fieldset( $this->msg( 'listusers' )->text() ) . Html::hidden( 'title', $self ); # Username field $out .= Xml::label( $this->msg( 'listusersfrom' )->text(), 'offset' ) . ' ' . - Xml::input( 'username', 20, $this->requestedUser, array( 'id' => 'offset' ) ) . ' '; + Html::input( + 'username', + $this->requestedUser, + 'text', + array( + 'id' => 'offset', + 'size' => 20, + 'autofocus' => $this->requestedUser === '' + ) + ) . ' '; # Group drop-down list $out .= Xml::label( $this->msg( 'group' )->text(), 'group' ) . ' ' . - Xml::openElement('select', array( 'name' => 'group', 'id' => 'group' ) ) . + Xml::openElement( 'select', array( 'name' => 'group', 'id' => 'group' ) ) . Xml::option( $this->msg( 'group-all' )->text(), '' ); - foreach( $this->getAllGroups() as $group => $groupText ) + foreach ( $this->getAllGroups() as $group => $groupText ) { $out .= Xml::option( $groupText, $group, $group == $this->requestedGroup ); + } $out .= Xml::closeElement( 'select' ) . '<br />'; - $out .= Xml::checkLabel( $this->msg( 'listusers-editsonly' )->text(), 'editsOnly', 'editsOnly', $this->editsOnly ); + $out .= Xml::checkLabel( + $this->msg( 'listusers-editsonly' )->text(), + 'editsOnly', + 'editsOnly', + $this->editsOnly + ); $out .= ' '; - $out .= Xml::checkLabel( $this->msg( 'listusers-creationsort' )->text(), 'creationSort', 'creationSort', $this->creationSort ); + $out .= Xml::checkLabel( + $this->msg( 'listusers-creationsort' )->text(), + 'creationSort', + 'creationSort', + $this->creationSort + ); + $out .= ' '; + $out .= Xml::checkLabel( + $this->msg( 'listusers-desc' )->text(), + 'desc', + 'desc', + $this->mDefaultDirection + ); $out .= '<br />'; wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) ); @@ -248,10 +305,11 @@ class UsersPager extends AlphabeticPager { */ function getAllGroups() { $result = array(); - foreach( User::getAllGroups() as $group ) { + foreach ( User::getAllGroups() as $group ) { $result[$group] = User::getGroupName( $group ); } asort( $result ); + return $result; } @@ -261,13 +319,14 @@ class UsersPager extends AlphabeticPager { */ function getDefaultQuery() { $query = parent::getDefaultQuery(); - if( $this->requestedGroup != '' ) { + if ( $this->requestedGroup != '' ) { $query['group'] = $this->requestedGroup; } - if( $this->requestedUser != '' ) { + if ( $this->requestedUser != '' ) { $query['username'] = $this->requestedUser; } wfRunHooks( 'SpecialListusersDefaultQuery', array( $this, &$query ) ); + return $query; } @@ -280,38 +339,40 @@ class UsersPager extends AlphabeticPager { protected static function getGroups( $uid ) { $user = User::newFromId( $uid ); $groups = array_diff( $user->getEffectiveGroups(), User::getImplicitGroups() ); + return $groups; } /** * Format a link to a group description page * - * @param $group String: group name - * @param $username String Username + * @param string $group group name + * @param string $username Username * @return string */ protected static function buildGroupLink( $group, $username ) { - return User::makeGroupLinkHtml( $group, htmlspecialchars( User::getGroupMember( $group, $username ) ) ); + return User::makeGroupLinkHtml( + $group, + htmlspecialchars( User::getGroupMember( $group, $username ) ) + ); } } /** * @ingroup SpecialPage */ -class SpecialListUsers extends SpecialPage { - +class SpecialListUsers extends IncludableSpecialPage { /** * Constructor */ public function __construct() { parent::__construct( 'Listusers' ); - $this->mIncludable = true; } /** * Show the special page * - * @param $par string (optional) A group to list users from + * @param string $par (optional) A group to list users from */ public function execute( $par ) { $this->setHeaders(); @@ -327,7 +388,7 @@ class SpecialListUsers extends SpecialPage { $s = $up->getPageHeader(); } - if( $usersbody ) { + if ( $usersbody ) { $s .= $up->getNavigationBar(); $s .= Html::rawElement( 'ul', array(), $usersbody ); $s .= $up->getNavigationBar(); @@ -337,4 +398,8 @@ class SpecialListUsers extends SpecialPage { $this->getOutput()->addHTML( $s ); } + + protected function getGroupName() { + return 'users'; + } } |