Changing the name of the anonymous user in admin->config changes the value of variable "anonymous" (variable table) but does not set the name value of UID 0 in the users table. The node display routines use users.name for the value to display, as does the watchdog event log.

I suspect that now that we have a dedicated UID 0 for the anonymous user, the anonymous entry in the variable table could go away. Is there any reason why it is needed?

It would be easy enough to fix the code to store the config value for the anonymous user in both places, but duplicating it seems like a bad idea.

Comments

matt westgate’s picture

You can find some history why we don't set the anonymous info in the database here.

Chris Johnson’s picture

Yes, and that was the wrong solution.

All checks for the anonymous user should be checking for uid == 0, and not the name.

Putting a NULL in users.name for users.uid == 0 causes problems elsewhere.

Chris Johnson’s picture

Assigned: Unassigned » Chris Johnson
StatusFileSize
new8.73 KB

Suggested patch attached.

1. Refactor common.inc::format_name() to only format the name and do nothing else.

2. Add theme hook theme.inc::theme_format_name() to allow formatting of author name by theme, e.g. if theme needs to shorten long names or theme designer wants to otherwise modify them.

3. Modify system.module::system_view_general() and system_settings_save() to use the {users} table name value for the anonymous user instead of a value in the {variables} table.

4. Create update_78() to set the name field in {users} to the current Anonymous users name for uid 0.

5. Modify database/database.*sql to correctly create the initial {users} table entry for the anonymous user.

gábor hojtsy’s picture

I agree with Chris. Since we have a database row for UID 0, we can store the username there. The setting change is a bit hackish though... And SQL code is written with all uppercase keywords and all lowercase column names thoughout Drupal... This patch does not conform to this style.

Chris Johnson’s picture

Yeah, the setting method is kind of ugly because the system module assumes[1] that all system settings will of course only ever be in the {variable} table.

One alternative I thought about was moving the setting of the anonymous user name to some other place where a hack would not be required, but there did not seem to be a better logical place for such a global setting.

I am open to suggestions on how to better set the anonymous name in the {users} table.

As for the SQL -- that's obviously a 5 second fix.

[1] we have an expression in the U.S. that plays with the word "assume" to create a phrase to remind people not to make assumptions, as they are nearly always wrong.

gábor hojtsy’s picture

I always expected it to be at /admin/system/modules/user, since it is a user setting :) That does not make much difference in coding, since this is also handled with vaiarble storage, but still it seems to be more logical IMHO.

Chris Johnson’s picture

StatusFileSize
new14.01 KB

New patch attached.

1. Refactor common.inc::format_name() to only format the name and do nothing else.

2. Add theme hook theme.inc::theme_format_name() to allow formatting of author name by theme, e.g. if theme needs to shorten long names or theme designer wants to otherwise modify them.

3. Remove setting of anonymous user name in the {variable} table in the system module.

4. Create update_79() to set the name field in {users} to the current Anonymous users name for uid 0.

5. Modify database/database.*sql to correctly create the initial {users} table entry for the anonymous user.

6. Add link to admin/user/edit/0 in both admin/config (legacy location) and admin/config/modules/user (per Goba's suggestion).

7. Fix user.module to prevent deletion of uid 0.

8. Modify user.module to present only those form items which it is sane to change for uid 0.

Over all goal: remove variable "anonymous" and instead use the users table entry for anonymous for the displayed name, to make it less confusing and cleaner.

dries’s picture

This patch does no longer apply but looks good otherwise. Changing its status to 'active'.

robin monks’s picture

Assigned: Chris Johnson » robin monks

I'm going to try to revive this old patch. I'm sure some of this has alreay been accomplished in other patches, but it's well worth a looksy.

Robin

robin monks’s picture

As far as I can see in my tests, the system has been /almost/ completly weened off of variable_get("anonymous", "Anonymous") in favor of $user->name. The remaining uses of this variable seem to be justified as "last resort" uses and the replacement of those is outside the scope of the bug (should they need to be replaced et al).

Robin

Anonymous’s picture