Last modified: 2013-03-23 09:38:33 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 T48255, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 46255 - User.php : please add a public function isUser( $user ) to check whether arbitrary(!) $user object is a user i.e. has account
User.php : please add a public function isUser( $user ) to check whether arbi...
Status: RESOLVED WORKSFORME
Product: MediaWiki
Classification: Unclassified
General/Unknown (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-18 09:42 UTC by T. Gries
Modified: 2013-03-23 09:38 UTC (History)
3 users (show)

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


Attachments

Description T. Gries 2013-03-18 09:42:05 UTC
I was surprised, that User.php has no public function to quickly check whether an arbitrary $user object is a user (with acccount).

After asking around, I implemented such a function locally in E:OpenID where that is needed:

private static function isUser( $user ) {
  return ( $user ) ? $user->loadFromId() : false;
}

but suggest you core developers add a proper function to the core.


see
https://gerrit.wikimedia.org/r/gitweb?p=mediawiki/extensions/OpenID.git;a=commit;h=HEAD

If you are of a distinct opinion, or have a better idea, pls. let me know, or even close the bug. I just wanted to mention, that core lacks such a function, which can be of general use elsewhere.
Comment 1 db [inactive,noenotif] 2013-03-19 18:39:24 UTC
Try to use
$user && $user->isLoggedIn()
or
$user && !$user->isAnon()
to detect, if the user object is a valid account

loadFromId assumed that you have set a id on the object.
Comment 2 T. Gries 2013-03-19 19:12:24 UTC
(In reply to comment #1)
> Try to use
> $user && $user->isLoggedIn()
> or
> $user && !$user->isAnon()
> to detect, if the user object is a valid account
> 
> loadFromId assumed that you have set a id on the object.

Exactly this is the case, because the incoming OpenID Identifier has an id (SpecialOpenIDIdentifier/id) from which a user object is created newFromID(i).

I do *not* want to test whether this is the or an logged-in user, but only, if there is an account with that id.
Comment 3 db [inactive,noenotif] 2013-03-21 20:27:59 UTC
That is done with isLoggedIn

The method name is misleading, you does not check, if the user behind the object is currently logged in the wiki. You only check, if there is a account.
Comment 4 T. Gries 2013-03-21 20:30:26 UTC
I don't want to check whether that user is logged-in (this can be done checking against $wgUser.)
Comment 5 Chad H. 2013-03-21 20:36:45 UTC
$user = User::newFromId( 1234 );
$user->loadFromDatabase();
Comment 6 T. Gries 2013-03-21 20:58:28 UTC
(In reply to comment #5)
> $user = User::newFromId( 1234 );
> $user->loadFromDatabase();

I do this

private static function isUser( $user ) {
  return ( $user ) ? $user->loadFromId() : false;
}

is is okay ?


https://gerrit.wikimedia.org/r/gitweb?p=mediawiki/extensions/OpenID.git;a=blob;f=SpecialOpenIDIdentifier.body.php;h=d8270c4c4e63602fc3a00124feff3aa923ea1498;hb=ae494618ee890a8fe7f77cc2f5951f1157a6d8ba#l46
Comment 7 T. Gries 2013-03-21 20:59:48 UTC
so, as no function will apparently added to core, I am in the mood of closing...
Comment 8 db [inactive,noenotif] 2013-03-23 09:38:33 UTC
isLoggedIn does your job, but the way you have it also possible

isLoggedin is calling getId which is calling loadFromId, so this is doing the same thing than your idea.

Calling isLoggedIn on $wgUser would check, if the visiting user has a registered account (yes, when he has a account, but not logged in, this will also give false ...)

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


Navigation
Links