2015-04-29 12:08:30 +00:00
|
|
|
<?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->dieUsage( 'Login is required', 'login-required' );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
$this->setWarning( 'The MW timestamp output format is deprecated' .
|
|
|
|
' here. In the future, ISO 8601 will always be used for ' .
|
|
|
|
'the output timestamp format. Adjust your client and ' .
|
|
|
|
'set timestampFormat to \'ISO_8601\'.' );
|
|
|
|
|
|
|
|
$outputTimestamp = $timestamp;
|
|
|
|
}
|
|
|
|
|
2015-04-29 12:08:30 +00:00
|
|
|
$this->getResult()->addValue( 'query', $this->getModuleName(), array(
|
|
|
|
'result' => 'success',
|
2016-07-20 22:20:59 +00:00
|
|
|
'timestamp' => $outputTimestamp,
|
2015-04-29 12:08:30 +00:00
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAllowedParams() {
|
|
|
|
return array(
|
|
|
|
'token' => array(
|
|
|
|
ApiBase::PARAM_REQUIRED => true,
|
|
|
|
),
|
2015-09-03 01:11:10 +00:00
|
|
|
'type' => array(
|
|
|
|
ApiBase::PARAM_REQUIRED => true,
|
|
|
|
ApiBase::PARAM_TYPE => array( 'alert', 'message', 'all' ),
|
2016-07-20 22:20:59 +00:00
|
|
|
),
|
|
|
|
'timestampFormat' => array(
|
|
|
|
// Not using the TS constants, since clients can't.
|
|
|
|
ApiBase::PARAM_DFLT => 'MW',
|
|
|
|
ApiBase::PARAM_TYPE => array( 'ISO_8601', 'MW' ),
|
|
|
|
),
|
2015-04-29 12:08:30 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function needsToken() {
|
|
|
|
return 'csrf';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTokenSalt() {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function mustBePosted() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isWriteMode() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see ApiBase::getExamplesMessages()
|
|
|
|
*/
|
|
|
|
protected function getExamplesMessages() {
|
|
|
|
return array(
|
2015-09-03 01:11:10 +00:00
|
|
|
'action=echomarkseen&type=all' => 'apihelp-echomarkseen-example-1',
|
2015-04-29 12:08:30 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getHelpUrls() {
|
|
|
|
return 'https://www.mediawiki.org/wiki/Echo_(Notifications)/API';
|
|
|
|
}
|
|
|
|
}
|