2015-04-29 12:08:30 +00:00
|
|
|
<?php
|
|
|
|
|
2020-01-11 00:12:18 +00:00
|
|
|
// This is a GET module, not a POST module, for multi-DC support. See T222851.
|
|
|
|
// Note that this module doesn't write to the database, only to the seentime cache.
|
2015-04-29 12:08:30 +00:00
|
|
|
class ApiEchoMarkSeen extends ApiBase {
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
// To avoid API warning, register the parameter used to bust browser cache
|
|
|
|
$this->getMain()->getVal( '_' );
|
|
|
|
|
|
|
|
$user = $this->getUser();
|
2020-12-22 15:36:58 +00:00
|
|
|
if ( !$user->isRegistered() ) {
|
2016-11-03 19:16:56 +00:00
|
|
|
$this->dieWithError( 'apierror-mustbeloggedin-generic', 'login-required' );
|
2015-04-29 12:08:30 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 01:11:10 +00:00
|
|
|
$params = $this->extractRequestParams();
|
2015-04-29 12:08:30 +00:00
|
|
|
$timestamp = wfTimestamp( TS_MW );
|
2015-08-24 23:43:38 +00:00
|
|
|
$seenTime = EchoSeenTime::newFromUser( $user );
|
2015-09-03 01:11:10 +00:00
|
|
|
$seenTime->setTime( $timestamp, $params['type'] );
|
2015-04-29 12:08:30 +00:00
|
|
|
|
2016-07-20 22:20:59 +00:00
|
|
|
if ( $params['timestampFormat'] === 'ISO_8601' ) {
|
|
|
|
$outputTimestamp = wfTimestamp( TS_ISO_8601, $timestamp );
|
|
|
|
} else {
|
|
|
|
// MW
|
2020-06-27 10:05:03 +00:00
|
|
|
$this->addDeprecation(
|
|
|
|
'apiwarn-echo-deprecation-timestampformat',
|
|
|
|
'action=echomarkseen×tampFormat=MW'
|
|
|
|
);
|
2016-07-20 22:20:59 +00:00
|
|
|
|
|
|
|
$outputTimestamp = $timestamp;
|
|
|
|
}
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$this->getResult()->addValue( 'query', $this->getModuleName(), [
|
2015-04-29 12:08:30 +00:00
|
|
|
'result' => 'success',
|
2016-07-20 22:20:59 +00:00
|
|
|
'timestamp' => $outputTimestamp,
|
2016-12-05 18:51:07 +00:00
|
|
|
] );
|
2015-04-29 12:08:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getAllowedParams() {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
|
|
|
'type' => [
|
2015-09-03 01:11:10 +00:00
|
|
|
ApiBase::PARAM_REQUIRED => true,
|
2016-12-05 18:51:07 +00:00
|
|
|
ApiBase::PARAM_TYPE => [ 'alert', 'message', 'all' ],
|
|
|
|
],
|
|
|
|
'timestampFormat' => [
|
2016-07-20 22:20:59 +00:00
|
|
|
// Not using the TS constants, since clients can't.
|
|
|
|
ApiBase::PARAM_DFLT => 'MW',
|
2016-12-05 18:51:07 +00:00
|
|
|
ApiBase::PARAM_TYPE => [ 'ISO_8601', 'MW' ],
|
|
|
|
],
|
|
|
|
];
|
2015-04-29 12:08:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see ApiBase::getExamplesMessages()
|
2018-08-13 07:25:22 +00:00
|
|
|
* @return string[]
|
2015-04-29 12:08:30 +00:00
|
|
|
*/
|
|
|
|
protected function getExamplesMessages() {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
2015-09-03 01:11:10 +00:00
|
|
|
'action=echomarkseen&type=all' => 'apihelp-echomarkseen-example-1',
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2015-04-29 12:08:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getHelpUrls() {
|
2019-08-27 06:13:35 +00:00
|
|
|
return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Echo_(Notifications)/API';
|
2015-04-29 12:08:30 +00:00
|
|
|
}
|
|
|
|
}
|