Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.948
diff -u -r1.948 user.module
--- modules/user/user.module	20 Dec 2008 18:24:41 -0000	1.948
+++ modules/user/user.module	23 Dec 2008 00:31:57 -0000
@@ -674,7 +674,7 @@
 function user_user_form(&$edit, &$account, $category = NULL) {
   if ($category == 'account') {
     $form_state = array();
-    return user_edit_form($form_state, arg(1), $edit);
+    return user_edit_form($form_state, (isset($account->uid) ? $account->uid : FALSE), $edit);
   }
 }
 
@@ -683,7 +683,7 @@
  */
 function user_user_validate(&$edit, &$account, $category = NULL) {
   if ($category == 'account') {
-    return _user_edit_validate(arg(1), $edit);
+    return _user_edit_validate($account, $edit);
   }
 }
 
@@ -692,7 +692,7 @@
  */
 function user_user_submit(&$edit, &$account, $category = NULL) {
   if ($category == 'account') {
-    return _user_edit_submit(arg(1), $edit);
+    return _user_edit_submit($account, $edit);
   }
 }
 
@@ -1458,7 +1458,8 @@
     '#title' => t('Account information'),
     '#weight' => -10,
   );
-  if (user_access('change own username') || $admin || $register) {
+  // Only show name field when: registration page; or user is editing own account and can change username; or an admin user.
+  if ($register || ($GLOBALS['user']->uid == $uid && user_access('change own username')) || $admin) {
     $form['account']['name'] = array('#type' => 'textfield',
       '#title' => t('Username'),
       '#default_value' => $edit['name'],
@@ -1559,10 +1560,10 @@
   return $form;
 }
 
-function _user_edit_validate($uid, &$edit) {
-  $user = user_load(array('uid' => $uid));
-  // Validate the username:
-  if (user_access('change own username') || user_access('administer users') || !$user->uid) {
+function _user_edit_validate($account, &$edit) {
+  $uid = isset($account->uid) ? $account->uid : FALSE;
+  // Validate the username when: new user account; or user is editing own account and can change username; or an admin user.
+  if (!$uid || ($GLOBALS['user']->uid == $uid && user_access('change own username')) || user_access('administer users')) {
     if ($error = user_validate_name($edit['name'])) {
       form_set_error('name', $error);
     }
@@ -1580,12 +1581,11 @@
   }
 }
 
-function _user_edit_submit($uid, &$edit) {
-  $user = user_load(array('uid' => $uid));
+function _user_edit_submit($account, &$edit) {
   // Delete picture if requested, and if no replacement picture was given.
   if (!empty($edit['picture_delete'])) {
-    if ($user->picture && file_exists($user->picture)) {
-      file_unmanaged_delete($user->picture);
+    if ($account->picture && file_exists($account->picture)) {
+      file_unmanaged_delete($account->picture);
     }
     $edit['picture'] = '';
   }
