Last modified: 2013-03-10 18:10:48 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 );
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.
Thanks. I am not sure, if NULL does remove the key. See my proposed change https://gerrit.wikimedia.org/r/#/c/53042/
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