Last modified: 2012-11-03 18:18:48 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 T39963, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 37963 - Calling User::getOption after User::setOption will return null instead of default values for an option if it isn't set
Calling User::getOption after User::setOption will return null instead of def...
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
User preferences (Other open bugs)
1.20.x
All All
: Unprioritized normal (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-06-26 11:40 UTC by Daniel A. R. Werner
Modified: 2012-11-03 18:18 UTC (History)
3 users (show)

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


Attachments

Description Daniel A. R. Werner 2012-06-26 11:40:32 UTC
Assuming the following:
 $user = new User;
 $user->setOption( 'someoption' );
 $user->getOption( 'someotheroption' );

the getOption will return null even though it is set in default options. When calling
 $user->getOption( 'someotheroption' );
 $user->setOption( 'someoption' );
instead, it will work perfectly fine.

This is because User::getOption() will check whether User::mOptions is set to null and in this case get the default options. It is not null anymore after setOption() though.
Therefore, the default options should be loaded in the constructor I guess. Might be that this is more expensive though. There could be a more complex solution to this, perhaps checking in setOption() whether options are null and then setting some internal member to check against in getOption()
Comment 1 Tyler Romeo 2012-08-02 20:57:47 UTC
Actually, both getOption() and setOption() call loadOptions(), which should be loading the default options into the object. However, it seems that loadOptions() refuses to work with anonymous users, which means the default options end up not getting loaded.

The only reason the second testcase (where you get and then set) even works is because getOption() has an additional check. The confusion here is because getOption() has an additional check (the if statement you see) that loads the default options.

I've prepared a fix for this and it is currently in review on Gerrit here: https://gerrit.wikimedia.org/r/17464

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


Navigation
Links