Last modified: 2013-03-10 18:10: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 T47967, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 45967 - User.php please implement User::deleteOption( $optionKey )
User.php please implement User::deleteOption( $optionKey )
Status: RESOLVED WORKSFORME
Product: MediaWiki
Classification: Unclassified
User preferences (Other open bugs)
1.21.x
All All
: Normal enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
: easy
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-03-10 17:25 UTC by T. Gries
Modified: 2013-03-10 18:10 UTC (History)
3 users (show)

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


Attachments

Description T. Gries 2013-03-10 17:25:02 UTC
tl;dr
in core please implement User::deleteOption( $key )
delete from user_property where (up_user=User) and (up_property=$key)


In my extension (OpenID) I need a method to delete all keys of $wgUser where they have key 'openid_trust'.

We already have User::setOption( $key, $value ) and User::resetOptions( $kind ); 
BUT: resetOptions is apparently not what I need, it is intended for something different (reset options to default values).

I suggest that a core developer adds a method for *deletion* of *any* entries $key of a user $user, i.e. something like

delete from user_property where (up_user=$user) and (up_property=$key)


Long version
============
 
I am unsure whether
 
$wgUser->resetOptions( 'openid_trust' ); // definition in includes/User.php
 
is intended to delete such a user_properties 'openid_trust',



When reading the documentation I feel, that resetOptions() is designed to delete properties of a certain kind, but not hook-definied properties like 'openid_trust'.
 
My current understanding is, that User:setOption() and User:resetOptions() are designed differently, and resetOptions is not the complementary action.
 
Therefore I suggest that a new function in core User:deleteOption( $key ) is necessary, which deletes all keys $key for User.
 
 
 
if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $trustedSiteToBeDeleted ) ) {
if ( $trustedSiteToBeDeleted === "*" ) {
// $this->SetUserTrustArray( $wgUser, array() );
// remove all trusted sites of that user
 
// DOES NOT WORK
$wgUser->resetOptions( 'openid_trust' );
// DOES NOT WORK

$wgUser->saveSettings();
$wgOut->addWikiMsg( 'openid-trusted-sites-delete-all-confirmation-success-text' );
} else {
$this->SetUserTrust( $wgUser, $trustedSiteToBeDeleted, NULL );
$wgUser->saveSettings();
$wgOut->addWikiMsg( 'openid-trusted-sites-delete-confirmation-success-text', $trustedSiteToBeDeleted );
Comment 1 db [inactive,noenotif] 2013-03-10 17:37:46 UTC
You can use User::setOption( 'openid_trust', null ) to set the option to the default value for this user, which results in deleting the row, when calling User::saveSettings.

User::resetOptions is to reset a group of preferences or all, not one.
Comment 2 T. Gries 2013-03-10 18:04:54 UTC
Thanks.

I am not sure, if NULL does remove the key.

See my proposed change https://gerrit.wikimedia.org/r/#/c/53042/
Comment 3 T. Gries 2013-03-10 18:10:48 UTC
ok, it works.

Because my extension-defined key openid_trust is reset to its default (unused) and then deleted.

I close the bug, and abandon the patch.

Thanks

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


Navigation
Links