MediaWiki  REL1_20
SpecialListusers.php
Go to the documentation of this file.
00001 <?php
00035 class UsersPager extends AlphabeticPager {
00036 
00041         function __construct( IContextSource $context = null, $par = null, $including = null ) {
00042                 if ( $context ) {
00043                         $this->setContext( $context );
00044                 }
00045 
00046                 $request = $this->getRequest();
00047                 $par = ( $par !== null ) ? $par : '';
00048                 $parms = explode( '/', $par );
00049                 $symsForAll = array( '*', 'user' );
00050                 if ( $parms[0] != '' && ( in_array( $par, User::getAllGroups() ) || in_array( $par, $symsForAll ) ) ) {
00051                         $this->requestedGroup = $par;
00052                         $un = $request->getText( 'username' );
00053                 } elseif ( count( $parms ) == 2 ) {
00054                         $this->requestedGroup = $parms[0];
00055                         $un = $parms[1];
00056                 } else {
00057                         $this->requestedGroup = $request->getVal( 'group' );
00058                         $un = ( $par != '' ) ? $par : $request->getText( 'username' );
00059                 }
00060                 if ( in_array( $this->requestedGroup, $symsForAll ) ) {
00061                         $this->requestedGroup = '';
00062                 }
00063                 $this->editsOnly = $request->getBool( 'editsOnly' );
00064                 $this->creationSort = $request->getBool( 'creationSort' );
00065                 $this->including = $including;
00066 
00067                 $this->requestedUser = '';
00068                 if ( $un != '' ) {
00069                         $username = Title::makeTitleSafe( NS_USER, $un );
00070                         if( ! is_null( $username ) ) {
00071                                 $this->requestedUser = $username->getText();
00072                         }
00073                 }
00074                 parent::__construct();
00075         }
00076 
00080         function getIndexField() {
00081                 return $this->creationSort ? 'user_id' : 'user_name';
00082         }
00083 
00087         function getQueryInfo() {
00088                 $dbr = wfGetDB( DB_SLAVE );
00089                 $conds = array();
00090                 // Don't show hidden names
00091                 if( !$this->getUser()->isAllowed( 'hideuser' ) ) {
00092                         $conds[] = 'ipb_deleted IS NULL';
00093                 }
00094 
00095                 $options = array();
00096 
00097                 if( $this->requestedGroup != '' ) {
00098                         $conds['ug_group'] = $this->requestedGroup;
00099                 } else {
00100                         //$options['USE INDEX'] = $this->creationSort ? 'PRIMARY' : 'user_name';
00101                 }
00102                 if( $this->requestedUser != '' ) {
00103                         # Sorted either by account creation or name
00104                         if( $this->creationSort ) {
00105                                 $conds[] = 'user_id >= ' . intval( User::idFromName( $this->requestedUser ) );
00106                         } else {
00107                                 $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser );
00108                         }
00109                 }
00110                 if( $this->editsOnly ) {
00111                         $conds[] = 'user_editcount > 0';
00112                 }
00113 
00114                 $options['GROUP BY'] = $this->creationSort ? 'user_id' : 'user_name';
00115 
00116                 $query = array(
00117                         'tables' => array( 'user', 'user_groups', 'ipblocks'),
00118                         'fields' => array(
00119                                 'user_name' => $this->creationSort ? 'MAX(user_name)' : 'user_name',
00120                                 'user_id' => $this->creationSort ? 'user_id' : 'MAX(user_id)',
00121                                 'edits' => 'MAX(user_editcount)',
00122                                 'numgroups' => 'COUNT(ug_group)',
00123                                 'singlegroup' => 'MAX(ug_group)', // the usergroup if there is only one
00124                                 'creation' => 'MIN(user_registration)',
00125                                 'ipb_deleted' => 'MAX(ipb_deleted)' // block/hide status
00126                         ),
00127                         'options' => $options,
00128                         'join_conds' => array(
00129                                 'user_groups' => array( 'LEFT JOIN', 'user_id=ug_user' ),
00130                                 'ipblocks' => array( 'LEFT JOIN', array(
00131                                         'user_id=ipb_user',
00132                                         'ipb_deleted' => 1,
00133                                         'ipb_auto' => 0
00134                                 )),
00135                         ),
00136                         'conds' => $conds
00137                 );
00138 
00139                 wfRunHooks( 'SpecialListusersQueryInfo', array( $this, &$query ) );
00140                 return $query;
00141         }
00142 
00147         function formatRow( $row ) {
00148                 if ( $row->user_id == 0 ) { #Bug 16487
00149                         return '';
00150                 }
00151 
00152                 $userName = $row->user_name;
00153 
00154                 $ulinks = Linker::userLink( $row->user_id, $userName );
00155                 $ulinks .= Linker::userToolLinks( $row->user_id, $userName );
00156 
00157                 $lang = $this->getLanguage();
00158 
00159                 $groups = '';
00160                 $groups_list = self::getGroups( $row->user_id );
00161                 if( !$this->including && count( $groups_list ) > 0 ) {
00162                         $list = array();
00163                         foreach( $groups_list as $group )
00164                                 $list[] = self::buildGroupLink( $group, $userName );
00165                         $groups = $lang->commaList( $list );
00166                 }
00167 
00168                 $item = $lang->specialList( $ulinks, $groups );
00169                 if( $row->ipb_deleted ) {
00170                         $item = "<span class=\"deleted\">$item</span>";
00171                 }
00172 
00173                 $edits = '';
00174                 global $wgEdititis;
00175                 if ( !$this->including && $wgEdititis ) {
00176                         $edits = ' [' . $this->msg( 'usereditcount' )->numParams( $row->edits )->escaped() . ']';
00177                 }
00178 
00179                 $created = '';
00180                 # Some rows may be NULL
00181                 if( !$this->including && $row->creation ) {
00182                         $user = $this->getUser();
00183                         $d = $lang->userDate( $row->creation, $user );
00184                         $t = $lang->userTime( $row->creation, $user );
00185                         $created = $this->msg( 'usercreated', $d, $t, $row->user_name )->escaped();
00186                         $created = ' ' . $this->msg( 'parentheses' )->rawParams( $created )->escaped();
00187                 }
00188 
00189                 wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) );
00190                 return Html::rawElement( 'li', array(), "{$item}{$edits}{$created}" );
00191         }
00192 
00193         function doBatchLookups() {
00194                 $batch = new LinkBatch();
00195                 # Give some pointers to make user links
00196                 foreach ( $this->mResult as $row ) {
00197                         $batch->add( NS_USER, $row->user_name );
00198                         $batch->add( NS_USER_TALK, $row->user_name );
00199                 }
00200                 $batch->execute();
00201                 $this->mResult->rewind();
00202         }
00203 
00207         function getPageHeader( ) {
00208                 global $wgScript;
00209 
00210                 list( $self ) = explode( '/', $this->getTitle()->getPrefixedDBkey() );
00211 
00212                 # Form tag
00213                 $out  = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listusers-form' ) ) .
00214                         Xml::fieldset( $this->msg( 'listusers' )->text() ) .
00215                         Html::hidden( 'title', $self );
00216 
00217                 # Username field
00218                 $out .= Xml::label( $this->msg( 'listusersfrom' )->text(), 'offset' ) . ' ' .
00219                         Xml::input( 'username', 20, $this->requestedUser, array( 'id' => 'offset' ) ) . ' ';
00220 
00221                 # Group drop-down list
00222                 $out .= Xml::label( $this->msg( 'group' )->text(), 'group' ) . ' ' .
00223                         Xml::openElement('select',  array( 'name' => 'group', 'id' => 'group' ) ) .
00224                         Xml::option( $this->msg( 'group-all' )->text(), '' );
00225                 foreach( $this->getAllGroups() as $group => $groupText )
00226                         $out .= Xml::option( $groupText, $group, $group == $this->requestedGroup );
00227                 $out .= Xml::closeElement( 'select' ) . '<br />';
00228                 $out .= Xml::checkLabel( $this->msg( 'listusers-editsonly' )->text(), 'editsOnly', 'editsOnly', $this->editsOnly );
00229                 $out .= '&#160;';
00230                 $out .= Xml::checkLabel( $this->msg( 'listusers-creationsort' )->text(), 'creationSort', 'creationSort', $this->creationSort );
00231                 $out .= '<br />';
00232 
00233                 wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) );
00234 
00235                 # Submit button and form bottom
00236                 $out .= Html::hidden( 'limit', $this->mLimit );
00237                 $out .= Xml::submitButton( $this->msg( 'allpagessubmit' )->text() );
00238                 wfRunHooks( 'SpecialListusersHeader', array( $this, &$out ) );
00239                 $out .= Xml::closeElement( 'fieldset' ) .
00240                         Xml::closeElement( 'form' );
00241 
00242                 return $out;
00243         }
00244 
00249         function getAllGroups() {
00250                 $result = array();
00251                 foreach( User::getAllGroups() as $group ) {
00252                         $result[$group] = User::getGroupName( $group );
00253                 }
00254                 asort( $result );
00255                 return $result;
00256         }
00257 
00262         function getDefaultQuery() {
00263                 $query = parent::getDefaultQuery();
00264                 if( $this->requestedGroup != '' ) {
00265                         $query['group'] = $this->requestedGroup;
00266                 }
00267                 if( $this->requestedUser != '' ) {
00268                         $query['username'] = $this->requestedUser;
00269                 }
00270                 wfRunHooks( 'SpecialListusersDefaultQuery', array( $this, &$query ) );
00271                 return $query;
00272         }
00273 
00280         protected static function getGroups( $uid ) {
00281                 $user = User::newFromId( $uid );
00282                 $groups = array_diff( $user->getEffectiveGroups(), User::getImplicitGroups() );
00283                 return $groups;
00284         }
00285 
00293         protected static function buildGroupLink( $group, $username ) {
00294                 return User::makeGroupLinkHtml( $group, htmlspecialchars( User::getGroupMember( $group, $username ) ) );
00295         }
00296 }
00297 
00301 class SpecialListUsers extends SpecialPage {
00302 
00306         public function __construct() {
00307                 parent::__construct( 'Listusers' );
00308                 $this->mIncludable = true;
00309         }
00310 
00316         public function execute( $par ) {
00317                 $this->setHeaders();
00318                 $this->outputHeader();
00319 
00320                 $up = new UsersPager( $this->getContext(), $par, $this->including() );
00321 
00322                 # getBody() first to check, if empty
00323                 $usersbody = $up->getBody();
00324 
00325                 $s = '';
00326                 if ( !$this->including() ) {
00327                         $s = $up->getPageHeader();
00328                 }
00329 
00330                 if( $usersbody ) {
00331                         $s .= $up->getNavigationBar();
00332                         $s .= Html::rawElement( 'ul', array(), $usersbody );
00333                         $s .= $up->getNavigationBar();
00334                 } else {
00335                         $s .= $this->msg( 'listusers-noresult' )->parseAsBlock();
00336                 }
00337 
00338                 $this->getOutput()->addHTML( $s );
00339         }
00340 }