From cc9f2dcf72da32dd15d215f61cef2548768dc586 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Tue, 1 Feb 2005 02:02:14 +0000 Subject: [PATCH] Fix #770. Does mysql group_concat at application level. Hacked querypage to flush out last result (see tryLastResult() to enable the hack). --- includes/QueryPage.php | 21 +++++++++++++ includes/SpecialListusers.php | 56 +++++++++++++++++++++++++++-------- 2 files changed, 64 insertions(+), 13 deletions(-) diff --git a/includes/QueryPage.php b/includes/QueryPage.php index 2b72e35c68..46582f0983 100644 --- a/includes/QueryPage.php +++ b/includes/QueryPage.php @@ -91,6 +91,16 @@ class QueryPage { function getPageHeader( ) { return ''; } + + /** + * Some special pages (for example SpecialListusers) might not return the + * current object formatted, but return the previous one instead. + * Setting this to return true, will call one more time wfFormatResult to + * be sure that the very last result is formatted and shown. + */ + function tryLastResult( ) { + return false; + } /** * This is the actual workhorse. It does everything needed to make a @@ -183,6 +193,7 @@ class QueryPage { if ( $num > 0 ) { $s = "
    "; + # Only read at most $num rows, because $res may contain the whole 1000 for ( $i = 0; $i < $num && $obj = $dbr->fetchObject( $res ); $i++ ) { $format = $this->formatResult( $sk, $obj ); @@ -192,6 +203,16 @@ class QueryPage { $s .= "{$format}\n"; } } + + if($this->tryLastResult()) { + // flush the very last result + $obj = null; + $format = $this->formatResult( $sk, $obj ); + if( $format ) { + $s .= "{$format}\n"; + } + } + $dbr->freeResult( $res ); $s .= '
'; $wgOut->addHTML( $s ); diff --git a/includes/SpecialListusers.php b/includes/SpecialListusers.php index ddc77be2b9..dcb19e25a2 100644 --- a/includes/SpecialListusers.php +++ b/includes/SpecialListusers.php @@ -27,7 +27,7 @@ /** * */ -require_once("QueryPage.php"); +require_once('QueryPage.php'); /** * This class is used to get a list of user. The ones with specials @@ -40,9 +40,11 @@ require_once("QueryPage.php"); class ListUsersPage extends QueryPage { var $requestedGroup = ''; var $requestedUser = ''; - + var $previousResult = false; + var $concatGroups = ''; + function getName() { - return "Listusers"; + return 'Listusers'; } function isSyndicated() { return false; } @@ -75,7 +77,7 @@ class ListUsersPage extends QueryPage { // build the dropdown list menu using datas from the database while($agroup = $dbr->fetchObject( $result )) { - $selected = ($agroup->group_id == $this->requestedGroup) ? " selected " : "" ; + $selected = ($agroup->group_id == $this->requestedGroup) ? ' selected ' : '' ; $out.= ''; } $out .= ' '; @@ -104,35 +106,63 @@ class ListUsersPage extends QueryPage { $userspace = Namespace::getUser(); $sql = "SELECT group_name as type, $userspace AS namespace, user_name AS title, user_name as value " . - "FROM $user LEFT JOIN $user_groups ON user_id =ug_user " . + "FROM $user ". + "LEFT JOIN $user_groups ON user_id =ug_user " . "LEFT JOIN $group ON ug_group = group_id "; - + if($this->requestedGroup != '') { $sql .= "WHERE group_id= '" . IntVal( $this->requestedGroup ) . "' "; if($this->requestedUser != '') { - $sql .= "AND user_name = " . $dbr->addQuotes( $this->requestedUser ) . " "; + $sql .= "AND user_name = " . $dbr->addQuotes( $this->requestedUser ) . ' '; } } else { if($this->requestedUser !='') { - $sql .= "WHERE user_name = " . $dbr->addQuotes( $this->requestedUser ) . " "; + $sql .= "WHERE user_name = " . $dbr->addQuotes( $this->requestedUser ) . ' '; } } return $sql; } + /** + * When calling formatResult we output the previous result instead of the + * current one. We need an additional step to flush out the last result. + */ + function tryLastResult( ) { + return true; + } + function sortDescending() { return false; } + function appendGroups($group) { + $this->concatGroups .= $group.' '; + } + + function clearGroups() { + $this->concatGroups = ''; + } +/* + var $previousResult = false; + var $concatGroups = ''; +*/ function formatResult( $skin, $result ) { global $wgContLang; - $name = $skin->makeLink( $wgContLang->getNsText($result->namespace) . ':' . $result->title, $result->title ); - if( '' != $result->type ) { - $name .= ' (' . - $skin->makeLink( wfMsgForContent( 'administrators' ), $result->type) . - ')'; + $name = false; + + if($this->previousResult->title != $result->title && $this->previousResult != false) { + // Different username, give back name(group1,group2) + $name = $skin->makeLink( $wgContLang->getNsText($this->previousResult->namespace) . ':' . $this->previousResult->title, $this->previousResult->title ); + $name .= $this->concatGroups ? '('.substr($this->concatGroups,0,-1).')' : ''; + $this->clearGroups(); } + + if($result->type != '') { + $this->appendGroups( $skin->makeLink( wfMsgForContent( 'administrators' ), $result->type ) ); + } + + $this->previousResult = $result; return $name; } } -- 2.20.1