From 76eb53053e83c71b930dca321398c9f13369762e Mon Sep 17 00:00:00 2001 From: Marius Hoch Date: Fri, 9 Nov 2012 22:23:14 +0100 Subject: [PATCH] Minor fixes to User and ApiQueryUsers I've fixed several PHP notices and the problem that rights returned by User::getRights() might have duplicates if altered by a hook (same for User::getEffectiveGroups). Change-Id: Id92af387d8c09414076bac40e83052cd6f913f42 --- includes/User.php | 10 ++++++---- includes/api/ApiQueryUsers.php | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/includes/User.php b/includes/User.php index f02cc29812..0aa613afca 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1102,10 +1102,10 @@ class User { } if ( is_array( $data ) ) { - if ( is_array( $data['user_groups'] ) ) { + if ( isset( $data['user_groups'] ) && is_array( $data['user_groups'] ) ) { $this->mGroups = $data['user_groups']; } - if ( is_array( $data['user_properties'] ) ) { + if ( isset( $data['user_properties'] ) && is_array( $data['user_properties'] ) ) { $this->loadOptions( $data['user_properties'] ); } } @@ -2357,7 +2357,7 @@ class User { $this->mRights = self::getGroupPermissions( $this->getEffectiveGroups() ); wfRunHooks( 'UserGetRights', array( $this, &$this->mRights ) ); // Force reindexation of rights when a hook has unset one of them - $this->mRights = array_values( $this->mRights ); + $this->mRights = array_values( array_unique( $this->mRights ) ); } return $this->mRights; } @@ -2389,6 +2389,8 @@ class User { ) ); # Hook for additional groups wfRunHooks( 'UserEffectiveGroups', array( &$this, &$this->mEffectiveGroups ) ); + // Force reindexation of groups when a hook has unset one of them + $this->mEffectiveGroups = array_values( array_unique( $this->mEffectiveGroups ) ); wfProfileOut( __METHOD__ ); } return $this->mEffectiveGroups; @@ -3979,7 +3981,7 @@ class User { // Pull from a slave to be less cruel to servers // Accuracy isn't the point anyway here $dbr = wfGetDB( DB_SLAVE ); - $count = $dbr->selectField( + $count = (int) $dbr->selectField( 'revision', 'COUNT(rev_user)', array( 'rev_user' => $this->getId() ), diff --git a/includes/api/ApiQueryUsers.php b/includes/api/ApiQueryUsers.php index 1cf8e31cfa..591ace93e1 100644 --- a/includes/api/ApiQueryUsers.php +++ b/includes/api/ApiQueryUsers.php @@ -138,7 +138,7 @@ class ApiQueryUsers extends ApiQueryBase { if ( !isset( $userGroups ) ) { $user = User::newFromRow( $row ); } else { - if ( !is_array( $userGroups[$row->user_name] ) ) { + if ( !isset( $userGroups[$row->user_name] ) || !is_array( $userGroups[$row->user_name] ) ) { $userGroups[$row->user_name] = array(); } $user = User::newFromRow( $row, array( 'user_groups' => $userGroups[$row->user_name] ) ); -- 2.20.1