From: Brion Vibber Date: Tue, 12 Apr 2011 17:04:56 +0000 (+0000) Subject: Revert r84805: broke CentralAuth by removing base UsersPager class used in other... X-Git-Tag: 1.31.0-rc.0~30905 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=02f82927d24e60c83e9cc90b177a5234e9cb0963;p=lhc%2Fweb%2Fwiklou.git Revert r84805: broke CentralAuth by removing base UsersPager class used in other special pages --- diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index a4ee20e752..ab7e1acc48 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -680,7 +680,6 @@ $wgAutoloadLocalClasses = array( 'SpecialImport' => 'includes/specials/SpecialImport.php', 'SpecialListFiles' => 'includes/specials/SpecialListfiles.php', 'SpecialListGroupRights' => 'includes/specials/SpecialListgrouprights.php', - 'SpecialListUsers' => 'includes/specials/SpecialListusers.php', 'SpecialLockdb' => 'includes/specials/SpecialLockdb.php', 'SpecialLog' => 'includes/specials/SpecialLog.php', 'SpecialMergeHistory' => 'includes/specials/SpecialMergeHistory.php', @@ -717,6 +716,7 @@ $wgAutoloadLocalClasses = array( 'UploadForm' => 'includes/specials/SpecialUpload.php', 'UploadSourceField' => 'includes/specials/SpecialUpload.php', 'UserrightsPage' => 'includes/specials/SpecialUserrights.php', + 'UsersPager' => 'includes/specials/SpecialListusers.php', 'WantedCategoriesPage' => 'includes/specials/SpecialWantedcategories.php', 'WantedFilesPage' => 'includes/specials/SpecialWantedfiles.php', 'WantedPagesPage' => 'includes/specials/SpecialWantedpages.php', diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 44aaf569e7..5eea301ca4 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -134,7 +134,7 @@ class SpecialPage { 'Preferences' => 'SpecialPreferences', 'Contributions' => 'SpecialContributions', 'Listgrouprights' => 'SpecialListGroupRights', - 'Listusers' => 'SpecialListusers', + 'Listusers' => array( 'SpecialPage', 'Listusers' ), 'Listadmins' => array( 'SpecialRedirectToSpecial', 'Listadmins', 'Listusers', 'sysop' ), 'Listbots' => array( 'SpecialRedirectToSpecial', 'Listbots', 'Listusers', 'bot' ), 'Activeusers' => 'SpecialActiveUsers', diff --git a/includes/specials/SpecialListusers.php b/includes/specials/SpecialListusers.php index a682914d50..eabb92d77c 100644 --- a/includes/specials/SpecialListusers.php +++ b/includes/specials/SpecialListusers.php @@ -32,7 +32,7 @@ * * @ingroup SpecialPage */ -class SpecialListUsers extends QueryPage { +class UsersPager extends AlphabeticPager { function __construct( $par=null ) { global $wgRequest; @@ -61,62 +61,30 @@ class SpecialListUsers extends QueryPage { $this->requestedUser = $username->getText(); } } - - $this->limit = $wgRequest->getVal( 'limit' ); - $this->offset = $wgRequest->getVal( 'offset' ); - - parent::__construct( 'Listusers' ); + parent::__construct(); } - function isExpensive() { return false; } - function isCacheable() { return false; } - function isSyndicated() { return false; } - function sortDescending() { return false; } - - function openList( $offset ) { - return "\n\n"; - } - - function linkParameters() { - return array( - 'group' => $this->requestedGroup, - 'editsOnly' => $this->editsOnly, - 'creationSort' => $this->creationSort, - 'requestedUser' => $this->requestedUser, - ); + function getIndexField() { + return $this->creationSort ? 'user_id' : 'user_name'; } function getQueryInfo() { - global $wgUser; $dbr = wfGetDB( DB_SLAVE ); - $conds = $jconds = array(); - $tables = array( 'user' ); - + $conds = array(); // Don't show hidden names if( !$wgUser->isAllowed('hideuser') ) { - $tables[] = 'ipblocks'; $conds[] = 'ipb_deleted IS NULL'; - $jconds['ipblocks'] = array( 'LEFT JOIN', array( - # Unique index on (ipb_address,ipb_user,ipb_auto) - 'ipb_address = user_name', - 'ipb_user = user_id', - 'ipb_auto = 0', - 'ipb_deleted = 1', - ) ); } + $options = array(); + if( $this->requestedGroup != '' ) { - $tables[] = 'user_groups'; $conds['ug_group'] = $this->requestedGroup; - # Unique index on (ug_user,ug_group) - $jconds['user_groups'] = array( 'LEFT JOIN', 'user_id = ug_user' ); + } else { + //$options['USE INDEX'] = $this->creationSort ? 'PRIMARY' : 'user_name'; } - if( $this->requestedUser != '' ) { # Sorted either by account creation or name if( $this->creationSort ) { @@ -125,15 +93,28 @@ class SpecialListUsers extends QueryPage { $conds[] = 'user_name >= ' . $dbr->addQuotes( $this->requestedUser ); } } - if( $this->editsOnly ) { $conds[] = 'user_editcount > 0'; } + $options['GROUP BY'] = $this->creationSort ? 'user_id' : 'user_name'; + $query = array( - 'tables' => $tables, - 'fields' => '*', - 'join_conds' => $jconds, + 'tables' => array( 'user', 'user_groups', 'ipblocks'), + 'fields' => array( + $this->creationSort ? 'MAX(user_name) AS user_name' : 'user_name', + $this->creationSort ? 'user_id' : 'MAX(user_id) AS user_id', + 'MAX(user_editcount) AS edits', + 'COUNT(ug_group) AS numgroups', + 'MAX(ug_group) AS singlegroup', // the usergroup if there is only one + 'MIN(user_registration) AS creation', + 'MAX(ipb_deleted) AS ipb_deleted' // block/hide status + ), + 'options' => $options, + 'join_conds' => array( + 'user_groups' => array( 'LEFT JOIN', 'user_id=ug_user' ), + 'ipblocks' => array( 'LEFT JOIN', 'user_id=ipb_user AND ipb_deleted=1 AND ipb_auto=0' ), + ), 'conds' => $conds ); @@ -141,21 +122,16 @@ class SpecialListUsers extends QueryPage { return $query; } - function formatResult( $skin, $row ) { + function formatRow( $row ) { global $wgLang; - if ( $row->user_id == 0 ){ - #Bug 16487 - return false; - } + if ($row->user_id == 0) #Bug 16487 + return ''; - $user = User::newFromId( $row->user_id ); - $name = $skin->link( - $user->getUserpage(), - $user->getName() - ); + $userPage = Title::makeTitle( NS_USER, $row->user_name ); + $name = $this->getSkin()->link( $userPage, htmlspecialchars( $userPage->getText() ) ); - $groups_list = array_diff( $user->getEffectiveGroups(), $user->getImplicitGroups() ); + $groups_list = self::getGroups( $row->user_id ); if( count( $groups_list ) > 0 ) { $list = array(); foreach( $groups_list as $group ) @@ -166,7 +142,7 @@ class SpecialListUsers extends QueryPage { } $item = wfSpecialList( $name, $groups ); - if( isset( $row->ipb_deleted ) ) { + if( $row->ipb_deleted ) { $item = "$item"; } @@ -180,36 +156,29 @@ class SpecialListUsers extends QueryPage { $created = ''; # Some rows may be NULL - if( $row->user_registration ) { - $d = $wgLang->date( wfTimestamp( TS_MW, $row->user_registration ), true ); - $t = $wgLang->time( wfTimestamp( TS_MW, $row->user_registration ), true ); - $created = ' (' . wfMessage( 'usercreated', $d, $t ) . ')'; + if( $row->creation ) { + $d = $wgLang->date( wfTimestamp( TS_MW, $row->creation ), true ); + $t = $wgLang->time( wfTimestamp( TS_MW, $row->creation ), true ); + $created = ' (' . wfMsg( 'usercreated', $d, $t ) . ')'; + $created = htmlspecialchars( $created ); } wfRunHooks( 'SpecialListusersFormatRow', array( &$item, $row ) ); - return "{$item}{$edits}{$created}"; - } - - function getOrderFields() { - return $this->creationSort ? array( 'user_id' ) : array( 'user_name' ); + return "
  • {$item}{$edits}{$created}
  • "; } - /** - * Cache page existence for performance - */ - function preprocessResults( $db, $res ) { + function getBody() { + if( !$this->mQueryDone ) { + $this->doQuery(); + } + $this->mResult->rewind(); $batch = new LinkBatch; - foreach ( $res as $row ) { - $batch->add( NS_USER, $row->user_name ); - $batch->add( NS_USER_TALK, $row->user_name ); + foreach ( $this->mResult as $row ) { + $batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) ); } $batch->execute(); - - // Back to start for display - if ( $db->numRows( $res ) > 0 ) { - // If there are no rows we get an error seeking. - $db->dataSeek( $res, 0 ); - } + $this->mResult->rewind(); + return parent::getBody(); } function getPageHeader( ) { @@ -229,16 +198,8 @@ class SpecialListUsers extends QueryPage { $out .= Xml::label( wfMsg( 'group' ), 'group' ) . ' ' . Xml::openElement('select', array( 'name' => 'group', 'id' => 'group' ) ) . Xml::option( wfMsg( 'group-all' ), '' ); - - $groups = array_unique( array_diff( User::getAllGroups(), array( '*', 'user' ) ) ); - foreach( $groups as $group ){ - $out .= Xml::option( - User::getGroupName( $group ), - $group, - $group == $this->requestedGroup - ); - } - + foreach( $this->getAllGroups() as $group => $groupText ) + $out .= Xml::option( $groupText, $group, $group == $this->requestedGroup ); $out .= Xml::closeElement( 'select' ) . '
    '; $out .= Xml::checkLabel( wfMsg('listusers-editsonly'), 'editsOnly', 'editsOnly', $this->editsOnly ); $out .= ' '; @@ -248,7 +209,7 @@ class SpecialListUsers extends QueryPage { wfRunHooks( 'SpecialListusersHeaderForm', array( $this, &$out ) ); # Submit button and form bottom - $out .= Html::hidden( 'limit', $this->limit ); + $out .= Html::hidden( 'limit', $this->mLimit ); $out .= Xml::submitButton( wfMsg( 'allpagessubmit' ) ); wfRunHooks( 'SpecialListusersHeader', array( $this, &$out ) ); $out .= Xml::closeElement( 'fieldset' ) . @@ -257,6 +218,45 @@ class SpecialListUsers extends QueryPage { return $out; } + /** + * Get a list of all explicit groups + * @return array + */ + function getAllGroups() { + $result = array(); + foreach( User::getAllGroups() as $group ) { + $result[$group] = User::getGroupName( $group ); + } + asort( $result ); + return $result; + } + + /** + * Preserve group and username offset parameters when paging + * @return array + */ + 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; + } + + /** + * Get a list of groups the specified user belongs to + * + * @param $uid Integer: user id + * @return array + */ + 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 * Also called by SpecialActiveUsers @@ -269,4 +269,28 @@ class SpecialListUsers extends QueryPage { $cache[$group] = User::makeGroupLinkHtml( $group, htmlspecialchars( User::getGroupMember( $group ) ) ); return $cache[$group]; } -} \ No newline at end of file +} + +/** + * constructor + * $par string (optional) A group to list users from + */ +function wfSpecialListusers( $par = null ) { + global $wgOut; + + $up = new UsersPager($par); + + # getBody() first to check, if empty + $usersbody = $up->getBody(); + $s = Xml::openElement( 'div', array('class' => 'mw-spcontent') ); + $s .= $up->getPageHeader(); + if( $usersbody ) { + $s .= $up->getNavigationBar(); + $s .= ''; + $s .= $up->getNavigationBar() ; + } else { + $s .= '

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

    '; + }; + $s .= Xml::closeElement( 'div' ); + $wgOut->addHTML( $s ); +}