MediaWiki
REL1_24
|
00001 <?php 00035 class UsersPager extends AlphabeticPager { 00036 00043 function __construct( IContextSource $context = null, $par = null, $including = null ) { 00044 if ( $context ) { 00045 $this->setContext( $context ); 00046 } 00047 00048 $request = $this->getRequest(); 00049 $par = ( $par !== null ) ? $par : ''; 00050 $parms = explode( '/', $par ); 00051 $symsForAll = array( '*', 'user' ); 00052 00053 if ( $parms[0] != '' && 00054 ( in_array( $par, User::getAllGroups() ) || in_array( $par, $symsForAll ) ) 00055 ) { 00056 $this->requestedGroup = $par; 00057 $un = $request->getText( 'username' ); 00058 } elseif ( count( $parms ) == 2 ) { 00059 $this->requestedGroup = $parms[0]; 00060 $un = $parms[1]; 00061 } else { 00062 $this->requestedGroup = $request->getVal( 'group' ); 00063 $un = ( $par != '' ) ? $par : $request->getText( 'username' ); 00064 } 00065 00066 if ( in_array( $this->requestedGroup, $symsForAll ) ) { 00067 $this->requestedGroup = ''; 00068 } 00069 $this->editsOnly = $request->getBool( 'editsOnly' ); 00070 $this->creationSort = $request->getBool( 'creationSort' ); 00071 $this->including = $including; 00072 $this->mDefaultDirection = $request->getBool( 'desc' ) 00073 ? IndexPager::DIR_DESCENDING 00074 : IndexPager::DIR_ASCENDING; 00075 00076 $this->requestedUser = ''; 00077 00078 if ( $un != '' ) { 00079 $username = Title::makeTitleSafe( NS_USER, $un ); 00080 00081 if ( !is_null( $username ) ) { 00082 $this->requestedUser = $username->getText(); 00083 } 00084 } 00085 00086 parent::__construct(); 00087 } 00088 00092 function getIndexField() { 00093 return $this->creationSort ? 'user_id' : 'user_name'; 00094 } 00095 00099 function getQueryInfo() { 00100 $dbr = wfGetDB( DB_SLAVE ); 00101 $conds = array(); 00102 00103 // Don't show hidden names 00104 if ( !$this->getUser()->isAllowed( 'hideuser' ) ) { 00105 $conds[] = 'ipb_deleted IS NULL OR ipb_deleted = 0'; 00106 } 00107 00108 $options = array(); 00109 00110 if ( $this->requestedGroup != '' ) { 00111 $conds['ug_group'] = $this->requestedGroup; 00112 } 00113 00114 if ( $this->requestedUser != '' ) { 00115 # Sorted either by account creation or name 00116 if ( $this->creationSort ) { 00117 $conds[] = 'user_id >= ' . intval( User::idFromName( $this->requestedUser ) ); 00118 } else { 00119 $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser ); 00120 } 00121 } 00122 00123 if ( $this->editsOnly ) { 00124 $conds[] = 'user_editcount > 0'; 00125 } 00126 00127 $options['GROUP BY'] = $this->creationSort ? 'user_id' : 'user_name'; 00128 00129 $query = array( 00130 'tables' => array( 'user', 'user_groups', 'ipblocks' ), 00131 'fields' => array( 00132 'user_name' => $this->creationSort ? 'MAX(user_name)' : 'user_name', 00133 'user_id' => $this->creationSort ? 'user_id' : 'MAX(user_id)', 00134 'edits' => 'MAX(user_editcount)', 00135 'numgroups' => 'COUNT(ug_group)', 00136 'singlegroup' => 'MAX(ug_group)', // the usergroup if there is only one 00137 'creation' => 'MIN(user_registration)', 00138 'ipb_deleted' => 'MAX(ipb_deleted)' // block/hide status 00139 ), 00140 'options' => $options, 00141 'join_conds' => array( 00142 'user_groups' => array( 'LEFT JOIN', 'user_id=ug_user' ), 00143 'ipblocks' => array( 00144 'LEFT JOIN', array( 00145 'user_id=ipb_user', 00146 'ipb_auto' => 0 00147 ) 00148 ), 00149 ), 00150 'conds' => $conds 00151 ); 00152 00153 wfRunHooks( 'SpecialListusersQueryInfo', array( $this, &$query ) ); 00154 00155 return $query; 00156 } 00157 00162 function formatRow( $row ) { 00163 if ( $row->user_id == 0 ) { #Bug 16487 00164 return ''; 00165 } 00166 00167 $userName = $row->user_name; 00168 00169 $ulinks = Linker::userLink( $row->user_id, $userName ); 00170 $ulinks .= Linker::userToolLinksRedContribs( 00171 $row->user_id, 00172 $userName, 00173 (int)$row->edits 00174 ); 00175 00176 $lang = $this->getLanguage(); 00177 00178 $groups = ''; 00179 $groups_list = self::getGroups( $row->user_id ); 00180 00181 if ( !$this->including && count( $groups_list ) > 0 ) { 00182 $list = array(); 00183 foreach ( $groups_list as $group ) { 00184 $list[] = self::buildGroupLink( $group, $userName ); 00185 } 00186 $groups = $lang->commaList( $list ); 00187 } 00188 00189 $item = $lang->specialList( $ulinks, $groups ); 00190 00191 if ( $row->ipb_deleted ) { 00192 $item = "<span class=\"deleted\">$item</span>"; 00193 } 00194 00195 $edits = ''; 00196 if ( !$this->including && $this->getConfig()->get( 'Edititis' ) ) { 00197 $count = $this->msg( 'usereditcount' )->numParams( $row->edits )->escaped(); 00198 $edits = $this->msg( 'word-separator' )->escaped() . $this->msg( 'brackets', $count )->escaped(); 00199 } 00200 00201 $created = ''; 00202 # Some rows may be null 00203 if ( !$this->including && $row->creation ) { 00204 $user = $this->getUser(); 00205 $d = $lang->userDate( $row->creation, $user ); 00206 $t = $lang->userTime( $row->creation, $user ); 00207 $created = $this->msg( 'usercreated', $d, $t, $row->user_name )->escaped(); 00208 $created = ' ' . $this->msg( 'parentheses' )->rawParams( $created )->escaped(); 00209 } 00210 $blocked = !is_null( $row->ipb_deleted ) ? 00211 ' ' . $this->msg( 'listusers-blocked', $userName )->escaped() : 00212 ''; 00213 00214 wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) ); 00215 00216 return Html::rawElement( 'li', array(), "{$item}{$edits}{$created}{$blocked}" ); 00217 } 00218 00219 function doBatchLookups() { 00220 $batch = new LinkBatch(); 00221 # Give some pointers to make user links 00222 foreach ( $this->mResult as $row ) { 00223 $batch->add( NS_USER, $row->user_name ); 00224 $batch->add( NS_USER_TALK, $row->user_name ); 00225 } 00226 $batch->execute(); 00227 $this->mResult->rewind(); 00228 } 00229 00233 function getPageHeader() { 00234 list( $self ) = explode( '/', $this->getTitle()->getPrefixedDBkey() ); 00235 00236 # Form tag 00237 $out = Xml::openElement( 00238 'form', 00239 array( 'method' => 'get', 'action' => wfScript(), 'id' => 'mw-listusers-form' ) 00240 ) . 00241 Xml::fieldset( $this->msg( 'listusers' )->text() ) . 00242 Html::hidden( 'title', $self ); 00243 00244 # Username field 00245 $out .= Xml::label( $this->msg( 'listusersfrom' )->text(), 'offset' ) . ' ' . 00246 Html::input( 00247 'username', 00248 $this->requestedUser, 00249 'text', 00250 array( 00251 'id' => 'offset', 00252 'size' => 20, 00253 'autofocus' => $this->requestedUser === '' 00254 ) 00255 ) . ' '; 00256 00257 # Group drop-down list 00258 $out .= Xml::label( $this->msg( 'group' )->text(), 'group' ) . ' ' . 00259 Xml::openElement( 'select', array( 'name' => 'group', 'id' => 'group' ) ) . 00260 Xml::option( $this->msg( 'group-all' )->text(), '' ); 00261 foreach ( $this->getAllGroups() as $group => $groupText ) { 00262 $out .= Xml::option( $groupText, $group, $group == $this->requestedGroup ); 00263 } 00264 $out .= Xml::closeElement( 'select' ) . '<br />'; 00265 $out .= Xml::checkLabel( 00266 $this->msg( 'listusers-editsonly' )->text(), 00267 'editsOnly', 00268 'editsOnly', 00269 $this->editsOnly 00270 ); 00271 $out .= ' '; 00272 $out .= Xml::checkLabel( 00273 $this->msg( 'listusers-creationsort' )->text(), 00274 'creationSort', 00275 'creationSort', 00276 $this->creationSort 00277 ); 00278 $out .= ' '; 00279 $out .= Xml::checkLabel( 00280 $this->msg( 'listusers-desc' )->text(), 00281 'desc', 00282 'desc', 00283 $this->mDefaultDirection 00284 ); 00285 $out .= '<br />'; 00286 00287 wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) ); 00288 00289 # Submit button and form bottom 00290 $out .= Html::hidden( 'limit', $this->mLimit ); 00291 $out .= Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ); 00292 wfRunHooks( 'SpecialListusersHeader', array( $this, &$out ) ); 00293 $out .= Xml::closeElement( 'fieldset' ) . 00294 Xml::closeElement( 'form' ); 00295 00296 return $out; 00297 } 00298 00303 function getAllGroups() { 00304 $result = array(); 00305 foreach ( User::getAllGroups() as $group ) { 00306 $result[$group] = User::getGroupName( $group ); 00307 } 00308 asort( $result ); 00309 00310 return $result; 00311 } 00312 00317 function getDefaultQuery() { 00318 $query = parent::getDefaultQuery(); 00319 if ( $this->requestedGroup != '' ) { 00320 $query['group'] = $this->requestedGroup; 00321 } 00322 if ( $this->requestedUser != '' ) { 00323 $query['username'] = $this->requestedUser; 00324 } 00325 wfRunHooks( 'SpecialListusersDefaultQuery', array( $this, &$query ) ); 00326 00327 return $query; 00328 } 00329 00336 protected static function getGroups( $uid ) { 00337 $user = User::newFromId( $uid ); 00338 $groups = array_diff( $user->getEffectiveGroups(), User::getImplicitGroups() ); 00339 00340 return $groups; 00341 } 00342 00350 protected static function buildGroupLink( $group, $username ) { 00351 return User::makeGroupLinkHtml( 00352 $group, 00353 htmlspecialchars( User::getGroupMember( $group, $username ) ) 00354 ); 00355 } 00356 } 00357 00361 class SpecialListUsers extends IncludableSpecialPage { 00365 public function __construct() { 00366 parent::__construct( 'Listusers' ); 00367 } 00368 00374 public function execute( $par ) { 00375 $this->setHeaders(); 00376 $this->outputHeader(); 00377 00378 $up = new UsersPager( $this->getContext(), $par, $this->including() ); 00379 00380 # getBody() first to check, if empty 00381 $usersbody = $up->getBody(); 00382 00383 $s = ''; 00384 if ( !$this->including() ) { 00385 $s = $up->getPageHeader(); 00386 } 00387 00388 if ( $usersbody ) { 00389 $s .= $up->getNavigationBar(); 00390 $s .= Html::rawElement( 'ul', array(), $usersbody ); 00391 $s .= $up->getNavigationBar(); 00392 } else { 00393 $s .= $this->msg( 'listusers-noresult' )->parseAsBlock(); 00394 } 00395 00396 $this->getOutput()->addHTML( $s ); 00397 } 00398 00406 public function prefixSearchSubpages( $search, $limit = 10 ) { 00407 $subpages = User::getAllGroups(); 00408 return self::prefixSearchArray( $search, $limit, $subpages ); 00409 } 00410 00411 protected function getGroupName() { 00412 return 'users'; 00413 } 00414 } 00415 00421 class SpecialListAdmins extends SpecialRedirectToSpecial { 00422 function __construct() { 00423 parent::__construct( 'Listadmins', 'Listusers', 'sysop' ); 00424 } 00425 } 00426 00432 class SpecialListBots extends SpecialRedirectToSpecial { 00433 function __construct() { 00434 parent::__construct( 'Listbots', 'Listusers', 'bot' ); 00435 } 00436 }