Last modified: 2013-07-25 09:02:57 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T26944, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 24944 - Need hook to allow user object to be modified before it is saved to the database
Need hook to allow user object to be modified before it is saved to the database
Status: PATCH_TO_REVIEW
Product: MediaWiki
Classification: Unclassified
User preferences (Other open bugs)
1.16.x
All All
: Low enhancement (vote)
: ---
Assigned To: Tyler Romeo
http://svn.wikimedia.org/viewvc/media...
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-08-26 15:03 UTC by Christian Neubauer
Modified: 2013-07-25 09:02 UTC (History)
3 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Christian Neubauer 2010-08-26 15:03:07 UTC
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.
Comment 1 Andrew Garrett 2010-08-26 16:46:09 UTC
What's the use case?
Comment 2 Christian Neubauer 2010-08-26 23:34:15 UTC
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.
Comment 3 Tyler Romeo 2012-10-09 03:30:33 UTC
https://gerrit.wikimedia.org/r/27266
Comment 4 Christian Neubauer 2012-10-09 14:25:57 UTC
Wooohooo!!! My hero!
Comment 5 Tyler Romeo 2013-03-17 19:18:12 UTC
The UserSaveOptions hook fulfills this functionality.
Comment 6 Christian Neubauer 2013-03-19 12:48:56 UTC
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.
Comment 7 Tyler Romeo 2013-03-19 21:27:43 UTC
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.
Comment 8 Christian Neubauer 2013-03-21 12:35:46 UTC
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.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links