Last modified: 2013-03-23 09:38:33 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.
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.
(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.
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.
I don't want to check whether that user is logged-in (this can be done checking against $wgUser.)
$user = User::newFromId( 1234 ); $user->loadFromDatabase();
(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
so, as no function will apparently added to core, I am in the mood of closing...
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 ...)