? lower_3.patch
? sites/pgsql.drupal.cvs
? sites/all/modules
? sites/default/files
? sites/default/settings.php
Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.198
diff -u -p -r1.198 bootstrap.inc
--- includes/bootstrap.inc	25 Oct 2007 15:38:24 -0000	1.198
+++ includes/bootstrap.inc	1 Nov 2007 19:46:53 -0000
@@ -831,7 +831,7 @@ function drupal_is_denied($type, $mask) 
   // these, we return 1 (denied). If no matching records or only ones
   // with status = 1, we get no return from db_result, so we return
   // (bool)NULL = 0 (allowed).
-  return (bool) db_result(db_query_range("SELECT 1 FROM {access} WHERE type = '%s' AND LOWER('%s') LIKE LOWER(mask) AND status = 0", $type, $mask, 0, 1));
+  return (bool) db_result(db_query_range("SELECT 1 FROM {access} WHERE type = '%s' AND '%s' LIKE mask AND status = 0", $type, strtolower($mask), 0, 1));
 }
 
 /**
Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.597
diff -u -p -r1.597 comment.module
--- modules/comment/comment.module	31 Oct 2007 17:50:47 -0000	1.597
+++ modules/comment/comment.module	1 Nov 2007 19:46:56 -0000
@@ -1132,7 +1132,7 @@ function comment_validate($edit) {
     $node = node_load($edit['nid']);
     if (variable_get('comment_anonymous_'. $node->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT) > COMMENT_ANONYMOUS_MAYNOT_CONTACT) {
       if ($edit['name']) {
-        $taken = db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE LOWER(name) = '%s'", $edit['name']));
+        $taken = db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE name_lower = '%s'", strtolower($edit['name'])));
 
         if ($taken != 0) {
           form_set_error('name', t('The name you used belongs to a registered user.'));
Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.167
diff -u -p -r1.167 system.install
--- modules/system/system.install	25 Oct 2007 20:41:16 -0000	1.167
+++ modules/system/system.install	1 Nov 2007 19:47:02 -0000
@@ -4455,6 +4455,56 @@ function system_update_6034() {
   return $ret;
 }
 
+function system_update_6035() {
+  $ret = array();
+  if (db_table_exists('term_data')) {
+    db_add_field($ret, 'term_data', 'name_lower', array('name' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
+    db_add_unique_key($ret, 'term_data', 'name_lower', array('name_lower'));
+  }
+  return $ret;
+}
+function system_update_6036() {
+  $ret = array();
+  db_add_field($ret, 'users', 'name_lower', array('name' => 'varchar', 'length' => 60, 'not null' => TRUE, 'default' => ''));
+  db_add_unique_key($ret, 'users', 'name_lower', array('name_lower'));
+  return $ret;
+}
+
+function _system_update_6036_strotolower($update_id, $table_name, $id, $field_name = 'name', $lower_name = 'name_lower') {
+  // Multi-part update. This must be done in PHP to avoid UTF-8 issues.
+  if (!isset($_SESSION['system_update_'. $update_id])) {
+    $_SESSION['system_update_'. $update_id] = 0;
+    $_SESSION['system_update_'. $update_id .'_max'] = db_result(db_query("SELECT MAX($id) FROM {". $table_name .'}'));
+  }
+  $limit = 20;
+  $result = db_query_range("SELECT $id AS id, $field_name AS name FROM {". $table_name ."} WHERE $id > %d ORDER BY $id ASC", $_SESSION['system_update_'. $update_id], 0, $limit);
+  while ($o = db_fetch_object($result)) {
+    db_query('UPDATE {'. $table_name ."} SET $lower_name = '%s' WHERE $id = %d", strtolower($o->name), $o->id);
+  }
+  if ($_SESSION['system_update_'. $update_id] == $_SESSION['system_update_'. $update_id .'_max']) {
+    unset($_SESSION['system_update_'. $update_id]);
+    unset($_SESSION['system_update_'. $update_id .'_max']);
+    return array();
+  }
+  return array('#finished' => $_SESSION['system_update_'. $update_id] / $_SESSION['system_update_'. $update_id .'_max']);
+}
+
+function system_update_6037() {
+  return _system_update_6036_strotolower(6037, 'users', 'uid');
+}
+
+function system_update_6038() {
+  if (db_table_exists('term_data')) {
+    return _system_update_6036_strotolower(6038, 'term_data', 'tid');
+  }
+}
+
+function system_update_6039() {
+  if (db_table_exists('term_data')) {
+    return _system_update_6036_strotolower(6039, 'access', 'aid', 'mask', 'mask');
+  }
+}
+
 /**
  * @} End of "defgroup updates-5.x-to-6.x"
  * The next series of updates should start at 7000.
Index: modules/taxonomy/taxonomy.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.install,v
retrieving revision 1.4
diff -u -p -r1.4 taxonomy.install
--- modules/taxonomy/taxonomy.install	21 Oct 2007 18:59:02 -0000	1.4
+++ modules/taxonomy/taxonomy.install	1 Nov 2007 19:47:03 -0000
@@ -28,6 +28,13 @@ function taxonomy_schema() {
         'default' => '',
         'description' => t('The term name.'),
       ),
+      'name_lower' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+        'description' => t('The term name in lowercase.'),
+      ),
       'description' => array(
         'type' => 'text',
         'not null' => FALSE,
Index: modules/taxonomy/taxonomy.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v
retrieving revision 1.385
diff -u -p -r1.385 taxonomy.module
--- modules/taxonomy/taxonomy.module	27 Oct 2007 13:39:07 -0000	1.385
+++ modules/taxonomy/taxonomy.module	1 Nov 2007 19:47:04 -0000
@@ -233,6 +233,7 @@ function taxonomy_save_term(&$form_value
     'weight' => 0
   );
 
+  $form_values['name_lower'] = strtolower($form_values['name']);
   if (!empty($form_values['tid']) && $form_values['name']) {
     drupal_write_record('term_data', $form_values, 'tid');
     $hook = 'update';
@@ -830,7 +831,7 @@ function _taxonomy_term_children($tid) {
  *   An array of matching term objects.
  */
 function taxonomy_get_term_by_name($name) {
-  $db_result = db_query(db_rewrite_sql("SELECT t.tid, t.* FROM {term_data} t WHERE LOWER(t.name) LIKE LOWER('%s')", 't', 'tid'), trim($name));
+  $db_result = db_query(db_rewrite_sql("SELECT t.tid, t.* FROM {term_data} t WHERE t.name_lower LIKE '%s'", 't', 'tid'), strtolower(trim($name)));
   $result = array();
   while ($term = db_fetch_object($db_result)) {
     $result[] = $term;
Index: modules/taxonomy/taxonomy.pages.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.pages.inc,v
retrieving revision 1.3
diff -u -p -r1.3 taxonomy.pages.inc
--- modules/taxonomy/taxonomy.pages.inc	25 Oct 2007 08:24:43 -0000	1.3
+++ modules/taxonomy/taxonomy.pages.inc	1 Nov 2007 19:47:04 -0000
@@ -81,7 +81,7 @@ function taxonomy_autocomplete($vid, $st
   $last_string = trim(array_pop($array));
   $matches = array();
   if ($last_string != '') {
-    $result = db_query_range(db_rewrite_sql("SELECT t.tid, t.name FROM {term_data} t WHERE t.vid = %d AND LOWER(t.name) LIKE LOWER('%%%s%%')", 't', 'tid'), $vid, $last_string, 0, 10);
+    $result = db_query_range(db_rewrite_sql("SELECT t.tid, t.name FROM {term_data} t WHERE t.vid = %d AND t.name_lower LIKE '%%%s%%'", 't', 'tid'), $vid, strtolower($last_string), 0, 10);
 
     $prefix = count($array) ? implode(', ', $array) .', ' : '';
 
Index: modules/user/user.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.admin.inc,v
retrieving revision 1.8
diff -u -p -r1.8 user.admin.inc
--- modules/user/user.admin.inc	27 Oct 2007 15:28:43 -0000	1.8
+++ modules/user/user.admin.inc	1 Nov 2007 19:47:06 -0000
@@ -717,6 +717,11 @@ function user_admin_access_check() {
  */
 function user_admin_access_add($mask = NULL, $type = NULL) {
   if ($edit = $_POST) {
+    $lower_mask = strtolower($edit['mask']);
+    if ($lower_mask != strtolower($edit['mask'])) {
+      drupal_set_message(t('For speed reasons, Drupal stores access rules in lower case. %mask was changed to %lower_mask,', array('%mask' => $edit['mask'], '%lower_mask' => $lower_mask)));
+      $edit['mask'] = $lower_mask;
+    }
     if (!$edit['mask']) {
       form_set_error('mask', t('You must enter a mask.'));
     }
@@ -739,6 +744,11 @@ function user_admin_access_add($mask = N
  */
 function user_admin_access_edit($aid = 0) {
   if ($edit = $_POST) {
+    $lower_mask = strtolower($edit['mask']);
+    if ($lower_mask != strtolower($edit['mask'])) {
+      drupal_set_message(t('For speed reasons, Drupal stores access rules in lower case. %mask was changed to %lower_mask,', array('%mask' => $edit['mask'], '%lower_mask' => $lower_mask)));
+      $edit['mask'] = $lower_mask;
+    }
     if (!$edit['mask']) {
       form_set_error('mask', t('You must enter a mask.'));
     }
Index: modules/user/user.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.install,v
retrieving revision 1.2
diff -u -p -r1.2 user.install
--- modules/user/user.install	10 Oct 2007 11:39:35 -0000	1.2
+++ modules/user/user.install	1 Nov 2007 19:47:06 -0000
@@ -142,6 +142,13 @@ function user_schema() {
         'default' => '',
         'description' => t('Unique user name.'),
       ),
+      'name_lower' => array(
+        'type' => 'varchar',
+        'length' => 60,
+        'not null' => TRUE,
+        'default' => '',
+        'description' => t('User name in lowercase.'),
+      ),
       'pass' => array(
         'type' => 'varchar',
         'length' => 32,
@@ -281,4 +288,3 @@ function user_schema() {
 
   return $schema;
 }
-
Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.857
diff -u -p -r1.857 user.module
--- modules/user/user.module	27 Oct 2007 14:01:12 -0000	1.857
+++ modules/user/user.module	1 Nov 2007 19:47:09 -0000
@@ -144,17 +144,26 @@ function user_load($array = array()) {
   }
 
   foreach ($array as $key => $value) {
-    if ($key == 'uid' || $key == 'status') {
-      $query[] = "$key = %d";
-      $params[] = $value;
-    }
-    else if ($key == 'pass') {
-      $query[] = "pass = '%s'";
-      $params[] = md5($value);
-    }
-    else {
-      $query[]= "LOWER($key) = LOWER('%s')";
-      $params[] = $value;
+    switch ($key) {
+      case 'uid': case 'status':
+        $query[] = "$key = %d";
+        $params[] = $value;
+        break;
+      case 'pass':
+        $query[] = "pass = '%s'";
+        $params[] = md5($value);
+        break;
+      // Loading by signature is rare enough that storing a lowercase version
+      // does not worth it.
+      case 'signature':
+        $query[] = "LOWER($key) = LOWER('%s')";
+        $params[] = $value;
+      case 'name':
+        $key = 'name_lower';
+        // fail over.
+      default:
+        $query[] = "$key = '%s'";
+        $params[] = strtolower($value);
     }
   }
   $result = db_query('SELECT * FROM {users} u WHERE '. implode(' AND ', $query), $params);
@@ -212,7 +221,19 @@ function user_save($account, $array = ar
         if (in_array($key, $user_fields)) {
           // Save standard fields
           $query .= "$key = '%s', ";
-          $v[] = $value;
+          switch ($key) {
+            case 'name':
+              $query .= "name_lower = '%s', ";
+              $v[] = $value;
+              $v[] = strtolower($value);
+              break;
+            case 'signature':
+              $v[] = $value;
+              break;
+            default:
+              $v[] = strtolower($value);
+              break;
+          }
         }
         else if ($key != 'roles') {
           // Roles is a special case: it used below.
@@ -275,6 +296,14 @@ function user_save($account, $array = ar
     // because we don't have a fully initialized user object yet.
     foreach ($array as $key => $value) {
       switch ($key) {
+        case 'name':
+          $fields[] = $key;
+          $values[] = $value;
+          $s[] = "'%s'";
+          $fields[] = 'name_lower';
+          $values[] = strtolower($value);
+          $s[] = "'%s'";
+          break;
         case 'pass':
           $fields[] = $key;
           $values[] = md5($value);
@@ -471,9 +500,7 @@ function user_access($string, $account =
  * @return boolean TRUE for blocked users, FALSE for active
  */
 function user_is_blocked($name) {
-  $deny  = db_fetch_object(db_query("SELECT name FROM {users} WHERE status = 0 AND name = LOWER('%s')", $name));
-
-  return $deny;
+  return db_fetch_object(db_query("SELECT name FROM {users} WHERE status = 0 AND name_lower = '%s'", strtolower($name)));
 }
 
 function user_fields() {
@@ -528,13 +555,13 @@ function user_search($op = 'search', $ke
         $keys = preg_replace('!\*+!', '%', $keys);
         if (user_access('administer users')) {
           // Administrators can also search in the otherwise private email field.
-          $result = pager_query("SELECT name, uid, mail FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%') OR LOWER(mail) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys, $keys);
+          $result = pager_query("SELECT name, uid, mail FROM {users} WHERE name_lower LIKE '%%%s%%' OR mail LIKE '%%%s%%'", 15, 0, NULL, strtolower($keys), strtolower($keys));
           while ($account = db_fetch_object($result)) {
             $find[] = array('title' => $account->name .' ('. $account->mail .')', 'link' => url('user/'. $account->uid, array('absolute' => TRUE)));
           }
         }
         else {
-          $result = pager_query("SELECT name, uid FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys);
+          $result = pager_query("SELECT name, uid FROM {users} WHERE name_lower LIKE '%%%s%%'", 15, 0, NULL, strtolower($keys));
           while ($account = db_fetch_object($result)) {
             $find[] = array('title' => $account->name, 'link' => url('user/'. $account->uid, array('absolute' => TRUE)));
           }
@@ -1361,7 +1388,7 @@ function _user_edit_validate($uid, &$edi
     if ($error = user_validate_name($edit['name'])) {
       form_set_error('name', $error);
     }
-    else if (db_result(db_query("SELECT COUNT(*) FROM {users} WHERE uid != %d AND LOWER(name) = LOWER('%s')", $uid, $edit['name'])) > 0) {
+    else if (db_result(db_query("SELECT COUNT(*) FROM {users} WHERE uid != %d AND name_lower = '%s'", $uid, strtolower($edit['name']))) > 0) {
       form_set_error('name', t('The name %name is already taken.', array('%name' => $edit['name'])));
     }
     else if (drupal_is_denied('user', $edit['name'])) {
@@ -1373,7 +1400,7 @@ function _user_edit_validate($uid, &$edi
   if ($error = user_validate_mail($edit['mail'])) {
     form_set_error('mail', $error);
   }
-  else if (db_result(db_query("SELECT COUNT(*) FROM {users} WHERE uid != %d AND LOWER(mail) = LOWER('%s')", $uid, $edit['mail'])) > 0) {
+  else if (db_result(db_query("SELECT COUNT(*) FROM {users} WHERE uid != %d AND mail = '%s'", $uid, strtolower($edit['mail']))) > 0) {
     form_set_error('mail', t('The e-mail address %email is already registered. <a href="@password">Have you forgotten your password?</a>', array('%email' => $edit['mail'], '@password' => url('user/password'))));
   }
   else if (drupal_is_denied('mail', $edit['mail'])) {
@@ -2055,7 +2082,7 @@ function user_block_user_action(&$object
  */
 function user_block_ip_action() {
   $ip = ip_address();
-  db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', '%s', %d)", $ip, 'host', 0);
+  db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', '%s', %d)", strtolower($ip), 'host', 0);
   watchdog('action', 'Banned IP address %ip', array('%ip' => $ip));
 }
 
