Merge "resourceloader: Omit non-existent messages in MessageBlobStore"
[lhc/web/wiklou.git] / includes / api / ApiQueryUserInfo.php
index 44e2703..59e0524 100644 (file)
@@ -67,8 +67,8 @@ class ApiQueryUserInfo extends ApiQueryBase {
                $vals['blockid'] = $block->getId();
                $vals['blockedby'] = $block->getByName();
                $vals['blockedbyid'] = $block->getBy();
-               $vals['blockreason'] = $block->mReason;
-               $vals['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $block->mTimestamp );
+               $vals['blockreason'] = $block->getReason();
+               $vals['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $block->getTimestamp() );
                $vals['blockexpiry'] = ApiResult::formatExpiry( $block->getExpiry(), 'infinite' );
                $vals['blockpartial'] = !$block->isSitewide();
                if ( $block->getSystemBlockType() !== null ) {
@@ -119,7 +119,7 @@ class ApiQueryUserInfo extends ApiQueryBase {
        protected function getCurrentUserInfo() {
                $user = $this->getUser();
                $vals = [];
-               $vals['id'] = intval( $user->getId() );
+               $vals['id'] = (int)$user->getId();
                $vals['name'] = $user->getName();
 
                if ( $user->isAnon() ) {
@@ -189,7 +189,7 @@ class ApiQueryUserInfo extends ApiQueryBase {
                if ( isset( $this->prop['editcount'] ) ) {
                        // use intval to prevent null if a non-logged-in user calls
                        // api.php?format=jsonfm&action=query&meta=userinfo&uiprop=editcount
-                       $vals['editcount'] = intval( $user->getEditCount() );
+                       $vals['editcount'] = (int)$user->getEditCount();
                }
 
                if ( isset( $this->prop['ratelimits'] ) ) {
@@ -202,13 +202,11 @@ class ApiQueryUserInfo extends ApiQueryBase {
                        $vals['realname'] = $user->getRealName();
                }
 
-               if ( $user->isAllowed( 'viewmyprivateinfo' ) ) {
-                       if ( isset( $this->prop['email'] ) ) {
-                               $vals['email'] = $user->getEmail();
-                               $auth = $user->getEmailAuthenticationTimestamp();
-                               if ( !is_null( $auth ) ) {
-                                       $vals['emailauthenticated'] = wfTimestamp( TS_ISO_8601, $auth );
-                               }
+               if ( $user->isAllowed( 'viewmyprivateinfo' ) && isset( $this->prop['email'] ) ) {
+                       $vals['email'] = $user->getEmail();
+                       $auth = $user->getEmailAuthenticationTimestamp();
+                       if ( $auth !== null ) {
+                               $vals['emailauthenticated'] = wfTimestamp( TS_ISO_8601, $auth );
                        }
                }
 
@@ -251,6 +249,13 @@ class ApiQueryUserInfo extends ApiQueryBase {
                        );
                }
 
+               if ( isset( $this->prop['latestcontrib'] ) ) {
+                       $ts = $this->getLatestContributionTime();
+                       if ( $ts !== null ) {
+                               $vals['latestcontrib'] = $ts;
+                       }
+               }
+
                return $vals;
        }
 
@@ -284,8 +289,8 @@ class ApiQueryUserInfo extends ApiQueryBase {
                foreach ( $this->getConfig()->get( 'RateLimits' ) as $action => $limits ) {
                        foreach ( $categories as $cat ) {
                                if ( isset( $limits[$cat] ) && !is_null( $limits[$cat] ) ) {
-                                       $retval[$action][$cat]['hits'] = intval( $limits[$cat][0] );
-                                       $retval[$action][$cat]['seconds'] = intval( $limits[$cat][1] );
+                                       $retval[$action][$cat]['hits'] = (int)$limits[$cat][0];
+                                       $retval[$action][$cat]['seconds'] = (int)$limits[$cat][1];
                                }
                        }
                }
@@ -293,6 +298,40 @@ class ApiQueryUserInfo extends ApiQueryBase {
                return $retval;
        }
 
+       /**
+        * @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__
+                       );
+               }
+
+               return $res ? wfTimestamp( TS_ISO_8601, $res ) : null;
+       }
+
        public function getAllowedParams() {
                return [
                        'prop' => [
@@ -315,6 +354,7 @@ class ApiQueryUserInfo extends ApiQueryBase {
                                        'unreadcount',
                                        'centralids',
                                        'preferencestoken',
+                                       'latestcontrib',
                                ],
                                ApiBase::PARAM_HELP_MSG_PER_VALUE => [
                                        'unreadcount' => [