Index: modules/archive.module =================================================================== RCS file: /cvs/drupal/drupal/modules/archive.module,v retrieving revision 1.80 diff -u -F^f -r1.80 archive.module --- modules/archive.module 24 Apr 2005 16:34:32 -0000 1.80 +++ modules/archive.module 1 Jul 2005 17:06:28 -0000 @@ -246,7 +246,7 @@ function archive_page($year = 0, $month $result = db_query_range($sql, $date, $date_end, 0, 20); while ($nid = db_fetch_object($result)) { - $output .= node_view(node_load(array('nid' => $nid->nid)), 1); + $output .= node_view(node_load($nid->nid), 1); } } return $output; Index: modules/blogapi.module =================================================================== RCS file: /cvs/drupal/drupal/modules/blogapi.module,v retrieving revision 1.44 diff -u -F^f -r1.44 blogapi.module --- modules/blogapi.module 6 Jun 2005 18:59:37 -0000 1.44 +++ modules/blogapi.module 1 Jul 2005 17:06:29 -0000 @@ -177,7 +177,7 @@ function blogapi_edit_post($req_params) return blogapi_error($user); } - $node = node_load(array('nid' => $params[0])); + $node = node_load($params[0]); if (!$node) { return blogapi_error(message_na()); } @@ -234,7 +234,7 @@ function blogapi_get_post($req_params) { return blogapi_error($user); } - $node = node_load(array('nid' => $params[0])); + $node = node_load($params[0]); $blog = _blogapi_get_post($node, true); @@ -433,7 +433,7 @@ function blogapi_publish_post($req_param $params = blogapi_convert($req_params); $user = blogapi_validate_user($params[1], $params[2]); - $node = node_load(array('nid' => $params[0])); + $node = node_load($params[0]); if (!$node) { return blogapi_error(t('Invalid post.')); } Index: modules/blog.module =================================================================== RCS file: /cvs/drupal/drupal/modules/blog.module,v retrieving revision 1.217 diff -u -F^f -r1.217 blog.module --- modules/blog.module 31 May 2005 21:14:26 -0000 1.217 +++ modules/blog.module 1 Jul 2005 17:06:29 -0000 @@ -143,7 +143,7 @@ function blog_page_user($uid) { $result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n WHERE type = 'blog' AND n.uid = %d AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10), 0, NULL, $account->uid); while ($node = db_fetch_object($result)) { - $output .= node_view(node_load(array('nid' => $node->nid)), 1); + $output .= node_view(node_load($node->nid), 1); } $output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); $output .= theme('xml_icon', url("blog/$account->uid/feed")); @@ -170,7 +170,7 @@ function blog_page_last() { $result = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), variable_get('default_nodes_main', 10)); while ($node = db_fetch_object($result)) { - $output .= node_view(node_load(array('nid' => $node->nid)), 1); + $output .= node_view(node_load($node->nid), 1); } $output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); $output .= theme('xml_icon', url('blog/feed')); @@ -195,7 +195,7 @@ function blog_form(&$node) { ** database and quote it in the blog: */ - if ($nid && $blog = node_load(array('nid' => $nid))) { + if ($nid && $blog = node_load($nid)) { $node->body = ''. $blog->body .' ['. l($blog->name, "node/$nid") .']'; } Index: modules/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment.module,v retrieving revision 1.356 diff -u -F^f -r1.356 comment.module --- modules/comment.module 29 Jun 2005 19:53:14 -0000 1.356 +++ modules/comment.module 1 Jul 2005 17:06:30 -0000 @@ -136,7 +136,7 @@ function comment_menu($may_cache) { } else { if (arg(0) == 'comment' && arg(1) == 'reply' && is_numeric(arg(2))) { - $node = node_load(array('nid' => arg(2))); + $node = node_load(arg(2)); if ($node->nid) { $items[] = array('path' => 'comment/reply', 'title' => t('reply to comment'), 'callback' => 'comment_reply', 'access' => node_access('view', $node), 'type' => MENU_CALLBACK); @@ -274,6 +274,7 @@ function comment_nodeapi(&$node, $op, $a case 'delete': db_query('DELETE FROM {comments} WHERE nid = %d', $node->nid); db_query('DELETE FROM {node_comment_statistics} WHERE nid = %d', $node->nid); + cache_clear_all('comment:'. $node->nid); break; case 'update index': @@ -376,7 +377,7 @@ function comment_edit($cid) { function comment_reply($nid, $pid = NULL) { // set the breadcrumb trail - $node = node_load(array('nid' => $nid)); + $node = node_load($nid); menu_set_location(array(array('path' => "node/$nid", 'title' => $node->title), array('path' => "comment/reply/$nid"))); $output = ''; @@ -514,7 +515,7 @@ function comment_preview($edit) { $output .= theme('comment_view', $comment); } else { - $output .= node_view(node_load(array('nid' => $edit['nid']))); + $output .= node_view(node_load($edit['nid'])); $edit['pid'] = 0; } @@ -544,6 +545,9 @@ function comment_post($edit) { // Allow modules to respond to the updating of a comment. module_invoke_all('comment', 'update', $edit); + // invalidate cache + cache_clear_all('comment:'. $edit['nid']); + // Add an entry to the watchdog log. watchdog('content', t('Comment: updated %subject.', array('%subject' => theme('placeholder', $edit['subject']))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $edit['nid'], NULL, NULL, 'comment-'. $edit['cid'])); } @@ -647,6 +651,9 @@ function comment_post($edit) { // Tell the other modules a new comment has been submitted. module_invoke_all('comment', 'insert', $edit); + // invalidate cache + cache_clear_all('comment:'. $edit['nid']); + // Add an entry to the watchdog log. watchdog('content', t('Comment: added %subject.', array('%subject' => theme('placeholder', $edit['subject']))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $edit['nid'], NULL, NULL, 'comment-'. $edit['cid'])); } @@ -831,6 +838,12 @@ function comment_render($node, $cid = 0) ** substring only. */ + $cache_id = 'comment:'. $node->nid; + if (!$user->uid && ($cache = cache_get($cache_id))) { + return $cache; + } + $cacheable = TRUE; + if ($order == 1) { if ($mode == 1 || $mode == 2) { $query .= ' ORDER BY c.timestamp DESC'; @@ -869,6 +882,7 @@ function comment_render($node, $cid = 0) while ($comment = db_fetch_object($result)) { $comment = drupal_unpack($comment); + $cacheable = $cacheable && filter_format_allowcache($comment->format); $comment->name = $comment->uid ? $comment->registered_name : $comment->name; $comment->depth = count(explode('.', $comment->thread)) - 1; @@ -904,6 +918,9 @@ function comment_render($node, $cid = 0) $output .= form_hidden('nid', $nid); $output .= ''; } + if (!$user->uid && $cacheable) { + cache_set($cache_id, $output, CACHE_PERMANENT); + } } // If enabled, show new comment form. @@ -1005,6 +1022,9 @@ function comment_save($id, $edit) { // Allow modules to respond to the updating of a comment. module_invoke_all('comment', 'update', $edit); + + // invalidate cache + cache_clear_all('comment:'. $edit['nid']); } /** @@ -1260,7 +1280,7 @@ function comment_moderate() { $votes[$mod->mid] = $mod->value; } - $node = node_load(array('nid' => db_result(db_query('SELECT nid FROM {comments} WHERE cid = %d', key($moderation))))); + $node = node_load(db_result(db_query('SELECT nid FROM {comments} WHERE cid = %d', key($moderation)))); if (user_access('administer comments') || comment_user_can_moderate($node)) { foreach ($moderation as $cid => $vote) { @@ -1283,6 +1303,9 @@ function comment_moderate() { db_query("UPDATE {comments} SET score = '$new_score', users = '%s' WHERE cid = %d", serialize($users), $cid); module_invoke_all('comment', 'moderate', $cid, $vote); + + // invalidate cache + cache_clear_all('comment:'. $comment->nid); } } } @@ -1616,6 +1639,7 @@ function _comment_delete_thread($comment watchdog('content', t('Comment: deleted %subject.', array('%subject' => theme('placeholder', $comment->subject)))); module_invoke_all('comment', 'delete', $comment); + cache_clear_all('comment:'. $comment->nid); // Delete the comment's replies: $result = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE pid = %d', $comment->cid); @@ -1668,7 +1692,7 @@ function _comment_update_node_statistics // comments exist if ($count > 0) { - $node = node_load(array('nid' => $nid)); + $node = node_load($nid); $last_reply = db_fetch_object(db_query_range('SELECT cid, name, timestamp, uid FROM {comments} WHERE nid = %d AND status = %d ORDER BY cid DESC', $nid, COMMENT_PUBLISHED, 0, 1)); db_query("UPDATE {node_comment_statistics} SET comment_count = %d, last_comment_timestamp = %d, last_comment_name = '%s', last_comment_uid = %d WHERE nid = %d", $count, $last_reply->timestamp, $last_reply->uid ? NULL : $last_reply->name, $last_reply->uid, $nid); } Index: modules/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node.module,v retrieving revision 1.501 diff -u -F^f -r1.501 node.module --- modules/node.module 29 Jun 2005 19:53:14 -0000 1.501 +++ modules/node.module 1 Jul 2005 17:06:32 -0000 @@ -329,9 +329,10 @@ function node_invoke_nodeapi(&$node, $op /** * Load a node object from the database. * + * @param $nid + * ID of the node to load. * @param $conditions - * An array of conditions to match against in the database query. Most calls - * will simply use array('nid' => 52). + * An additional array of conditions to match against in the database query. * @param $revision * Which numbered revision to load. Defaults to the current version. * @param $reset @@ -340,19 +341,25 @@ function node_invoke_nodeapi(&$node, $op * @return * A fully-populated node object. */ -function node_load($conditions, $revision = NULL, $reset = NULL) { +function node_load($nid = 0, $conditions = array(), $revision = NULL, $reset = NULL) { static $nodes = array(); if ($reset) { $nodes = array(); } - $cachable = (count($conditions) == 1 && isset($conditions['nid']) && $revision == NULL); - - if ($cachable && isset($nodes[$conditions['nid']])) { - return $nodes[$conditions['nid']]; + if ($nid) { + $conditions['nid'] = $nid; + $cachable = $revision == NULL; + if ($cachable && $nodes[$nid]) { + return $nodes[$nid]; + } } + if (empty($conditions)) { + return FALSE; + } + // Turn the conditions into a query. foreach ($conditions as $key => $value) { $cond[] = 'n.'. db_escape_string($key) ." = '". db_escape_string($value) ."'"; @@ -387,7 +394,7 @@ function node_load($conditions, $revisio } if ($cachable) { - $nodes[$conditions['nid']] = $node; + $nodes[$nid] = $node; } return $node; @@ -566,7 +573,7 @@ function node_search($op = 'search', $ke $find = do_search($keys, 'node', 'INNER JOIN {node} n ON n.nid = i.sid '. $join .' INNER JOIN {users} u ON n.uid = u.uid', 'n.status = 1'. (empty($where) ? '' : ' AND '. $where)); $results = array(); foreach ($find as $item) { - $node = node_load(array('nid' => $item)); + $node = node_load($item); $extra = node_invoke_nodeapi($node, 'search result'); $results[] = array('link' => url('node/'. $item), 'type' => node_invoke($node, 'node_name'), @@ -668,7 +675,7 @@ function node_menu($may_cache) { } else { if (arg(0) == 'node' && is_numeric(arg(1))) { - $node = node_load(array('nid' => arg(1))); + $node = node_load(arg(1)); if ($node->nid) { $items[] = array('path' => 'node/'. arg(1), 'title' => t('view'), 'callback' => 'node_page', @@ -969,7 +976,7 @@ function node_types_configure($type = NU */ function node_revision_overview($nid) { if (user_access('administer nodes')) { - $node = node_load(array('nid' => $nid)); + $node = node_load($nid); drupal_set_title(check_plain($node->title)); @@ -1003,7 +1010,7 @@ function node_revision_create($node) { // "Revision" is the name of the field used to indicate that we have to // create a new revision of a node. if ($node->nid && $node->revision) { - $prev = node_load(array('nid' => $node->nid)); + $prev = node_load($node->nid); $node->revisions = $prev->revisions; unset($prev->revisions); $node->revisions[] = array('uid' => $user->uid, 'timestamp' => time(), 'node' => $prev, 'history' => $node->history); @@ -1019,7 +1026,7 @@ function node_revision_rollback($nid, $r global $user; if (user_access('administer nodes')) { - $node = node_load(array('nid' => $nid)); + $node = node_load($nid); // Extract the specified revision: $rev = $node->revisions[$revision]['node']; @@ -1050,7 +1057,7 @@ function node_revision_rollback($nid, $r */ function node_revision_delete($nid, $revision) { if (user_access('administer nodes')) { - $node = node_load(array('nid' => $nid)); + $node = node_load($nid); unset($node->revisions[$revision]); @@ -1130,7 +1137,7 @@ function node_feed($nodes = 0, $channel while ($node = db_fetch_object($nodes)) { // Load the specified node: - $item = node_load(array('nid' => $node->nid)); + $item = node_load($node->nid); $link = url("node/$node->nid", NULL, NULL, 1); // Filter and prepare node teaser @@ -1431,7 +1438,7 @@ function node_add($type) { function node_edit($id) { global $user; - $node = node_load(array('nid' => $id)); + $node = node_load($id); drupal_set_title(check_plain($node->title)); @@ -1563,7 +1570,7 @@ function node_submit(&$node) { * Ask for confirmation, and delete the node. */ function node_delete($edit) { - $node = node_load(array('nid' => $edit['nid'])); + $node = node_load($edit['nid']); if (node_access('delete', $node)) { @@ -1614,7 +1621,7 @@ function node_page_default() { $output = ''; while ($node = db_fetch_object($result)) { - $output .= node_view(node_load(array('nid' => $node->nid)), 1); + $output .= node_view(node_load($node->nid), 1); } $output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); } @@ -1664,7 +1671,7 @@ function node_page() { break; case 'edit': if (is_numeric(arg(1))) { - $node = node_load(array('nid' => arg(1))); + $node = node_load(arg(1)); if ($node->nid) { drupal_set_title($node->title); return node_edit(arg(1)); @@ -1676,7 +1683,7 @@ function node_page() { break; case 'view': if (is_numeric(arg(1))) { - $node = node_load(array('nid' => arg(1)), $_GET['revision']); + $node = node_load(arg(1), $_GET['revision']); if ($node->nid) { drupal_set_title(check_plain($node->title)); return node_show($node, arg(2)); @@ -1737,7 +1744,7 @@ function node_update_index() { while ($node = db_fetch_object($result)) { $last_comment = $node->last_comment_timestamp; - $node = node_load(array('nid' => $node->nid)); + $node = node_load($node->nid); // We update this variable per node in case cron times out, or if the node // cannot be indexed (PHP nodes which call drupal_goto, for example). @@ -1985,4 +1992,4 @@ function node_db_rewrite_sql($query, $pr * @} End of "defgroup node_access". */ -?> +?> \ No newline at end of file Index: modules/poll.module =================================================================== RCS file: /cvs/drupal/drupal/modules/poll.module,v retrieving revision 1.165 diff -u -F^f -r1.165 poll.module --- modules/poll.module 27 Jun 2005 18:33:32 -0000 1.165 +++ modules/poll.module 1 Jul 2005 17:06:32 -0000 @@ -54,7 +54,7 @@ function poll_block($op = 'list', $delta $sql = db_rewrite_sql("SELECT MAX(n.created) FROM {node} n INNER JOIN {poll} p ON p.nid = n.nid WHERE n.status = 1 AND p.active = 1 AND n.moderate = 0"); $timestamp = db_result(db_query($sql)); if ($timestamp) { - $poll = node_load(array('type' => 'poll', 'created' => $timestamp, 'moderate' => 0, 'status' => 1)); + $poll = node_load(NULL, array('type' => 'poll', 'created' => $timestamp, 'moderate' => 0, 'status' => 1)); if ($poll->nid) { // poll_view() dumps the output into $poll->body. @@ -203,7 +203,7 @@ function poll_menu($may_cache) { } else { if (arg(0) == 'node' && is_numeric(arg(1))) { - $node = node_load(array('nid' => arg(1))); + $node = node_load(arg(1)); if ($node->type == 'poll' && $node->allowvotes) { $items[] = array('path' => 'node/'. arg(1) .'/results', @@ -360,7 +360,7 @@ function poll_view_results(&$node, $teas * Callback for the 'results' tab for polls you can vote on */ function poll_results() { - if ($node = node_load(array('nid' => arg(1)))) { + if ($node = node_load(arg(1))) { drupal_set_title(check_plain($node->title)); return node_show($node, 0); } @@ -374,7 +374,7 @@ function poll_results() { */ function poll_vote(&$node) { $nid = arg(2); - if ($node = node_load(array('nid' => $nid))) { + if ($node = node_load($nid)) { $edit = $_POST['edit']; $choice = $edit['choice']; $vote = $_POST['vote']; Index: modules/profile.module =================================================================== RCS file: /cvs/drupal/drupal/modules/profile.module,v retrieving revision 1.100 diff -u -F^f -r1.100 profile.module --- modules/profile.module 27 Jun 2005 18:33:32 -0000 1.100 +++ modules/profile.module 1 Jul 2005 17:06:32 -0000 @@ -215,7 +215,7 @@ function profile_load_profile(&$user) { } function profile_save_profile(&$edit, &$user, $category) { - if (($_GET['q'] == 'user/register') ? 1 : 0) { + if ($_GET['q'] == 'user/register' || $_GET['q'] == 'admin/user/create') { $result = db_query('SELECT fid, name, type FROM {profile_fields} WHERE register = 1 AND visibility != %d ORDER BY category, weight', PROFILE_HIDDEN); } else { @@ -316,7 +316,7 @@ function _profile_form_explanation($fiel function profile_form_profile($edit, $user, $category) { - if (($_GET['q'] == 'user/register') ? 1 : 0) { + if ($_GET['q'] == 'user/register' || $_GET['q'] == 'admin/user/create') { $result = db_query('SELECT * FROM {profile_fields} WHERE register = 1 ORDER BY category, weight'); } else { @@ -416,7 +416,7 @@ function _profile_map_month($month) { function profile_validate_profile($edit, $category) { - if (($_GET['q'] == 'user/register') ? 1 : 0) { + if ($_GET['q'] == 'user/register' || $_GET['q'] == 'admin/user/create') { $result = db_query('SELECT * FROM {profile_fields} WHERE register = 1 ORDER BY category, weight'); } else { @@ -432,7 +432,7 @@ function profile_validate_profile($edit, } } } - else if ($field->required && !user_access('administer users')) { + else if ($field->required) { form_set_error($field->name, t('The field %field is required.', array('%field' => theme('placeholder', $field->title)))); } } Index: modules/statistics.module =================================================================== RCS file: /cvs/drupal/drupal/modules/statistics.module,v retrieving revision 1.196 diff -u -F^f -r1.196 statistics.module --- modules/statistics.module 7 Jun 2005 18:54:37 -0000 1.196 +++ modules/statistics.module 1 Jul 2005 17:06:33 -0000 @@ -160,7 +160,7 @@ function statistics_access_log($aid) { } function statistics_node_tracker() { - if ($node = node_load(array('nid' => arg(1)))) { + if ($node = node_load(arg(1))) { $header = array( array('data' => t('Time'), 'field' => 'a.timestamp', 'sort' => 'desc'), Index: modules/taxonomy.module =================================================================== RCS file: /cvs/drupal/drupal/modules/taxonomy.module,v retrieving revision 1.209 diff -u -F^f -r1.209 taxonomy.module --- modules/taxonomy.module 27 Jun 2005 18:33:33 -0000 1.209 +++ modules/taxonomy.module 1 Jul 2005 17:06:34 -0000 @@ -1005,7 +1005,7 @@ function taxonomy_select_nodes($tids = a function taxonomy_render_nodes($result) { if (db_num_rows($result) > 0) { while ($node = db_fetch_object($result)) { - $output .= node_view(node_load(array('nid' => $node->nid)), 1); + $output .= node_view(node_load($node->nid), 1); } $output .= theme('pager', NULL, variable_get('default_nodes_main', 10), 0); } Index: modules/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user.module,v retrieving revision 1.487 diff -u -F^f -r1.487 user.module --- modules/user.module 27 Jun 2005 18:33:33 -0000 1.487 +++ modules/user.module 1 Jul 2005 17:06:35 -0000 @@ -1023,8 +1023,10 @@ function user_pass_rehash($password, $ti function user_register($edit = array()) { global $user, $base_url; - // If we are already logged on, go to the user page instead. - if ($user->uid) { + $admin = user_access('administer users'); + + // If we aren't admin but already logged on, go to the user page instead. + if (!$admin && $user->uid) { drupal_goto('user/'. $user->uid); } @@ -1033,15 +1035,15 @@ function user_register($edit = array()) if (!form_get_errors()) { $from = variable_get('site_mail', ini_get('sendmail_from')); - $pass = user_password(); + $pass = $admin ? $edit['pass'] : user_password(); // TODO: Is this necessary? Won't session_write() replicate this? unset($edit['session']); - if (array_intersect(array_keys($edit), array('uid', 'roles', 'init', 'session', 'status'))) { + if (!$admin && array_intersect(array_keys($edit), array('uid', 'roles', 'init', 'session', 'status'))) { watchdog('security', t('Detected malicious attempt to alter protected user fields.'), WATCHDOG_WARNING); drupal_goto('user/register'); } - $account = user_save('', array_merge($edit, array('pass' => $pass, 'init' => $edit['mail'], 'roles' => array(_user_authenticated_id()), 'status' => (variable_get('user_register', 1) == 1 ? 1 : 0)))); + $account = user_save('', array_merge($edit, array('pass' => $pass, 'init' => $edit['mail'], 'roles' => array('authenticated user' => _user_authenticated_id()), 'status' => $admin || variable_get('user_register', 1)))); watchdog('user', t('New user: %name %email.', array('%name' => theme('placeholder', $edit['name']), '%email' => theme('placeholder', '<'. $edit['mail'] .'>'))), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $account->uid .'/edit')); $variables = array('%username' => $edit['name'], '%site' => variable_get('site_name', 'drupal'), '%password' => $pass, '%uri' => $base_url, '%uri_brief' => substr($base_url, strlen('http://')), '%mailto' => $edit['mail'], '%date' => format_date(time()), '%login_uri' => url('user', NULL, NULL, TRUE), '%edit_uri' => url('user/'. $account->uid .'/edit', NULL, NULL, TRUE), '%login_url' => user_pass_reset_url($account)); @@ -1058,7 +1060,12 @@ function user_register($edit = array()) return form($output); } else { - if ($account->status) { + if ($admin) { + drupal_set_message(t('Created a new user account. No e-mail has been sent.')); + + drupal_goto('admin/user'); + } + else if ($account->status) { // Create new user account, no administrator approval required. $subject = _user_mail_text('welcome_subject', $variables); $body = _user_mail_text('welcome_body', $variables); @@ -1081,12 +1088,21 @@ function user_register($edit = array()) // Display the registration form. $output .= variable_get('user_registration_help', ''); $affiliates = user_auth_help_links(); - if (count($affiliates) > 0) { + if (!$admin && count($affiliates) > 0) { $affiliates = implode(', ', $affiliates); $output .= '

'. t('Note: if you have an account with one of our affiliates (%s), you may login now instead of registering.', array('%s' => $affiliates, '%login_uri' => url('user'))) .'

'; } - $default = form_textfield(t('Username'), 'name', $edit['name'], 30, 64, t('Your full name or your preferred username; only letters, numbers and spaces are allowed.'), NULL, TRUE); - $default .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 30, 64, t('A password and instructions will be sent to this e-mail address, so make sure it is accurate.'), NULL, TRUE); + if ($admin) { + $descriptions = array('name' => t('Provide the username of the new account.'), 'mail' => t('Provide the e-mail address associated with the new account.'), 'pass' => t('Provide a password for the new account.')); + } + else { + $descriptions = array('name' => t('Your full name or your preferred username; only letters, numbers and spaces are allowed.'), 'mail' => t('A password and instructions will be sent to this e-mail address, so make sure it is accurate.')); + } + $default = form_textfield(t('Username'), 'name', $edit['name'], 30, 64, $descriptions['name'], NULL, TRUE); + $default .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 30, 64, $descriptions['mail'], NULL, TRUE); + if ($admin) { + $default .= form_password(t('Password'), 'pass', $edit['pass'], 30, 55, $descriptions['pass'], NULL, TRUE); + } $extra = _user_forms($edit, $account, $category, 'register'); // Only display form_group around default fields if there are other groups. if ($extra) { @@ -1153,7 +1169,7 @@ function user_edit_validate($uid, &$edit } // Validate the user roles: - if (user_access('administer users')) { + if (user_access('administer users') && $_GET['q'] != 'admin/user/create') { if (!$edit['roles']) { form_set_error('roles', t('You must select at least one role.')); $edit['roles'] = array(); @@ -1367,34 +1383,6 @@ function user_configure_settings() { return $output; } -function user_admin_create($edit = array()) { - - if ($edit) { - // Because the admin form doesn't have roles selection they need to be set to validate properly - $edit['roles'] = array(_user_authenticated_id() => 'authenticated user'); - user_module_invoke('validate', $edit, $edit, 'account'); - - if (!form_get_errors()) { - watchdog('user', t('New user: %name %email.', array('%name' => theme('placeholder', $edit['name']), '%email' => theme('placeholder', '<'. $edit['mail'] .'>')))); - - user_save('', array('name' => $edit['name'], 'pass' => $edit['pass'], 'init' => $edit['mail'], 'mail' => $edit['mail'], 'roles' => $edit['roles'], 'status' => 1)); - - drupal_set_message(t('Created a new user account. No e-mail has been sent.')); - - drupal_goto('admin/user'); - } - } - - $output = form_textfield(t('Username'), 'name', $edit['name'], 30, 55, t('Provide the username of the new account.'), NULL, TRUE); - $output .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 30, 55, t('Provide the e-mail address associated with the new account.'), NULL, TRUE); - $output .= form_password(t('Password'), 'pass', $edit['pass'], 30, 55, t('Provide a password for the new account.'), NULL, TRUE); - $output .= form_submit(t('Create account')); - - $output = form_group(t('Create new user account'), $output); - - return form($output); -} - /** * Menu callback: check an access rule */ @@ -1755,9 +1743,9 @@ function user_admin() { case t('Search'): $output = search_form(url('admin/user/search'), $_POST['edit']['keys'], 'user') . search_data($_POST['edit']['keys'], 'user'); break; - case t('Create account'): + case t('Create new account'): case 'create': - $output = user_admin_create($edit); + $output = user_register($edit); break; default: $output = user_admin_account();