Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiEchoMarkSeen
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 4
42
0.00% covered (danger)
0.00%
0 / 1
 execute
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
12
 getAllowedParams
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 getExamplesMessages
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 getHelpUrls
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace 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.
7use ApiBase;
8use MediaWiki\Extension\Notifications\SeenTime;
9use Wikimedia\ParamValidator\ParamValidator;
10
11class ApiEchoMarkSeen extends ApiBase {
12
13    public function execute() {
14        // To avoid API warning, register the parameter used to bust browser cache
15        $this->getMain()->getVal( '_' );
16
17        $user = $this->getUser();
18        if ( !$user->isRegistered() ) {
19            $this->dieWithError( 'apierror-mustbeloggedin-generic', 'login-required' );
20        }
21
22        $params = $this->extractRequestParams();
23        $timestamp = wfTimestamp( TS_MW );
24        $seenTime = SeenTime::newFromUser( $user );
25        $seenTime->setTime( $timestamp, $params['type'] );
26
27        if ( $params['timestampFormat'] === 'ISO_8601' ) {
28            $outputTimestamp = wfTimestamp( TS_ISO_8601, $timestamp );
29        } else {
30            // MW
31            $this->addDeprecation(
32                'apiwarn-echo-deprecation-timestampformat',
33                'action=echomarkseen&timestampFormat=MW'
34            );
35
36            $outputTimestamp = $timestamp;
37        }
38
39        $this->getResult()->addValue( 'query', $this->getModuleName(), [
40            'result' => 'success',
41            'timestamp' => $outputTimestamp,
42        ] );
43    }
44
45    public function getAllowedParams() {
46        return [
47            'type' => [
48                ParamValidator::PARAM_REQUIRED => true,
49                ParamValidator::PARAM_TYPE => [ 'alert', 'message', 'all' ],
50            ],
51            'timestampFormat' => [
52                // Not using the TS constants, since clients can't.
53                ParamValidator::PARAM_DEFAULT => 'MW',
54                ParamValidator::PARAM_TYPE => [ 'ISO_8601', 'MW' ],
55            ],
56        ];
57    }
58
59    /**
60     * @see ApiBase::getExamplesMessages()
61     * @return string[]
62     */
63    protected function getExamplesMessages() {
64        return [
65            'action=echomarkseen&type=all' => 'apihelp-echomarkseen-example-1',
66        ];
67    }
68
69    public function getHelpUrls() {
70        return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Echo_(Notifications)/API';
71    }
72}