? .bzr ? lower_10.patch ? lower_11.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 3 Nov 2007 14:44:18 -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 3 Nov 2007 14:44:21 -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 3 Nov 2007 14:44:28 -0000 @@ -251,7 +251,7 @@ function system_install() { // presumed to be a serialized array. Install will change uid 1 immediately // anyways. So we insert the superuser here, the uid is 2 here for now, but // very soon it will be changed to 1. - db_query("INSERT INTO {users} (name, mail, created, data) VALUES('%s', '%s', %d, '%s')", 'placeholder-for-uid-1', 'placeholder-for-uid-1', time(), serialize(array())); + db_query("INSERT INTO {users} (name, name_lower, mail, created, data) VALUES('%s', '%s', '%s', %d, '%s')", 'placeholder-for-uid-1', 'placeholder-for-uid-1', 'placeholder-for-uid-1', time(), serialize(array())); // This sets the above two users to 1 -1 = 0 (anonymous) and // 2- 1 = 1 (superuser). We skip uid 2 but that's not a big problem. db_query('UPDATE {users} SET uid = uid - 1'); @@ -4455,6 +4455,71 @@ 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('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')); + db_add_index($ret, 'term_data', 'name_lower', array('name_lower')); + } + return $ret; +} +function system_update_6036() { + $ret = array(); + db_add_field($ret, 'users', 'name_lower', array('type' => 'varchar', 'length' => 60, 'not null' => TRUE, 'default' => '')); + return $ret; +} + +function _system_update_6036_strtolower($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; + $sql = 'UPDATE {'. $table_name ."} SET $lower_name = '%s'"; + if ($table_name == 'users') { + $sql .= ", mail = '%s', init = '%s'"; + $fields = "$field_name, mail, init, $id"; + } + else { + $fields = "$field_name, $id"; + + } + $sql .= " WHERE $id = %d"; + $result = db_query_range("SELECT $fields FROM {". $table_name ."} WHERE $id > %d ORDER BY $id ASC", $_SESSION['system_update_'. $update_id], 0, $limit); + while ($a = db_fetch_array($result)) { + db_query($sql, array_map('strtolower', $a)); + ++$_SESSION['system_update_'. $update_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_strtolower(6037, 'users', 'uid'); +} + +function system_update_6038() { + $ret = array(); + db_add_unique_key($ret, 'users', 'name_lower', array('name_lower')); + db_drop_unique_key($ret, 'users', 'name'); + return $ret; +} + +function system_update_6039() { + if (db_table_exists('term_data')) { + return _system_update_6036_strtolower(6039, 'term_data', 'tid'); + } +} + +function system_update_6040() { + return _system_update_6036_strtolower(6040, '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 3 Nov 2007 14:44:28 -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, @@ -43,7 +50,10 @@ function taxonomy_schema() { ), ), 'primary key' => array('tid'), - 'indexes' => array('vid' => array('vid')), + 'indexes' => array( + 'vid' => array('vid'), + 'name_lower' => array('name_lower'), + ), ); $schema['term_hierarchy'] = array( 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 3 Nov 2007 14:44:29 -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 3 Nov 2007 14:44:29 -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 3 Nov 2007 14:44:31 -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 != $edit['mask']) { + drupal_set_message(t('For performance 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 != $edit['mask']) { + drupal_set_message(t('For performance 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 3 Nov 2007 14:44:31 -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, @@ -252,9 +259,11 @@ function user_schema() { ), 'indexes' => array( 'access' => array('access'), - 'created' => array('created') + 'created' => array('created'), + ), + 'unique keys' => array( + 'name_lower' => array('name_lower'), ), - 'unique keys' => array('name' => array('name')), 'primary key' => array('uid'), ); @@ -281,4 +290,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 3 Nov 2007 14:44:35 -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 + // is not worth it. + case 'signature': + $query[] = "LOWER($key) = LOWER('%s')"; + $params[] = $value; + case 'name': + $key = 'name_lower'; + // fall through. + 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); @@ -287,6 +316,12 @@ function user_save($account, $array = ar $values[] = $value; $s[] = "%d"; break; + case 'mail': + case 'init': + $fields[] = $key; + $values[] = strtolower($value); + $s[] = "'%s'"; + break; default: if (substr($key, 0, 4) !== 'auth' && in_array($key, $user_fields)) { $fields[] = $key; @@ -471,9 +506,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 +561,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 +1394,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 +1406,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. Have you forgotten your password?', array('%email' => $edit['mail'], '@password' => url('user/password')))); } else if (drupal_is_denied('mail', $edit['mail'])) { @@ -2055,7 +2088,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)); } Index: modules/user/user.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.pages.inc,v retrieving revision 1.3 diff -u -p -r1.3 user.pages.inc --- modules/user/user.pages.inc 27 Oct 2007 14:01:12 -0000 1.3 +++ modules/user/user.pages.inc 3 Nov 2007 14:44:35 -0000 @@ -12,7 +12,7 @@ function user_autocomplete($string = '') { $matches = array(); if ($string) { - $result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER('%s%%')", $string, 0, 10); + $result = db_query_range("SELECT name FROM {users} WHERE name_lower LIKE '%s%%'", strtolower($string), 0, 10); while ($user = db_fetch_object($result)) { $matches[$user->name] = check_plain($user->name); }