mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-25 00:05:29 +00:00
de536d09d9
Specify which notification types allow notifying the event agent in $wgEchoNotifications, and stop specifying it in the event_extra data. Putting 'notifyAgent' => true in event_extra will still work, but is discouraged. Change-Id: I4f558654ec23757dd4ecd6986eb3e9a5593f5386
113 lines
2.9 KiB
PHP
113 lines
2.9 KiB
PHP
<?php
|
|
|
|
class ApiEchoArticleReminder extends ApiBase {
|
|
|
|
public function execute() {
|
|
$this->getMain()->setCacheMode( 'private' );
|
|
$user = $this->getUser();
|
|
if ( $user->isAnon() ) {
|
|
$this->dieWithError( 'apierror-mustbeloggedin-generic', 'login-required' );
|
|
}
|
|
|
|
$params = $this->extractRequestParams();
|
|
$result = [];
|
|
$userTimestamp = new MWTimestamp( $params['timestamp'] );
|
|
$nowTimestamp = new MWTimestamp();
|
|
// We need $params['timestamp'] to be a future timestamp:
|
|
// $userTimestamp < $nowTimestamp = invert 0
|
|
// $userTimestamp > $nowTimestamp = invert 1
|
|
if ( $userTimestamp->diff( $nowTimestamp )->invert === 0 ) {
|
|
$this->dieWithError( [ 'apierror-badparameter', 'timestamp' ], 'timestamp-not-in-future', null, 400 );
|
|
}
|
|
|
|
$eventCreation = EchoEvent::create( [
|
|
'type' => 'article-reminder',
|
|
'agent' => $user,
|
|
'title' => $this->getTitleFromTitleOrPageId( $params ),
|
|
'extra' => [
|
|
'comment' => $params['comment'],
|
|
],
|
|
] );
|
|
|
|
if ( !$eventCreation ) {
|
|
$this->dieWithError( 'apierror-echo-event-creation-failed', null, null, 500 );
|
|
}
|
|
|
|
/* Temp - removing the delay just for now:
|
|
$job = new JobSpecification(
|
|
'articleReminder',
|
|
[
|
|
'userId' => $user->getId(),
|
|
'timestamp' => $params['timestamp'],
|
|
'comment' => $params['comment'],
|
|
],
|
|
[ 'removeDuplicates' => true ],
|
|
Title::newFromID( $params['pageid'] )
|
|
);
|
|
JobQueueGroup::singleton()->push( $job );*/
|
|
$result += [
|
|
'result' => 'success'
|
|
];
|
|
$this->getResult()->addValue( 'query', $this->getModuleName(), $result );
|
|
}
|
|
|
|
public function getAllowedParams() {
|
|
return [
|
|
'pageid' => [
|
|
ApiBase::PARAM_TYPE => 'integer',
|
|
],
|
|
'title' => [
|
|
ApiBase::PARAM_TYPE => 'string',
|
|
],
|
|
'comment' => [
|
|
ApiBase::PARAM_TYPE => 'string',
|
|
],
|
|
'timestamp' => [
|
|
ApiBase::PARAM_REQUIRED => true,
|
|
ApiBase::PARAM_TYPE => 'timestamp',
|
|
],
|
|
'token' => [
|
|
ApiBase::PARAM_REQUIRED => true,
|
|
],
|
|
];
|
|
}
|
|
|
|
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() {
|
|
$todayDate = new DateTime();
|
|
$oneDay = new DateInterval( 'P1D' );
|
|
$tomorrowDate = $todayDate->add( $oneDay );
|
|
$tomorrowDateTimestamp = new MWTimestamp( $tomorrowDate );
|
|
$tomorrowTimestampStr = $tomorrowDateTimestamp->getTimestamp( TS_ISO_8601 );
|
|
return [
|
|
"action=echoarticlereminder&pageid=1×tamp=$tomorrowTimestampStr&comment=example"
|
|
=> 'apihelp-echoarticlereminder-example-1',
|
|
"action=echoarticlereminder&title=Main_Page×tamp=$tomorrowTimestampStr"
|
|
=> 'apihelp-echoarticlereminder-example-2',
|
|
];
|
|
}
|
|
|
|
public function getHelpUrls() {
|
|
return 'https://www.mediawiki.org/wiki/Echo_(Notifications)/API';
|
|
}
|
|
}
|