Fix #770. Does mysql group_concat at application level. Hacked querypage to flush...
authorAntoine Musso <hashar@users.mediawiki.org>
Tue, 1 Feb 2005 02:02:14 +0000 (02:02 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Tue, 1 Feb 2005 02:02:14 +0000 (02:02 +0000)
includes/QueryPage.php
includes/SpecialListusers.php

index 2b72e35..46582f0 100644 (file)
@@ -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 = "<ol start='" . ( $offset + 1 ) . "' class='special'>";
+
                        # 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 .= "<li{$attr}>{$format}</li>\n";
                                }
                        }
+
+                       if($this->tryLastResult()) {
+                               // flush the very last result
+                               $obj = null;
+                               $format = $this->formatResult( $sk, $obj );
+                               if( $format ) {
+                                       $s .= "<li{$attr}>{$format}</li>\n";
+                               }
+                       }
+                       
                        $dbr->freeResult( $res );
                        $s .= '</ol>';
                        $wgOut->addHTML( $s );
index ddc77be..dcb19e2 100644 (file)
@@ -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.= '<option value="'.$agroup->group_id.'" '.$selected.'>'.$agroup->group_name.'</option>';
                }
                $out .= '</select> ';
@@ -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;
        }
 }