? 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 .= ''; } - $form['masquerade_desc'] = array( - '#prefix' => '
', - '#markup' => $markup_value, - '#suffix' => '
', - ); + if ($markup_value) { + $form['masquerade_desc'] = array( + '#prefix' => '
', + '#markup' => $markup_value, + '#suffix' => '
', + ); + } return $form; } @@ -740,17 +733,17 @@ function masquerade_switch_user($uid) { ':uid_to' => $new_user->uid, )); if (!user_access($perm) && !isset($_SESSION['masquerading']) && !$results->fetchColumn()) { - watchdog('masquerade', 'This user requires administrative permissions to switch to the user %user.', array('%user' => $new_user->name), WATCHDOG_ERROR); + watchdog('masquerade', 'This user requires administrative permissions to switch to the user %user.', array('%user' => format_username($new_user)), WATCHDOG_ERROR); return FALSE; } if ($user->uid == $uid || isset($user->masquerading)) { - watchdog('masquerade', 'This user is already %user.', array('%user' => $new_user->name), WATCHDOG_ERROR); + watchdog('masquerade', 'This user is already %user.', array('%user' => format_username($new_user)), WATCHDOG_ERROR); return FALSE; } if (variable_get('site_offline', 0) && !user_access('administer site configuration', $new_user)) { - drupal_set_message(t('It is not possible to masquerade in off-line mode as %user does not have the %config-perm permission. Please set the site status to "online" to masquerade as %user.', array('%user' => $new_user->name, '%config-perm' => 'administer site configuration', '@site-maintenance' => url('admin/settings/site-maintenance')))); + drupal_set_message(t('It is not possible to masquerade in off-line mode as %user does not have the %config-perm permission. Please set the site status to "online" to masquerade as %user.', array('%user' => format_username($new_user), '%config-perm' => 'administer site configuration', '@site-maintenance' => url('admin/settings/site-maintenance')))); return FALSE; } @@ -763,7 +756,7 @@ function masquerade_switch_user($uid) { $query->execute(); // switch user - watchdog('masquerade', 'User %user now masquerading as %masq_as.', array('%user' => $user->name, '%masq_as' => $new_user->name ? $new_user->name : variable_get('anonymous', t('Anonymous'))), WATCHDOG_INFO); + watchdog('masquerade', 'User %user now masquerading as %masq_as.', array('%user' => format_username($user), '%masq_as' => format_username($new_user)), WATCHDOG_INFO); drupal_set_message(t('You are now masquerading as !masq_as.', array('!masq_as' => theme('username', array('account' => $new_user))))); $user->masquerading = $new_user->uid; $user = $new_user; @@ -805,7 +798,7 @@ function masquerade_switch_back() { $query = db_delete('masquerade'); $query->condition($conditions); $query->execute(); - $oldname = ($user->uid == 0 ? variable_get('anonymous', t('Anonymous')) : $user->name); + $oldname = format_username($user); $user = user_load($uid); - watchdog('masquerade', 'User %user no longer masquerading as %masq_as.', array('%user' => $user->name, '%masq_as' => $oldname), WATCHDOG_INFO); + watchdog('masquerade', 'User %user no longer masquerading as %masq_as.', array('%user' => format_username($user), '%masq_as' => $oldname), WATCHDOG_INFO); }