Page MenuHomePhabricator

Need hook to allow user object to be modified before it is saved to the database
Open, LowPublicFeature

Description

In 1.16, when the preferences form is submitted, there doesn't seem to be any way to modify the user object before it is saved to the database. When the preference form is submitted it calls Preferences->tryFormSubmit which in turn calls User->saveSettings. There are two hooks that fire after the user object has been saved (UserSaveSettings and UserSaveOptions) but that doesn't help.

You used to be able to use the SavePreferences hook but it's gone in 1.16.


Version: 1.16.x
Severity: enhancement
URL: http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/Preferences.php?view=markup

Details

Reference
bz24944

Event Timeline

bzimport raised the priority of this task from to Low.Nov 21 2014, 11:07 PM
bzimport set Reference to bz24944.

Modifying the user member variables before they are saved to the database. Without a hook, you can't do any sort of validation, modification, etc. Say I want to examine the user's name and auto-update their email address based on that or auto create a signature for the user. Or generate a nickname based on their real name. The only field you can validate right now is the email address which has a dedicated hook.

The UserSaveOptions hook fulfills this functionality.

Nope it doesn't. Like I said in the original description, the UserSaveOptions hook is fired after the user object is saved and only allows you to modify user preferences. You can't for example change the user email address before the user object is saved.

That's not true at all. UserSaveOptions is fired before the options are saved on User.php:4397. Furthermore, the User object itself is passed as one of the parameters, so you can change the email address if you want as well.

You are wrong sir. The user object in the DB is updated on User.php:3080, then saveOptions() is called on User.php:3098 which in turn fires the UserSaveOptions hook. The email address, password, username, etc are already set and saved by the time the options hook fires.

You can modify the user object that is passed into the UserSaveOptions hook but then you will have to save it again yourself manually which doesn't make any sense since it's just been saved by the call to saveSettings().

The old SavePreferences hook used to fire before the user object was saved which allowed you to do things like automatically set a user's email address when you were using a SSO or PKI third party plugin to automatically log your users in. Perhaps there is some way to do this still that I'm overlooking but the UserSaveOptions hook is not it.

Aklapper subscribed.

@Parent5446: Hi, I'm resetting the task assignee due to inactivity. Please feel free to reclaim this task if you plan to work on this - it would be welcome! Also see https://www.mediawiki.org/wiki/Bug_management/Assignee_cleanup for more information - thanks!

Aklapper changed the subtype of this task from "Task" to "Feature Request".Feb 4 2022, 11:00 AM