From c7408f22535dde206b17b0cd711f3676aa66eb2b Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Fri, 22 Mar 2019 17:54:02 -0700 Subject: [PATCH] Add meta=userinfo&uiprop=latestcontrib Returns the timestamp of user's latest contribution. Bug: T208636 Change-Id: I73b20c61b9a46d308b406315fac05e5972d3009e --- RELEASE-NOTES-1.33 | 2 ++ includes/api/ApiQueryUserInfo.php | 42 +++++++++++++++++++++++++++++++ includes/api/i18n/en.json | 1 + includes/api/i18n/qqq.json | 1 + 4 files changed, 46 insertions(+) diff --git a/RELEASE-NOTES-1.33 b/RELEASE-NOTES-1.33 index 93d3253762..9dabb83d4f 100644 --- a/RELEASE-NOTES-1.33 +++ b/RELEASE-NOTES-1.33 @@ -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 diff --git a/includes/api/ApiQueryUserInfo.php b/includes/api/ApiQueryUserInfo.php index a38d877d99..729ab231db 100644 --- a/includes/api/ApiQueryUserInfo.php +++ b/includes/api/ApiQueryUserInfo.php @@ -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' => [ diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index f5cdddbb09..0d4874c81b 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -1318,6 +1318,7 @@ "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 $2 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 $1prop=centralids, 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.", diff --git a/includes/api/i18n/qqq.json b/includes/api/i18n/qqq.json index 9abcfe24fd..0b5eb399c7 100644 --- a/includes/api/i18n/qqq.json +++ b/includes/api/i18n/qqq.json @@ -1233,6 +1233,7 @@ "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}}", -- 2.20.1