PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
authorDan
Sun, 06 Dec 2009 21:51:32 -0500
changeset 1147 7ddd475bc661
parent 1146 4a90e6e46937
child 1148 dcf6e9394e02
PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
includes/dbal.php
includes/namespaces/user.php
--- a/includes/dbal.php	Sun Dec 06 18:22:02 2009 -0500
+++ b/includes/dbal.php	Sun Dec 06 21:51:32 2009 -0500
@@ -511,6 +511,28 @@
     return mysql_affected_rows();
   }
   
+  /**
+   * Get a list of columns in the given table
+   * @param string Table
+   * @return array
+   */
+  
+  function columns_in($table)
+  {
+    if ( !is_string($table) )
+      return false;
+    $q = $this->sql_query("SHOW COLUMNS IN $table;");
+    if ( !$q )
+      $this->_die();
+    
+    $columns = array();
+    while ( $row = $this->fetchrow_num() )
+    {
+      $columns[] = $row[0];
+    }
+    return $columns;
+  }
+  
   function sql_type_cast(&$value)
 	{
 		if ( is_float($value) )
@@ -1219,6 +1241,30 @@
     return pg_affected_rows();
   }
   
+  /**
+   * Get a list of columns in the given table
+   * @param string Table
+   * @return array
+   */
+  
+  function columns_in($table)
+  {
+    if ( !is_string($table) )
+      return false;
+    $q = $this->sql_query("SELECT * FROM $table LIMIT 1 OFFSET 0;");
+    if ( !$q )
+      $this->_die();
+    if ( $this->numrows() < 1 )
+    {
+      // FIXME: Have another way to do this if the table is empty
+      return false;
+    }
+    
+    $row = $this->fetchrow();
+    $this->free_result();
+    return array_keys($row);
+  }
+  
   function sql_type_cast(&$value)
 	{
 		if ( is_float($value) )
--- a/includes/namespaces/user.php	Sun Dec 06 18:22:02 2009 -0500
+++ b/includes/namespaces/user.php	Sun Dec 06 21:51:32 2009 -0500
@@ -82,6 +82,8 @@
     $target_username = preg_replace('/^' . str_replace('/', '\\/', preg_quote($paths->nslist['User'])) . '/', '', $target_username);
     list($target_username) = explode('/', $target_username);
     
+    $ux_columns = $db->columns_in(table_prefix . 'users_extra');
+    
     $output->set_title($this->title);
     $q = $db->sql_query('SELECT u.username, u.user_id AS authoritative_uid, u.real_name, u.email, u.reg_time, u.user_has_avatar, u.avatar_type, x.*, COUNT(c.comment_id) AS n_comments
                            FROM '.table_prefix.'users u
@@ -90,7 +92,7 @@
                            LEFT JOIN '.table_prefix.'comments AS c
                              ON ( ( c.user_id=u.user_id AND c.name=u.username AND c.approved=1 ) OR ( c.comment_id IS NULL AND c.approved IS NULL ) )
                            WHERE u.username=\'' . $db->escape($target_username) . '\'
-                           GROUP BY u.username, u.user_id, u.real_name, u.email, u.reg_time, u.user_has_avatar, u.avatar_type, x.user_id, x.user_aim, x.user_yahoo, x.user_msn, x.user_xmpp, x.user_homepage, x.user_location, x.user_job, x.user_hobbies, x.email_public;');
+                           GROUP BY u.username, u.user_id, u.real_name, u.email, u.reg_time, u.user_has_avatar, u.avatar_type, x.' . implode(', x.', $ux_columns) . ';');
     if ( !$q )
       $db->_die();