mediawiki-extensions-Echo/includes/api/ApiEchoMarkSeen.php
Thiemo Kreuz c1c3c7b672 Make "@… array" type hints more specific
There are about 200 of such generic "array" type hints in this code base,
the majority in @param tags. I started with what I found most relevant:
@var and @return tags. I might continue working on this later, but
wanted to stop for now to keep this patch moderately small.

Change-Id: Iff0d9590a794ae0f885466ef6bb336b0b42a6cd3
2018-08-13 09:27:37 +02:00

81 lines
1.8 KiB
PHP

<?php
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();
if ( $user->isAnon() ) {
$this->dieWithError( 'apierror-mustbeloggedin-generic', 'login-required' );
}
$params = $this->extractRequestParams();
$timestamp = wfTimestamp( TS_MW );
$seenTime = EchoSeenTime::newFromUser( $user );
$seenTime->setTime( $timestamp, $params['type'] );
if ( $params['timestampFormat'] === 'ISO_8601' ) {
$outputTimestamp = wfTimestamp( TS_ISO_8601, $timestamp );
} else {
// MW
$this->addDeprecation( 'apiwarn-echo-deprecation-timestampformat', 'action=echomarkseen&timestampFormat=MW' );
$outputTimestamp = $timestamp;
}
$this->getResult()->addValue( 'query', $this->getModuleName(), [
'result' => 'success',
'timestamp' => $outputTimestamp,
] );
}
public function getAllowedParams() {
return [
'token' => [
ApiBase::PARAM_REQUIRED => true,
],
'type' => [
ApiBase::PARAM_REQUIRED => true,
ApiBase::PARAM_TYPE => [ 'alert', 'message', 'all' ],
],
'timestampFormat' => [
// Not using the TS constants, since clients can't.
ApiBase::PARAM_DFLT => 'MW',
ApiBase::PARAM_TYPE => [ 'ISO_8601', 'MW' ],
],
];
}
public function needsToken() {
return 'csrf';
}
public function getTokenSalt() {
return '';
}
public function mustBePosted() {
return true;
}
public function isWriteMode() {
return true;
}
/**
* @see ApiBase::getExamplesMessages()
* @return string[]
*/
protected function getExamplesMessages() {
return [
'action=echomarkseen&type=all' => 'apihelp-echomarkseen-example-1',
];
}
public function getHelpUrls() {
return 'https://www.mediawiki.org/wiki/Echo_(Notifications)/API';
}
}