? 1007052-masq-block-info.patch ? 822098-masq-username.patch Index: masquerade.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/masquerade/masquerade.module,v retrieving revision 1.42 diff -u -p -r1.42 masquerade.module --- masquerade.module 24 Dec 2010 13:38:41 -0000 1.42 +++ masquerade.module 25 Dec 2010 09:54:14 -0000 @@ -88,10 +88,10 @@ function masquerade_menu() { $items = array(); $default_test_user = _masquerade_user_load(variable_get('masquerade_test_user', '')); - if ($default_test_user && ($default_test_user->uid || $default_test_user->name == variable_get('anonymous', t('Anonymous')))) { + if (isset($default_test_user->uid)) { $items['masquerade/switch/' . $default_test_user->uid] = array( 'title' => 'Masquerade as @testuser', - 'title arguments' => array('@testuser' => $default_test_user->name), + 'title arguments' => array('@testuser' => format_username($default_test_user)), 'page callback' => 'masquerade_switch_user_page', 'page arguments' => array(2), 'access callback' => 'masquerade_menu_access', @@ -338,7 +338,7 @@ function masquerade_user_logout($account global $user; cache_clear_all($user->uid, 'cache_menu', TRUE); $real_user = user_load($user->masquerading); - watchdog('masquerade', "User %user no longer masquerading as %masq_as.", array('%user' => $real_user->name, '%masq_as' => $user->name), WATCHDOG_INFO); + watchdog('masquerade', "User %user no longer masquerading as %masq_as.", array('%user' => format_username($real_user), '%masq_as' => format_username($user)), WATCHDOG_INFO); $query = db_delete('masquerade'); $query->condition('sid', session_id()); @@ -361,7 +361,7 @@ function masquerade_user_view($account, if (user_access($perm) && empty($account->masquerading) && $user->uid != $account->uid) { $account->content['masquerade'] = array( - '#markup' => l(t('Masquerade as !user', array('!user' => $account->name)), 'masquerade/switch/' . $account->uid, array('query' => array('token' => drupal_get_token('masquerade/switch/' . $account->uid)), 'destination' => $_GET['q'], 'attributes' => array('class' => 'masquerade-switch'))), + '#markup' => l(t('Masquerade as !user', array('!user' => format_username($account))), 'masquerade/switch/' . $account->uid, array('query' => array('token' => drupal_get_token('masquerade/switch/' . $account->uid)), 'destination' => $_GET['q'], 'attributes' => array('class' => 'masquerade-switch'))), '#weight' => 10, ); } @@ -508,39 +508,30 @@ function masquerade_block_1() { global $user; $quick_switch_links = array(); $markup_value = ''; - if (isset($_SESSION['masquerading'])) { + if (isset($_SESSION) && isset($_SESSION['masquerading'])) { $quick_switch_links[] = l(t('Switch back'), 'masquerade/unswitch', array('query' => array('token' => drupal_get_token('masquerade/unswitch')))); if ($user->uid > 0) { - $markup_value = t('You are masquerading as %masq_as.', array('@user-url' => url('user/' . $user->uid), '%masq_as' => $user->name)); + $markup_value = t('You are masquerading as %masq_as.', array('@user-url' => url('user/' . $user->uid), '%masq_as' => format_username($user))); } else { - $markup_value = t('You are masquerading as %anonymous.', array('%anonymous' => variable_get('anonymous', t('Anonymous')))); + $markup_value = t('You are masquerading as %anonymous.', array('%anonymous' => format_username($user))); } } else { - $masquerade_switches = variable_get('masquerade_quick_switches', array()); - - // Add in user-specific switches. - $results = db_query("SELECT uid_to FROM {masquerade_users} WHERE uid_from = :uid_from", array(':uid_from' => $user->uid)); - while ($uid_to = $results->fetchColumn()) { - // Avoid dupes if an account has been added to quick switches and {masquerade_users}. - if (!in_array($uid_to, $masquerade_switches)) { - $masquerade_switches[] = $uid_to; - } - } - - foreach ($masquerade_switches as $switch_user) { - if (!isset($_SESSION['user']->uid) || $switch_user != $_SESSION['user']->uid) { - $user_name = user_load($switch_user); - $switch_link = 'masquerade/switch/' . $user_name->uid; - if ($user_name->uid) { - $quick_switch_links[] = l($user_name->name, $switch_link, array('query' => array('token' => drupal_get_token($switch_link)))); - } - if ($switch_user == 0) { - $user_name->name = variable_get('anonymous', t('Anonymous')); - $quick_switch_links[] = l($user_name->name, $switch_link, array('query' => array('token' => drupal_get_token($switch_link)))); - } - } + // Get user-specific switches. + $user_switches = db_query("SELECT uid_to FROM {masquerade_users} WHERE uid_from = :uid_from", array( + ':uid_from' => $user->uid, + ))->fetchCol(); + // Avoid dupes if an account has been added to quick switches and {masquerade_users}. + $user_switches = array_unique(array_merge(variable_get('masquerade_quick_switches', array()), $user_switches)); + // Exclude yourself from the list. + $user_switches = array_diff($user_switches, array($user->uid)); + + $users = user_load_multiple($user_switches); + foreach ($users as $uid => $account) { + $switch_link = 'masquerade/switch/' . $uid; + $switch_name = format_username($account); + $quick_switch_links[] = l($switch_name, $switch_link, array('query' => array('token' => drupal_get_token($switch_link)))); } if (masquerade_menu_access('autocomplete')) { @@ -564,11 +555,13 @@ function masquerade_block_1() { if ($quick_switch_links) { $markup_value .= '