mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-27 17:20:40 +00:00
Split the Echo API into their own write/read APIs
Change-Id: I0ab85c91c6fbe17e9a1c7dc9e504980f629a5065
This commit is contained in:
parent
b8d504e307
commit
2b57fbd3c2
5
Echo.php
5
Echo.php
|
@ -90,6 +90,8 @@ $wgJobClasses['MWEchoNotificationEmailBundleJob'] = 'MWEchoNotificationEmailBund
|
|||
// API
|
||||
$wgAutoloadClasses['ApiEchoNotifications'] = $dir . 'api/ApiEchoNotifications.php';
|
||||
$wgAPIMetaModules['notifications'] = 'ApiEchoNotifications';
|
||||
$wgAutoloadClasses['ApiEchoMarkRead'] = $dir . 'api/ApiEchoMarkRead.php';
|
||||
$wgAPIModules['echomarkread'] = 'ApiEchoMarkRead';
|
||||
|
||||
// Special page
|
||||
$wgAutoloadClasses['SpecialNotifications'] = $dir . 'special/SpecialNotifications.php';
|
||||
|
@ -145,7 +147,8 @@ $wgResourceModules += array(
|
|||
'dependencies' => array(
|
||||
'jquery.ui.button',
|
||||
'mediawiki.api',
|
||||
'mediawiki.Uri'
|
||||
'mediawiki.Uri',
|
||||
'mediawiki.user'
|
||||
),
|
||||
'messages' => array(
|
||||
'cancel',
|
||||
|
|
93
api/ApiEchoMarkRead.php
Normal file
93
api/ApiEchoMarkRead.php
Normal file
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
class ApiEchoMarkRead extends ApiBase {
|
||||
|
||||
public function __construct( $query, $moduleName ) {
|
||||
parent::__construct( $query, $moduleName );
|
||||
}
|
||||
|
||||
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' );
|
||||
}
|
||||
|
||||
$notifUser = MWEchoNotifUser::newFromUser( $user );
|
||||
|
||||
$params = $this->extractRequestParams();
|
||||
|
||||
// There is no need to trigger markRead if all notifications are read
|
||||
if ( $notifUser->getNotificationCount() > 0 ) {
|
||||
if ( count( $params['list'] ) ) {
|
||||
// Make sure there is a limit to the update
|
||||
$notifUser->markRead( array_slice( $params['list'], 0, ApiBase::LIMIT_SML2 ) );
|
||||
} elseif ( $params['all'] ) {
|
||||
$notifUser->markAllRead();
|
||||
}
|
||||
}
|
||||
|
||||
$result = array( 'result' => 'success', 'count' => $notifUser->getFormattedNotificationCount() );
|
||||
$this->getResult()->addValue( 'query', $this->getModuleName(), $result );
|
||||
}
|
||||
|
||||
public function getAllowedParams() {
|
||||
return array(
|
||||
'list' => array(
|
||||
ApiBase::PARAM_ISMULTI => true,
|
||||
),
|
||||
'all' => array(
|
||||
ApiBase::PARAM_REQUIRED => false,
|
||||
ApiBase::PARAM_TYPE => 'boolean'
|
||||
),
|
||||
'token' => array(
|
||||
ApiBase::PARAM_REQUIRED => true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function getParamDescription() {
|
||||
return array(
|
||||
'list' => 'A list of notification IDs to mark as read',
|
||||
'all' => "If set to true, marks all of a user's notifications as read",
|
||||
'token' => 'edit token',
|
||||
);
|
||||
}
|
||||
|
||||
public function needsToken() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getTokenSalt() {
|
||||
return '';
|
||||
}
|
||||
|
||||
public function mustBePosted() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isWriteMode() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getDescription() {
|
||||
return 'Mark notifications as read for the current user';
|
||||
}
|
||||
|
||||
public function getExamples() {
|
||||
return array(
|
||||
'api.php?action=echomarkread&list=8',
|
||||
'api.php?action=echomarkread&all=true'
|
||||
);
|
||||
}
|
||||
|
||||
public function getHelpUrls() {
|
||||
return 'https://www.mediawiki.org/wiki/Echo_(notifications)/API';
|
||||
}
|
||||
|
||||
public function getVersion() {
|
||||
return __CLASS__ . '-0.1';
|
||||
}
|
||||
}
|
|
@ -18,6 +18,11 @@ class ApiEchoNotifications extends ApiQueryBase {
|
|||
|
||||
$params = $this->extractRequestParams();
|
||||
|
||||
// @Todo - markread/markallread has been migrated to a separate new API module,
|
||||
// any related code in this API should be removed in a follow-up patch so that
|
||||
// anything integrated with markread will have time to switch to the new markread
|
||||
// API, also to give client js code enough time to refresh
|
||||
//
|
||||
// There is no need to trigger markRead if all notifications are read
|
||||
if ( $notifUser->getNotificationCount() > 0 ) {
|
||||
if ( count( $params['markread'] ) ) {
|
||||
|
@ -178,10 +183,12 @@ class ApiEchoNotifications extends ApiQueryBase {
|
|||
),
|
||||
'markread' => array(
|
||||
ApiBase::PARAM_ISMULTI => true,
|
||||
ApiBase::PARAM_DEPRECATED => true,
|
||||
),
|
||||
'markallread' => array(
|
||||
ApiBase::PARAM_REQUIRED => false,
|
||||
ApiBase::PARAM_TYPE => 'boolean'
|
||||
ApiBase::PARAM_TYPE => 'boolean',
|
||||
ApiBase::PARAM_DEPRECATED => true,
|
||||
),
|
||||
'format' => array(
|
||||
ApiBase::PARAM_TYPE => array(
|
||||
|
|
|
@ -140,13 +140,12 @@
|
|||
.click( function ( e ) {
|
||||
e.preventDefault();
|
||||
api.post( {
|
||||
'action' : 'query',
|
||||
'meta' : 'notifications',
|
||||
'notmarkallread' : true,
|
||||
'notprop' : 'count'
|
||||
'action' : 'echomarkread',
|
||||
'all' : true,
|
||||
'token': mw.user.tokens.get( 'editToken' )
|
||||
} ).done( function ( result ) {
|
||||
if ( result.query.notifications.count !== undefined ) {
|
||||
count = result.query.notifications.count;
|
||||
if ( result.query.echomarkread.count !== undefined ) {
|
||||
count = result.query.echomarkread.count;
|
||||
mw.echo.overlay.updateCount( count );
|
||||
// Reset header to 'Notifications'
|
||||
$( '#mw-echo-overlay-title-text').msg( 'echo-overlay-title' );
|
||||
|
@ -241,13 +240,12 @@
|
|||
// only need to mark as read if there is unread item
|
||||
if ( unread.length > 0 ) {
|
||||
api.post( {
|
||||
'action' : 'query',
|
||||
'meta' : 'notifications',
|
||||
'notmarkread' : unread.join( '|' ),
|
||||
'notprop' : 'count'
|
||||
'action' : 'echomarkread',
|
||||
'list' : unread.join( '|' ),
|
||||
'token': mw.user.tokens.get( 'editToken' )
|
||||
} ).done( function ( result ) {
|
||||
if ( result.query.notifications.count !== undefined ) {
|
||||
count = result.query.notifications.count;
|
||||
if ( result.query.echomarkread.count !== undefined ) {
|
||||
count = result.query.echomarkread.count;
|
||||
mw.echo.overlay.updateCount( count );
|
||||
}
|
||||
} );
|
||||
|
|
|
@ -131,16 +131,15 @@
|
|||
var api = new mw.Api(), that = this;
|
||||
|
||||
api.post( {
|
||||
'action' : 'query',
|
||||
'meta' : 'notifications',
|
||||
'notmarkread' : unread.join( '|' ),
|
||||
'notprop' : 'count'
|
||||
'action' : 'echomarkread',
|
||||
'list' : unread.join( '|' ),
|
||||
'token': mw.user.tokens.get( 'editToken' )
|
||||
} ).done( function ( result ) {
|
||||
// update the badge if the link is enabled
|
||||
if ( result.query.notifications.count !== undefined &&
|
||||
if ( result.query.echomarkread.count !== undefined &&
|
||||
$( '#pt-notifications').length && typeof mw.echo.overlay === 'object'
|
||||
) {
|
||||
mw.echo.overlay.updateCount( result.query.notifications.count );
|
||||
mw.echo.overlay.updateCount( result.query.echomarkread.count );
|
||||
}
|
||||
that.onSuccess();
|
||||
} ).fail( function () {
|
||||
|
|
Loading…
Reference in a new issue