Debian Codegraph @

extensions/Echo/includes/Api/ApiEchoMarkSeen.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\Notifications\Api;
4
5 // This is a GET module, not a POST module, for multi-DC support. See T222851.
6 // Note that this module doesn't write to the database, only to the seentime cache.
7 use MediaWiki\Api\ApiBase;
8 use MediaWiki\Extension\Notifications\SeenTime;
9 use Wikimedia\ParamValidator\ParamValidator;
10
11 class ApiEchoMarkSeen extends ApiBase {
12 use ApiEchoPermissionsTrait;
13
14 public function execute() {
15 $this->checkReadNotificationsPermissions();
16
17 // To avoid API warning, register the parameter used to bust browser cache
18 $this->getMain()->getVal( '_' );
19
20 $params = $this->extractRequestParams();
21 $timestamp = wfTimestamp( TS_MW );
22 $seenTime = SeenTime::newFromUser( $this->getUser() );
23 $seenTime->setTime( $timestamp, $params['type'] );
24
25 if ( $params['timestampFormat'] === 'ISO_8601' ) {
26 $outputTimestamp = wfTimestamp( TS_ISO_8601, $timestamp );
27 } else {
28 // MW
29 $this->addDeprecation(
30 'apiwarn-echo-deprecation-timestampformat',
31 'action=echomarkseen&timestampFormat=MW'
32 );
33
34 $outputTimestamp = $timestamp;
35 }
36
37 $this->getResult()->addValue( 'query', $this->getModuleName(), [
38 'result' => 'success',
39 'timestamp' => $outputTimestamp,
40 ] );
41 }
42
43 public function getAllowedParams() {
44 return [
45 'type' => [
46 ParamValidator::PARAM_REQUIRED => true,
47 ParamValidator::PARAM_TYPE => [ 'alert', 'message', 'all' ],
48 ],
49 'timestampFormat' => [
50 // Not using the TS constants, since clients can't.
51 ParamValidator::PARAM_DEFAULT => 'MW',
52 ParamValidator::PARAM_TYPE => [ 'ISO_8601', 'MW' ],
53 ],
54 ];
55 }
56
57 /**
58 * @see ApiBase::getExamplesMessages()
59 * @return string[]
60 */
61 protected function getExamplesMessages() {
62 return [
63 'action=echomarkseen&type=all' => 'apihelp-echomarkseen-example-1',
64 ];
65 }
66
67 public function getHelpUrls() {
68 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Echo_(Notifications)/API';
69 }
70 }