Add meta=userinfo&uiprop=latestcontrib
authorMax Semenik <maxsem.wiki@gmail.com>
Sat, 23 Mar 2019 00:54:02 +0000 (17:54 -0700)
committerMax Semenik <maxsem.wiki@gmail.com>
Sat, 23 Mar 2019 00:54:02 +0000 (17:54 -0700)
Returns the timestamp of user's latest contribution.

Bug: T208636
Change-Id: I73b20c61b9a46d308b406315fac05e5972d3009e

RELEASE-NOTES-1.33
includes/api/ApiQueryUserInfo.php
includes/api/i18n/en.json
includes/api/i18n/qqq.json

index 93d3253..9dabb83 100644 (file)
@@ -156,6 +156,8 @@ For notes on 1.32.x and older releases, see HISTORY.
   if entirewatchlist is set, so updates may not be visible immediately
 * Block info will be added to "blocked" errors from more modules.
 * (T216245) Autoblocks will now be spread by action=edit and action=move.
+* action=query&meta=userinfo has a new uiprop, 'latestcontrib', that returns
+  the date of user's latest contribution.
 
 === Action API internal changes in 1.33 ===
 * A number of deprecated methods for API documentation, intended for overriding
index a38d877..729ab23 100644 (file)
@@ -251,6 +251,13 @@ class ApiQueryUserInfo extends ApiQueryBase {
                        );
                }
 
+               if ( isset( $this->prop['latestcontrib'] ) ) {
+                       $ts = $this->getLatestContributionTime();
+                       if ( $ts !== null ) {
+                               $vals['latestcontrib'] = $ts;
+                       }
+               }
+
                return $vals;
        }
 
@@ -293,6 +300,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 +356,7 @@ class ApiQueryUserInfo extends ApiQueryBase {
                                        'unreadcount',
                                        'centralids',
                                        'preferencestoken',
+                                       'latestcontrib',
                                ],
                                ApiBase::PARAM_HELP_MSG_PER_VALUE => [
                                        'unreadcount' => [
index f5cdddb..0d4874c 100644 (file)
        "apihelp-query+userinfo-paramvalue-prop-registrationdate": "Adds the user's registration date.",
        "apihelp-query+userinfo-paramvalue-prop-unreadcount": "Adds the count of unread pages on the user's watchlist (maximum $1; returns <samp>$2</samp> if more).",
        "apihelp-query+userinfo-paramvalue-prop-centralids": "Adds the central IDs and attachment status for the user.",
+       "apihelp-query+userinfo-paramvalue-prop-latestcontrib": "Adds the date of user's latest contribution.",
        "apihelp-query+userinfo-param-attachedwiki": "With <kbd>$1prop=centralids</kbd>, indicate whether the user is attached with the wiki identified by this ID.",
        "apihelp-query+userinfo-example-simple": "Get information about the current user.",
        "apihelp-query+userinfo-example-data": "Get additional information about the current user.",
index 9abcfe2..0b5eb39 100644 (file)
        "apihelp-query+userinfo-paramvalue-prop-registrationdate": "{{doc-apihelp-paramvalue|query+userinfo|prop|registrationdate}}",
        "apihelp-query+userinfo-paramvalue-prop-unreadcount": "{{doc-apihelp-paramvalue|query+userinfo|prop|unreadcount|params=* $1 - Maximum value for the \"unreadcount\" property.\n* $2 - Return value when there are more unread pages.|paramstart=3}}",
        "apihelp-query+userinfo-paramvalue-prop-centralids": "{{doc-apihelp-paramvalue|query+userinfo|prop|centralids}}",
+       "apihelp-query+userinfo-paramvalue-prop-latestcontrib": "{{doc-apihelp-paramvalue|query+userinfo|prop|latestcontrib}}",
        "apihelp-query+userinfo-param-attachedwiki": "{{doc-apihelp-param|query+userinfo|attachedwiki}}",
        "apihelp-query+userinfo-example-simple": "{{doc-apihelp-example|query+userinfo}}",
        "apihelp-query+userinfo-example-data": "{{doc-apihelp-example|query+userinfo}}",