Index: masquerade.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/masquerade/masquerade.module,v
retrieving revision 1.16.2.28
diff -u -r1.16.2.28 masquerade.module
--- masquerade.module   10 Sep 2009 20:58:21 -0000   1.16.2.28
+++ masquerade.module   21 Oct 2009 04:14:56 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: masquerade.module,v 1.16.2.28 2009/09/10 20:58:21 deviantintegral Exp $
+// $Id: masquerade.module,v 1.16.2.29 2009/10/02 15:56:53 deviantintegral Exp $
 
 /**
  * @file masquerade.module
@@ -63,10 +63,10 @@
   $items = array();
 
   $default_test_user = _masquerade_test_user();
-  if ($default_test_user->uid) {
+  if ($default_test_user->uid || $default_test_user->name == variable_get('anonymous', t('Anonymous'))) {
     $items['masquerade/switch/' . $default_test_user->uid] = array(
       'title' => 'Masquerade as @testuser',
-     'title arguments' => array('@testuser' => $default_test_user->name),
+      'title arguments' => array('@testuser' => $default_test_user->name),
       'page callback' => 'masquerade_switch_user',
       'page arguments' => array(2),
        'access callback' => 'masquerade_access',
@@ -187,6 +187,9 @@
   $quick_switch_users = array();
   foreach ((variable_get('masquerade_quick_switches', array())) as $uid) {
     $u = user_load(array('uid' => $uid));
+    if( $uid == 0 ) {
+         $u->name = variable_get('anonymous', t('Anonymous'));
+      }
     $quick_switch_users[] = $u->name;
   }
   $form['masquerade_quick_switches'] = array(
@@ -207,7 +210,8 @@
 
 function masquerade_admin_settings_validate($form, &$form_state) {
   unset($form);
-  $test_user = user_load(array('name' => $form_state['values']['masquerade_test_user']));
+
+  $test_user = _masquerade_user_load($form_state['values']['masquerade_test_user']);
   if (!$test_user) {
     form_set_error('masquerade_test_user', t('%user does not exist. Please enter a valid username.', array('%user' => $form_state['values']['masquerade_test_user'])));
   }
@@ -215,7 +219,7 @@
   // A comma-separated list of users.
   $masquerade_switches = drupal_explode_tags($form_state['values']['masquerade_quick_switches']);
   foreach ($masquerade_switches as $switch_user) {
-    $test_user = user_load(array('name' => $switch_user));
+    $test_user = _masquerade_user_load($switch_user);
     if (!$test_user) {
       form_set_error('masquerade_quick_switches', t('%user does not exist. Please enter a valid username.', array('%user' => $switch_user)));
     }
@@ -227,7 +231,7 @@
   $masquerade_switches = drupal_explode_tags($form_state['values']['masquerade_quick_switches']);
   $masquerade_uids = array();
   foreach ($masquerade_switches as $masquerade_name) {
-    $u = user_load(array('name' => $masquerade_name));
+    $u = _masquerade_user_load($masquerade_name);
     $masquerade_uids[] = $u->uid;
   }
   variable_set('masquerade_quick_switches', $masquerade_uids);
@@ -241,12 +245,29 @@
 }
 
 function _masquerade_test_user() {
-  $test_user->uid = 0;
-  $test_user->name = '';
-
-  $test_user = user_load(array('name' => variable_get('masquerade_test_user', $test_user->name)));
+  $user = _masquerade_user_load(variable_get('masquerade_test_user', ''));
+  return $user;
+}
 
-  return $test_user;
+/**
+ * Load users to accomodate for the anonymous 'user'
+ */
+function _masquerade_user_load($username) {
+  if ($username == '') {
+      return true;
+   }
+  else {
+     $user = '';
+     $anon = variable_get('anonymous', t('Anonymous'));
+     if ($username == $anon) {
+       $user = user_load(array('name' => ''));
+         $user->name = $anon;
+      }
+    else {
+       $user = user_load(array('name' => $username));
+      }
+     return $user;
+   }
 }
 
 /**
@@ -387,9 +414,10 @@
     foreach ($masquerade_switches as $switch_user) {
       if ($switch_user != $_SESSION['user']->uid) {
         $user_name = user_load(array('uid' => $switch_user));
-        if ($user_name->uid) {
-          $quick_switch_link[] = l($user_name->name, 'masquerade/switch/'. $user_name->uid);
-        }
+        if( $switch_user == 0 ) {
+               $user_name->name = variable_get('anonymous', t('Anonymous'));
+            }
+        $quick_switch_link[] = l($user_name->name, 'masquerade/switch/'. $user_name->uid);
       }
     }
 
@@ -469,7 +497,7 @@
 /**
  * Returns JS array for Masquerade autocomplete fields.
  */
-function masquerade_autocomplete($string) {
+function d($string) {
   $matches = array();
   $result = db_query_range("SELECT u.name FROM {users} u WHERE LOWER(u.name) LIKE LOWER('%s%%')", $string, 0, 10);
   while ($user = db_fetch_object($result)) {
@@ -502,6 +530,10 @@
   while ($user = db_fetch_object($result)) {
     $matches[$prefix . $user->name] = check_plain($user->name);
   }
+  //This will add anonymous to the list, but not sorted
+  if (stripos(variable_get('anonymous', t('Anonymous')), $last_string) === 0) {
+    $matches[$prefix . variable_get('anonymous', t('Anonymous'))] = variable_get('anonymous', t('Anonymous'));
+  }
   if (module_exists('alt_login')) {
     $result = db_query_range("SELECT alt_login FROM {alt_login} u WHERE LOWER(alt_login) LIKE LOWER('%s%%')", $string, 0, 10);
     while ($user = db_fetch_object($result)) {
@@ -594,4 +626,4 @@
   watchdog('masquerade', 'User %user no longer masquerading as %masq_as.', array('%user' => $user->name, '%masq_as' => $oldname), WATCHDOG_INFO);
   drupal_set_message(t('You are no longer masquerading as %masq_as and are now logged in as %user.', array('%user' => $user->name, '%masq_as' => $oldname)));
   drupal_goto(referer_uri());
-}
+}
\ No newline at end of file

Success, CVS operation completed