Merge "Follow-up 8697ba8: No need for two dependencies on the same module"
[lhc/web/wiklou.git] / includes / api / ApiQueryUserInfo.php
index ba7280d..28dea3b 100644 (file)
@@ -34,7 +34,9 @@ class ApiQueryUserInfo extends ApiQueryBase {
 
        const WL_UNREAD_LIMIT = 1000;
 
+       /** @var array */
        private $params = [];
+       /** @var array */
        private $prop = [];
 
        public function __construct( ApiQuery $query, $moduleName ) {
@@ -159,8 +161,7 @@ class ApiQueryUserInfo extends ApiQueryBase {
                }
 
                if ( isset( $this->prop['rights'] ) ) {
-                       // User::getRights() may return duplicate values, strip them
-                       $vals['rights'] = array_values( array_unique( $user->getRights() ) );
+                       $vals['rights'] = $this->getPermissionManager()->getUserPermissions( $user );
                        ApiResult::setArrayType( $vals['rights'], 'array' ); // even if empty
                        ApiResult::setIndexedTagName( $vals['rights'], 'r' ); // even if empty
                }
@@ -180,7 +181,7 @@ class ApiQueryUserInfo extends ApiQueryBase {
 
                if ( isset( $this->prop['preferencestoken'] ) &&
                        !$this->lacksSameOriginSecurity() &&
-                       $user->isAllowed( 'editmyoptions' )
+                       $this->getPermissionManager()->userHasRight( $user, 'editmyoptions' )
                ) {
                        $vals['preferencestoken'] = $user->getEditToken( '', $this->getMain()->getRequest() );
                }
@@ -201,7 +202,8 @@ class ApiQueryUserInfo extends ApiQueryBase {
                        $vals['realname'] = $user->getRealName();
                }
 
-               if ( $user->isAllowed( 'viewmyprivateinfo' ) && isset( $this->prop['email'] ) ) {
+               if ( $this->getPermissionManager()->userHasRight( $user, 'viewmyprivateinfo' ) &&
+                               isset( $this->prop['email'] ) ) {
                        $vals['email'] = $user->getEmail();
                        $auth = $user->getEmailAuthenticationTimestamp();
                        if ( $auth !== null ) {
@@ -301,32 +303,17 @@ class ApiQueryUserInfo extends ApiQueryBase {
         * @return string|null ISO 8601 timestamp of current user's last contribution or null if none
         */
        protected function getLatestContributionTime() {
-               global $wgActorTableSchemaMigrationStage;
-
                $user = $this->getUser();
                $dbr = $this->getDB();
 
-               if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_READ_NEW ) {
-                       if ( $user->getActorId() === null ) {
-                               return null;
-                       }
-                       $res = $dbr->selectField( 'revision_actor_temp',
-                               'MAX(revactor_timestamp)',
-                               [ 'revactor_actor' => $user->getActorId() ],
-                               __METHOD__
-                       );
-               } else {
-                       if ( $user->isLoggedIn() ) {
-                               $conds = [ 'rev_user' => $user->getId() ];
-                       } else {
-                               $conds = [ 'rev_user_text' => $user->getName() ];
-                       }
-                       $res = $dbr->selectField( 'revision',
-                               'MAX(rev_timestamp)',
-                               $conds,
-                               __METHOD__
-                       );
+               if ( $user->getActorId() === null ) {
+                       return null;
                }
+               $res = $dbr->selectField( 'revision_actor_temp',
+                       'MAX(revactor_timestamp)',
+                       [ 'revactor_actor' => $user->getActorId() ],
+                       __METHOD__
+               );
 
                return $res ? wfTimestamp( TS_ISO_8601, $res ) : null;
        }